#include "system.h"#include "gpsposition.h"
#include "flightbatterystate.h"
/* WS2812 library */
#define nLED 3
unsigned char bufLED[nLED*3];
void setLED(unsigned short n, unsigned char r, unsigned char g, unsigned char b) {
if (n < nLED) {
unsigned short offset = 3*n;
bufLED[offset++] = r;
bufLED[offset++] = g;
bufLED[offset++] = b;
}
}
void sendLED() {
ChangeBaud(9600);
SendBuffer(bufLED, sizeof(bufLED));
}
/* end of RGB-LED library */
short LEDupdate=1;
short TMPArmed=2;
short r=0,g=0,b=0;
TestValSet(1);
GPSPositionData GPSData;
short TPMGPS=4;
FlightBatteryStateData BatteryData;
short TMPBattery=4;
TestValSet(2);
while(TestValGet() > 0)
{
FlightBatteryStateGet(&BatteryData);
if ((BatteryData.Voltage < 10.4) && (TMPBattery != 1))
{
TMPBattery = 1;
setLED(0,170,0,0);
LEDupdate=1;
}
if ((BatteryData.Voltage < 10.8) && (BatteryData.Voltage > 10.4) && (TMPBattery != 2))
{
TMPBattery = 2;
setLED(0,170,170,0);
LEDupdate=1;
}
if ((10.8 < BatteryData.Voltage) && (TMPBattery != 3))
{
TMPBattery = 3;
setLED(0,0,170,0);
LEDupdate=1;
}
if (armed() && (TMPArmed != 1))
{
setLED(1,170,0,0);
TMPArmed = 1;
LEDupdate=1;
}
else if (!armed() && (TMPArmed != 0))
{
setLED(1,0,170,0);
TMPArmed = 0;
LEDupdate=1;
}
GPSPositionGet(&GPSData);
if ((GPSData.Satellites < 5) && (TPMGPS != 1))
{
TPMGPS = 1;
setLED(2,170,0,0);
LEDupdate=1;
}
if ((GPSData.Satellites < 7) && (GPSData.Satellites > 4) && (TPMGPS != 2))
{
TPMGPS = 2;
setLED(2,170,170,0);
LEDupdate=1;
}
if ((6 < GPSData.Satellites) && (GPSData.PDOP <= 3.5) && (TPMGPS != 3))
{
TPMGPS = 3;
setLED(2,0,170,0);
LEDupdate=1;
}
if (LEDupdate == 1) {
sendLED();
LEDupdate = 0;
}
delay(500);
}
TestValSet(99);