Browse Source

added NKRO emulation functionality and set it as default communication mode

master
Emanuele Caruso 10 years ago
parent
commit
f736088a1b
1 changed files with 45 additions and 4 deletions
  1. 45
    4
      StenoFW.ino

+ 45
- 4
StenoFW.ino View File

// Protocol state // Protocol state
#define GEMINI 0 #define GEMINI 0
#define TXBOLT 1 #define TXBOLT 1
int protocol = GEMINI;
#define NKRO 2
int protocol = NKRO;


// This is called when the keyboard is connected // This is called when the keyboard is connected
void setup() { void setup() {
Keyboard.begin();
Serial.begin(9600); Serial.begin(9600);
for (int i = 0; i < COLS; i++) for (int i = 0; i < COLS; i++)
pinMode(colPins[i], INPUT_PULLUP); pinMode(colPins[i], INPUT_PULLUP);
digitalWrite(rowPins[i], HIGH); digitalWrite(rowPins[i], HIGH);
} }
} }

// Send current chord using NKRO Keyboard emulation
void sendChordNkro() {
// QWERTY mapping
char qwertyMapping[ROWS][COLS] = {
{'q', 'w', 'e', 'r', 't', ' '},
{'a', 's', 'd', 'f', 'g', ' '},
{'c', 'v', 'n', 'm', '3', ' '},
{'u', 'i', 'o', 'p', '[', ' '},
{'j', 'k', 'l', ';', '\'', ' '}
};
int keyCounter = 0;
char qwertyKeys[ROWS * COLS];
boolean firstKeyPressed = false;
// Calculate qwerty keys array using qwertyMappings[][]
for (int i = 0; i < ROWS; i++)
for (int j = 0; j < COLS; j++)
if (currentChord[i][j]) {
qwertyKeys[keyCounter] = qwertyMapping[i][j];
keyCounter++;
}
// Emulate keyboard key presses
for (int i = 0; i < keyCounter; i++) {
if (qwertyKeys[i] != ' ') {
Keyboard.press(qwertyKeys[i]);
if (!firstKeyPressed) firstKeyPressed = true;
else Keyboard.release(qwertyKeys[i]);
}
}
Keyboard.releaseAll();
}
// Send current chord over serial using the Gemini protocol. // Send current chord over serial using the Gemini protocol.
void sendChordGemini() { void sendChordGemini() {
return; return;
} }
if (protocol == GEMINI) {
if (protocol == NKRO) {
sendChordNkro();
} else if (protocol == GEMINI) {
sendChordGemini(); sendChordGemini();
} else { } else {
sendChordTxBolt(); sendChordTxBolt();
// accidental activation? // accidental activation?
// //
// Current functions: // Current functions:
// PH-PB -> Set NKRO Keyboard emulation mode
// PH-G -> Set Gemini PR protocol mode // PH-G -> Set Gemini PR protocol mode
// PH-B -> Set TX Bolt protocol mode // PH-B -> Set TX Bolt protocol mode
void fn1() { void fn1() {
// "PH" -> Set protocol // "PH" -> Set protocol
if (currentChord[0][2] && currentChord[0][3]) { if (currentChord[0][2] && currentChord[0][3]) {
// "-PB" -> NKRO Keyboard
if (currentChord[3][1] && currentChord[4][1]) {
protocol = NKRO;
}
// "-G" -> Gemini PR // "-G" -> Gemini PR
if (currentChord[4][2]) {
else if (currentChord[4][2]) {
protocol = GEMINI; protocol = GEMINI;
} }
// "-B" -> TX Bolt // "-B" -> TX Bolt
if (currentChord[4][1]) {
else if (currentChord[4][1]) {
protocol = TXBOLT; protocol = TXBOLT;
} }
} }