Skip to content

Instantly share code, notes, and snippets.

@jboecker
Last active December 12, 2020 15:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jboecker/0c10894ffe4394d52f24 to your computer and use it in GitHub Desktop.
Save jboecker/0c10894ffe4394d52f24 to your computer and use it in GitHub Desktop.
/* PS2Keyboard library example
Adapted to control (parts of) the A-10C CDU keyboard
through DCS-BIOS.
PS2Keyboard now requries both pins specified for begin()
keyboard.begin(data_pin, irq_pin);
Valid irq pins:
Arduino: 2, 3
Arduino Mega: 2, 3, 18, 19, 20, 21
Teensy 1.0: 0, 1, 2, 3, 4, 6, 7, 16
Teensy 2.0: 5, 6, 7, 8
Teensy++ 1.0: 0, 1, 2, 3, 18, 19, 36, 37
Teensy++ 2.0: 0, 1, 2, 3, 18, 19, 36, 37
Sanguino: 2, 10, 11
for more information you can read the original wiki in arduino.cc
at http://www.arduino.cc/playground/Main/PS2Keyboard
or http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html
Like the Original library and example this is under LGPL license.
Modified by Cuninganreset@gmail.com on 2010-03-22
Modified by Paul Stoffregen <paul@pjrc.com> June 2010
*/
#include <PS2Keyboard.h>
const int DataPin = 4;
const int IRQpin = 3;
PS2Keyboard keyboard;
void setup() {
delay(1000);
keyboard.begin(DataPin, IRQpin);
// Serial.begin(500000);
Serial.begin(500000);
}
void pressCDUButton(char* btn) {
Serial.write("CDU_");
Serial.write(btn);
Serial.write(" 1\n");
Serial.write("CDU_");
Serial.write(btn);
Serial.write(" 0\n");
}
void loop() {
if (keyboard.available()) {
// read the next key
char c = keyboard.read();
if (c >= 'a' && c <= 'z') {
// a-z -> A-Z
c = c - 32;
}
if (c >= 'A' && c <= 'Z') {
// A-Z
char buf[2];
buf[1] = 0;
buf[0] = c;
pressCDUButton(buf);
}
if (c >= '0' && c <= '9') {
char buf[2];
buf[1] = 0;
buf[0] = c;
pressCDUButton(buf);
}
if (c == PS2_PAGEDOWN) {
Serial.write("CDU_PG 0\n");
Serial.write("CDU_PG 1\n");
} else if (c == PS2_PAGEUP) {
Serial.write("CDU_PG 2\n");
Serial.write("CDU_PG 1\n");
}
if (c == '/') pressCDUButton("SLASH");
if (c == ' ') pressCDUButton("SPC");
if (c == '.') pressCDUButton("POINT");
if (c == PS2_ENTER) pressCDUButton("MK");
if (c == PS2_TAB) pressCDUButton("FA");
if (c == PS2_ESC) pressCDUButton("CLR");
if (c == PS2_DELETE) pressCDUButton("BCK");
if (c == PS2_RIGHTARROW) {
Serial.write("CDU_SCROLL 2\n");
Serial.write("CDU_SCROLL 1\n");
}
if (c == PS2_LEFTARROW) {
Serial.write("CDU_SCROLL 0\n");
Serial.write("CDU_SCROLL 1\n");
}
if (c == '+') {
Serial.write("CDU_DATA 2\n");
Serial.write("CDU_DATA 1\n");
}
if (c == '-') {
Serial.write("CDU_DATA 0\n");
Serial.write("CDU_DATA 1\n");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment