voilier-team-1/implementation/battery.c

38 lines
717 B
C
Raw Normal View History

#include "battery.h"
#include "adc.h"
#include "remote.h"
extern MyUART_Struct_Typedef uartCool;
void battery(uint32_t data)
{
int i;
float percentBattery = ((float)data)/MAX_BAT;
uint8_t batteryBar[12], batteryGauge=percentBattery*10;
if(batteryGauge>10)
{
batteryGauge = 10;
}
batteryBar[0] = '[';
for(i=1; i<=(10-batteryGauge); i++)
{
batteryBar[i]='.';
}
while(i<11)
{
batteryBar[i]='#';
i++;
}
batteryBar[i]=']';
MyUART_SendArray(&uartCool, batteryBar, 12);
}
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);
}