diff --git a/src/config.cpp b/src/config.cpp index 85ad9ed..afa3f27 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -96,6 +96,7 @@ void CConfig::Load (void) m_bEncoderEnabled = m_Properties.GetNumber ("EncoderEnabled", 0) != 0; m_nEncoderPinClock = m_Properties.GetNumber ("EncoderPinClock", 10); m_nEncoderPinData = m_Properties.GetNumber ("EncoderPinData", 9); + m_nEncoderPinSwitch = m_Properties.GetNumber ("EncoderPinSwitch", 11); m_bMIDIDumpEnabled = m_Properties.GetNumber ("MIDIDumpEnabled", 0) != 0; m_bProfileEnabled = m_Properties.GetNumber ("ProfileEnabled", 0) != 0; @@ -256,6 +257,11 @@ unsigned CConfig::GetEncoderPinData (void) const return m_nEncoderPinData; } +unsigned CConfig::GetEncoderPinSwitch (void) const +{ + return m_nEncoderPinSwitch; +} + bool CConfig::GetMIDIDumpEnabled (void) const { return m_bMIDIDumpEnabled; diff --git a/src/config.h b/src/config.h index c9e72d2..6c11bf1 100644 --- a/src/config.h +++ b/src/config.h @@ -108,6 +108,7 @@ public: bool GetEncoderEnabled (void) const; unsigned GetEncoderPinClock (void) const; unsigned GetEncoderPinData (void) const; + unsigned GetEncoderPinSwitch (void) const; // Debug bool GetMIDIDumpEnabled (void) const; @@ -152,6 +153,7 @@ private: bool m_bEncoderEnabled; unsigned m_nEncoderPinClock; unsigned m_nEncoderPinData; + unsigned m_nEncoderPinSwitch; bool m_bMIDIDumpEnabled; bool m_bProfileEnabled; diff --git a/src/minidexed.ini b/src/minidexed.ini index 82a7c91..9723a1a 100644 --- a/src/minidexed.ini +++ b/src/minidexed.ini @@ -44,6 +44,7 @@ ButtonActionHome=longpress EncoderEnabled=1 EncoderPinClock=10 EncoderPinData=9 +EncoderPinSwitch=11 # Debug MIDIDumpEnabled=0 diff --git a/src/userinterface.cpp b/src/userinterface.cpp index cf7c1f2..5836dc2 100644 --- a/src/userinterface.cpp +++ b/src/userinterface.cpp @@ -36,6 +36,7 @@ CUserInterface::CUserInterface (CMiniDexed *pMiniDexed, CGPIOManager *pGPIOManag m_pLCDBuffered (0), m_pUIButtons (0), m_pRotaryEncoder (0), + m_bSwitchPressed (false), m_Menu (this, pMiniDexed) { } @@ -109,12 +110,9 @@ bool CUserInterface::Initialize (void) if (m_pConfig->GetEncoderEnabled ()) { - // NOTE: There is no way to disable the switch pin with this driver - // so I have set it to 0 which is a reserved pin used by pi hats. - // Even if this pin triggers it shouldn't cause any real issues. m_pRotaryEncoder = new CKY040 (m_pConfig->GetEncoderPinClock (), m_pConfig->GetEncoderPinData (), - 0, + m_pConfig->GetEncoderPinSwitch (), m_pGPIOManager); assert (m_pRotaryEncoder); @@ -217,12 +215,43 @@ void CUserInterface::EncoderEventHandler (CKY040::TEvent Event) { switch (Event) { + case CKY040::EventSwitchDown: + m_bSwitchPressed = true; + break; + + case CKY040::EventSwitchUp: + m_bSwitchPressed = false; + break; + case CKY040::EventClockwise: - m_Menu.EventHandler (CUIMenu::MenuEventStepUp); + m_Menu.EventHandler (m_bSwitchPressed ? CUIMenu::MenuEventPressAndStepUp + : CUIMenu::MenuEventStepUp); break; case CKY040::EventCounterclockwise: - m_Menu.EventHandler (CUIMenu::MenuEventStepDown); + m_Menu.EventHandler (m_bSwitchPressed ? CUIMenu::MenuEventPressAndStepDown + : CUIMenu::MenuEventStepDown); + break; + + case CKY040::EventSwitchClick: + m_Menu.EventHandler (CUIMenu::MenuEventBack); + break; + + case CKY040::EventSwitchDoubleClick: + m_Menu.EventHandler (CUIMenu::MenuEventSelect); + break; + + case CKY040::EventSwitchTripleClick: + m_Menu.EventHandler (CUIMenu::MenuEventHome); + break; + + case CKY040::EventSwitchHold: + if (m_pRotaryEncoder->GetHoldSeconds () >= 120) + { + delete m_pLCD; // reset LCD + + reboot (); + } break; default: diff --git a/src/userinterface.h b/src/userinterface.h index 4a31fa0..202872a 100644 --- a/src/userinterface.h +++ b/src/userinterface.h @@ -71,6 +71,7 @@ private: CUIButtons *m_pUIButtons; CKY040 *m_pRotaryEncoder; + bool m_bSwitchPressed; CUIMenu m_Menu; };