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-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);
|
|
|
|
if(actualMinutes == rtcBattery.minutes)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
actualMinutes = rtcBattery.minutes;
|
2023-04-10 23:48:53 +02:00
|
|
|
float percentBattery = ((float)data)/MAX_BAT;
|
2023-04-11 11:28:42 +02:00
|
|
|
uint8_t batteryBar[13]={'[','.','.','.','.','.','.','.','.','.','.',']',0x20}, batteryGauge=percentBattery*10, i;
|
2023-04-10 23:48:53 +02:00
|
|
|
if(batteryGauge>10)
|
2023-04-07 15:28:30 +02:00
|
|
|
{
|
2023-04-10 23:48:53 +02:00
|
|
|
batteryGauge = 10;
|
2023-04-07 15:28:30 +02:00
|
|
|
}
|
2023-04-11 11:28:42 +02:00
|
|
|
char timerClock[8] = {'[','.','.','h','.','.',']',0x20};
|
|
|
|
sprintf(timerClock+1,"%.*d",2,rtcBattery.hours);
|
|
|
|
timerClock[3]=':';
|
|
|
|
sprintf(timerClock+4,"%.*d",2,rtcBattery.minutes);
|
|
|
|
timerClock[3]='\t';
|
|
|
|
MyUART_SendArray(&uartCool, (uint8_t *)timerClock, 8);
|
|
|
|
|
|
|
|
for(i=(10-batteryGauge); i<11; i++)
|
2023-04-10 23:48:53 +02:00
|
|
|
{
|
|
|
|
batteryBar[i]='#';
|
2023-04-07 15:28:30 +02:00
|
|
|
}
|
2023-04-11 11:28:42 +02:00
|
|
|
MyUART_SendArray(&uartCool, batteryBar, 13);
|
|
|
|
|
|
|
|
char batteryPercentString[3];
|
|
|
|
sprintf(batteryPercentString,"%.*g",2,percentBattery*100);
|
|
|
|
batteryPercentString[2]='%';
|
|
|
|
MyUART_SendArray(&uartCool, (uint8_t *)batteryPercentString, 6);
|
|
|
|
|
|
|
|
MyUART_Send(&uartCool, '\n');
|
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);
|
|
|
|
}
|