#include "system.h"
#include "flightbatterystate.h"
TestValSet(1);
FlightBatteryStateData BatteryData;
unsigned long last;
unsigned long now;
short timeStarted=0;
short wasArmed=0;
int b_LOW[6] = {100,200,100,200,100,200};
int b_LOST[2] = {400,1000};
void beepX(unsigned int t[], unsigned int x)
{
unsigned int k;
PWMOutSet(6, 0);
for(k=0; k<x; ++k) {
PWMOutSet(6, ((k&1)?0:2500));
sync(t[k]);
}
PWMOutSet(6, 0);
}
void batterystatus()
{
FlightBatteryStateGet(&BatteryData);
now = time();
if ((wasArmed==1) && (BatteryData.Voltage < 13.2) && (timeStarted == 0))
{
last = time();
timeStarted = 1;
}
else if ((wasArmed==1) && (BatteryData.Voltage < 13.2) && (timeStarted == 1) && ((now-last) > 5000))
{
beepX(b_LOW,6);
timeStarted = 0;
printf("Value: %d \n", now-last);
}
}
int findME()
{
if (AccessoryValGet(0) > 0)
{
beepX(b_LOST,2);
return 1;
}
else if ((wasArmed==1) && (TxChannelValGet(3) > 60000))
{
beepX(b_LOST,2);
return 1;
}
return 0;
}
int main()
{
sync(0);
while (TestValGet() > 0)
{
if (armed())
{
wasArmed=1;
}
if (findME() != 1)
{
batterystatus();
}
sync(150);
}
return 11;
}
exit(main());