Skip to content

Commit 18a9f18

Browse files
committed
#51 improved support for keyboards. More testing.
1 parent 76c5310 commit 18a9f18

File tree

9 files changed

+232
-390
lines changed

9 files changed

+232
-390
lines changed

examples/dynamicMenuItems/dynamicMenuItems.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Test environment: Seeed MG126 - Adafruit 128x128 display, encoder on device pins.
66
*
7-
* Although it's set up to run on SAMD/MKR there is no reason it could not be easily reconfigured for any
7+
* Although it's set up to run on SAMD there is no reason it could not be easily reconfigured for any
88
* other board.
99
*/
1010

examples/keyboardEthernetShield/keyboardEthernetShield.emf

Lines changed: 104 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@
433433
"codeOptions": {
434434
"embeddedPlatform": "ARDUINO",
435435
"lastDisplayUuid": "61f370f4-0294-41cf-8988-1458f242914a",
436-
"lastInputUuid": "6dd87e7d-e751-4912-a70d-91793b1d3d87",
436+
"lastInputUuid": "71DAF854-DF8D-4F0B-9039-23C5583C85B1",
437437
"lastRemoteUuid": "0877131c-e03e-426b-8eaf-228e01f5e7f1",
438438
"lastRemoteUuids": [
439439
"0877131c-e03e-426b-8eaf-228e01f5e7f1"
@@ -508,50 +508,135 @@
508508
"subsystem": "DISPLAY"
509509
},
510510
{
511-
"name": "SW_POLLING_MODE",
512-
"latestValue": "SWITCHES_POLL_EVERYTHING",
511+
"name": "MK_KEYBOARD_NEXT",
512+
"latestValue": "B",
513513
"subsystem": "INPUT"
514514
},
515515
{
516-
"name": "SWITCH_IODEVICE",
517-
"latestValue": "io23017",
516+
"name": "MK_KEYBOARD_BACK",
517+
"latestValue": "A",
518518
"subsystem": "INPUT"
519519
},
520520
{
521-
"name": "ENCODER_PIN_A",
522-
"latestValue": "6",
521+
"name": "MK_KEYBOARD_ENTER",
522+
"latestValue": "*",
523523
"subsystem": "INPUT"
524524
},
525525
{
526-
"name": "ENCODER_PIN_B",
527-
"latestValue": "7",
526+
"name": "MK_KEYBOARD_DEL",
527+
"latestValue": "#",
528528
"subsystem": "INPUT"
529529
},
530530
{
531-
"name": "ENCODER_PIN_OK",
532-
"latestValue": "5",
531+
"name": "MK_KEYBOARD_LAYOUT",
532+
"latestValue": "LAYOUT_3X4",
533533
"subsystem": "INPUT"
534534
},
535535
{
536-
"name": "ENCODER_BACK_PIN",
537-
"latestValue": "-1",
536+
"name": "MK_ROW_PIN_0",
537+
"latestValue": "22",
538+
"subsystem": "INPUT"
539+
},
540+
{
541+
"name": "MK_ROW_PIN_1",
542+
"latestValue": "23",
543+
"subsystem": "INPUT"
544+
},
545+
{
546+
"name": "MK_ROW_PIN_2",
547+
"latestValue": "24",
548+
"subsystem": "INPUT"
549+
},
550+
{
551+
"name": "MK_ROW_PIN_3",
552+
"latestValue": "25",
553+
"subsystem": "INPUT"
554+
},
555+
{
556+
"name": "MK_COL_PIN_0",
557+
"latestValue": "26",
558+
"subsystem": "INPUT"
559+
},
560+
{
561+
"name": "MK_COL_PIN_1",
562+
"latestValue": "27",
538563
"subsystem": "INPUT"
539564
},
540565
{
541-
"name": "ENCODER_NEXT_PIN",
566+
"name": "MK_COL_PIN_2",
567+
"latestValue": "28",
568+
"subsystem": "INPUT"
569+
},
570+
{
571+
"name": "MK_COL_PIN_3",
542572
"latestValue": "-1",
543573
"subsystem": "INPUT"
544574
},
545575
{
546-
"name": "PULLUP_LOGIC",
547-
"latestValue": "true",
576+
"name": "MK_REPEAT_START",
577+
"latestValue": "850",
548578
"subsystem": "INPUT"
549579
},
550580
{
551-
"name": "ENCODER_IS_QUARTER_CYCLE",
581+
"name": "MK_REPEAT_INTERVAL",
582+
"latestValue": "350",
583+
"subsystem": "INPUT"
584+
},
585+
{
586+
"name": "MK_KEYBOARD_DEVICE",
587+
"latestValue": "devicePins",
588+
"subsystem": "INPUT"
589+
},
590+
{
591+
"name": "MK_KEYBOARD_INTERRUPTS",
552592
"latestValue": "false",
553593
"subsystem": "INPUT"
554594
},
595+
{
596+
"name": "SEPARATOR",
597+
"latestValue": "",
598+
"subsystem": "INPUT"
599+
},
600+
{
601+
"name": "MK_NEED_ENCODER",
602+
"latestValue": "true",
603+
"subsystem": "INPUT"
604+
},
605+
{
606+
"name": "MK_USE_PULL_UP",
607+
"latestValue": "true",
608+
"subsystem": "INPUT"
609+
},
610+
{
611+
"name": "MK_ENCODER_A",
612+
"latestValue": "6",
613+
"subsystem": "INPUT"
614+
},
615+
{
616+
"name": "MK_ENCODER_B",
617+
"latestValue": "7",
618+
"subsystem": "INPUT"
619+
},
620+
{
621+
"name": "MK_ENCODER_SEL",
622+
"latestValue": "5",
623+
"subsystem": "INPUT"
624+
},
625+
{
626+
"name": "MK_ENCODER_DEVICE",
627+
"latestValue": "io23017",
628+
"subsystem": "INPUT"
629+
},
630+
{
631+
"name": "MK_POLLING_MODE",
632+
"latestValue": "SWITCHES_NO_POLLING",
633+
"subsystem": "INPUT"
634+
},
635+
{
636+
"name": "MK_ENCODER_TYPE",
637+
"latestValue": "FULL_CYCLE",
638+
"subsystem": "INPUT"
639+
},
555640
{
556641
"name": "ETH_CONCURRENT_CONNECTIONS",
557642
"latestValue": "2",
@@ -620,6 +705,7 @@
620705
"menuInMenuCollection": {
621706
"menuDefinitions": []
622707
},
623-
"packageNamespace": ""
708+
"packageNamespace": "",
709+
"appIsModular": false
624710
}
625711
}

