From 9b8a61c0483cd3cc86092cef2af1cd804263403a Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 3 Feb 2023 12:34:37 +1100 Subject: [PATCH] AP_EFI: correct EFI ignition_voltage flag values --- libraries/AP_EFI/AP_EFI.cpp | 15 ++++++++++++++- libraries/AP_EFI/AP_EFI_State.h | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libraries/AP_EFI/AP_EFI.cpp b/libraries/AP_EFI/AP_EFI.cpp index 27a2916c03..cf57efcf38 100644 --- a/libraries/AP_EFI/AP_EFI.cpp +++ b/libraries/AP_EFI/AP_EFI.cpp @@ -247,6 +247,19 @@ void AP_EFI::send_mavlink_status(mavlink_channel_t chan) if (!backend) { return; } + + float ignition_voltage; + if (isnan(state.ignition_voltage) || + is_equal(state.ignition_voltage, -1.0f)) { + // zero means "unknown" in mavlink, 0.0001 means 0 volts + ignition_voltage = 0; + } else if (is_zero(state.ignition_voltage)) { + // zero means "unknown" in mavlink, 0.0001 means 0 volts + ignition_voltage = 0.0001f; + } else { + ignition_voltage = state.ignition_voltage; + }; + mavlink_msg_efi_status_send( chan, AP_EFI::is_healthy(), @@ -266,7 +279,7 @@ void AP_EFI::send_mavlink_status(mavlink_channel_t chan) KELVIN_TO_C(state.cylinder_status.exhaust_gas_temperature), state.throttle_out, state.pt_compensation, - state.ignition_voltage + ignition_voltage ); } diff --git a/libraries/AP_EFI/AP_EFI_State.h b/libraries/AP_EFI/AP_EFI_State.h index 6b0abc93d2..97acbecd6b 100644 --- a/libraries/AP_EFI/AP_EFI_State.h +++ b/libraries/AP_EFI/AP_EFI_State.h @@ -199,7 +199,7 @@ struct EFI_State { Cylinder_Status cylinder_status; // ignition voltage in Volts - float ignition_voltage; + float ignition_voltage = -1; // -1 is "unknown"; // throttle output percentage float throttle_out;