From 131663cd63df9f7f076867f1264544f80d7a79ee Mon Sep 17 00:00:00 2001 From: Paul Carpenter Date: Mon, 2 Mar 2020 11:46:57 +0000 Subject: [PATCH] V1.0.5 Add Italain and Spanish keyboard layouts other tidy ups --- examples/International/International.ino | 12 ++ examples/KeyToLCD/KeyToLCD.ino | 53 +------ library.properties | 4 +- src/PS2KeyData.h | 190 +++++++++++++++++------ src/PS2KeyMap.cpp | 10 +- src/PS2KeyMap.h | 10 +- 6 files changed, 179 insertions(+), 100 deletions(-) diff --git a/examples/International/International.ino b/examples/International/International.ino index 322e4f2..71ef0aa 100644 --- a/examples/International/International.ino +++ b/examples/International/International.ino @@ -18,6 +18,7 @@ September 2014 Uno and Mega 2560 September 2014 using Arduino V1.6.0 January 2016 Uno, Mega 2560 and Due using Arduino 1.6.7 and Due Board Manager V1.6.6 + March 2020 Extend for Italian and Spanish keyboards PS2KeyMap uses a default US-ASCII Map but different country mappings can be selected on the fly @@ -28,6 +29,8 @@ G for UK keyboard D for German keyboard F for French keyboard + I for Italian keyboard + E for Spanish keyboard Defaults to US on start up @@ -96,6 +99,7 @@ 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" + " I for IT E for ES\n" " All keys on keyboard echoed here" ); // Start keyboard setup while outputting keyboard.begin( DATAPIN, IRQPIN ); @@ -141,6 +145,14 @@ if( code > 0 ) case 'f': found = keymap.selectMap( (char *)"FR" ); break; + case 'E': + case 'e': + found = keymap.selectMap( (char *)"ES" ); + break; + case 'I': + case 'i': + found = keymap.selectMap( (char *)"IT" ); + break; case 'G': case 'g': found = keymap.selectMap( (char *)"UK" ); diff --git a/examples/KeyToLCD/KeyToLCD.ino b/examples/KeyToLCD/KeyToLCD.ino index 33df651..7c43e17 100644 --- a/examples/KeyToLCD/KeyToLCD.ino +++ b/examples/KeyToLCD/KeyToLCD.ino @@ -17,6 +17,7 @@ September 2014 Uno and Mega 2560 September 2014 using Arduino V1.6.0 January 2016 Uno, Mega 2560 and Due using Arduino 1.6.7 and Due Board Manager V1.6.6 + March 2020 Simplify example This sketch displays text received from PS2 keyboard to LCD on same Arduino. Importantly it maps the keyboard to UTF-8 @@ -137,38 +138,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(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, - PS2_KEY_F9, PS2_KEY_F10, PS2_KEY_F11, PS2_KEY_F12 }; -const char spacestr[] PROGMEM = " "; -const char tabstr[] PROGMEM = "[Tab]"; -const char escstr[] PROGMEM = "[ESC]"; -const char delstr[] PROGMEM = "[Del]"; -const char f1str[] PROGMEM = "[F1]"; -const char f2str[] PROGMEM = "[F2]"; -const char f3str[] PROGMEM = "[F3]"; -const char f4str[] PROGMEM = "[F4]"; -const char f5str[] PROGMEM = "[F5]"; -const char f6str[] PROGMEM = "[F6]"; -const char f7str[] PROGMEM = "[F7]"; -const char f8str[] PROGMEM = "[F8]"; -const char f9str[] PROGMEM = "[F9]"; -const char f10str[] PROGMEM = "[F10]"; -const char f11str[] PROGMEM = "[F11]"; -const char f12str[] PROGMEM = "[F12]"; - -// Due to AVR Harvard architecture array of string pointers to actual strings -const char *const keys[] PROGMEM = { - spacestr, tabstr, escstr, delstr, f1str, f2str, - f3str, f4str, f5str, f6str, f7str, f8str, - f9str, f10str, f11str, f12str }; -const int8_t sizes[] PROGMEM = { 1, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5 }; -char buffer[ 8 ]; - -#else -const uint8_t codes[] = { PS2_KEY_SPACE, PS2_KEY_TAB, PS2_KEY_ESC, +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, PS2_KEY_F8, PS2_KEY_F9, PS2_KEY_F10, PS2_KEY_F11, @@ -176,8 +146,8 @@ const uint8_t codes[] = { PS2_KEY_SPACE, PS2_KEY_TAB, PS2_KEY_ESC, const char *const keys[] = { " ", "[Tab]", "[ESC]", "[Del]", "[F1]", "[F2]", "[F3]", "[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 }; -#endif +int8_t sizes[] = { 1, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5 }; + // Class initialisation/instantiation // keyboard library @@ -320,30 +290,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(PS2_REQUIRES_PROGMEM) - if( base == pgm_read_byte( codes + idx ) ) -#else if( base == codes[ idx ] ) -#endif { /* String outputs */ mode = 1; -#if defined(PS2_REQUIRES_PROGMEM) - c = pgm_read_byte( sizes + idx ); -#else - c = sizes[ idx ]; -#endif + c = sizes[ idx ]; cols += c - 1; check_cursor( ); /* when cursor reset keep track */ if( cols == 0 ) cols = c; -#if defined(PS2_REQUIRES_PROGMEM) - strcpy_P( buffer, (char*)pgm_read_word( &( keys[ idx ] ) ) ); - lcd.print( buffer ); -#else lcd.print( keys[ idx ] ); -#endif cols++; check_cursor( ); break; diff --git a/library.properties b/library.properties index 35219b3..ab793cd 100644 --- a/library.properties +++ b/library.properties @@ -1,12 +1,12 @@ name=PS2KeyMap -version=1.0.4 +version=1.0.5 author=Paul Carpenter maintainer=Paul Carpenter sentence=PS2 keyboard codes from PS2KeyAdvanced to UTF-8 for any Latin language keyboard. paragraph=Takes integer values from PS2KeyAdvanced to convert using selectable country mapping and you can add your own country mapping. category=Other url=https://github.com/techpaul/PS2KeyMap.git -architectures=avr,sam +architectures=avr,sam,samd1 depends=PS2KeyAdvanced includes=PS2KeyAdvanced.h,PS2KeyMap.h diff --git a/src/PS2KeyData.h b/src/PS2KeyData.h index ac4636d..85fc140 100644 --- a/src/PS2KeyData.h +++ b/src/PS2KeyData.h @@ -1,10 +1,11 @@ -/* Version V1.0.4 +/* Version V1.0.5 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 + March 2020 - Paul Carpenter - add Spanish and Italian Mappings PRIVATE to library data and key mapping tables @@ -60,46 +61,46 @@ const uint16_t PROGMEM _US_ASCII[][ 2 ] = { #else const uint16_t _US_ASCII[][ 2 ] = { #endif - { PS2_SHIFT + PS2_KEY_1, '!' }, - { PS2_SHIFT + PS2_KEY_2, '@' }, - { PS2_SHIFT + PS2_KEY_3, '#' }, - { PS2_SHIFT + PS2_KEY_4, '$' }, - { PS2_SHIFT + PS2_KEY_5, '%' }, - { PS2_SHIFT + PS2_KEY_6, '^' }, - { PS2_SHIFT + PS2_KEY_7, '&' }, - { PS2_SHIFT + PS2_KEY_8, '*' }, - { PS2_SHIFT + PS2_KEY_9, '(' }, - { PS2_SHIFT + PS2_KEY_0, ')' }, - { PS2_KEY_KP_DOT, '.' }, - { PS2_KEY_KP_ENTER, PS2_ENTER }, - { PS2_KEY_KP_PLUS, '+' }, - { PS2_KEY_KP_MINUS, '-' }, - { PS2_KEY_KP_TIMES, '*' }, - { PS2_KEY_KP_DIV, '/' }, - { PS2_KEY_KP_COMMA, ',' }, - { PS2_KEY_KP_EQUAL, '=' }, - { PS2_KEY_APOS, '\'' }, - { PS2_SHIFT + PS2_KEY_APOS, '"' }, - { PS2_KEY_COMMA, ',' }, - { PS2_SHIFT + PS2_KEY_COMMA, '<' }, - { PS2_KEY_MINUS, '-' }, - { PS2_SHIFT + PS2_KEY_MINUS, '_' }, - { PS2_KEY_DOT, '.' }, - { PS2_SHIFT + PS2_KEY_DOT, '>' }, - { PS2_KEY_DIV, '/' }, - { PS2_SHIFT + PS2_KEY_DIV, '?' }, - { PS2_KEY_SINGLE, '`' }, - { PS2_SHIFT + PS2_KEY_SINGLE, '~' }, - { PS2_KEY_SEMI, ';' }, - { PS2_SHIFT + PS2_KEY_SEMI, ':' }, - { PS2_KEY_BACK, '\\' }, - { PS2_SHIFT + PS2_KEY_BACK, '|' }, - { PS2_KEY_OPEN_SQ, '[' }, - { PS2_SHIFT + PS2_KEY_OPEN_SQ, '{' }, - { PS2_KEY_CLOSE_SQ, ']' }, - { PS2_SHIFT + PS2_KEY_CLOSE_SQ, '}' }, - { PS2_KEY_EQUAL, '=' }, - { PS2_SHIFT + PS2_KEY_EQUAL, '+' } + { PS2_SHIFT + PS2_KEY_1, '!' }, + { PS2_SHIFT + PS2_KEY_2, '@' }, + { PS2_SHIFT + PS2_KEY_3, '#' }, + { PS2_SHIFT + PS2_KEY_4, '$' }, + { PS2_SHIFT + PS2_KEY_5, '%' }, + { PS2_SHIFT + PS2_KEY_6, '^' }, + { PS2_SHIFT + PS2_KEY_7, '&' }, + { PS2_SHIFT + PS2_KEY_8, '*' }, + { PS2_SHIFT + PS2_KEY_9, '(' }, + { PS2_SHIFT + PS2_KEY_0, ')' }, + { PS2_KEY_KP_DOT, '.' }, + { PS2_KEY_KP_ENTER, PS2_ENTER }, + { PS2_KEY_KP_PLUS, '+' }, + { PS2_KEY_KP_MINUS, '-' }, + { PS2_KEY_KP_TIMES, '*' }, + { PS2_KEY_KP_DIV, '/' }, + { PS2_KEY_KP_COMMA, ',' }, + { PS2_KEY_KP_EQUAL, '=' }, + { PS2_KEY_APOS, '\'' }, + { PS2_SHIFT + PS2_KEY_APOS, '"' }, + { PS2_KEY_COMMA, ',' }, + { PS2_SHIFT + PS2_KEY_COMMA, '<' }, + { PS2_KEY_MINUS, '-' }, + { PS2_SHIFT + PS2_KEY_MINUS, '_' }, + { PS2_KEY_DOT, '.' }, + { PS2_SHIFT + PS2_KEY_DOT, '>' }, + { PS2_KEY_DIV, '/' }, + { PS2_SHIFT + PS2_KEY_DIV, '?' }, + { PS2_KEY_SINGLE, '`' }, + { PS2_SHIFT + PS2_KEY_SINGLE, '~' }, + { PS2_KEY_SEMI, ';' }, + { PS2_SHIFT + PS2_KEY_SEMI, ':' }, + { PS2_KEY_BACK, '\\' }, + { PS2_SHIFT + PS2_KEY_BACK, '|' }, + { PS2_KEY_OPEN_SQ, '[' }, + { PS2_SHIFT + PS2_KEY_OPEN_SQ, '{' }, + { PS2_KEY_CLOSE_SQ, ']' }, + { PS2_SHIFT + PS2_KEY_CLOSE_SQ, '}' }, + { PS2_KEY_EQUAL, '=' }, + { PS2_SHIFT + PS2_KEY_EQUAL, '+' } }; #if defined(PS2_REQUIRES_PROGMEM) @@ -272,6 +273,97 @@ const uint16_t _DEmap[][ 2 ] = { { PS2_KEY_EUROPE2, '<' } }; #endif +#ifdef SPANISH +#if defined(PS2_REQUIRES_PROGMEM) +const uint16_t PROGMEM _ESmap[][ 2 ] = { +#else +const uint16_t _ESmap[][ 2 ] = { +#endif + { PS2_KEY_SINGLE, PS2_MASCULINE_ORDINAL }, + { PS2_SHIFT + PS2_KEY_SINGLE, PS2_FEMININE_ORDINAL }, + { PS2_KEY_SINGLE + PS2_ALT_GR, '\\' }, + { '1' + PS2_ALT_GR, '|' }, + { PS2_SHIFT + '@', '"' }, + { '2' + PS2_ALT_GR, '@' }, + { PS2_SHIFT + '#', PS2_MIDDLE_DOT }, + { '3' + PS2_ALT_GR, '#' }, + { '4' + PS2_ALT_GR, '~' }, + { PS2_SHIFT + '^', '&' }, + { '6' + PS2_ALT_GR, PS2_NOT_SIGN }, + { PS2_SHIFT + '&', '/' }, + { PS2_SHIFT + '*', '(' }, + { PS2_SHIFT + '(', ')' }, + { PS2_SHIFT + ')', '=' }, + { '-', '\'' }, + { PS2_SHIFT + '_', '?' }, + { '=', PS2_INVERTED_EXCLAMATION }, + { PS2_SHIFT + '+', PS2_INVERTED_QUESTION_MARK }, + { '[', '`' }, + { PS2_SHIFT + '{', '^' }, + { '[' + PS2_ALT_GR, '[' }, + { ']', '+' }, + { PS2_SHIFT + '}', '*' }, + { ']' + PS2_ALT_GR, ']' }, + { ';', PS2_n_TILDE }, + { PS2_SHIFT + ':', PS2_N_TILDE }, + { '\'', PS2_ACUTE_ACCENT }, + { PS2_SHIFT + '"', PS2_DIAERESIS }, + { '\'' + PS2_ALT_GR, '{' }, + { '\\', PS2_c_CEDILLA }, + { PS2_SHIFT + '|', PS2_C_CEDILLA }, + { '\\' + PS2_ALT_GR, '}' }, + { PS2_SHIFT + PS2_KEY_EUROPE2, '>' }, + { PS2_KEY_EUROPE2, '<' }, + { PS2_SHIFT + '<', ';' }, + { PS2_SHIFT + '>', ':' }, + { PS2_KEY_DIV, '-' }, + { PS2_SHIFT + PS2_KEY_DIV, '+' } + }; +#endif +#ifdef ITALIAN +#if defined(PS2_REQUIRES_PROGMEM) +const uint16_t PROGMEM _ITmap[][ 2 ] = { +#else +const uint16_t _ITmap[][ 2 ] = { +#endif + { PS2_KEY_SINGLE, '\\' }, + { PS2_SHIFT + PS2_KEY_SINGLE, '|' }, + { '@', '"' }, + { PS2_SHIFT + '#', PS2_POUND_SIGN }, + { '3' + PS2_ALT_GR, '#' }, + { PS2_SHIFT + '^', '&' }, + { PS2_SHIFT + '&', '/' }, + { '7' + PS2_ALT_GR, '{' }, + { PS2_SHIFT + '*', '(' }, + { '8' + PS2_ALT_GR, '[' }, + { PS2_SHIFT + '(', ')' }, + { '9' + PS2_ALT_GR, ']' }, + { PS2_SHIFT + ')', '=' }, + { '0' + PS2_ALT_GR, '}' }, + { '-', '\'' }, + { PS2_SHIFT + '_', '?' }, + { '=', PS2_i_GRAVE }, + { PS2_SHIFT + '+', '^' }, + { 'q' + PS2_ALT_GR, '@' }, + { '[', PS2_e_GRAVE }, + { PS2_SHIFT + '{', PS2_e_ACUTE }, + { ']', '+' }, + { PS2_SHIFT + '}', '*' }, + { ']' + PS2_ALT_GR, '~' }, + { ';', PS2_o_GRAVE }, + { PS2_SHIFT + ':', PS2_c_CEDILLA }, + { '\'', PS2_a_GRAVE }, + { PS2_SHIFT + '"', PS2_DEGREE_SIGN }, + { '\\', PS2_u_GRAVE }, + { PS2_SHIFT + '|', PS2_SECTION_SIGN }, + { PS2_SHIFT + PS2_KEY_EUROPE2, '>' }, + { PS2_KEY_EUROPE2, '<' }, + { PS2_SHIFT + '<', ';' }, + { PS2_SHIFT + '>', ':' }, + { PS2_KEY_DIV, '-' }, + { PS2_SHIFT + PS2_KEY_DIV, '+' } + }; +#endif #ifdef SPECIAL #if defined(PS2_REQUIRES_PROGMEM) const uint16_t PROGMEM _SpecialMap[][ 2 ] = { @@ -290,9 +382,12 @@ typedef struct { } PS2Advmap; // Actual map structure array ( 2 entries for GB and UK for same map -// Because many people dont know ISO code for UK is GB ) -// Actually held in RAM but small in size -const PS2Advmap _KeyMaps[] = { +// Because many people don't know ISO code for UK is GB ) +#if defined(PS2_REQUIRES_PROGMEM) +const PS2Advmap PROGMEM _KeyMaps[ ] = { +#else +const PS2Advmap _KeyMaps[ ] = { +#endif { "US", sizeof( _US_ASCII ) / ( 2 * sizeof( uint16_t ) ), (uint16_t *)_US_ASCII }, #ifdef FRENCH { "FR", sizeof( _FRmap ) / ( 2 * sizeof( uint16_t ) ), (uint16_t *)_FRmap }, @@ -300,11 +395,16 @@ const PS2Advmap _KeyMaps[] = { #ifdef GERMAN { "DE", sizeof( _DEmap ) / ( 2 * sizeof( uint16_t ) ), (uint16_t *)_DEmap }, #endif +#ifdef SPANISH + { "ES", sizeof( _ESmap ) / ( 2 * sizeof( uint16_t ) ), (uint16_t *)_ESmap }, +#endif +#ifdef ITALIAN + { "IT", sizeof( _ITmap ) / ( 2 * sizeof( uint16_t ) ), (uint16_t *)_ITmap }, +#endif #ifdef SPECIAL { "--", sizeof( _SpecialMap ) / ( 2 * sizeof( uint16_t ) ), (uint16_t* )_SpecialMap }, #endif { "UK", sizeof( _UKmap ) / ( 2 * sizeof( uint16_t ) ), (uint16_t *)_UKmap }, { "GB", sizeof( _UKmap ) / ( 2 * sizeof( uint16_t ) ), (uint16_t *)_UKmap } }; - #endif diff --git a/src/PS2KeyMap.cpp b/src/PS2KeyMap.cpp index 439efc5..8e4cd55 100644 --- a/src/PS2KeyMap.cpp +++ b/src/PS2KeyMap.cpp @@ -1,13 +1,13 @@ -/* Version V1.0.4 +/* Version V1.0.5 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 + March 2020 - Paul Carpenter - add Spanish and Italian Mappings IMPORTANT WARNING - If using a DUE or similar board with 3V3 I/O you MUST put a level translator like a Texas Instruments TXS0102 or FET circuit as the signals are Bi-directional (signals transmitted from both ends on same wire). @@ -24,6 +24,8 @@ UK - By selecting with string "UK" or "GB" DE - German if define GERMAN exists FR - French if define FRENCH exists + ES - Spanish if define SPANISH exists + IT - Italian if define ITALIAN exists -- Special if you have created your own mapping see PS2KeyMap.h US and UK mappings are base layouts always compiled. All mappings are done @@ -43,6 +45,8 @@ // or comment to exclude //#define GERMAN //#define FRENCH + //#define SPANISH + //#define ITALIAN //#define SPECIAL Library converts key codes from PS2KeyAdvanced to enable full ASCCII/UTF-8 @@ -172,6 +176,8 @@ */ /*------------------ Code starts here -------------------------*/ +#include +// Internal headers for library defines/codes/etc #include #include "PS2KeyMap.h" #include "PS2KeyData.h" diff --git a/src/PS2KeyMap.h b/src/PS2KeyMap.h index 4bdd52b..4fcb5db 100644 --- a/src/PS2KeyMap.h +++ b/src/PS2KeyMap.h @@ -1,13 +1,13 @@ -/* Version V1.0.4 +/* Version V1.0.5 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 + March 2020 - Paul Carpenter - add Spanish and Italian Mappings - IMPORTANT WARNING - + IMPORTANT WARNING If using a DUE or similar board with 3V3 I/O you MUST put a level translator like a Texas Instruments TXS0102 or FET circuit as the signals are Bi-directional (signals transmitted from both ends on same wire). @@ -35,6 +35,8 @@ // or comment to exclude //#define GERMAN //#define FRENCH + //#define SPANISH + //#define ITALIAN //#define SPECIAL The functions in this library takes the unsigned int values produced from @@ -130,6 +132,8 @@ // or comment to exclude #define GERMAN #define FRENCH +#define SPANISH +#define ITALIAN //#define SPECIAL /* UTF-8 single byte LATIN encodings