2011-07-17 07:32:00 -03:00
|
|
|
static void update_lights()
|
2011-06-16 14:03:26 -03:00
|
|
|
{
|
|
|
|
switch(led_mode){
|
|
|
|
case NORMAL_LEDS:
|
|
|
|
update_motor_light();
|
|
|
|
update_GPS_light();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUTO_TRIM_LEDS:
|
|
|
|
dancing_light();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void update_GPS_light(void)
|
2011-06-16 14:03:26 -03:00
|
|
|
{
|
|
|
|
// GPS LED on if we have a fix or Blink GPS LED if we are receiving data
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
switch (g_gps->status()){
|
|
|
|
|
|
|
|
case(2):
|
2012-01-23 18:10:03 -04:00
|
|
|
if(home_is_set) { // JLN update
|
|
|
|
digitalWrite(C_LED_PIN, LED_ON); //Turn LED C on when gps has valid fix AND home is set.
|
|
|
|
} else {
|
|
|
|
digitalWrite(C_LED_PIN, LED_OFF);
|
|
|
|
}
|
2011-06-16 14:03:26 -03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case(1):
|
|
|
|
if (g_gps->valid_read == true){
|
|
|
|
GPS_light = !GPS_light; // Toggle light on and off to indicate gps messages being received, but no GPS fix lock
|
|
|
|
if (GPS_light){
|
2011-11-12 23:44:36 -04:00
|
|
|
digitalWrite(C_LED_PIN, LED_OFF);
|
2011-06-16 14:03:26 -03:00
|
|
|
}else{
|
2011-11-12 23:44:36 -04:00
|
|
|
digitalWrite(C_LED_PIN, LED_ON);
|
2011-06-16 14:03:26 -03:00
|
|
|
}
|
|
|
|
g_gps->valid_read = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-11-12 23:44:36 -04:00
|
|
|
digitalWrite(C_LED_PIN, LED_OFF);
|
2011-06-16 14:03:26 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void update_motor_light(void)
|
2011-06-16 14:03:26 -03:00
|
|
|
{
|
2012-04-04 10:57:50 -03:00
|
|
|
if(motors.armed() == false){
|
2011-06-16 14:03:26 -03:00
|
|
|
motor_light = !motor_light;
|
|
|
|
|
|
|
|
// blink
|
|
|
|
if(motor_light){
|
2011-11-12 23:44:36 -04:00
|
|
|
digitalWrite(A_LED_PIN, LED_ON);
|
2011-06-16 14:03:26 -03:00
|
|
|
}else{
|
2011-11-12 23:44:36 -04:00
|
|
|
digitalWrite(A_LED_PIN, LED_OFF);
|
2011-06-16 14:03:26 -03:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if(!motor_light){
|
|
|
|
motor_light = true;
|
2011-11-12 23:44:36 -04:00
|
|
|
digitalWrite(A_LED_PIN, LED_ON);
|
2011-06-16 14:03:26 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-17 07:32:00 -03:00
|
|
|
static void dancing_light()
|
2011-06-16 14:03:26 -03:00
|
|
|
{
|
|
|
|
static byte step;
|
|
|
|
|
|
|
|
if (step++ == 3)
|
|
|
|
step = 0;
|
|
|
|
|
|
|
|
switch(step)
|
|
|
|
{
|
|
|
|
case 0:
|
2011-11-12 23:44:36 -04:00
|
|
|
digitalWrite(C_LED_PIN, LED_OFF);
|
|
|
|
digitalWrite(A_LED_PIN, LED_ON);
|
2011-06-16 14:03:26 -03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2011-11-12 23:44:36 -04:00
|
|
|
digitalWrite(A_LED_PIN, LED_OFF);
|
|
|
|
digitalWrite(B_LED_PIN, LED_ON);
|
2011-06-16 14:03:26 -03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2011-11-12 23:44:36 -04:00
|
|
|
digitalWrite(B_LED_PIN, LED_OFF);
|
|
|
|
digitalWrite(C_LED_PIN, LED_ON);
|
2011-06-16 14:03:26 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-07-17 07:32:00 -03:00
|
|
|
static void clear_leds()
|
2011-06-16 14:03:26 -03:00
|
|
|
{
|
2011-11-12 23:44:36 -04:00
|
|
|
digitalWrite(A_LED_PIN, LED_OFF);
|
|
|
|
digitalWrite(B_LED_PIN, LED_OFF);
|
|
|
|
digitalWrite(C_LED_PIN, LED_OFF);
|
2011-09-04 21:15:36 -03:00
|
|
|
motor_light = false;
|
2011-08-14 15:56:31 -03:00
|
|
|
led_mode = NORMAL_LEDS;
|
2011-06-16 14:03:26 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#if MOTOR_LEDS == 1
|
2011-07-17 07:32:00 -03:00
|
|
|
static void update_motor_leds(void)
|
2011-06-16 14:03:26 -03:00
|
|
|
{
|
2012-04-04 10:57:50 -03:00
|
|
|
if (motors.armed()){
|
2011-09-16 22:56:51 -03:00
|
|
|
if (low_batt == true){
|
|
|
|
// blink rear
|
|
|
|
static bool blink = false;
|
|
|
|
|
|
|
|
if (blink){
|
2011-12-26 04:32:53 -04:00
|
|
|
digitalWrite(RE_LED, LED_ON);
|
|
|
|
digitalWrite(FR_LED, LED_ON);
|
|
|
|
digitalWrite(RI_LED, LED_OFF);
|
|
|
|
digitalWrite(LE_LED, LED_OFF);
|
2011-09-16 22:56:51 -03:00
|
|
|
}else{
|
2011-12-26 04:32:53 -04:00
|
|
|
digitalWrite(RE_LED, LED_OFF);
|
|
|
|
digitalWrite(FR_LED, LED_OFF);
|
|
|
|
digitalWrite(RI_LED, LED_ON);
|
|
|
|
digitalWrite(LE_LED, LED_ON);
|
2011-09-16 22:56:51 -03:00
|
|
|
}
|
|
|
|
blink = !blink;
|
|
|
|
}else{
|
2011-12-26 04:32:53 -04:00
|
|
|
digitalWrite(RE_LED, LED_ON);
|
|
|
|
digitalWrite(FR_LED, LED_ON);
|
|
|
|
digitalWrite(RI_LED, LED_ON);
|
|
|
|
digitalWrite(LE_LED, LED_ON);
|
2011-09-16 22:56:51 -03:00
|
|
|
}
|
|
|
|
}else {
|
2011-12-26 04:32:53 -04:00
|
|
|
digitalWrite(RE_LED, LED_OFF);
|
|
|
|
digitalWrite(FR_LED, LED_OFF);
|
|
|
|
digitalWrite(RI_LED, LED_OFF);
|
|
|
|
digitalWrite(LE_LED, LED_OFF);
|
2011-06-16 14:03:26 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-07-10 21:47:08 -03:00
|
|
|
|