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