User interface - Online Offline LED and speaker

This commit is contained in:
Dejvino 2023-04-06 07:46:24 +02:00
parent c64f2e44fa
commit eadfe70f1d

View File

@ -5,6 +5,9 @@
#include <TimerOne.h> #include <TimerOne.h>
// pinout config // pinout config
const int pinLedOffline = 10; // out
const int pinLedOnline = 9; // out
const int pinSpeaker = 8; // out
const int pinData = 6; // out, host data const int pinData = 6; // out, host data
const int pinStatus = 7; // in, host status const int pinStatus = 7; // in, host status
const int clockPin = 5; // out, kbd clock const int clockPin = 5; // out, kbd clock
@ -22,6 +25,7 @@ volatile int data = 0;
int test = 0; int test = 0;
volatile int counter = 0; volatile int counter = 0;
int numbits = 10; int numbits = 10;
volatile int typedKey = -1;
// MODS >>> // MODS >>>
// [1] send debug scancode information to serial port // [1] send debug scancode information to serial port
@ -31,7 +35,7 @@ bool modConsoleLog = true;
// ---------- // ----------
// KBD Output // KBD Output
// ---------- // ----------
volatile long lastChange = 0; volatile long lastChange = -100000;
volatile int x = 0; volatile int x = 0;
volatile int dataWord = 0; volatile int dataWord = 0;
volatile int dataState = 0; volatile int dataState = 0;
@ -54,6 +58,7 @@ void sendKey(byte key) {
dataDelay = 0; dataDelay = 0;
packetDelay = 0; packetDelay = 0;
packetTail = 15; packetTail = 15;
typedKey = key;
//Serial.print("Sending key "); Serial.println((int) key); //Serial.print("Sending key "); Serial.println((int) key);
} }
@ -365,6 +370,17 @@ void onTimerInterrupt()
slaveClockStep = (slaveClockStep + 1) % slaveClockDivider; slaveClockStep = (slaveClockStep + 1) % slaveClockDivider;
} }
// --------------
// User Interface
// --------------
void updateOnlineLeds()
{
long timeNow = millis();
bool online = (lastChange > timeNow) || ((timeNow - lastChange) < 10000);
digitalWrite(pinLedOffline, online ? LOW : HIGH);
digitalWrite(pinLedOnline, online ? HIGH : LOW);
}
// ---- // ----
// Main // Main
// ---- // ----
@ -374,12 +390,17 @@ void setup(void)
setupKeyMapping(); setupKeyMapping();
pinMode(pinLedOffline, OUTPUT);
pinMode(pinLedOnline, OUTPUT);
pinMode(pinSpeaker, OUTPUT);
pinMode(pinData, OUTPUT); pinMode(pinData, OUTPUT);
pinMode(dataPin, INPUT); pinMode(dataPin, INPUT);
pinMode(outPin, OUTPUT); pinMode(outPin, OUTPUT);
pinMode(clockPin, OUTPUT); pinMode(clockPin, OUTPUT);
pinMode(pinStatus, INPUT_PULLUP); pinMode(pinStatus, INPUT_PULLUP);
digitalWrite(pinLedOffline, HIGH);
digitalWrite(pinLedOnline, HIGH);
digitalWrite(pinData, HIGH); digitalWrite(pinData, HIGH);
digitalWrite(outPin, LOW); digitalWrite(outPin, LOW);
@ -388,6 +409,23 @@ void setup(void)
Timer1.initialize(timerDelay); Timer1.initialize(timerDelay);
Timer1.attachInterrupt(onTimerInterrupt); Timer1.attachInterrupt(onTimerInterrupt);
delay(500);
tone(pinSpeaker, 650, 200);
digitalWrite(pinLedOffline, LOW);
digitalWrite(pinLedOnline, HIGH);
delay(200);
tone(pinSpeaker, 500, 200);
digitalWrite(pinLedOffline, HIGH);
digitalWrite(pinLedOnline, LOW);
delay(200);
digitalWrite(pinLedOffline, LOW);
digitalWrite(pinLedOnline, LOW);
delay(500);
updateOnlineLeds();
tone(pinSpeaker, 440, 200);
delay(200);
Serial.println("Keyboard ready"); Serial.println("Keyboard ready");
} }
@ -419,5 +457,13 @@ void loop(void)
Serial.print("QWE "); Serial.println((int)k); Serial.print("QWE "); Serial.println((int)k);
if (qwe % 5 == 0) delay(2000); if (qwe % 5 == 0) delay(2000);
/**/ /**/
updateOnlineLeds();
if (typedKey != -1) {
tone(pinSpeaker, 200 + typedKey, 100);
typedKey = -1;
}
delay(5);
} }