Skip to content

Commit

Permalink
Configurable GPIO buttons (#274)
Browse files Browse the repository at this point in the history
* Default behavior changed: Click to enter menus, long-press to leave menus, double-click to go to the home screen (configurable)
* Buttons can have click, double click and long press events
* Changed default config, added new options and renamed EncoderPinSwitch to ButtonPinShortcut

Co-authored-by: Kevin <diyelectromusic@gmail.com>
Co-authored-by: Stephen Brown <steve@fig14.com>
  • Loading branch information
3 people authored Jul 15, 2022
1 parent 0a5ec7d commit 50e9b7b
Show file tree
Hide file tree
Showing 10 changed files with 777 additions and 28 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ MiniDexed*
sdcard
*.zip
*.img

# Editor related files
*.swp
*.swo
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CMSIS_DIR = ../CMSIS_5/CMSIS
OBJS = main.o kernel.o minidexed.o config.o userinterface.o uimenu.o \
mididevice.o midikeyboard.o serialmididevice.o pckeyboard.o \
sysexfileloader.o performanceconfig.o perftimer.o \
effect_compressor.o effect_platervbstereo.o
effect_compressor.o effect_platervbstereo.o uibuttons.o

OPTIMIZE = -O3

Expand Down
87 changes: 81 additions & 6 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,25 @@ void CConfig::Load (void)
m_nLCDPinData7 = m_Properties.GetNumber ("LCDPinData7", 25);
m_nLCDI2CAddress = m_Properties.GetNumber ("LCDI2CAddress", 0);

m_nButtonPinPrev = m_Properties.GetNumber ("ButtonPinPrev", 0);
m_nButtonPinNext = m_Properties.GetNumber ("ButtonPinNext", 0);
m_nButtonPinBack = m_Properties.GetNumber ("ButtonPinBack", 11);
m_nButtonPinSelect = m_Properties.GetNumber ("ButtonPinSelect", 11);
m_nButtonPinHome = m_Properties.GetNumber ("ButtonPinHome", 11);
m_nButtonPinShortcut = m_Properties.GetNumber ("ButtonPinShortcut", 11);

m_ButtonActionPrev = m_Properties.GetString ("ButtonActionPrev", "");
m_ButtonActionNext = m_Properties.GetString ("ButtonActionNext", "");
m_ButtonActionBack = m_Properties.GetString ("ButtonActionBack", "doubleclick");
m_ButtonActionSelect = m_Properties.GetString ("ButtonActionSelect", "click");
m_ButtonActionHome = m_Properties.GetString ("ButtonActionHome", "longpress");

m_nDoubleClickTimeout = m_Properties.GetNumber ("DoubleClickTimeout", 400);
m_nLongPressTimeout = m_Properties.GetNumber ("LongPressTimeout", 600);

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;
Expand Down Expand Up @@ -180,6 +195,71 @@ unsigned CConfig::GetLCDI2CAddress (void) const
return m_nLCDI2CAddress;
}

unsigned CConfig::GetButtonPinPrev (void) const
{
return m_nButtonPinPrev;
}

unsigned CConfig::GetButtonPinNext (void) const
{
return m_nButtonPinNext;
}

unsigned CConfig::GetButtonPinBack (void) const
{
return m_nButtonPinBack;
}

unsigned CConfig::GetButtonPinSelect (void) const
{
return m_nButtonPinSelect;
}

unsigned CConfig::GetButtonPinHome (void) const
{
return m_nButtonPinHome;
}

unsigned CConfig::GetButtonPinShortcut (void) const
{
return m_nButtonPinShortcut;
}

const char *CConfig::GetButtonActionPrev (void) const
{
return m_ButtonActionPrev.c_str();
}

const char *CConfig::GetButtonActionNext (void) const
{
return m_ButtonActionNext.c_str();
}

const char *CConfig::GetButtonActionBack (void) const
{
return m_ButtonActionBack.c_str();
}

const char *CConfig::GetButtonActionSelect (void) const
{
return m_ButtonActionSelect.c_str();
}

const char *CConfig::GetButtonActionHome (void) const
{
return m_ButtonActionHome.c_str();
}

unsigned CConfig::GetDoubleClickTimeout (void) const
{
return m_nDoubleClickTimeout;
}

unsigned CConfig::GetLongPressTimeout (void) const
{
return m_nLongPressTimeout;
}

