diff --git a/terminal_keyboard_emulator.ino b/terminal_keyboard_emulator.ino index 843c137..6cabb0d 100644 --- a/terminal_keyboard_emulator.ino +++ b/terminal_keyboard_emulator.ino @@ -26,6 +26,7 @@ int test = 0; volatile int counter = 0; int numbits = 10; volatile int typedKey = -1; +bool hostOnline = false; // MODS >>> // [1] send debug scancode information to serial port @@ -373,12 +374,13 @@ void onTimerInterrupt() // -------------- // User Interface // -------------- -void updateOnlineLeds() +void updateOnlineStatus() { long timeNow = millis(); - bool online = (lastChange > timeNow) || ((timeNow - lastChange) < 10000); - digitalWrite(pinLedOffline, online ? LOW : HIGH); - digitalWrite(pinLedOnline, online ? HIGH : LOW); + hostOnline = (lastChange > timeNow) || ((timeNow - lastChange) < 10000); + + digitalWrite(pinLedOffline, hostOnline ? LOW : HIGH); + digitalWrite(pinLedOnline, hostOnline ? HIGH : LOW); } // ---- @@ -422,7 +424,7 @@ void setup(void) digitalWrite(pinLedOnline, LOW); delay(500); - updateOnlineLeds(); + updateOnlineStatus(); tone(pinSpeaker, 440, 200); delay(200); @@ -458,8 +460,12 @@ void loop(void) if (qwe % 5 == 0) delay(2000); /**/ - updateOnlineLeds(); - if (typedKey != -1) { + updateOnlineStatus(); + if (nextKeyReady && !hostOnline) { // skip sending key without a host (used for USB) + nextKeyReady = false; + typedKey = nextKey; + } + if (!nextKeyReady && typedKey != -1) { tone(pinSpeaker, 200 + typedKey, 100); typedKey = -1; }