From 2e5a41e8c94e1114d95840d498f706e66d5ded4c Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sun, 6 Mar 2016 12:34:07 +0100 Subject: [PATCH] Sensors: Use correct ranges for mode slots --- src/modules/sensors/sensors.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/modules/sensors/sensors.cpp b/src/modules/sensors/sensors.cpp index 7f9612c11c..8ced037d3d 100644 --- a/src/modules/sensors/sensors.cpp +++ b/src/modules/sensors/sensors.cpp @@ -1897,11 +1897,14 @@ Sensors::rc_poll() if (_parameters.rc_map_flightmode > 0) { - const unsigned slot_min = 1000; - const unsigned slot_max = 2000; - const unsigned num_slots = 6; + const float slot_min = -1.0f; + const float slot_max = 1.0f; + /* the number of valid slots is one less than the max marker */ + const unsigned num_slots = manual_control_setpoint_s::MODE_SLOT_MAX - 1; + /* we need the maximum index below, not the number of slots, so slots - 1 */ + const unsigned max_index = num_slots - 1; - manual.mode_slot = ((_rc.channels[_parameters.rc_map_flightmode - 1] - slot_min) * num_slots) / (slot_max - slot_min); + manual.mode_slot = ((_rc.channels[_parameters.rc_map_flightmode - 1] - slot_min) * max_index) / (slot_max - slot_min); } else { /* mode switches */