From 7dae3abac906bee5b72f8720616dddd933b3f18d Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 18 Apr 2016 18:29:21 +0200 Subject: [PATCH] Sensors: Adjust mode switch ranges --- src/modules/sensors/sensors.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/modules/sensors/sensors.cpp b/src/modules/sensors/sensors.cpp index 78be227e90..b41ed90db6 100644 --- a/src/modules/sensors/sensors.cpp +++ b/src/modules/sensors/sensors.cpp @@ -1949,8 +1949,8 @@ Sensors::rc_poll() const float slot_width_half = 2.0f / num_slots / 2.0f; /* min is -1, max is +1, range is 2. We offset below min and max */ - const float slot_min = -1.0f - slot_width_half; - const float slot_max = 1.0f + slot_width_half; + const float slot_min = -1.0f - 0.05f; + const float slot_max = 1.0f + 0.05f; /* the slot gets mapped by first normalizing into a 0..1 interval using min * and max. Then the right slot is obtained by multiplying with the number of @@ -1959,6 +1959,10 @@ Sensors::rc_poll() */ manual.mode_slot = (((((_rc.channels[_parameters.rc_map_flightmode - 1] - slot_min) * num_slots) + slot_width_half) / (slot_max - slot_min)) + (1.0f / num_slots)); + + if (manual.mode_slot >= num_slots) { + manual.mode_slot = num_slots - 1; + } } /* mode switches */