2023-04-07 15:28:30 +02:00
|
|
|
#include "battery.h"
|
|
|
|
|
|
|
|
extern MyUART_Struct_Typedef uartCool;
|
2023-04-11 11:28:42 +02:00
|
|
|
int actualMinutes =-1;
|
2023-04-11 14:38:54 +02:00
|
|
|
uint32_t oldAdc =0;
|
2023-04-07 15:28:30 +02:00
|
|
|
|
|
|
|
void battery(uint32_t data)
|
|
|
|
{
|
2023-04-11 11:28:42 +02:00
|
|
|
MyRTC_Struct_TypeDef rtcBattery;
|
|
|
|
MyRTC_GetTime(&rtcBattery);
|
2023-04-11 14:38:54 +02:00
|
|
|
|
|
|
|
if((actualMinutes == rtcBattery.minutes) && isClose(oldAdc,data,50)) //pas de precision/10 %
|
2023-04-11 11:28:42 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-04-11 14:38:54 +02:00
|
|
|
|
|
|
|
oldAdc = data;
|
2023-04-11 11:28:42 +02:00
|
|
|
actualMinutes = rtcBattery.minutes;
|
2023-04-10 23:48:53 +02:00
|
|
|
float percentBattery = ((float)data)/MAX_BAT;
|
2023-04-11 14:38:54 +02:00
|
|
|
char batteryBar[13]="[__________]";
|
|
|
|
char testChar[24];
|
|
|
|
|
|
|
|
getGauge(batteryBar, percentBattery);
|
|
|
|
sprintf(testChar,"[%.2d:%.2d] %s %.2d%%",rtcBattery.hours,rtcBattery.minutes,batteryBar,(int)(percentBattery*100));
|
|
|
|
MyUART_SendArray(&uartCool, (uint8_t *)testChar, 24);
|
|
|
|
|
|
|
|
MyUART_Send(&uartCool, '\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
void getGauge(char gauge[], float percent)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
percent=percent*10;
|
|
|
|
if(percent>10)
|
2023-04-07 15:28:30 +02:00
|
|
|
{
|
2023-04-11 14:38:54 +02:00
|
|
|
percent = 10.0;
|
2023-04-07 15:28:30 +02:00
|
|
|
}
|
2023-04-11 14:38:54 +02:00
|
|
|
for(i=(10-percent)+1; i<11; i++)
|
2023-04-10 23:48:53 +02:00
|
|
|
{
|
2023-04-11 14:38:54 +02:00
|
|
|
gauge[i]='#';
|
2023-04-07 15:28:30 +02:00
|
|
|
}
|
2023-04-11 14:38:54 +02:00
|
|
|
gauge[12]='\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
char isClose(uint32_t data, uint32_t compare, int precision)
|
|
|
|
{
|
|
|
|
if(data < precision)
|
|
|
|
{
|
|
|
|
return !(data >= compare+precision);
|
|
|
|
}
|
|
|
|
return !((data >= compare+precision) || (data <= compare-precision));
|
2023-04-07 15:28:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void initBattery(void)
|
|
|
|
{
|
|
|
|
MyADC_Init_Periph(battery);
|
|
|
|
MyADC_Struct_TypeDef adcBattery = {ADC1,10,cycles41d5};
|
|
|
|
MyADC_Init(&adcBattery);
|
2023-04-11 11:28:42 +02:00
|
|
|
MyGPIO_Struct_TypeDef gpioBattery = {GPIOC,0,In_Analog};
|
2023-04-07 15:28:30 +02:00
|
|
|
MyGPIO_Init(&gpioBattery);
|
|
|
|
}
|