2023-04-07 15:28:30 +02:00
|
|
|
#include "battery.h"
|
|
|
|
#include "adc.h"
|
|
|
|
#include "remote.h"
|
|
|
|
|
|
|
|
extern MyUART_Struct_Typedef uartCool;
|
|
|
|
|
|
|
|
void battery(uint32_t data)
|
|
|
|
{
|
2023-04-10 23:48:53 +02:00
|
|
|
int i;
|
|
|
|
float percentBattery = ((float)data)/MAX_BAT;
|
|
|
|
uint8_t batteryBar[12], batteryGauge=percentBattery*10;
|
|
|
|
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-10 23:48:53 +02:00
|
|
|
batteryBar[0] = '[';
|
|
|
|
for(i=1; i<=(10-batteryGauge); i++)
|
|
|
|
{
|
|
|
|
batteryBar[i]='.';
|
|
|
|
}
|
|
|
|
while(i<11)
|
|
|
|
{
|
|
|
|
batteryBar[i]='#';
|
|
|
|
i++;
|
2023-04-07 15:28:30 +02:00
|
|
|
}
|
2023-04-10 23:48:53 +02:00
|
|
|
batteryBar[i]=']';
|
|
|
|
MyUART_SendArray(&uartCool, batteryBar, 12);
|
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);
|
|
|
|
MyGPIO_Struct_TypeDef gpioBattery = {GPIOC,0,In_Analog};;
|
|
|
|
MyGPIO_Init(&gpioBattery);
|
|
|
|
}
|