bool CConfig::GetEncoderEnabled (void) const
{
return m_bEncoderEnabled;
Expand All @@ -195,11 +275,6 @@ unsigned CConfig::GetEncoderPinData (void) const
return m_nEncoderPinData;
}

unsigned CConfig::GetEncoderPinSwitch (void) const
{
return m_nEncoderPinSwitch;
}

bool CConfig::GetMIDIDumpEnabled (void) const
{
return m_bMIDIDumpEnabled;
Expand Down
38 changes: 36 additions & 2 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,32 @@ class CConfig // Configuration for MiniDexed
unsigned GetLCDPinData6 (void) const;
unsigned GetLCDPinData7 (void) const;
unsigned GetLCDI2CAddress (void) const;

// GPIO Button Navigation
// GPIO pin numbers are chip numbers, not header positions
unsigned GetButtonPinPrev (void) const;
unsigned GetButtonPinNext (void) const;
unsigned GetButtonPinBack (void) const;
unsigned GetButtonPinSelect (void) const;
unsigned GetButtonPinHome (void) const;
unsigned GetButtonPinShortcut (void) const;

// Action type for buttons: "click", "doubleclick", "longpress", ""
const char *GetButtonActionPrev (void) const;
const char *GetButtonActionNext (void) const;
const char *GetButtonActionBack (void) const;
const char *GetButtonActionSelect (void) const;
const char *GetButtonActionHome (void) const;

// Timeouts for button events in milliseconds
unsigned GetDoubleClickTimeout (void) const;
unsigned GetLongPressTimeout (void) const;

// KY-040 Rotary Encoder
// GPIO pin numbers are chip numbers, not header positions
bool GetEncoderEnabled (void) const;
unsigned GetEncoderPinClock (void) const;
unsigned GetEncoderPinData (void) const;
unsigned GetEncoderPinSwitch (void) const;

// Debug
bool GetMIDIDumpEnabled (void) const;
Expand Down Expand Up @@ -122,11 +141,26 @@ class CConfig // Configuration for MiniDexed
unsigned m_nLCDPinData6;
unsigned m_nLCDPinData7;
unsigned m_nLCDI2CAddress;

unsigned m_nButtonPinPrev;
unsigned m_nButtonPinNext;
unsigned m_nButtonPinBack;
unsigned m_nButtonPinSelect;
unsigned m_nButtonPinHome;
unsigned m_nButtonPinShortcut;

std::string m_ButtonActionPrev;
std::string m_ButtonActionNext;
std::string m_ButtonActionBack;
std::string m_ButtonActionSelect;
std::string m_ButtonActionHome;

unsigned m_nDoubleClickTimeout;
unsigned m_nLongPressTimeout;

bool m_bEncoderEnabled;
unsigned m_nEncoderPinClock;
unsigned m_nEncoderPinData;
unsigned m_nEncoderPinSwitch;

bool m_bMIDIDumpEnabled;
bool m_bProfileEnabled;
Expand Down
2 changes: 1 addition & 1 deletion src/mididevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,6 @@ void CMIDIDevice::SendSystemExclusiveVoice(uint8_t nVoice, const unsigned nCable
for(Iterator = s_DeviceMap.begin(); Iterator != s_DeviceMap.end(); ++Iterator)
{
Iterator->second->Send (voicedump, sizeof(voicedump)*sizeof(uint8_t));
LOGDBG("Send SYSEX voice dump %u to \"%s\"",nVoice,Iterator->first.c_str());
// LOGDBG("Send SYSEX voice dump %u to \"%s\"",nVoice,Iterator->first.c_str());
}
}
20 changes: 19 additions & 1 deletion src/minidexed.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,29 @@ LCDPinData6=24
LCDPinData7=25
LCDI2CAddress=0x00

# GPIO Button Navigation
# Any buttons set to 0 will be ignored
ButtonPinPrev=0
ButtonActionPrev=
ButtonPinNext=0
ButtonActionNext=
ButtonPinBack=11
ButtonActionBack=longpress
ButtonPinSelect=11
ButtonActionSelect=click
ButtonPinHome=11
ButtonActionHome=doubleclick
ButtonPinShortcut=11
# (Shortcut doesn't have an action)

# Timeouts in milliseconds for double click and long press
DoubleClickTimeout=400
LongPressTimeout=400

# KY-040 Rotary Encoder
EncoderEnabled=1
EncoderPinClock=10
EncoderPinData=9
EncoderPinSwitch=11

# Debug
MIDIDumpEnabled=0
Expand Down
Loading

0 comments on commit 50e9b7b

Please sign in to comment.