1
0
Fork 0

Implement enigma types

master
NaiJi ✨ 2 years ago
parent 9f6d693719
commit 4536cebb65

@ -1,167 +1,25 @@
/* Simple keyboard to serial port at 115200 baud
PS2KeyAdvanced library example
Advanced support PS2 Keyboard to get every key code byte from a PS2 Keyboard
for testing purposes.
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).
Failure to do so may damage your Arduino Due or similar board.
Test History
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
This is for a LATIN style keyboard using Scan code set 2. See various
websites on what different scan code sets use. Scan Code Set 2 is the
default scan code set for PS2 keyboards on power up.
Will support most keyboards even ones with multimedia keys or even 24 function keys.
The circuit:
* KBD Clock (PS2 pin 1) to an interrupt pin on Arduino ( this example pin 3 )
* KBD Data (PS2 pin 5) to a data pin ( this example pin 4 )
* +5V from Arduino to PS2 pin 4
* GND from Arduino to PS2 pin 3
The connector to mate with PS2 keyboard is a 6 pin Female Mini-Din connector
PS2 Pins to signal
1 KBD Data
3 GND
4 +5V
5 KBD Clock
Keyboard has 5V and GND connected see plenty of examples and
photos around on Arduino site and other sites about the PS2 Connector.
Interrupts
Clock pin from PS2 keyboard MUST be connected to an interrupt
pin, these vary with the different types of Arduino
PS2KeyAdvanced requires both pins specified for begin()
keyboard.begin( data_pin, irq_pin );
Valid irq pins:
Arduino Uno: 2, 3
Arduino Due: All pins, except 13 (LED)
Arduino Mega: 2, 3, 18, 19, 20, 21
Teensy 2.0: All pins, except 13 (LED)
Teensy 2.0: 5, 6, 7, 8
Teensy 1.0: 0, 1, 2, 3, 4, 6, 7, 16
Teensy++ 2.0: 0, 1, 2, 3, 18, 19, 36, 37
Teensy++ 1.0: 0, 1, 2, 3, 18, 19, 36, 37
Sanguino: 2, 10, 11
Read method Returns an UNSIGNED INT containing
Make/Break status
Caps status
Shift, CTRL, ALT, ALT GR, GUI keys
Flag for function key not a displayable/printable character
8 bit key code
Code Ranges (bottom byte of unsigned int)
0 invalid/error
1-1F Functions (Caps, Shift, ALT, Enter, DEL... )
1A-1F Functions with ASCII control code
(DEL, BS, TAB, ESC, ENTER, SPACE)
20-61 Printable characters noting
0-9 = 0x30 to 0x39 as ASCII
A to Z = 0x41 to 0x5A as upper case ASCII type codes
8B Extra European key
61-A0 Function keys and other special keys (plus F2 and F1)
61-78 F1 to F24
79-8A Multimedia
8B NOT included
8C-8E ACPI power
91-A0 and F2 and F1 - Special multilingual
A8-FF Keyboard communications commands (note F2 and F1 are special
codes for special multi-lingual keyboards)
By using these ranges it is possible to perform detection of any key and do
easy translation to ASCII/UTF-8 avoiding keys that do not have a valid code.
Top Byte is 8 bits denoting as follows with defines for bit code
Define name bit description
PS2_BREAK 15 1 = Break key code
(MSB) 0 = Make Key code
PS2_SHIFT 14 1 = Shift key pressed as well (either side)
0 = NO shift key
PS2_CTRL 13 1 = Ctrl key pressed as well (either side)
0 = NO Ctrl key
PS2_CAPS 12 1 = Caps Lock ON
0 = Caps lock OFF
PS2_ALT 11 1 = Left Alt key pressed as well
0 = NO Left Alt key
PS2_ALT_GR 10 1 = Right Alt (Alt GR) key pressed as well
0 = NO Right Alt key
PS2_GUI 9 1 = GUI key pressed as well (either)
0 = NO GUI key
PS2_FUNCTION 8 1 = FUNCTION key non-printable character (plus space, tab, enter)
0 = standard character key
Error Codes
Most functions return 0 or 0xFFFF as error, other codes to note and
handle appropriately
0xAA keyboard has reset and passed power up tests
will happen if keyboard plugged in after code start
0xFC Keyboard General error or power up fail
See PS2Keyboard.h file for returned definitions of Keys
Note defines starting
PS2_KEY_* are the codes this library returns
PS2_* remaining defines for use in higher levels
To get the key as ASCII/UTF-8 single byte character conversion requires use
of PS2KeyMap library AS WELL.
Written by Paul Carpenter, PC Services <sales@pcserviceselectronics.co.uk>
*/
#include <PS2KeyAdvanced.h>
#include "enigma_types.h"
/* Keyboard constants Change to suit your Arduino
define pins used for data and clock from keyboard */
#define DATAPIN 2
#define IRQPIN 3
uint16_t c;
PS2KeyAdvanced keyboard;
void setup( )
void setup()
{
// Configure the keyboard library
keyboard.begin( DATAPIN, IRQPIN );
Serial.begin( 115200 );
Serial.println( "PS2 Advanced Key Simple Test:" );
keyboard.begin(DATAPIN, IRQPIN);
Serial.begin(115200);
}
void loop( )
void loop()
{
if( keyboard.available( ) )
{
// read the next key
c = keyboard.read( );
if( c > 0 )
if (keyboard.available())
{
Serial.print( "Value " );
Serial.print( c, HEX );
Serial.print( " - Status Bits " );
Serial.print( c >> 8, HEX );
Serial.print( " Code " );
Serial.println( c & 0xFF, HEX );
const uint16_t key = keyboard.read();
if (key > 0)
{
const String value = String(key, HEX);
}
}
}
}

@ -0,0 +1,59 @@
// Латинский алфавит в HEX представлении
const String key_values[26] =
{
"51", // Code51 - q
"57", // Code57 - w
"45", // Code45 - e
"52", // Code52 - r
"54", // Code54 - t
"59", // Code59 - y
"55", // Code55 - u
"49", // Code49 - i
"4F", // Code4F - o
"50", // Code50 - p
"41", // Code41 - a
"53", // Code53 - s
"44", // Code44 - d
"46", // Code46 - f
"47", // Code47 - g
"48", // Code48 - h
"4A", // Code4A - j
"4B", // Code4B - k
"4C", // Code4C - l
"5A", // Code5A - z
"58", // Code58 - x
"43", // Code43 - c
"56", // Code56 - v
"42", // Code42 - b
"4E", // Code4E - n
"4D" // Code4D - m
};
// Сдвиг в алфавите для каждого из трёх "дисков".
// Обязан быть в отрезке [0; 25], так как полный круг
// возвращает значение обратно в 0.
// Таким образом, при конфигурации { 1, 2, 5 } и
// нажатой ' d ' сначала произойдёт сдвиг на 1, ' d '
// станет ' f ', потом на 2, ' f ' станет ' h ',
// в конце ещё сдвиг на 5 и ' h ' станет ' x '.
const size_t key_shifts[3] =
{
1,
2,
5
};
// Соединение на коммутационной панели
struct Plug
{
size_t left_index = 0;
size_t right_index = 0;
};
// Все соединения коммутационной панели.
// Для примера всего 2, но может быть до 13
const Plug plugboard[2] =
{
{0, 1}, // ' q ' <- -> ' w '
{4, 10} // ' t ' <- -> ' a '
};
Loading…
Cancel
Save