Skip to content

Commit 2d38873

Browse files
committed
Configure for latest Arduino Library Manager versions
Tidy up conditionals for adding platforms Simplify examples
1 parent f2fb320 commit 2d38873

File tree

8 files changed

+47
-91
lines changed

8 files changed

+47
-91
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# PS2KeyAdvanced
22
## Arduino PS2 Keyboard FULL keyboard protocol support and full keys to integer coding
33
**V1.0.6** January 2020 - Fix typos, correct keyboard reset status improve library.properties
4-
and additional platform handling
4+
and additional reduction for easier platform handling
55

66
V1.0.4 August 2018 - Minor reduction in available() method to remove redundant extra safety checks on buffers
77

examples/KeyToLCD/KeyToLCD.ino

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ int8_t rows = 0;
122122
/* messages constants */
123123
/* Key codes and strings for keys producing a string */
124124
/* three arrays in same order ( keycode, string to display, length of string ) */
125-
#if defined(ARDUINO_ARCH_AVR)
125+
#if defined(PS2_REQUIRES_PROGMEM)
126126
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,
@@ -152,7 +152,7 @@ const char *const keys[] PROGMEM = {
152152
const int8_t sizes[] PROGMEM = { 1, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5 };
153153
char buffer[ 8 ];
154154

155-
#elif defined(ARDUINO_ARCH_SAM)
155+
#else
156156
const uint8_t codes[] = { PS2_KEY_SPACE, PS2_KEY_TAB, PS2_KEY_ESC,
157157
PS2_KEY_DELETE, PS2_KEY_F1, PS2_KEY_F2, PS2_KEY_F3,
158158
PS2_KEY_F4, PS2_KEY_F5, PS2_KEY_F6, PS2_KEY_F7,
@@ -162,9 +162,6 @@ const char *const keys[] = { " ", "[Tab]", "[ESC]", "[Del]", "[F1]", "[F2]", "
162162
"[F4]", "[F5]", "[F6]", "[F7]", "[F8]",
163163
"[F9]", "[F10]", "[F11]", "[F12]" };
164164
const int8_t sizes[] = { 1, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5 };
165-
166-
#else
167-
#error “This library only supports boards with an AVR or SAM processor.”
168165
#endif
169166

170167
// initialize the keyboard library with the numbers of the interface pins
@@ -187,15 +184,9 @@ lcd.begin( MAX_COL, MAX_ROW );
187184
lcd.clear(); // clear the screen
188185
lcd.cursor(); // Enable Cursor
189186
lcd.blink(); // Blinking cursor
190-
#if defined(ARDUINO_ARCH_AVR)
191-
lcd.print( F( "PC Services" ) ); // Display sign-on text
192-
lcd.setCursor( 0,1 );
193-
lcd.print( F( "Keyboard to LCD" ) );
194-
#elif defined(ARDUINO_ARCH_SAM)
195187
lcd.print( "PC Services" ); // Display sign-on text
196188
lcd.setCursor( 0,1 );
197189
lcd.print( "Keyboard to LCD" );
198-
#endif
199190
lcd.setCursor( 12,0 );
200191
cols = 12; // update cursor position
201192
rows = 0;
@@ -312,27 +303,27 @@ if( keyboard.available() )
312303
if( c != PS2_KEY_EUROPE2 && ( c < PS2_KEY_KP0 || c >= PS2_KEY_F1 ) )
313304
{ // Non printable sort which ones we can print
314305
for( idx = 0; idx < sizeof( codes ); idx++ )
315-
#if defined(ARDUINO_ARCH_AVR)
306+
#if defined(PS2_REQUIRES_PROGMEM)
316307
if( c == pgm_read_byte( codes + idx ) )
317-
#elif defined(ARDUINO_ARCH_SAM)
308+
#else
318309
if( c == codes[ idx ] )
319310
#endif
320311
{ /* String outputs */
321312
mode = 1;
322-
#if defined(ARDUINO_ARCH_AVR)
313+
#if defined(PS2_REQUIRES_PROGMEM)
323314
c = pgm_read_byte( sizes + idx );
324-
#elif defined(ARDUINO_ARCH_SAM)
315+
#else
325316
c = sizes[ idx ];
326317
#endif
327318
cols += c - 1;
328319
check_cursor( );
329320
/* when cursor reset keep track */
330321
if( cols == 0 )
331322
cols = c;
332-
#if defined(ARDUINO_ARCH_AVR)
323+
#if defined(PS2_REQUIRES_PROGMEM)
333324
strcpy_P( buffer, (char*)pgm_read_word( &( keys[ idx ] ) ) );
334325
lcd.print( buffer );
335-
#elif defined(ARDUINO_ARCH_SAM)
326+
#else
336327
lcd.print( keys[ idx ] );
337328
#endif
338329
cols++;

examples/SimpleTest/SimpleTest.ino

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,7 @@ void setup()
144144
// Configure the keyboard library
145145
keyboard.begin( DATAPIN, IRQPIN );
146146
Serial.begin( 115200 );
147-
#if defined(ARDUINO_ARCH_AVR)
148-
Serial.println( F( "PS2 Advanced Key Simple Test:" ) );
149-
#elif defined(ARDUINO_ARCH_SAM)
150147
Serial.println( "PS2 Advanced Key Simple Test:" );
151-
#endif
152148
}
153149

154150

@@ -160,19 +156,11 @@ if( keyboard.available() )
160156
c = keyboard.read();
161157
if( c > 0 )
162158
{
163-
#if defined(ARDUINO_ARCH_AVR)
164-
Serial.print( F( "Value " ) );
165-
Serial.print( c, HEX );
166-
Serial.print( F( " - Status Bits " ) );
167-
Serial.print( c >> 8, HEX );
168-
Serial.print( F( " Code " ) );
169-
#elif defined(ARDUINO_ARCH_SAM)
170159
Serial.print( "Value " );
171160
Serial.print( c, HEX );
172161
Serial.print( " - Status Bits " );
173162
Serial.print( c >> 8, HEX );
174163
Serial.print( " Code " );
175-
#endif
176164
Serial.println( c & 0xFF, HEX );
177165
}
178166
}

examples/advcodetest/advcodetest.ino

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,15 @@ PS2KeyAdvanced keyboard;
154154
void setup()
155155
{
156156
Serial.begin( 115200 );
157-
#if defined(ARDUINO_ARCH_AVR)
158-
Serial.println( F( "PS2 Advanced Key - Advanced Test:" ) );
159-
#elif defined(ARDUINO_ARCH_SAM)
160-
Serial.println( "PS2 Advanced Key - Advanced Test:" );
161-
#endif
157+
Serial.println( "PS2 Advanced Key - Advanced Test:" );
162158

163159
// Configure the keyboard library
164160
keyboard.begin( DATAPIN, IRQPIN );
165161
keyboard.echo(); // ping keyboard to see if there
166162
delay( 6 );
167163
c = keyboard.read();
168164
if( (c & 0xFF) == PS2_KEY_ECHO )
169-
#if defined(ARDUINO_ARCH_AVR)
170-
Serial.println( F( "Keyboard OK.." ) );
171-
#elif defined(ARDUINO_ARCH_SAM)
172165
Serial.println( "Keyboard OK.." );
173-
#endif
174166
}
175167

176168

@@ -187,70 +179,38 @@ if( keyboard.available() )
187179
switch( c & 0xFF )
188180
{
189181
case PS2_KEY_R:
190-
#if defined(ARDUINO_ARCH_AVR)
191-
Serial.println( F( "Reset" ) );
192-
#elif defined(ARDUINO_ARCH_SAM)
193182
Serial.println( "Reset" );
194-
#endif
195183
keyboard.resetKey(); // Reset keyboard
196184
break;
197185
case PS2_KEY_S:
198-
#if defined(ARDUINO_ARCH_AVR)
199-
Serial.println( F( "Get Scancode set in use" ) );
200-
#elif defined(ARDUINO_ARCH_SAM)
201186
Serial.println( "Get Scancode set in use" );
202-
#endif
203187
keyboard.getScanCodeSet(); // Get which scan code set
204188
break;
205189
case PS2_KEY_G:
206-
#if defined(ARDUINO_ARCH_AVR)
207-
Serial.print( F( "Get current lock status = " ) );
208-
#elif defined(ARDUINO_ARCH_SAM)
209190
Serial.print( "Get current lock status = " );
210-
#endif
211191
c = keyboard.getLock(); // Get current lock status
212192
Serial.println( c, HEX );
213193
break;
214194
case PS2_KEY_I:
215-
#if defined(ARDUINO_ARCH_AVR)
216-
Serial.println( F( "Read ID code" ) );
217-
#elif defined(ARDUINO_ARCH_SAM)
218195
Serial.println( "Read ID code" );
219-
#endif
220196
keyboard.readID(); // Get which scan code set
221197
break;
222198
case PS2_KEY_E:
223-
#if defined(ARDUINO_ARCH_AVR)
224-
Serial.println( F( "Echo" ) );
225-
#elif defined(ARDUINO_ARCH_SAM)
226199
Serial.println( "Echo" );
227-
#endif
228200
keyboard.echo(); // Get which scan code set
229201
break;
230202
case PS2_KEY_T:
231-
#if defined(ARDUINO_ARCH_AVR)
232-
Serial.println( F( "Typematic Rate" ) );
233-
#elif defined(ARDUINO_ARCH_SAM)
234203
Serial.println( "Typematic Rate" );
235-
#endif
236204
keyboard.typematic( 31, 3); // Get slowest
237205
break;
238206
case PS2_KEY_B:
239-
#if defined(ARDUINO_ARCH_AVR)
240-
Serial.print( F( "No Break Codes " ) );
241-
#elif defined(ARDUINO_ARCH_SAM)
242207
Serial.print( "No Break Codes " );
243-
#endif
244208
breaks ^= 1;;
245209
Serial.println( breaks );
246210
keyboard.setNoBreak( breaks ); // set break mode
247211
break;
248212
case PS2_KEY_N:
249-
#if defined(ARDUINO_ARCH_AVR)
250-
Serial.print( F( "No Repeat Makes for CTRL... " ) );
251-
#elif defined(ARDUINO_ARCH_SAM)
252213
Serial.print( "No Repeat Makes for CTRL... " );
253-
#endif
254214
repeats ^= 1;
255215
Serial.println( repeats );
256216
keyboard.setNoRepeat( repeats ); // Set repeat modet

library.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
name=PS2KeyAdvanced
2-
version=1.0.5
2+
version=1.0.6
33
author=Paul Carpenter <[email protected]>
44
maintainer=Paul Carpenter <[email protected]>
55
sentence=PS2 keyboard FULL control and ALL keys processing, as well as LED control.
66
paragraph=Provides ability to convert long key stroke code sequences to a single integer, for all keys ANY Latin keyboard, even multimedia and 24 Function key keyboards.
77
category=Other
88
url=https://github.com/techpaul/PS2KeyAdvanced.git
99
architectures=avr,sam
10+
includes=PS2KeyAdvanced.h
11+

src/PS2KeyAdvanced.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ void set_lock( );
144144

145145
/* Constant control functions to flags array
146146
in translated key code value order */
147-
#if defined(ARDUINO_ARCH_AVR)
147+
#if defined(PS2_REQUIRES_PROGMEM)
148148
const uint8_t PROGMEM control_flags[] = {
149-
#elif defined(ARDUINO_ARCH_SAM)
149+
#else
150150
const uint8_t control_flags[] = {
151151
#endif
152152
_SHIFT, _SHIFT, _CTRL, _CTRL,
@@ -291,8 +291,9 @@ else
291291
_ps2mode &= ~_PS2_BUSY;
292292
send_next(); // Check for more to send
293293
}
294-
}
295-
// fall through to default
294+
}
295+
_bitcount = 0; // end of byte
296+
break;
296297
default: // in case of weird error and end of byte reception resync
297298
_bitcount = 0;
298299
}
@@ -439,7 +440,8 @@ switch( _bitcount )
439440
_tx_ready &= ~_COMMAND;
440441
if( !( _ps2mode & _WAIT_RESPONSE ) ) // if not wait response
441442
send_next(); // check anything else to queue up
442-
// fall through to default
443+
_bitcount = 0; // end of byte
444+
break;
443445
default: // in case of weird error and end of byte reception re-sync
444446
_bitcount = 0;
445447
}
@@ -669,11 +671,11 @@ if( index & _E0_MODE )
669671
{
670672
length = sizeof( extended_key ) / sizeof( extended_key[ 0 ] );
671673
for( index = 0; index < length; index++ )
672-
#if defined(ARDUINO_ARCH_AVR)
674+
#if defined(PS2_REQUIRES_PROGMEM)
673675
if( data == pgm_read_byte( &extended_key[ index ][ 0 ] ) )
674676
{
675677
retdata = pgm_read_byte( &extended_key[ index ][ 1 ] );
676-
#elif defined(ARDUINO_ARCH_SAM)
678+
#else
677679
if( data == extended_key[ index ][ 0 ] )
678680
{
679681
retdata = extended_key[ index ][ 1 ];
@@ -685,11 +687,11 @@ else
685687
{
686688
length = sizeof( single_key ) / sizeof( single_key[ 0 ] );
687689
for( index = 0; index < length; index++ )
688-
#if defined(ARDUINO_ARCH_AVR)
690+
#if defined(PS2_REQUIRES_PROGMEM)
689691
if( data == pgm_read_byte( &single_key[ index ][ 0 ] ) )
690692
{
691693
retdata = pgm_read_byte( &single_key[ index ][ 1 ] );
692-
#elif defined(ARDUINO_ARCH_SAM)
694+
#else
693695
if( data == single_key[ index ][ 0 ] )
694696
{
695697
retdata = single_key[ index ][ 1 ];
@@ -746,9 +748,9 @@ if( retdata > 0 )
746748
else
747749
if( retdata >= PS2_KEY_L_SHIFT && retdata <= PS2_KEY_R_GUI )
748750
{ // Update bits for _SHIFT, _CTRL, _ALT, _ALT GR, _GUI in status
749-
#if defined(ARDUINO_ARCH_AVR)
751+
#if defined(PS2_REQUIRES_PROGMEM)
750752
index = pgm_read_byte( &control_flags[ retdata - PS2_KEY_L_SHIFT ] );
751-
#elif defined(ARDUINO_ARCH_SAM)
753+
#else
752754
index = control_flags[ retdata - PS2_KEY_L_SHIFT ];
753755
#endif
754756
if( PS2_keystatus & _BREAK )
@@ -764,9 +766,9 @@ if( retdata > 0 )
764766
// Numeric keypad ONLY works in numlock state or when _SHIFT status
765767
if( retdata >= PS2_KEY_KP0 && retdata <= PS2_KEY_KP_DOT )
766768
if( !( PS2_led_lock & PS2_LOCK_NUM ) || ( PS2_keystatus & _SHIFT ) )
767-
#if defined(ARDUINO_ARCH_AVR)
769+
#if defined(PS2_REQUIRES_PROGMEM)
768770
retdata = pgm_read_byte( &scroll_remap[ retdata - PS2_KEY_KP0 ] );
769-
#elif defined(ARDUINO_ARCH_SAM)
771+
#else
770772
retdata = scroll_remap[ retdata - PS2_KEY_KP0 ];
771773
#endif
772774
// Sort break code handling or ignore for all having processed the _SHIFT etc status

src/PS2KeyAdvanced.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@
135135
#define PS2KeyAdvanced_h
136136
#include "Arduino.h"
137137

138+
// Platform specific areas
139+
// Harvard architecture settings for PROGMEM
140+
// Add separate for EACH architecture as easier to maintain
141+
// AVR
142+
#if defined(ARDUINO_ARCH_AVR)
143+
#define PS2_REQUIRES_PROGMEM 1
144+
#endif
145+
146+
// Invalid architecture
147+
#if !( defined( ARDUINO_ARCH_AVR ) || defined( ARDUINO_ARCH_SAM ) )
148+
#warning Library is not supported on this board Use at own risk
149+
#endif
150+
138151
/* Flags/bit masks for status bits in returned unsigned int value */
139152
#define PS2_BREAK 0x8000
140153
#define PS2_SHIFT 0x4000

src/PS2KeyTable.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
In codes can only be 1 - 0x9F, plus 0xF2 and 0xF1
6565
Out Codes in range 1 to 0x9F
6666
*/
67-
#if defined(ARDUINO_ARCH_AVR)
67+
#if defined(PS2_REQUIRES_PROGMEM)
6868
const uint8_t PROGMEM single_key[][ 2 ] = {
69-
#elif defined(ARDUINO_ARCH_SAM)
69+
#else
7070
const uint8_t single_key[][ 2 ] = {
7171
#endif
7272
{ PS2_KC_NUM, PS2_KEY_NUM },
@@ -183,9 +183,9 @@ const uint8_t single_key[][ 2 ] = {
183183
};
184184

185185
/* Two byte Key table after an E0 byte received */
186-
#if defined(ARDUINO_ARCH_AVR)
186+
#if defined(PS2_REQUIRES_PROGMEM)
187187
const uint8_t PROGMEM extended_key[][ 2 ] = {
188-
#elif defined(ARDUINO_ARCH_SAM)
188+
#else
189189
const uint8_t extended_key[][ 2 ] = {
190190
#endif
191191
{ PS2_KC_IGNORE, PS2_KEY_IGNORE },
@@ -233,9 +233,9 @@ const uint8_t extended_key[][ 2 ] = {
233233

234234
/* Scroll lock numeric keypad re-mappings for NOT NUMLOCK */
235235
/* in translated code order order is important */
236-
#if defined(ARDUINO_ARCH_AVR)
236+
#if defined(PS2_REQUIRES_PROGMEM)
237237
const uint8_t PROGMEM scroll_remap[] = {
238-
#elif defined(ARDUINO_ARCH_SAM)
238+
#else
239239
const uint8_t scroll_remap[] = {
240240
#endif
241241
PS2_KEY_INSERT, // PS2_KEY_KP0

0 commit comments

Comments
 (0)