From 46381430e1c4f714c3408f92f48b5470524705c4 Mon Sep 17 00:00:00 2001 From: George Belmont Date: Fri, 14 Aug 2020 08:14:06 -0400 Subject: [PATCH 1/2] Added option to invert rotary encoder CLK/DATA pins to reverse operation for certain encoders (Issue#185) --- options.txt | 8 ++++++-- src/iec_bus.cpp | 3 ++- src/iec_bus.h | 18 +++++++++++++++++- src/main.cpp | 2 ++ src/options.cpp | 3 ++- src/options.h | 4 ++++ 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/options.txt b/options.txt index 10f7de6..c3cd196 100644 --- a/options.txt +++ b/options.txt @@ -132,9 +132,13 @@ GraphIEC = 1 // // Please see dmRotary.h for full implementation details. // -//RotaryEncoderEnable = 1 +// Updated to address issue #185 and allow for inversion of rotary operation +// for certain encoders. - 08/13/2020 by Geo... +// +RotaryEncoderEnable = 1 +RotaryEncoderInvert = 1 // This option will display the temperature of the Pi's CPU. -// It should be about 52°C anything above 65°C is bad and there is something wrong with your hardware +// It should be about 52�C anything above 65�C is bad and there is something wrong with your hardware //DisplayTemperature = 1 diff --git a/src/iec_bus.cpp b/src/iec_bus.cpp index c9caca9..1640d91 100644 --- a/src/iec_bus.cpp +++ b/src/iec_bus.cpp @@ -74,7 +74,8 @@ unsigned IEC_Bus::gplev0; //ROTARY: Added for rotary encoder support - 09/05/2019 by Geo... RotaryEncoder IEC_Bus::rotaryEncoder; bool IEC_Bus::rotaryEncoderEnable; - +//ROTARY: Added for rotary encoder inversion (Issue#185) - 08/13/2020 by Geo... +bool IEC_Bus::rotaryEncoderInvert; void IEC_Bus::ReadGPIOUserInput( int buttonCount) { diff --git a/src/iec_bus.h b/src/iec_bus.h index 9d7059f..3665b87 100644 --- a/src/iec_bus.h +++ b/src/iec_bus.h @@ -366,7 +366,15 @@ public: //ROTARY: Added for rotary encoder support - 09/05/2019 by Geo... if (IEC_Bus::rotaryEncoderEnable == true) { - IEC_Bus::rotaryEncoder.Initialize(RPI_GPIO22, RPI_GPIO23, RPI_GPIO27); + //ROTARY: Added for rotary encoder inversion (Issue#185) - 08/13/2020 by Geo... + if (IEC_Bus::rotaryEncoderInvert == true) + { + IEC_Bus::rotaryEncoder.Initialize(RPI_GPIO23, RPI_GPIO22, RPI_GPIO27); + } + else + { + IEC_Bus::rotaryEncoder.Initialize(RPI_GPIO22, RPI_GPIO23, RPI_GPIO27); + } } } @@ -661,6 +669,12 @@ public: rotaryEncoderEnable = value; } + //ROTARY: Added for rotary encoder inversion (Issue#185) - 08/13/2020 by Geo... + static inline void SetRotaryEncoderInvert(bool value) + { + rotaryEncoderInvert = value; + } + // CA1 input ATN // If CA1 is ever set to output // - CA1 will start to drive pb7 @@ -728,6 +742,8 @@ private: //ROTARY: Added for rotary encoder support - 09/05/2019 by Geo... static RotaryEncoder rotaryEncoder; static bool rotaryEncoderEnable; + //ROTARY: Added for rotary encoder inversion (Issue#185) - 08/13/2020 by Geo... + static bool rotaryEncoderInvert; }; #endif diff --git a/src/main.cpp b/src/main.cpp index 77dcfac..c8e32f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1940,6 +1940,8 @@ extern "C" IEC_Bus::SetIgnoreReset(options.IgnoreReset()); //ROTARY: Added for rotary encoder support - 09/05/2019 by Geo... IEC_Bus::SetRotaryEncoderEnable(options.RotaryEncoderEnable()); + //ROTARY: Added for rotary encoder inversion (Issue#185) - 08/13/2020 by Geo... + IEC_Bus::SetRotaryEncoderInvert(options.RotaryEncoderInvert()); #if not defined(EXPERIMENTALZERO) if (!options.SoundOnGPIO()) { diff --git a/src/options.cpp b/src/options.cpp index 4d409d9..2774263 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -159,7 +159,7 @@ Options::Options(void) , buttonBack(4) , buttonInsert(5) , rotaryEncoderEnable(0) //ROTARY: - + , rotaryEncoderInvert(0) //ROTARY: { autoMountImageName[0] = 0; strcpy(ROMFontName, "chargen"); @@ -251,6 +251,7 @@ void Options::Process(char* buffer) ELSE_CHECK_DECIMAL_OPTION(buttonBack) ELSE_CHECK_DECIMAL_OPTION(buttonInsert) ELSE_CHECK_DECIMAL_OPTION(rotaryEncoderEnable) //ROTARY: + ELSE_CHECK_DECIMAL_OPTION(rotaryEncoderInvert) //ROTARY: else if ((strcasecmp(pOption, "AutoBaseName") == 0)) { strncpy(autoBaseName, pValue, 255); diff --git a/src/options.h b/src/options.h index 374dda0..889e4b9 100644 --- a/src/options.h +++ b/src/options.h @@ -109,6 +109,8 @@ public: //ROTARY: Added for rotary encoder support - 09/05/2019 by Geo... inline unsigned int RotaryEncoderEnable() const { return rotaryEncoderEnable; } + //ROTARY: Added for rotary encoder inversion (Issue#185) - 08/13/2020 by Geo... + inline unsigned int RotaryEncoderInvert() const { return rotaryEncoderInvert; } // Page up and down will jump a different amount based on the maximum number rows displayed. // Perhaps we should use some keyboard modifier to the the other screen? @@ -191,6 +193,8 @@ private: //ROTARY: Added for rotary encoder support - 09/05/2019 by Geo... unsigned int rotaryEncoderEnable; + //ROTARY: Added for rotary encoder inversion (Issue#185) - 08/13/2020 by Geo... + unsigned int rotaryEncoderInvert; }; #endif From 91a213132ade2761d4a13b1a6897d32d00d3b22b Mon Sep 17 00:00:00 2001 From: George Belmont Date: Fri, 14 Aug 2020 08:17:25 -0400 Subject: [PATCH 2/2] Fixed options.txt to leave RotaryEncoderEnable and RotaryEncoderInvert turned off by default. --- options.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/options.txt b/options.txt index c3cd196..551eaf2 100644 --- a/options.txt +++ b/options.txt @@ -135,8 +135,8 @@ GraphIEC = 1 // Updated to address issue #185 and allow for inversion of rotary operation // for certain encoders. - 08/13/2020 by Geo... // -RotaryEncoderEnable = 1 -RotaryEncoderInvert = 1 +//RotaryEncoderEnable = 1 +//RotaryEncoderInvert = 1 // This option will display the temperature of the Pi's CPU. // It should be about 52�C anything above 65�C is bad and there is something wrong with your hardware