Skip to content

Commit e521ddb

Browse files
committed
#41 improvements to keyboard support
1 parent f83c9e2 commit e521ddb

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

examples/keyboardEthernetShield/keyboardEthernetShield.emf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"lastEdited": {
3-
"seconds": 1585206203,
3+
"seconds": 1585213908,
44
"nanos": 0
55
},
66
"codeOptions": {

src/tcMenuKeyboard.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "BaseRenderers.h"
77
#include "tcMenuKeyboard.h"
88
#include <IoLogging.h>
9+
#include "EditableLargeNumberMenuItem.h"
910

1011
/**
1112
* this makes the index based selections feel more natural
@@ -38,6 +39,10 @@ void MenuEditingKeyListener::keyPressed(char key, bool held) {
3839
else if (editor->getMenuType() == MENUTYPE_TEXT_VALUE) {
3940
processMultiEditKeyPress(reinterpret_cast<TextMenuItem*>(editor), key);
4041
}
42+
else if (editor->getMenuType() == MENUTYPE_LARGENUM_VALUE) {
43+
processLargeNumberPress(reinterpret_cast<EditableLargeNumberMenuItem*>(editor), key);
44+
45+
}
4146
else if (isMenuRuntimeMultiEdit(editor)) {
4247
processIntegerMultiEdit(reinterpret_cast<EditableMultiPartMenuItem<byte[4]>*>(editor), key);
4348
}
@@ -156,6 +161,17 @@ void MenuEditingKeyListener::processAnalogKeyPress(AnalogMenuItem* item, char ke
156161
item->setFromWholeAndFraction(currentValue);
157162
}
158163

164+
void MenuEditingKeyListener::processLargeNumberPress(EditableLargeNumberMenuItem* item, char key) {
165+
if(key >= '0' && key <= '9') {
166+
item->valueChanged(key - '0');
167+
if (!item->nextPart()) {
168+
clearState();
169+
item->setEditing(false);
170+
}
171+
}
172+
173+
}
174+
159175
void MenuEditingKeyListener::processMultiEditKeyPress(TextMenuItem* item, char key) {
160176
item->valueChanged(findPositionInEditorSet(key));
161177
if (!item->nextPart()) {

src/tcMenuKeyboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ enum MenuEditingKeyMode: byte {
2121
KEYEDIT_MULTIEDIT_INT_START = 100,
2222
};
2323

24+
class EditableLargeNumberMenuItem;
25+
2426
/**
2527
* An implementation of the key listener that can be used with TcMenu to edit menu items and control
2628
* the menu. When not in edit mode, the keyboard 0-9 keys can be used to select menu items. Pressing
@@ -50,6 +52,7 @@ class MenuEditingKeyListener : public KeyboardListener {
5052
void processAnalogKeyPress(AnalogMenuItem* item, char key);
5153
void processMultiEditKeyPress(TextMenuItem* item, char key);
5254
void processIntegerMultiEdit(EditableMultiPartMenuItem<byte[4]>* item, char key);
55+
void processLargeNumberPress(EditableLargeNumberMenuItem*, char key);
5356
void clearState();
5457
};
5558

0 commit comments

Comments
 (0)