Skip to content

Commit 0abe6c9

Browse files
committed
Configure for latest Arduino Library Manager versions
Tidy up conditionals for adding platforms Simplify examples
1 parent 5c4aeed commit 0abe6c9

File tree

7 files changed

+45
-86
lines changed

7 files changed

+45
-86
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
## This library requires PS2KeyAdvanced as well to work
55

6-
**V1.0.3** July 2018 Improved keywords file
6+
**V1.0.4** January 2020 Work better with new library manager spec and better
7+
additional platform possibilities
8+
9+
V1.0.3 July 2018 Improved keywords file
710

811
First Public Release Version V1.0.2
912

examples/International/International.ino

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,8 @@
7878

7979
/* Keyboard constants Change to suit your Arduino
8080
define pins used for data and clock from keyboard */
81-
//#define DATAPIN 4
82-
//#define IRQPIN 3
83-
#if defined(ARDUINO_ARCH_AVR)
84-
#define DATAPIN 19
85-
#define IRQPIN 18
86-
#elif defined(ARDUINO_ARCH_SAM)
87-
#define DATAPIN 14
88-
#define IRQPIN 15
89-
#endif
81+
#define DATAPIN 4
82+
#define IRQPIN 3
9083

9184
PS2KeyAdvanced keyboard;
9285
PS2KeyMap keymap;
@@ -98,21 +91,12 @@ uint8_t found;
9891
void setup()
9992
{
10093
Serial.begin( 115200 );
101-
#if defined(ARDUINO_ARCH_AVR)
102-
Serial.println( F( "PS2KeyMap plus PS2KeyAdvanced Libraries" ) );
103-
Serial.println( F( "International Keyboard Test:" ) );
104-
Serial.print( F( "Default is US layout, type a key to change layout\n"
105-
" U for US G for GB/UK\n" ) );
106-
Serial.println( F( " D for DE F for FR\n"
107-
" All keys on keyboard echoed here" ) );
108-
#elif defined(ARDUINO_ARCH_SAM)
10994
Serial.println( "PS2KeyMap plus PS2KeyAdvanced Libraries" );
11095
Serial.println( "International Keyboard Test:" );
11196
Serial.print( "Default is US layout, type a key to change layout\n"
11297
" U for US G for GB/UK\n" );
11398
Serial.println( " D for DE F for FR\n"
11499
" All keys on keyboard echoed here" );
115-
#endif
116100
// Start keyboard setup while outputting
117101
keyboard.begin( DATAPIN, IRQPIN );
118102
// Disable Break codes (key release) from PS2KeyAdvanced
@@ -128,28 +112,13 @@ code = keyboard.available();
128112
if( code > 0 )
129113
{
130114
code = keyboard.read();
131-
#if defined(ARDUINO_ARCH_AVR)
132-
Serial.print( F( "Value " ) );
133-
#elif defined(ARDUINO_ARCH_SAM)
134115
Serial.print( "Value " );
135-
#endif
136116
Serial.print( code, HEX );
137117
code = keymap.remapKey( code );
138118
if( code > 0 )
139119
{
140120
if( ( code & 0xFF ) )
141121
{
142-
#if defined(ARDUINO_ARCH_AVR)
143-
Serial.print( F( " mapped " ) );
144-
Serial.print( code, HEX );
145-
Serial.print( F( " - Status Bits " ) );
146-
Serial.print( code >> 8, HEX );
147-
Serial.print( F( " Code " ) );
148-
Serial.print( code & 0xFF, HEX );
149-
Serial.print( F( " ( " ) );
150-
Serial.write( code & 0xFF );
151-
Serial.print( F( " )\n" ) );
152-
#elif defined(ARDUINO_ARCH_SAM)
153122
Serial.print( " mapped " );
154123
Serial.print( code, HEX );
155124
Serial.print( " - Status Bits " );
@@ -159,7 +128,6 @@ if( code > 0 )
159128
Serial.print( " ( " );
160129
Serial.write( code & 0xFF );
161130
Serial.print( " )\n" );
162-
#endif
163131
}
164132
// process special commands
165133
found = 0;
@@ -184,20 +152,12 @@ if( code > 0 )
184152
}
185153
if( found )
186154
{
187-
#if defined(ARDUINO_ARCH_AVR)
188-
Serial.print( F( "Keyboard set to " ) );
189-
#elif defined(ARDUINO_ARCH_SAM)
190155
Serial.print( "Keyboard set to " );
191-
#endif
192156
Serial.println( keymap.getMap( ) );
193157
}
194158
}
195159
else
196-
#if defined(ARDUINO_ARCH_AVR)
197-
Serial.println( F( " Keyboard protocol or function" ) );
198-
#elif defined(ARDUINO_ARCH_SAM)
199160
Serial.println( " Keyboard protocol or function" );
200-
#endif
201161
}
202162
delay( 100 );
203163
}

examples/KeyToLCD/KeyToLCD.ino

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@
118118
#define D5 7
119119
#define D4 6
120120

121-
/* LCD Constants to match your display */
121+
/* LCD Constants to match your display 16 x 2 */
122122
/* Columns in display */
123123
#define MAX_COL 16
124124
/* Rows in display */
125125
#define MAX_ROW 2
126126

127-
/* LCD Constants to match your display */
127+
/* LCD Constants to match your display 20 x 4 */
128128
/* Columns in display */
129-
#define MAX_COL 20
129+
//#define MAX_COL 20
130130
/* Rows in display */
131-
#define MAX_ROW 4
131+
//#define MAX_ROW 4
132132

133133
/* current cursor position */
134134
signed char cols = 0;
@@ -137,7 +137,7 @@ signed char rows = 0;
137137
/* messages constants */
138138
/* Key codes and strings for keys producing a string */
139139
/* three arrays in same order ( keycode, string to display, length of string ) */
140-
#if defined(ARDUINO_ARCH_AVR)
140+
#if defined(PS2_REQUIRES_PROGMEM)
141141
const uint8_t codes[] PROGMEM = { PS2_KEY_SPACE, PS2_KEY_TAB, PS2_KEY_ESC, PS2_KEY_DELETE,
142142
PS2_KEY_F1, PS2_KEY_F2, PS2_KEY_F3, PS2_KEY_F4,
143143
PS2_KEY_F5, PS2_KEY_F6, PS2_KEY_F7, PS2_KEY_F8,
@@ -167,7 +167,7 @@ const char *const keys[] PROGMEM = {
167167
const int8_t sizes[] PROGMEM = { 1, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5 };
168168
char buffer[ 8 ];
169169

170-
#elif defined(ARDUINO_ARCH_SAM)
170+
#else
171171
const uint8_t codes[] = { PS2_KEY_SPACE, PS2_KEY_TAB, PS2_KEY_ESC,
172172
PS2_KEY_DELETE, PS2_KEY_F1, PS2_KEY_F2, PS2_KEY_F3,
173173
PS2_KEY_F4, PS2_KEY_F5, PS2_KEY_F6, PS2_KEY_F7,
@@ -177,12 +177,9 @@ const char *const keys[] = { " ", "[Tab]", "[ESC]", "[Del]", "[F1]", "[F2]", "
177177
"[F4]", "[F5]", "[F6]", "[F7]", "[F8]",
178178
"[F9]", "[F10]", "[F11]", "[F12]" };
179179
const int8_t sizes[] = { 1, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5 };
180-
181-
#else
182-
#error “This library only supports boards with an AVR or SAM processor.”
183180
#endif
184181

185-
// Class initialisation/instanciation
182+
// Class initialisation/instantiation
186183
// keyboard library
187184
PS2KeyAdvanced keyboard;
188185
// Initialise the keyboard remapping to UTF-8
@@ -200,15 +197,9 @@ lcd.begin( MAX_COL, MAX_ROW );
200197
lcd.clear(); // clear the screen
201198
lcd.cursor(); // Enable Cursor
202199
lcd.blink(); // Blinking cursor
203-
#if defined(ARDUINO_ARCH_AVR)
204-
lcd.print( F( "PC Services" ) ); // Display signon text
205-
lcd.setCursor( 0,1 );
206-
lcd.print( F( "Keyboard to LCD" ) );
207-
#elif defined(ARDUINO_ARCH_SAM)
208200
lcd.print( "PC Services" ); // Display signon text
209201
lcd.setCursor( 0,1 );
210202
lcd.print( "Keyboard to LCD" );
211-
#endif
212203
keyboard.begin( DATAPIN, IRQPIN );// Setup keyboard pins
213204
keyboard.setNoBreak( 1 ); // No break codes for keys (when key released)
214205
keyboard.setNoRepeat( 1 ); // Don't repeat shift ctrl etc
@@ -329,28 +320,28 @@ if( keyboard.available() )
329320
if( base != PS2_KEY_EUROPE2 && ( base < PS2_KEY_KP0 || base >= PS2_KEY_F1 ) )
330321
{ // Non printable sort which ones we can print
331322
for( idx = 0; idx < sizeof( codes ); idx++ )
332-
#if defined(ARDUINO_ARCH_AVR)
323+
#if defined(PS2_REQUIRES_PROGMEM)
333324
if( base == pgm_read_byte( codes + idx ) )
334-
#elif defined(ARDUINO_ARCH_SAM)
325+
#else
335326
if( base == codes[ idx ] )
336327
#endif
337328
{
338329
/* String outputs */
339330
mode = 1;
340-
#if defined(ARDUINO_ARCH_AVR)
331+
#if defined(PS2_REQUIRES_PROGMEM)
341332
c = pgm_read_byte( sizes + idx );
342-
#elif defined(ARDUINO_ARCH_SAM)
333+
#else
343334
c = sizes[ idx ];
344335
#endif
345336
cols += c - 1;
346337
check_cursor( );
347338
/* when cursor reset keep track */
348339
if( cols == 0 )
349340
cols = c;
350-
#if defined(ARDUINO_ARCH_AVR)
341+
#if defined(PS2_REQUIRES_PROGMEM)
351342
strcpy_P( buffer, (char*)pgm_read_word( &( keys[ idx ] ) ) );
352343
lcd.print( buffer );
353-
#elif defined(ARDUINO_ARCH_SAM)
344+
#else
354345
lcd.print( keys[ idx ] );
355346
#endif
356347
cols++;

library.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=PS2KeyMap
2-
version=1.0.2
2+
version=1.0.4
33
author=Paul Carpenter <[email protected]>
44
maintainer=Paul Carpenter <[email protected]>
55
sentence=PS2 keyboard codes from PS2KeyAdvanced to UTF-8 for any Latin language keyboard.
@@ -8,3 +8,5 @@ category=Other
88
url=https://github.com/techpaul/PS2KeyMap.git
99
architectures=avr,sam
1010
depends=PS2KeyAdvanced
11+
includes=PS2KeyAdvanced.h,PS2KeyMap.h
12+

src/PS2KeyData.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
/* Version V1.0.2
1+
/* Version V1.0.4
22
PS2KeyMap.h - PS2KeyAdvanced library
33
Copyright (c) 2007 Free Software Foundation. All right reserved.
44
Written by Paul Carpenter, PC Services <[email protected]>
55
Created September 2014
66
Updated January 2016 - Paul Carpenter - add tested on Due and tidy ups for V1.5 Library Management
7+
January 2020 - Paul Carpenter - extend library properties for V2.2 of Arduino Library Management
78
8-
PRIVATE to library data and keymapping tables
9+
PRIVATE to library data and key mapping tables
910
1011
This library REQUIRES PS2KeyAdvanced and PS2KeyMap.h as the codes used to
1112
remap to ASCII/UTF-8 are specific to that library to match ALL keys on a keyboard
@@ -44,19 +45,19 @@
4445

4546
/* Standard ASCII control characters array */
4647
/* in order of PS2_KEY_* values order is important */
47-
#if defined(ARDUINO_ARCH_AVR)
48+
#if defined(PS2_REQUIRES_PROGMEM)
4849
const uint8_t PROGMEM _control_codes[] = {
49-
#elif defined(ARDUINO_ARCH_SAM)
50+
#else
5051
const uint8_t _control_codes[] = {
5152
#endif
5253
PS2_DELETE, PS2_ESC, PS2_BACKSPACE,
5354
PS2_TAB, PS2_ENTER, PS2_SPACE
5455
};
5556

5657
// convert codes based on SHIFT and not SHIFT only for base US-ASCII
57-
#if defined(ARDUINO_ARCH_AVR)
58+
#if defined(PS2_REQUIRES_PROGMEM)
5859
const uint16_t PROGMEM _US_ASCII[][ 2 ] = {
59-
#elif defined(ARDUINO_ARCH_SAM)
60+
#else
6061
const uint16_t _US_ASCII[][ 2 ] = {
6162
#endif
6263
{ PS2_SHIFT + PS2_KEY_1, '!' },
@@ -101,9 +102,9 @@ const uint16_t _US_ASCII[][ 2 ] = {
101102
{ PS2_SHIFT + PS2_KEY_EQUAL, '+' }
102103
};
103104

104-
#if defined(ARDUINO_ARCH_AVR)
105+
#if defined(PS2_REQUIRES_PROGMEM)
105106
const uint16_t PROGMEM _UKmap[][ 2 ] = {
106-
#elif defined(ARDUINO_ARCH_SAM)
107+
#else
107108
const uint16_t _UKmap[][ 2 ] = {
108109
#endif
109110
{ PS2_SHIFT + '@', '"' },
@@ -117,9 +118,9 @@ const uint16_t _UKmap[][ 2 ] = {
117118
{ PS2_SHIFT + PS2_KEY_EUROPE2, '|' },
118119
};
119120
#ifdef FRENCH
120-
#if defined(ARDUINO_ARCH_AVR)
121+
#if defined(PS2_REQUIRES_PROGMEM)
121122
const uint16_t PROGMEM _FRmap[][ 2 ] = {
122-
#elif defined(ARDUINO_ARCH_SAM)
123+
#else
123124
const uint16_t _FRmap[][ 2 ] = {
124125
#endif
125126
{ '`', PS2_SUPERSCRIPT_TWO },
@@ -209,9 +210,9 @@ const uint16_t _FRmap[][ 2 ] = {
209210
};
210211
#endif
211212
#ifdef GERMAN
212-
#if defined(ARDUINO_ARCH_AVR)
213+
#if defined(PS2_REQUIRES_PROGMEM)
213214
const uint16_t PROGMEM _DEmap[][ 2 ] = {
214-
#elif defined(ARDUINO_ARCH_SAM)
215+
#else
215216
const uint16_t _DEmap[][ 2 ] = {
216217
#endif
217218
{ '`', '^' },
@@ -272,9 +273,9 @@ const uint16_t _DEmap[][ 2 ] = {
272273
};
273274
#endif
274275
#ifdef SPECIAL
275-
#if defined(ARDUINO_ARCH_AVR)
276+
#if defined(PS2_REQUIRES_PROGMEM)
276277
const uint16_t PROGMEM _SpecialMap[][ 2 ] = {
277-
#elif defined(ARDUINO_ARCH_SAM)
278+
#else
278279
const uint16_t _SpecialMap[][ 2 ] = {
279280
#endif
280281
// Insert your Special mapping DIFFERENCES from US-ASCII here

src/PS2KeyMap.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
/* Version V1.0.2
1+
/* Version V1.0.4
22
PS2KeyMap.cpp - PS2KeyMap library
33
Copyright (c) 2007 Free Software Foundation. All right reserved.
44
Written by Paul Carpenter, PC Services <[email protected]>
55
Created September 2014
66
Updated January 2016 - Paul Carpenter - add tested on Due and tidy ups for V1.5 Library Management
7+
January 2020 - Paul Carpenter - extend library properties for V2.2 of Arduino Library Management
78
89
IMPORTANT WARNING
910
@@ -212,11 +213,11 @@ result = data & ( PS2_ALT_GR + PS2_SHIFT + 0xFF );
212213

213214
// scan Lookup Table (array) jumping 2 integers at a time
214215
for( idx = 0; idx < size; idx += 2 )
215-
#if defined(ARDUINO_ARCH_AVR)
216+
#if defined(PS2_REQUIRES_PROGMEM)
216217
if( result == pgm_read_word( maparray + idx ) )
217218
{ // second integer is the replacement value
218219
result = pgm_read_word( maparray + idx + 1 );
219-
#elif defined(ARDUINO_ARCH_SAM)
220+
#else
220221
if( result == *( maparray + idx ) )
221222
{ // second integer is the replacement value
222223
result = *( maparray + idx + 1 );
@@ -285,9 +286,9 @@ temp = code & 0xFF;
285286
if( temp >= PS2_KEY_DELETE && temp <= PS2_KEY_SPACE )
286287
{
287288
code &= ~( PS2_FUNCTION + 0xFF ); // convert to ASCII code not function
288-
#if defined(ARDUINO_ARCH_AVR)
289+
#if defined(PS2_REQUIRES_PROGMEM)
289290
temp = pgm_read_byte( &_control_codes[ temp - PS2_KEY_DELETE ] );
290-
#elif defined(ARDUINO_ARCH_SAM)
291+
#else
291292
temp = _control_codes[ temp - PS2_KEY_DELETE ];
292293
#endif
293294
code |= temp;

src/PS2KeyMap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
/* Version V1.0.2
1+
/* Version V1.0.4
22
PS2KeyMap.h - PS2KeyAdvanced library
33
Copyright (c) 2007 Free Software Foundation. All right reserved.
44
Written by Paul Carpenter, PC Services <[email protected]>
55
Created September 2014
66
Updated January 2016 - Paul Carpenter - add tested on Due and tidy ups for V1.5 Library Management
7+
January 2020 - Paul Carpenter - extend library properties for V2.2 of Arduino Library Management
78
89
IMPORTANT WARNING
910

0 commit comments

Comments
 (0)