From 4bfcbf7a059f1319f007b68c95e38e339981c8b7 Mon Sep 17 00:00:00 2001 From: Risto Date: Mon, 21 Jun 2021 18:43:40 +0200 Subject: [PATCH] Adds support for correct Alps EC10E roller hookup (#261) Enhanced roller update (thx to Mike Blandford https://www.rcgroups.com/forums/showpost.php?p=46929617&postcount=9974 ) * TX12 should also have ROTARY_ENCODER_GRANULARITY 2 --- radio/src/opentx.h | 4 -- .../arm/stm32/rotary_encoder_driver.cpp | 41 +++++++++++-------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/radio/src/opentx.h b/radio/src/opentx.h index cc9f4aff8..77e685c95 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -580,10 +580,6 @@ bool setTrimValue(uint8_t phase, uint8_t idx, int trim); #if defined(PCBSKY9X) #define ROTARY_ENCODER_GRANULARITY (2 << g_eeGeneral.rotarySteps) -#elif defined(RADIO_FAMILY_T16) && !defined(RADIO_T18) - #define ROTARY_ENCODER_GRANULARITY (1) -#elif defined(RADIO_TX12) - #define ROTARY_ENCODER_GRANULARITY (1) #else #define ROTARY_ENCODER_GRANULARITY (2) #endif diff --git a/radio/src/targets/common/arm/stm32/rotary_encoder_driver.cpp b/radio/src/targets/common/arm/stm32/rotary_encoder_driver.cpp index 570e134b1..6efe31295 100644 --- a/radio/src/targets/common/arm/stm32/rotary_encoder_driver.cpp +++ b/radio/src/targets/common/arm/stm32/rotary_encoder_driver.cpp @@ -72,25 +72,34 @@ void rotaryEncoderInit() void rotaryEncoderCheck() { #if (defined(RADIO_FAMILY_T16) && !defined(RADIO_T18)) || defined(RADIO_TX12) - static uint8_t state = 0; + static uint8_t state = 0; uint8_t pins = ROTARY_ENCODER_POSITION(); if (pins != (state & 0x03) && !(readKeys() & (1 << KEY_ENTER))) { - if ((pins & 0x01) ^ ((pins & 0x02) >> 1)) { - if ((state & 0x03) == 3) - ++rotencValue; - else - --rotencValue; - } - else - { - if ((state & 0x03) == 3) - --rotencValue; - else if ((state & 0x03) == 0) - ++rotencValue; - } - state &= ~0x03 ; - state |= pins ; + if ((pins ^ (state & 0x03)) == 0x03) + { + if (pins == 3) + { + rotencValue += 2; + } + else + { + rotencValue -= 2; + } + } + else + { + if ((state & 0x01) ^ ((pins & 0x02) >> 1)) + { + rotencValue -= 1; + } + else + { + rotencValue += 1; + } + } + state &= ~0x03; + state |= pins; #else uint8_t newPosition = ROTARY_ENCODER_POSITION(); if (newPosition != rotencPosition && !(readKeys() & (1 << KEY_ENTER))) {