Merge WIP: reading keys works
This commit is contained in:
parent
980ea104ff
commit
2bc8080e67
@ -5,16 +5,15 @@
|
|||||||
#include <TimerOne.h>
|
#include <TimerOne.h>
|
||||||
|
|
||||||
// pinout config
|
// pinout config
|
||||||
const int pinData = 6;
|
const int pinData = 6; // out, host data
|
||||||
const int pinStatus = 7;
|
const int pinStatus = 7; // in, host status
|
||||||
const int clockPin = 5;
|
const int clockPin = 5; // out, kbd clock
|
||||||
const int dataPin = 3;
|
const int dataPin = 3; // in, kbd data
|
||||||
const int outPin = 4;
|
const int outPin = 4; // out, kbd led
|
||||||
const int speakerPin = 6;
|
|
||||||
|
|
||||||
// constant config
|
// constant config
|
||||||
const int slaveClockDivider = 16;
|
const int slaveClockDivider = 4;
|
||||||
const int timerDelay = 530 / slaveClockDivider;
|
const int timerDelay = 528 / slaveClockDivider;
|
||||||
|
|
||||||
// variables
|
// variables
|
||||||
volatile int slaveClockStep = 0;
|
volatile int slaveClockStep = 0;
|
||||||
@ -27,8 +26,6 @@ int numbits = 10;
|
|||||||
// MODS >>>
|
// MODS >>>
|
||||||
// [1] send debug scancode information to serial port
|
// [1] send debug scancode information to serial port
|
||||||
bool modConsoleLog = true;
|
bool modConsoleLog = true;
|
||||||
// [2] play speaker sounds of keys
|
|
||||||
bool modKeySounds = true;
|
|
||||||
// <<< MODS
|
// <<< MODS
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
@ -48,6 +45,7 @@ volatile byte nextKey = 0;
|
|||||||
void typeKey(byte key) {
|
void typeKey(byte key) {
|
||||||
nextKey = key;
|
nextKey = key;
|
||||||
nextKeyReady = true;
|
nextKeyReady = true;
|
||||||
|
Serial.print("Typing key "); Serial.println((int) key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendKey(byte key) {
|
void sendKey(byte key) {
|
||||||
@ -56,6 +54,7 @@ void sendKey(byte key) {
|
|||||||
dataDelay = 0;
|
dataDelay = 0;
|
||||||
packetDelay = 0;
|
packetDelay = 0;
|
||||||
packetTail = 15;
|
packetTail = 15;
|
||||||
|
Serial.print("Sending key "); Serial.println((int) key);
|
||||||
//Timer1.initialize(timerDelay);
|
//Timer1.initialize(timerDelay);
|
||||||
//Timer1.start();
|
//Timer1.start();
|
||||||
}
|
}
|
||||||
@ -64,8 +63,10 @@ void onHostStatusChange() {
|
|||||||
long timeNow = millis();
|
long timeNow = millis();
|
||||||
long changeDiff = timeNow - lastChange;
|
long changeDiff = timeNow - lastChange;
|
||||||
lastChange = timeNow;
|
lastChange = timeNow;
|
||||||
|
digitalWrite(pinData, digitalRead(pinStatus));
|
||||||
if (changeDiff >= 10 && nextKeyReady) {
|
if (changeDiff >= 10 && nextKeyReady) {
|
||||||
nextKeyReady = false;
|
nextKeyReady = false;
|
||||||
|
Serial.println("Status change with key");
|
||||||
sendKey(nextKey);
|
sendKey(nextKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,7 +149,7 @@ char translateKeyToChar(int key) {
|
|||||||
if (sizeof(m) <= key) {
|
if (sizeof(m) <= key) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return m[key];
|
return key; //m[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
void printChar(char keyChar) {
|
void printChar(char keyChar) {
|
||||||
@ -168,6 +169,8 @@ void processKbdByte(int data) {
|
|||||||
Keyboard.release(keyChar);
|
Keyboard.release(keyChar);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typeKey(keyChar);
|
||||||
|
|
||||||
if (modConsoleLog) {
|
if (modConsoleLog) {
|
||||||
Serial.print("Press: ");
|
Serial.print("Press: ");
|
||||||
printChar(keyChar);
|
printChar(keyChar);
|
||||||
@ -212,7 +215,6 @@ void setup(void)
|
|||||||
//Timer1.stop();
|
//Timer1.stop();
|
||||||
|
|
||||||
Serial.println("Keyboard ready");
|
Serial.println("Keyboard ready");
|
||||||
tone(speakerPin, 80, 50);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(void)
|
void loop(void)
|
||||||
@ -227,7 +229,6 @@ void loop(void)
|
|||||||
// type key from keyboard
|
// type key from keyboard
|
||||||
if (counter >= numbits) {
|
if (counter >= numbits) {
|
||||||
processKbdByte(data);
|
processKbdByte(data);
|
||||||
if (modKeySounds) tone(speakerPin, 60 + int(data), 25);
|
|
||||||
data = B0;
|
data = B0;
|
||||||
counter = 0;
|
counter = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user