diff --git a/README.md b/README.md index 9ff0ffc..f4d38be 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,10 @@ ## This library requires PS2KeyAdvanced as well to work -**V1.0.3** July 2018 Improved keywords file +**V1.0.4** January 2020 Work better with new library manager spec and better +additional platform possibilities + +V1.0.3 July 2018 Improved keywords file First Public Release Version V1.0.2 diff --git a/examples/International/International.ino b/examples/International/International.ino index 60f9864..322e4f2 100644 --- a/examples/International/International.ino +++ b/examples/International/International.ino @@ -78,15 +78,8 @@ /* Keyboard constants Change to suit your Arduino define pins used for data and clock from keyboard */ -//#define DATAPIN 4 -//#define IRQPIN 3 -#if defined(ARDUINO_ARCH_AVR) -#define DATAPIN 19 -#define IRQPIN 18 -#elif defined(ARDUINO_ARCH_SAM) -#define DATAPIN 14 -#define IRQPIN 15 -#endif +#define DATAPIN 4 +#define IRQPIN 3 PS2KeyAdvanced keyboard; PS2KeyMap keymap; @@ -98,21 +91,12 @@ uint8_t found; void setup() { Serial.begin( 115200 ); -#if defined(ARDUINO_ARCH_AVR) -Serial.println( F( "PS2KeyMap plus PS2KeyAdvanced Libraries" ) ); -Serial.println( F( "International Keyboard Test:" ) ); -Serial.print( F( "Default is US layout, type a key to change layout\n" - " U for US G for GB/UK\n" ) ); -Serial.println( F( " D for DE F for FR\n" - " All keys on keyboard echoed here" ) ); -#elif defined(ARDUINO_ARCH_SAM) Serial.println( "PS2KeyMap plus PS2KeyAdvanced Libraries" ); Serial.println( "International Keyboard Test:" ); Serial.print( "Default is US layout, type a key to change layout\n" " U for US G for GB/UK\n" ); Serial.println( " D for DE F for FR\n" " All keys on keyboard echoed here" ); -#endif // Start keyboard setup while outputting keyboard.begin( DATAPIN, IRQPIN ); // Disable Break codes (key release) from PS2KeyAdvanced @@ -128,28 +112,13 @@ code = keyboard.available(); if( code > 0 ) { code = keyboard.read(); -#if defined(ARDUINO_ARCH_AVR) - Serial.print( F( "Value " ) ); -#elif defined(ARDUINO_ARCH_SAM) Serial.print( "Value " ); -#endif Serial.print( code, HEX ); code = keymap.remapKey( code ); if( code > 0 ) { if( ( code & 0xFF ) ) { -#if defined(ARDUINO_ARCH_AVR) - Serial.print( F( " mapped " ) ); - Serial.print( code, HEX ); - Serial.print( F( " - Status Bits " ) ); - Serial.print( code >> 8, HEX ); - Serial.print( F( " Code " ) ); - Serial.print( code & 0xFF, HEX ); - Serial.print( F( " ( " ) ); - Serial.write( code & 0xFF ); - Serial.print( F( " )\n" ) ); -#elif defined(ARDUINO_ARCH_SAM) Serial.print( " mapped " ); Serial.print( code, HEX ); Serial.print( " - Status Bits " ); @@ -159,7 +128,6 @@ if( code > 0 ) Serial.print( " ( " ); Serial.write( code & 0xFF ); Serial.print( " )\n" ); -#endif } // process special commands found = 0; @@ -184,20 +152,12 @@ if( code > 0 ) } if( found ) { -#if defined(ARDUINO_ARCH_AVR) - Serial.print( F( "Keyboard set to " ) ); -#elif defined(ARDUINO_ARCH_SAM) Serial.print( "Keyboard set to " ); -#endif Serial.println( keymap.getMap( ) ); } } else -#if defined(ARDUINO_ARCH_AVR) - Serial.println( F( " Keyboard protocol or function" ) ); -#elif defined(ARDUINO_ARCH_SAM) Serial.println( " Keyboard protocol or function" ); -#endif } delay( 100 ); } diff --git a/examples/KeyToLCD/KeyToLCD.ino b/examples/KeyToLCD/KeyToLCD.ino index 4546ab9..33df651 100644 --- a/examples/KeyToLCD/KeyToLCD.ino +++ b/examples/KeyToLCD/KeyToLCD.ino @@ -118,17 +118,17 @@ #define D5 7 #define D4 6 -/* LCD Constants to match your display */ +/* LCD Constants to match your display 16 x 2 */ /* Columns in display */ #define MAX_COL 16 /* Rows in display */ #define MAX_ROW 2 -/* LCD Constants to match your display */ +/* LCD Constants to match your display 20 x 4 */ /* Columns in display */ -#define MAX_COL 20 +//#define MAX_COL 20 /* Rows in display */ -#define MAX_ROW 4 +//#define MAX_ROW 4 /* current cursor position */ signed char cols = 0; @@ -137,7 +137,7 @@ signed char rows = 0; /* messages constants */ /* Key codes and strings for keys producing a string */ /* three arrays in same order ( keycode, string to display, length of string ) */ -#if defined(ARDUINO_ARCH_AVR) +#if defined(PS2_REQUIRES_PROGMEM) const uint8_t codes[] PROGMEM = { PS2_KEY_SPACE, PS2_KEY_TAB, PS2_KEY_ESC, PS2_KEY_DELETE, PS2_KEY_F1, PS2_KEY_F2, PS2_KEY_F3, PS2_KEY_F4, PS2_KEY_F5, PS2_KEY_F6, PS2_KEY_F7, PS2_KEY_F8, @@ -167,7 +167,7 @@ const char *const keys[] PROGMEM = { const int8_t sizes[] PROGMEM = { 1, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5 }; char buffer[ 8 ]; -#elif defined(ARDUINO_ARCH_SAM) +#else const uint8_t codes[] = { PS2_KEY_SPACE, PS2_KEY_TAB, PS2_KEY_ESC, PS2_KEY_DELETE, PS2_KEY_F1, PS2_KEY_F2, PS2_KEY_F3, 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]", " "[F4]", "[F5]", "[F6]", "[F7]", "[F8]", "[F9]", "[F10]", "[F11]", "[F12]" }; const int8_t sizes[] = { 1, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5 }; - -#else - #error “This library only supports boards with an AVR or SAM processor.” #endif -// Class initialisation/instanciation +// Class initialisation/instantiation // keyboard library PS2KeyAdvanced keyboard; // Initialise the keyboard remapping to UTF-8 @@ -200,15 +197,9 @@ lcd.begin( MAX_COL, MAX_ROW ); lcd.clear(); // clear the screen lcd.cursor(); // Enable Cursor lcd.blink(); // Blinking cursor -#if defined(ARDUINO_ARCH_AVR) -lcd.print( F( "PC Services" ) ); // Display signon text -lcd.setCursor( 0,1 ); -lcd.print( F( "Keyboard to LCD" ) ); -#elif defined(ARDUINO_ARCH_SAM) lcd.print( "PC Services" ); // Display signon text lcd.setCursor( 0,1 ); lcd.print( "Keyboard to LCD" ); -#endif keyboard.begin( DATAPIN, IRQPIN );// Setup keyboard pins keyboard.setNoBreak( 1 ); // No break codes for keys (when key released) keyboard.setNoRepeat( 1 ); // Don't repeat shift ctrl etc @@ -329,17 +320,17 @@ if( keyboard.available() ) if( base != PS2_KEY_EUROPE2 && ( base < PS2_KEY_KP0 || base >= PS2_KEY_F1 ) ) { // Non printable sort which ones we can print for( idx = 0; idx < sizeof( codes ); idx++ ) -#if defined(ARDUINO_ARCH_AVR) +#if defined(PS2_REQUIRES_PROGMEM) if( base == pgm_read_byte( codes + idx ) ) -#elif defined(ARDUINO_ARCH_SAM) +#else if( base == codes[ idx ] ) #endif { /* String outputs */ mode = 1; -#if defined(ARDUINO_ARCH_AVR) +#if defined(PS2_REQUIRES_PROGMEM) c = pgm_read_byte( sizes + idx ); -#elif defined(ARDUINO_ARCH_SAM) +#else c = sizes[ idx ]; #endif cols += c - 1; @@ -347,10 +338,10 @@ if( keyboard.available() ) /* when cursor reset keep track */ if( cols == 0 ) cols = c; -#if defined(ARDUINO_ARCH_AVR) +#if defined(PS2_REQUIRES_PROGMEM) strcpy_P( buffer, (char*)pgm_read_word( &( keys[ idx ] ) ) ); lcd.print( buffer ); -#elif defined(ARDUINO_ARCH_SAM) +#else lcd.print( keys[ idx ] ); #endif cols++; diff --git a/library.properties b/library.properties index 13d9787..35219b3 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=PS2KeyMap -version=1.0.2 +version=1.0.4 author=Paul Carpenter maintainer=Paul Carpenter sentence=PS2 keyboard codes from PS2KeyAdvanced to UTF-8 for any Latin language keyboard. @@ -8,3 +8,5 @@ category=Other url=https://github.com/techpaul/PS2KeyMap.git architectures=avr,sam depends=PS2KeyAdvanced +includes=PS2KeyAdvanced.h,PS2KeyMap.h + diff --git a/src/PS2KeyData.h b/src/PS2KeyData.h index a61cd04..ac4636d 100644 --- a/src/PS2KeyData.h +++ b/src/PS2KeyData.h @@ -1,11 +1,12 @@ -/* Version V1.0.2 +/* Version V1.0.4 PS2KeyMap.h - PS2KeyAdvanced library Copyright (c) 2007 Free Software Foundation. All right reserved. Written by Paul Carpenter, PC Services Created September 2014 Updated January 2016 - Paul Carpenter - add tested on Due and tidy ups for V1.5 Library Management + January 2020 - Paul Carpenter - extend library properties for V2.2 of Arduino Library Management - PRIVATE to library data and keymapping tables + PRIVATE to library data and key mapping tables This library REQUIRES PS2KeyAdvanced and PS2KeyMap.h as the codes used to remap to ASCII/UTF-8 are specific to that library to match ALL keys on a keyboard @@ -44,9 +45,9 @@ /* Standard ASCII control characters array */ /* in order of PS2_KEY_* values order is important */ -#if defined(ARDUINO_ARCH_AVR) +#if defined(PS2_REQUIRES_PROGMEM) const uint8_t PROGMEM _control_codes[] = { -#elif defined(ARDUINO_ARCH_SAM) +#else const uint8_t _control_codes[] = { #endif PS2_DELETE, PS2_ESC, PS2_BACKSPACE, @@ -54,9 +55,9 @@ const uint8_t _control_codes[] = { }; // convert codes based on SHIFT and not SHIFT only for base US-ASCII -#if defined(ARDUINO_ARCH_AVR) +#if defined(PS2_REQUIRES_PROGMEM) const uint16_t PROGMEM _US_ASCII[][ 2 ] = { -#elif defined(ARDUINO_ARCH_SAM) +#else const uint16_t _US_ASCII[][ 2 ] = { #endif { PS2_SHIFT + PS2_KEY_1, '!' }, @@ -101,9 +102,9 @@ const uint16_t _US_ASCII[][ 2 ] = { { PS2_SHIFT + PS2_KEY_EQUAL, '+' } }; -#if defined(ARDUINO_ARCH_AVR) +#if defined(PS2_REQUIRES_PROGMEM) const uint16_t PROGMEM _UKmap[][ 2 ] = { -#elif defined(ARDUINO_ARCH_SAM) +#else const uint16_t _UKmap[][ 2 ] = { #endif { PS2_SHIFT + '@', '"' }, @@ -117,9 +118,9 @@ const uint16_t _UKmap[][ 2 ] = { { PS2_SHIFT + PS2_KEY_EUROPE2, '|' }, }; #ifdef FRENCH -#if defined(ARDUINO_ARCH_AVR) +#if defined(PS2_REQUIRES_PROGMEM) const uint16_t PROGMEM _FRmap[][ 2 ] = { -#elif defined(ARDUINO_ARCH_SAM) +#else const uint16_t _FRmap[][ 2 ] = { #endif { '`', PS2_SUPERSCRIPT_TWO }, @@ -209,9 +210,9 @@ const uint16_t _FRmap[][ 2 ] = { }; #endif #ifdef GERMAN -#if defined(ARDUINO_ARCH_AVR) +#if defined(PS2_REQUIRES_PROGMEM) const uint16_t PROGMEM _DEmap[][ 2 ] = { -#elif defined(ARDUINO_ARCH_SAM) +#else const uint16_t _DEmap[][ 2 ] = { #endif { '`', '^' }, @@ -272,9 +273,9 @@ const uint16_t _DEmap[][ 2 ] = { }; #endif #ifdef SPECIAL -#if defined(ARDUINO_ARCH_AVR) +#if defined(PS2_REQUIRES_PROGMEM) const uint16_t PROGMEM _SpecialMap[][ 2 ] = { -#elif defined(ARDUINO_ARCH_SAM) +#else const uint16_t _SpecialMap[][ 2 ] = { #endif // Insert your Special mapping DIFFERENCES from US-ASCII here diff --git a/src/PS2KeyMap.cpp b/src/PS2KeyMap.cpp index 7e474ac..439efc5 100644 --- a/src/PS2KeyMap.cpp +++ b/src/PS2KeyMap.cpp @@ -1,9 +1,10 @@ -/* Version V1.0.2 +/* Version V1.0.4 PS2KeyMap.cpp - PS2KeyMap library Copyright (c) 2007 Free Software Foundation. All right reserved. Written by Paul Carpenter, PC Services Created September 2014 Updated January 2016 - Paul Carpenter - add tested on Due and tidy ups for V1.5 Library Management + January 2020 - Paul Carpenter - extend library properties for V2.2 of Arduino Library Management IMPORTANT WARNING @@ -212,11 +213,11 @@ result = data & ( PS2_ALT_GR + PS2_SHIFT + 0xFF ); // scan Lookup Table (array) jumping 2 integers at a time for( idx = 0; idx < size; idx += 2 ) -#if defined(ARDUINO_ARCH_AVR) +#if defined(PS2_REQUIRES_PROGMEM) if( result == pgm_read_word( maparray + idx ) ) { // second integer is the replacement value result = pgm_read_word( maparray + idx + 1 ); -#elif defined(ARDUINO_ARCH_SAM) +#else if( result == *( maparray + idx ) ) { // second integer is the replacement value result = *( maparray + idx + 1 ); @@ -285,9 +286,9 @@ temp = code & 0xFF; if( temp >= PS2_KEY_DELETE && temp <= PS2_KEY_SPACE ) { code &= ~( PS2_FUNCTION + 0xFF ); // convert to ASCII code not function -#if defined(ARDUINO_ARCH_AVR) +#if defined(PS2_REQUIRES_PROGMEM) temp = pgm_read_byte( &_control_codes[ temp - PS2_KEY_DELETE ] ); -#elif defined(ARDUINO_ARCH_SAM) +#else temp = _control_codes[ temp - PS2_KEY_DELETE ]; #endif code |= temp; diff --git a/src/PS2KeyMap.h b/src/PS2KeyMap.h index cbd92e8..4bdd52b 100644 --- a/src/PS2KeyMap.h +++ b/src/PS2KeyMap.h @@ -1,9 +1,10 @@ -/* Version V1.0.2 +/* Version V1.0.4 PS2KeyMap.h - PS2KeyAdvanced library Copyright (c) 2007 Free Software Foundation. All right reserved. Written by Paul Carpenter, PC Services Created September 2014 Updated January 2016 - Paul Carpenter - add tested on Due and tidy ups for V1.5 Library Management + January 2020 - Paul Carpenter - extend library properties for V2.2 of Arduino Library Management IMPORTANT WARNING