Added isClose to test if the adc changes brutally, and getGauge which simplifies the battery bar.
This commit is contained in:
parent
33d73b2c82
commit
b232a42eba
2 changed files with 36 additions and 22 deletions
|
@ -2,43 +2,55 @@
|
|||
|
||||
extern MyUART_Struct_Typedef uartCool;
|
||||
int actualMinutes =-1;
|
||||
uint32_t oldAdc =0;
|
||||
|
||||
void battery(uint32_t data)
|
||||
{
|
||||
MyRTC_Struct_TypeDef rtcBattery;
|
||||
MyRTC_GetTime(&rtcBattery);
|
||||
if(actualMinutes == rtcBattery.minutes)
|
||||
|
||||
if((actualMinutes == rtcBattery.minutes) && isClose(oldAdc,data,50)) //pas de precision/10 %
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
oldAdc = data;
|
||||
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);
|
||||
char batteryBar[13]="[__________]";
|
||||
char testChar[24];
|
||||
|
||||
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);
|
||||
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)
|
||||
{
|
||||
percent = 10.0;
|
||||
}
|
||||
for(i=(10-percent)+1; i<11; i++)
|
||||
{
|
||||
gauge[i]='#';
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
void initBattery(void)
|
||||
{
|
||||
MyADC_Init_Periph(battery);
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#define MAX_BAT 1145
|
||||
|
||||
void battery(uint32_t data);
|
||||
void getGauge(char gauge[], float percent);
|
||||
void initBattery(void);
|
||||
char isClose(uint32_t data, uint32_t compare, int precision);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue