feat: Option for inverting rotary encoder direction (#1690)

* feat: Add option for rotary encoder direction
Based heavily on opentx/opentx#8852 by @3djc

* companion ui elements

* Cleanup

* Hook up UI, reading setting from yaml

* Teach simulator about rotEncDirection

* Simu and radio default scroll direction correction
Otherwise the "default" would be the opposite to how it has always been

* Remove what will be a confict with fix in #1586

* Wasn't using rotEncDirection consistently

* Zorro RE dir is opp to TX16, TX12, TPro, X9D+2019
This commit is contained in:
Peter Feerick
2022-03-22 16:14:57 +10:00
committed by GitHub
parent b36e456ca7
commit b54ad7169a
47 changed files with 416 additions and 326 deletions
@@ -71,6 +71,14 @@ void rotaryEncoderInit()
NVIC_SetPriority(ROTARY_ENCODER_TIMER_IRQn, 7);
}
#if defined(BOOT)
#define INC_ROT 1
#define INC_ROT_2 2
#else
#define INC_ROT (g_eeGeneral.rotEncDirection ? -1 : 1);
#define INC_ROT_2 (g_eeGeneral.rotEncDirection ? -2 : 2);
#endif
void rotaryEncoderCheck()
{
#if (defined(RADIO_FAMILY_T16) && !defined(RADIO_T18)) || defined(RADIO_TX12)
@@ -82,22 +90,22 @@ void rotaryEncoderCheck()
{
if (pins == 3)
{
rotencValue += 2;
rotencValue += INC_ROT_2;
}
else
{
rotencValue -= 2;
rotencValue -= INC_ROT_2;
}
}
else
{
if ((state & 0x01) ^ ((pins & 0x02) >> 1))
{
rotencValue -= 1;
rotencValue -= INC_ROT;
}
else
{
rotencValue += 1;
rotencValue += INC_ROT;
}
}
state &= ~0x03;
@@ -105,14 +113,14 @@ void rotaryEncoderCheck()
#else
uint8_t newPosition = ROTARY_ENCODER_POSITION();
if (newPosition != rotencPosition && !(readKeys() & (1 << KEY_ENTER))) {
#if defined(ROTARY_ENCODER_INVERT)
if (!((rotencPosition & 0x01) ^ ((newPosition & 0x02) >> 1))) {
#if defined(RADIO_ZORRO) // zorro def. rotation dir is inverse of other radios
if (!(rotencPosition & 0x01) ^ ((newPosition & 0x02) >> 1)) {
#else
if ((rotencPosition & 0x01) ^ ((newPosition & 0x02) >> 1)) {
#endif
--rotencValue;
rotencValue -= INC_ROT;
} else {
++rotencValue;
rotencValue += INC_ROT;
}
rotencPosition = newPosition;
#endif