Plane: treat PWM below 900 as invalid for mode switch

the FrSky X8R receiver will briefly give a PWM of 874 on channel 5
when connection is lost to the transmitter. We need to ensure this
doesn't cause a mode switch
This commit is contained in:
Andrew Tridgell 2014-03-08 16:49:57 +11:00
parent 3a3397d926
commit 8574303a94

View File

@ -16,6 +16,11 @@ static void read_control_switch()
return; return;
} }
if (hal.scheduler->millis() - failsafe.last_valid_rc_ms > 100) {
// only use signals that are less than 0.1s old.
return;
}
// we look for changes in the switch position. If the // we look for changes in the switch position. If the
// RST_SWITCH_CH parameter is set, then it is a switch that can be // RST_SWITCH_CH parameter is set, then it is a switch that can be
// used to force re-reading of the control switch. This is useful // used to force re-reading of the control switch. This is useful
@ -57,9 +62,10 @@ static void read_control_switch()
} }
} }
static uint8_t readSwitch(void){ static uint8_t readSwitch(void)
{
uint16_t pulsewidth = hal.rcin->read(g.flight_mode_channel - 1); uint16_t pulsewidth = hal.rcin->read(g.flight_mode_channel - 1);
if (pulsewidth <= 800 || pulsewidth >= 2200) return 255; // This is an error condition if (pulsewidth <= 900 || pulsewidth >= 2200) return 255; // This is an error condition
if (pulsewidth > 1230 && pulsewidth <= 1360) return 1; if (pulsewidth > 1230 && pulsewidth <= 1360) return 1;
if (pulsewidth > 1360 && pulsewidth <= 1490) return 2; if (pulsewidth > 1360 && pulsewidth <= 1490) return 2;
if (pulsewidth > 1490 && pulsewidth <= 1620) return 3; if (pulsewidth > 1490 && pulsewidth <= 1620) return 3;