Skip to content

Commit

Permalink
V1.0.5 Add Italain and Spanish keyboard layouts other tidy ups
Browse files Browse the repository at this point in the history
  • Loading branch information
techpaul committed Mar 2, 2020
1 parent 0abe6c9 commit 131663c
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 100 deletions.
12 changes: 12 additions & 0 deletions examples/International/International.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand 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 );
Expand Down Expand Up @@ -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" );
Expand Down
53 changes: 5 additions & 48 deletions examples/KeyToLCD/KeyToLCD.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,47 +138,16 @@ 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,
PS2_KEY_F12 };
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
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name=PS2KeyMap
version=1.0.4
version=1.0.5
author=Paul Carpenter <[email protected]>
maintainer=Paul Carpenter <[email protected]>
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

190 changes: 145 additions & 45 deletions src/PS2KeyData.h
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 ] = {
Expand All @@ -290,21 +382,29 @@ 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 },
#endif
#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
Loading

0 comments on commit 131663c

Please sign in to comment.