Revert "Removed encoder button support"

This reverts commit c050e04db1.
pull/274/head
Stephen Brown 3 years ago
parent 37ad81b718
commit 1a9eddaf05
  1. 6
      src/config.cpp
  2. 2
      src/config.h
  3. 1
      src/minidexed.ini
  4. 41
      src/userinterface.cpp
  5. 1
      src/userinterface.h

@ -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;

@ -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;

@ -44,6 +44,7 @@ ButtonActionHome=longpress
EncoderEnabled=1
EncoderPinClock=10
EncoderPinData=9
EncoderPinSwitch=11
# Debug
MIDIDumpEnabled=0

@ -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:

@ -71,6 +71,7 @@ private:
CUIButtons *m_pUIButtons;
CKY040 *m_pRotaryEncoder;
bool m_bSwitchPressed;
CUIMenu m_Menu;
};

Loading…
Cancel
Save