From ce6bf053b83dcbe3b9611c3b617a216207da1b09 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 14 Jun 2019 09:18:27 +0200 Subject: [PATCH] Throttle warning screen reworking --- radio/src/gui/128x64/radio_setup.cpp | 2 +- radio/src/gui/212x64/radio_setup.cpp | 2 +- radio/src/gui/480x272/radio_setup.cpp | 2 +- radio/src/opentx.cpp | 54 +++++++++++++-------------- radio/src/opentx.h | 2 +- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/radio/src/gui/128x64/radio_setup.cpp b/radio/src/gui/128x64/radio_setup.cpp index a9fc6f4e5..34e8bfe76 100644 --- a/radio/src/gui/128x64/radio_setup.cpp +++ b/radio/src/gui/128x64/radio_setup.cpp @@ -632,7 +632,7 @@ void menuRadioSetup(event_t event) else if (reusableBuffer.generalSettings.stickMode != g_eeGeneral.stickMode) { pausePulses(); g_eeGeneral.stickMode = reusableBuffer.generalSettings.stickMode; - checkTHR(); + checkThrottleStick(); resumePulses(); waitKeysReleased(); } diff --git a/radio/src/gui/212x64/radio_setup.cpp b/radio/src/gui/212x64/radio_setup.cpp index ca81fb18b..17d376cc8 100644 --- a/radio/src/gui/212x64/radio_setup.cpp +++ b/radio/src/gui/212x64/radio_setup.cpp @@ -500,7 +500,7 @@ void menuRadioSetup(event_t event) else if (reusableBuffer.generalSettings.stickMode != g_eeGeneral.stickMode) { pausePulses(); g_eeGeneral.stickMode = reusableBuffer.generalSettings.stickMode; - checkTHR(); + checkThrottleStick(); resumePulses(); waitKeysReleased(); } diff --git a/radio/src/gui/480x272/radio_setup.cpp b/radio/src/gui/480x272/radio_setup.cpp index 2e7dc655b..f7c5c4248 100644 --- a/radio/src/gui/480x272/radio_setup.cpp +++ b/radio/src/gui/480x272/radio_setup.cpp @@ -480,7 +480,7 @@ bool menuRadioSetup(event_t event) else if (reusableBuffer.generalSettings.stickMode != g_eeGeneral.stickMode) { pausePulses(); g_eeGeneral.stickMode = reusableBuffer.generalSettings.stickMode; - checkTHR(); + checkThrottleStick(); resumePulses(); waitKeysReleased(); } diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 598a531bf..43abbc78f 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -57,9 +57,14 @@ const uint8_t bchout_ar[] = { 0x87, 0x8D, 0x93, 0x9C, 0xB1, 0xB4, 0xC6, 0xC9, 0xD2, 0xD8, 0xE1, 0xE4 }; +uint8_t channel_order(uint8_t setup, uint8_t x) +{ + return ((*(bchout_ar + setup) >> (6 - (x - 1) * 2)) & 3) + 1; +} + uint8_t channel_order(uint8_t x) { - return ( ((*(bchout_ar + g_eeGeneral.templateSetup) >> (6-(x-1) * 2)) & 3 ) + 1 ); + return channel_order(g_eeGeneral.templateSetup, x); } /* @@ -867,9 +872,10 @@ void checkAll() checkLowEEPROM(); #endif - if (g_eeGeneral.chkSum == evalChkSum()) { - checkTHR(); - } + // we don't check the throttle stick if the radio is not calibrated + if (g_eeGeneral.chkSum == evalChkSum()) + checkThrottleStick(); + checkSwitches(); checkFailsafe(); checkRSSIAlarmsDisabled(); @@ -906,28 +912,32 @@ void checkLowEEPROM() } #endif -void checkTHR() +bool isThrottleWarningAlertNeeded() { - uint8_t thrchn = ((g_model.thrTraceSrc==0) || (g_model.thrTraceSrc>NUM_POTS+NUM_SLIDERS)) ? THR_STICK : g_model.thrTraceSrc+NUM_STICKS-1; + if (g_model.disableThrottleWarning) { + return false; + } + // throttle channel is either the stick according stick mode (already handled in evalInputs) // or P1 to P3; // in case an output channel is choosen as throttle source (thrTraceSrc>NUM_POTS+NUM_SLIDERS) we assume the throttle stick is the input // no other information available at the moment, and good enough to my option (otherwise too much exceptions...) - - if (g_model.disableThrottleWarning) { - return; - } + uint8_t thrchn = ((g_model.thrTraceSrc==0) || (g_model.thrTraceSrc>NUM_POTS+NUM_SLIDERS)) ? THR_STICK : g_model.thrTraceSrc+NUM_STICKS-1; GET_ADC_IF_MIXER_NOT_RUNNING(); - evalInputs(e_perout_mode_notrainer); // let do evalInputs do the job int16_t v = calibratedAnalogs[thrchn]; - if (g_model.thrTraceSrc && g_model.throttleReversed) { //TODO : proper review of THR source definition and handling + if (g_model.thrTraceSrc && g_model.throttleReversed) { // TODO : proper review of THR source definition and handling v = -v; } - if (v <= THRCHK_DEADBAND-1024) { - return; // prevent warning if throttle input OK + return v > THRCHK_DEADBAND - 1024; +} + +void checkThrottleStick() +{ + if (!isThrottleWarningAlertNeeded()) { + return; } // first - display warning; also deletes inputs if any have been before @@ -938,15 +948,9 @@ void checkTHR() bool refresh = false; #endif - while (1) { - - GET_ADC_IF_MIXER_NOT_RUNNING(); - - evalInputs(e_perout_mode_notrainer); // let do evalInputs do the job - - v = calibratedAnalogs[thrchn]; - if (g_model.thrTraceSrc && g_model.throttleReversed) { //TODO : proper review of THR source definition and handling - v = -v; + while (!getEvent()) { + if (!isThrottleWarningAlertNeeded()) { + return; } #if defined(PWR_BUTTON_PRESS) @@ -967,10 +971,6 @@ void checkTHR() } #endif - if (keyDown() || v <= THRCHK_DEADBAND-1024) { - break; - } - doLoopCommonActions(); wdt_reset(); diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 5bf6981de..6ca4173cc 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -616,7 +616,7 @@ extern uint16_t maxMixerDuration; #endif void checkLowEEPROM(); -void checkTHR(); +void checkThrottleStick(); void checkSwitches(); void checkAlarm(); void checkAll();