Added configuration for buttons debounce time

pull/793/head
Javier Nonis 4 weeks ago
parent ec837532fe
commit cc5acfbd50
  1. 6
      src/config.cpp
  2. 2
      src/config.h
  3. 3
      src/minidexed.ini
  4. 12
      src/uibuttons.cpp
  5. 7
      src/uibuttons.h

@ -161,6 +161,7 @@ void CConfig::Load (void)
m_nDoubleClickTimeout = m_Properties.GetNumber ("DoubleClickTimeout", 400);
m_nLongPressTimeout = m_Properties.GetNumber ("LongPressTimeout", 600);
m_nButtonsDebounceTime = m_Properties.GetNumber ("ButtonsDebounceTime", 60);
m_nButtonPinPgmUp = m_Properties.GetNumber ("ButtonPinPgmUp", 0);
m_nButtonPinPgmDown = m_Properties.GetNumber ("ButtonPinPgmDown", 0);
@ -557,6 +558,11 @@ unsigned CConfig::GetLongPressTimeout (void) const
return m_nLongPressTimeout;
}
unsigned CConfig::GetButtonsDebounceTime(void) const
{
return m_nButtonsDebounceTime;
}
unsigned CConfig::GetButtonPinPgmUp (void) const
{
return m_nButtonPinPgmUp;

@ -190,6 +190,7 @@ public:
// Timeouts for button events in milliseconds
unsigned GetDoubleClickTimeout (void) const;
unsigned GetLongPressTimeout (void) const;
unsigned GetButtonsDebounceTime (void) const;
// GPIO Button Program and TG Selection
// GPIO pin numbers are chip numbers, not header positions
@ -329,6 +330,7 @@ private:
unsigned m_nDoubleClickTimeout;
unsigned m_nLongPressTimeout;
unsigned m_nButtonsDebounceTime;
unsigned m_nMIDIButtonCh;
unsigned m_nMIDIButtonNotes;

@ -114,6 +114,9 @@ ButtonActionTGDown=
DoubleClickTimeout=400
LongPressTimeout=400
# Buttons debounce time
# ButtonsDebounceTime=60
# MIDI Button Navigation
# Specify MIDI CC to act as a button (0 = ununsed, so don't use CC 0)
# NB: Off < 64 < ON

@ -59,7 +59,7 @@ void CUIButton::reset (void)
m_numClicks = 0;
}
boolean CUIButton::Initialize (unsigned pinNumber, unsigned doubleClickTimeout, unsigned longPressTimeout)
boolean CUIButton::Initialize (unsigned pinNumber, unsigned doubleClickTimeout, unsigned longPressTimeout, unsigned debounceTime)
{
assert (!m_pin);
assert(longPressTimeout >= doubleClickTimeout);
@ -67,10 +67,11 @@ boolean CUIButton::Initialize (unsigned pinNumber, unsigned doubleClickTimeout,
m_pinNumber = pinNumber;
m_doubleClickTimeout = doubleClickTimeout;
m_longPressTimeout = longPressTimeout;
m_debounceTime = debounceTime;
// Initialise timing values
m_timer = m_longPressTimeout;
m_debounceTimer = DEBOUNCE_TIME;
m_debounceTimer = m_debounceTime;
if (m_pinNumber != 0)
{
@ -151,7 +152,7 @@ CUIButton::BtnTrigger CUIButton::ReadTrigger (void)
}
// Debounce here - we don't need to do anything if the debounce timer is active
if (m_debounceTimer < DEBOUNCE_TIME) {
if (m_debounceTimer < m_debounceTime) {
m_debounceTimer++;
return BtnTriggerNone;
}
@ -275,6 +276,7 @@ boolean CUIButtons::Initialize (void)
// Read the button configuration
m_doubleClickTimeout = m_pConfig->GetDoubleClickTimeout ();
m_longPressTimeout = m_pConfig->GetLongPressTimeout ();
m_debounceTime = m_pConfig->GetButtonsDebounceTime ();
m_prevPin = m_pConfig->GetButtonPinPrev ();
m_prevAction = CUIButton::triggerTypeFromString( m_pConfig->GetButtonActionPrev ());
m_nextPin = m_pConfig->GetButtonPinNext ();
@ -386,7 +388,7 @@ boolean CUIButtons::Initialize (void)
}
else if (m_buttons[j].getPinNumber() == 0) {
// This is un-initialised so can be assigned
m_buttons[j].Initialize(pins[i], doubleClickTimeout, longPressTimeout);
m_buttons[j].Initialize(pins[i], doubleClickTimeout, longPressTimeout, m_debounceTime);
break;
}
}
@ -405,7 +407,7 @@ boolean CUIButtons::Initialize (void)
if (m_buttons[j].getPinNumber() == 0) {
// This is un-initialised so can be assigned
// doubleClickTimeout and longPressTimeout are ignored for MIDI buttons at present
m_buttons[j].Initialize(pins[i], doubleClickTimeout, longPressTimeout);
m_buttons[j].Initialize(pins[i], doubleClickTimeout, longPressTimeout, m_debounceTime);
break;
}
}

@ -26,7 +26,6 @@
#include "config.h"
#define BUTTONS_UPDATE_NUM_TICKS 100
#define DEBOUNCE_TIME 300
#define MAX_GPIO_BUTTONS 11 // 5 UI buttons, 6 Program/Bank/TG Select buttons
#define MAX_MIDI_BUTTONS 11
#define MAX_BUTTONS (MAX_GPIO_BUTTONS+MAX_MIDI_BUTTONS)
@ -65,7 +64,7 @@ public:
~CUIButton (void);
void reset (void);
boolean Initialize (unsigned pinNumber, unsigned doubleClickTimeout, unsigned longPressTimeout);
boolean Initialize (unsigned pinNumber, unsigned doubleClickTimeout, unsigned longPressTimeout, unsigned debounceTime);
void setClickEvent(BtnEvent clickEvent);
void setDoubleClickEvent(BtnEvent doubleClickEvent);
@ -92,6 +91,8 @@ private:
uint16_t m_timer;
// Debounce timer
uint16_t m_debounceTimer;
// Debounce time
unsigned m_debounceTime;
// Number of clicks recorded since last timer reset
uint8_t m_numClicks;
// Event to fire on click
@ -136,6 +137,8 @@ private:
unsigned m_doubleClickTimeout;
// Timeout for long press in tenths of a millisecond
unsigned m_longPressTimeout;
// Debounce time
unsigned m_debounceTime;
// Configuration for buttons
unsigned m_prevPin;

Loading…
Cancel
Save