Skip to content

Commit 527f8c8

Browse files
committed
Tidy up examples and ensure NUM lock with SHIFT correct action
1 parent af6c05f commit 527f8c8

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

examples/KeyToLCD/KeyToLCD.ino

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ Also example of strings and string array in flash memory
104104
#define RS 12
105105
#define ENA 11
106106
#define RW 10
107-
#define D7 7
107+
#define D7 9
108108
#define D6 8
109-
#define D5 9
110-
#define D4 10
109+
#define D5 7
110+
#define D4 6
111111

112112
/* LCD Constants to match your display */
113113
/* Columns in display */
@@ -123,10 +123,11 @@ int8_t rows = 0;
123123
/* Key codes and strings for keys producing a string */
124124
/* three arrays in same order ( keycode, string to display, length of string ) */
125125
#if defined(ARDUINO_ARCH_AVR)
126-
const uint8_t codes[] PROGMEM = { PS2_KEY_TAB, PS2_KEY_ESC, PS2_KEY_DELETE,
126+
const uint8_t codes[] PROGMEM = { PS2_KEY_SPACE, PS2_KEY_TAB, PS2_KEY_ESC, PS2_KEY_DELETE,
127127
PS2_KEY_F1, PS2_KEY_F2, PS2_KEY_F3, PS2_KEY_F4,
128128
PS2_KEY_F5, PS2_KEY_F6, PS2_KEY_F7, PS2_KEY_F8,
129129
PS2_KEY_F9, PS2_KEY_F10, PS2_KEY_F11, PS2_KEY_F12 };
130+
const char spacestr[] PROGMEM = " ";
130131
const char tabstr[] PROGMEM = "[Tab]";
131132
const char escstr[] PROGMEM = "[ESC]";
132133
const char delstr[] PROGMEM = "[Del]";
@@ -143,20 +144,25 @@ const char f10str[] PROGMEM = "[F10]";
143144
const char f11str[] PROGMEM = "[F11]";
144145
const char f12str[] PROGMEM = "[F12]";
145146

146-
const int8_t sizes[] PROGMEM = { 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5 };
147+
// Due to AVR Harvard architecture array of string pointers to actual strings
147148
const char *const keys[] PROGMEM = {
148-
tabstr, escstr, delstr, f1str, f2str, f3str,
149-
f4str, f5str, f6str, f7str, f8str,
149+
spacestr, tabstr, escstr, delstr, f1str, f2str,
150+
f3str, f4str, f5str, f6str, f7str, f8str,
150151
f9str, f10str, f11str, f12str };
152+
const int8_t sizes[] PROGMEM = { 1, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5 };
151153
char buffer[ 8 ];
154+
152155
#elif defined(ARDUINO_ARCH_SAM)
153-
const uint8_t codes[] = { PS2_KEY_TAB, PS2_KEY_ESC, PS2_KEY_DELETE, PS2_KEY_F1, PS2_KEY_F2,
154-
PS2_KEY_F3, PS2_KEY_F4, PS2_KEY_F5, PS2_KEY_F6, PS2_KEY_F7,
155-
PS2_KEY_F8, PS2_KEY_F9, PS2_KEY_F10, PS2_KEY_F11, PS2_KEY_F12 };
156-
const char *const keys[] = { "[Tab]", "[ESC]", "[Del]", "[F1]", "[F2]", "[F3]",
156+
const uint8_t codes[] = { PS2_KEY_SPACE, PS2_KEY_TAB, PS2_KEY_ESC,
157+
PS2_KEY_DELETE, PS2_KEY_F1, PS2_KEY_F2, PS2_KEY_F3,
158+
PS2_KEY_F4, PS2_KEY_F5, PS2_KEY_F6, PS2_KEY_F7,
159+
PS2_KEY_F8, PS2_KEY_F9, PS2_KEY_F10, PS2_KEY_F11,
160+
PS2_KEY_F12 };
161+
const char *const keys[] = { " ", "[Tab]", "[ESC]", "[Del]", "[F1]", "[F2]", "[F3]",
157162
"[F4]", "[F5]", "[F6]", "[F7]", "[F8]",
158163
"[F9]", "[F10]", "[F11]", "[F12]" };
159-
const int8_t sizes[] = { 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5 };
164+
const int8_t sizes[] = { 1, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5 };
165+
160166
#else
161167
#error “This library only supports boards with an AVR or SAM processor.”
162168
#endif
@@ -231,6 +237,7 @@ if( keyboard.available() )
231237
switch( c ) /* Cursor movements */
232238
{
233239
case PS2_KEY_ENTER: /* Cursor to beginning of next line or start */
240+
case PS2_KEY_KP_ENTER:
234241
cols = 0;
235242
rows++;
236243
if( rows >= MAX_ROW )

src/PS2KeyAdvanced.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,9 @@ if( retdata > 0 )
760760
PS2_keystatus |= index;
761761
}
762762
else
763-
// Numeric keypad ONLY works in numlock state
763+
// Numeric keypad ONLY works in numlock state or when _SHIFT status
764764
if( retdata >= PS2_KEY_KP0 && retdata <= PS2_KEY_KP_DOT )
765-
if( !( PS2_led_lock & PS2_LOCK_NUM ) )
765+
if( !( PS2_led_lock & PS2_LOCK_NUM ) || ( PS2_keystatus & _SHIFT ) )
766766
#if defined(ARDUINO_ARCH_AVR)
767767
retdata = pgm_read_byte( &scroll_remap[ retdata - PS2_KEY_KP0 ] );
768768
#elif defined(ARDUINO_ARCH_SAM)

0 commit comments

Comments
 (0)