examples/keyboardEthernetShield/keyboardEthernetShield.ino

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* This script demonstrates the use of a matrix keyboard with a rotary encoder also attached, this allows for the
3+
* best of both worlds where the encoder is used for rotational type editing, and the keyboard where it is appropriate.
4+
* This sketch is setup for MEGA2560 AVR with a 20x4 LCD on I2C and also an encoder on I2C. It also assumes an I2C ROM.
5+
* However, you can take the ideas from this sketch and apply them in your own designs.
6+
*
7+
* More information about matrix keyboard support:
8+
* https://www.thecoderscorner.com/products/arduino-libraries/io-abstraction/matrix-keyboard-keypad-manager/
9+
10+
*/
111
#include "keyboardEthernetShield_menu.h"
212
#include <IoAbstractionWire.h>
313
#include <RemoteAuthentication.h>
@@ -21,44 +31,6 @@ const char pgmListPressed[] PROGMEM = "List Item Pressed";
2131
const char pgmHeaderSavedItem[] PROGMEM = "Saved Item";
2232
const char * romSpaceNames = "item 01item 02item 03item 04item 05item 06item 07item 08item 09item 10 ";
2333

24-
//
25-
// Here we add the keyboard components to the menu. For more general documentation of keyboards
26-
// https://www.thecoderscorner.com/products/arduino-libraries/io-abstraction/matrix-keyboard-keypad-manager/
27-
//
28-
29-
// First we create a standard layout, in this case the 3x4 layout but there's also a 4x4 one
30-
// You can also generate your own layouts for this. The class is KeyboardLayout.
31-
MAKE_KEYBOARD_LAYOUT_3X4(keyboardLayout)
32-
//MAKE_KEYBOARD_LAYOUT_4X4(keyboardLayout)
33-
34-
// The matrix keyboard manager itself, looks after the keyboard, notifies of changes etc.
35-
MatrixKeyboardManager keyboard;
36-
37-
// This is the tcMenu standard keyboard listener. It allows control of the menu by keyboard
38-
// You could also write your own keyboard interface if this didn't work as expected for you.
39-
MenuEditingKeyListener menuKeyListener;
40-
41-
// end keyboard components
42-
43-
//
44-
// This function is called by setup() further down to initialise the keyboard.
45-
//
46-
void setupKeyboard() {
47-
// set up the pin mappings.
48-
keyboardLayout.setRowPin(0, 22);
49-
keyboardLayout.setRowPin(1, 23);
50-
keyboardLayout.setRowPin(2, 24);
51-
keyboardLayout.setRowPin(3, 25);
52-
keyboardLayout.setColPin(0, 26);
53-
keyboardLayout.setColPin(1, 27);
54-
keyboardLayout.setColPin(2, 28);
55-
56-
// initialise and set the repeat key intervals.
57-
keyboard.initialise(ioUsingArduino(), &keyboardLayout, &menuKeyListener);
58-
keyboard.setRepeatKeyMillis(850, 350);
59-
60-
}
61-
6234
//
6335
// Creating a grid layout just for a specific menu item. The flags menu under additional is laid out in a grid format,
6436
// where the menu items are presented two per row.
@@ -104,8 +76,6 @@ void setup() {
10476
authenticator->resetAllKeys();
10577
}
10678

107-
setupKeyboard();
108-
10979
// here we use the EEPROM to load back the last set of values.
11080
menuMgr.load(0xf8f3);
11181

0 commit comments

Comments
 (0)