Skip to content

Commit 3edd1be

Browse files
author
dave
committed
#218 allow switch frequency to be changed
1 parent cd484ce commit 3edd1be

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/SwitchInput.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ bool SwitchInput::addSwitchListener(pinid_t pin, SwitchListener* listener, uint8
175175
return keys.add(KeyboardItem(pin, listener, repeat, invertLogic));
176176
}
177177

178+
void SwitchInput::setRepeatInterval(pinid_t pin, uint8_t interval) {
179+
auto keyItem = keys.getByKey(pin);
180+
if(keyItem) {
181+
keyItem->setRepeatInterval(interval);
182+
}
183+
}
184+
178185
bool SwitchInput::internalAddSwitch(pinid_t pin, bool invertLogic) {
179186
if (ioDevice == nullptr) initialise(internalDigitalIo(), true);
180187

src/SwitchInput.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ class KeyboardItem {
163163

164164
void changeOnPressed(KeyCallbackFn pFunction);
165165
void changeListener(SwitchListener* listener);
166+
167+
void setRepeatInterval(uint8_t newInterval) { repeatInterval = newInterval;}
166168
};
167169

168170
/**
@@ -740,6 +742,14 @@ class SwitchInput {
740742
return keys.removeByKey(pin);
741743
}
742744

745+
/**
746+
* Allows for reconfiguration of the repeat key at runtime,
747+
* it uses the same repeat interval as when adding a switch.
748+
* @param pin the pin to reconfigure
749+
* @param interval the new interval - see add switch
750+
*/
751+
void setRepeatInterval(pinid_t pin, uint8_t interval);
752+
743753
private:
744754
bool internalAddSwitch(pinid_t pin, bool invertLogic);
745755

0 commit comments

Comments
 (0)