voilier-team-1/implementation/battery.c

49 lines
1.3 KiB
C

#include "battery.h"
extern MyUART_Struct_Typedef uartCool;
int actualMinutes =-1;
void battery(uint32_t data)
{
MyRTC_Struct_TypeDef rtcBattery;
MyRTC_GetTime(&rtcBattery);
if(actualMinutes == rtcBattery.minutes)
{
return;
}
actualMinutes = rtcBattery.minutes;
float percentBattery = ((float)data)/MAX_BAT;
uint8_t batteryBar[13]={'[','.','.','.','.','.','.','.','.','.','.',']',0x20}, batteryGauge=percentBattery*10, i;
if(batteryGauge>10)
{
batteryGauge = 10;
}
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++)
{
batteryBar[i]='#';
}
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');
}
void initBattery(void)
{
MyADC_Init_Periph(battery);
MyADC_Struct_TypeDef adcBattery = {ADC1,10,cycles41d5};
MyADC_Init(&adcBattery);
MyGPIO_Struct_TypeDef gpioBattery = {GPIOC,0,In_Analog};
MyGPIO_Init(&gpioBattery);
}