From 4071eacc9214d5ef6b9ac1f2e47afaeb8359de35 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 5 Nov 2022 10:39:45 +0100 Subject: [PATCH] fix(simu): rotencDt must be updated as well (#2676) The acceleration calculation is relying on it to compute dx/dt. --- radio/src/simu.cpp | 10 ++++++++++ radio/src/targets/simu/opentxsimulator.cpp | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/radio/src/simu.cpp b/radio/src/simu.cpp index 8872140b0..b9849d838 100644 --- a/radio/src/simu.cpp +++ b/radio/src/simu.cpp @@ -466,6 +466,8 @@ void OpenTxSim::updateKeysAndSwitches(bool start) #endif } +extern volatile uint32_t rotencDt; + long OpenTxSim::onTimeout(FXObject*, FXSelector, void*) { if (hasFocus()) { @@ -485,6 +487,14 @@ long OpenTxSim::onTimeout(FXObject*, FXSelector, void*) else { rotencAction = false; } + + static uint32_t last_tick = 0; + if (rotencAction) { + uint32_t now = RTOS_GET_MS(); + uint32_t dt = now - last_tick; + rotencDt += dt; + last_tick = now; + } #endif } diff --git a/radio/src/targets/simu/opentxsimulator.cpp b/radio/src/targets/simu/opentxsimulator.cpp index 6853385ef..a32994bc9 100644 --- a/radio/src/targets/simu/opentxsimulator.cpp +++ b/radio/src/targets/simu/opentxsimulator.cpp @@ -273,12 +273,21 @@ void OpenTxSimulator::setInputValue(int type, uint8_t index, int16_t value) } } +extern volatile uint32_t rotencDt; + void OpenTxSimulator::rotaryEncoderEvent(int steps) { #if defined(ROTARY_ENCODER_NAVIGATION) - (g_eeGeneral.rotEncMode >= ROTARY_ENCODER_MODE_INVERT_BOTH ? steps *= -1 - : steps); - ROTARY_ENCODER_NAVIGATION_VALUE += steps * ROTARY_ENCODER_GRANULARITY; + static uint32_t last_tick = 0; + if (steps != 0) { + if (g_eeGeneral.rotEncMode >= ROTARY_ENCODER_MODE_INVERT_BOTH) steps *= -1; + ROTARY_ENCODER_NAVIGATION_VALUE += steps * ROTARY_ENCODER_GRANULARITY; + // TODO: set rotencDt + uint32_t now = RTOS_GET_MS(); + uint32_t dt = now - last_tick; + rotencDt += dt; + last_tick = now; + } #else // TODO : this should probably be handled in the GUI int key;