Skip to content

Commit

Permalink
Configure for latest Arduino Library Manager versions
Browse files Browse the repository at this point in the history
Tidy up conditionals for adding platforms
Simplify examples
  • Loading branch information
techpaul committed Jan 23, 2020
1 parent 5c4aeed commit 0abe6c9
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 86 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
44 changes: 2 additions & 42 deletions examples/International/International.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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 " );
Expand All @@ -159,7 +128,6 @@ if( code > 0 )
Serial.print( " ( " );
Serial.write( code & 0xFF );
Serial.print( " )\n" );
#endif
}
// process special commands
found = 0;
Expand All @@ -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 );
}
35 changes: 13 additions & 22 deletions examples/KeyToLCD/KeyToLCD.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -329,28 +320,28 @@ 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;
check_cursor( );
/* 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++;
Expand Down
4 changes: 3 additions & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=PS2KeyMap
version=1.0.2
version=1.0.4
author=Paul Carpenter <[email protected]>
maintainer=Paul Carpenter <[email protected]>
sentence=PS2 keyboard codes from PS2KeyAdvanced to UTF-8 for any Latin language keyboard.
Expand All @@ -8,3 +8,5 @@ category=Other
url=https://github.com/techpaul/PS2KeyMap.git
architectures=avr,sam
depends=PS2KeyAdvanced
includes=PS2KeyAdvanced.h,PS2KeyMap.h

29 changes: 15 additions & 14 deletions src/PS2KeyData.h
Original file line number Diff line number Diff line change
@@ -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 <[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
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
Expand Down Expand Up @@ -44,19 +45,19 @@

/* 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,
PS2_TAB, PS2_ENTER, PS2_SPACE
};

// 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, '!' },
Expand Down Expand Up @@ -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 + '@', '"' },
Expand All @@ -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 },
Expand Down Expand Up @@ -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
{ '`', '^' },
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/PS2KeyMap.cpp
Original file line number Diff line number Diff line change
@@ -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 <[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
IMPORTANT WARNING
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/PS2KeyMap.h
Original file line number Diff line number Diff line change
@@ -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 <[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
IMPORTANT WARNING
Expand Down

0 comments on commit 0abe6c9

Please sign in to comment.