mirror of https://github.com/ArduPilot/ardupilot
AP_RPM: avoid attach interrupt retry and spam to GCS if PIN = -1
This commit is contained in:
parent
304a40d3b7
commit
0b18622e59
|
@ -50,22 +50,24 @@ void AP_RPM_Pin::update(void)
|
||||||
{
|
{
|
||||||
if (last_pin != get_pin()) {
|
if (last_pin != get_pin()) {
|
||||||
// detach from last pin
|
// detach from last pin
|
||||||
if (last_pin != (uint8_t)-1 &&
|
if (interrupt_attached) {
|
||||||
!hal.gpio->detach_interrupt(last_pin)) {
|
// ignore this failure of the user may be stuck
|
||||||
gcs().send_text(MAV_SEVERITY_WARNING, "RPM: Failed to detach from pin %u", last_pin);
|
IGNORE_RETURN(hal.gpio->detach_interrupt(last_pin));
|
||||||
// ignore this failure or the user may be stuck
|
interrupt_attached = false;
|
||||||
}
|
}
|
||||||
irq_state[state.instance].dt_count = 0;
|
irq_state[state.instance].dt_count = 0;
|
||||||
irq_state[state.instance].dt_sum = 0;
|
irq_state[state.instance].dt_sum = 0;
|
||||||
// attach to new pin
|
// attach to new pin
|
||||||
last_pin = get_pin();
|
last_pin = get_pin();
|
||||||
if (last_pin) {
|
if (last_pin > 0) {
|
||||||
hal.gpio->pinMode(last_pin, HAL_GPIO_INPUT);
|
hal.gpio->pinMode(last_pin, HAL_GPIO_INPUT);
|
||||||
if (!hal.gpio->attach_interrupt(
|
if (hal.gpio->attach_interrupt(
|
||||||
last_pin,
|
last_pin,
|
||||||
FUNCTOR_BIND_MEMBER(&AP_RPM_Pin::irq_handler, void, uint8_t, bool, uint32_t),
|
FUNCTOR_BIND_MEMBER(&AP_RPM_Pin::irq_handler, void, uint8_t, bool, uint32_t),
|
||||||
AP_HAL::GPIO::INTERRUPT_RISING)) {
|
AP_HAL::GPIO::INTERRUPT_RISING)) {
|
||||||
gcs().send_text(MAV_SEVERITY_WARNING, "RPM: Failed to attach to pin %u", last_pin);
|
interrupt_attached = true;
|
||||||
|
} else {
|
||||||
|
gcs().send_text(MAV_SEVERITY_WARNING, "RPM: Failed to attach to pin %d", last_pin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,8 @@ public:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
ModeFilterFloat_Size5 signal_quality_filter {3};
|
ModeFilterFloat_Size5 signal_quality_filter {3};
|
||||||
uint8_t last_pin = -1;
|
int8_t last_pin = -1; // last pin number checked vs PIN parameter
|
||||||
|
bool interrupt_attached; // true if an interrupt has been attached to last_pin
|
||||||
struct IrqState {
|
struct IrqState {
|
||||||
uint32_t last_pulse_us;
|
uint32_t last_pulse_us;
|
||||||
uint32_t dt_sum;
|
uint32_t dt_sum;
|
||||||
|
|
Loading…
Reference in New Issue