From 6414887dcc7cdfdfa59c65b1c554ad0c9e58d170 Mon Sep 17 00:00:00 2001 From: vassilis Date: Sun, 30 May 2010 01:58:15 +0000 Subject: [PATCH] Flight/ManualControl Added support for reversing inputs git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@685 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../Modules/ManualControl/manualcontrol.c | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/flight/OpenPilot/Modules/ManualControl/manualcontrol.c b/flight/OpenPilot/Modules/ManualControl/manualcontrol.c index 4003b2182..72742b8e1 100644 --- a/flight/OpenPilot/Modules/ManualControl/manualcontrol.c +++ b/flight/OpenPilot/Modules/ManualControl/manualcontrol.c @@ -192,13 +192,27 @@ static float scaleChannel(int16_t value, int16_t max, int16_t min, int16_t neutr { float valueScaled; // Scale - if ( value >= neutral) + if ( (max > min && value >= neutral) || (min > max && value <= neutral) ) { - valueScaled = (float)(value-neutral)/(float)(max-neutral); + if ( max != neutral ) + { + valueScaled = (float)(value-neutral)/(float)(max-neutral); + } + else + { + valueScaled = 0; + } } else { - valueScaled = (float)(value-neutral)/(float)(neutral-min); + if ( min != neutral ) + { + valueScaled = (float)(value-neutral)/(float)(neutral-min); + } + else + { + valueScaled = 0; + } } // Bound if ( valueScaled > 1.0 )