Ok, here is how you can replicate the problem. I have one computer (A) connected over a serial port to the Serial1 of the Leonardo (the Rx and Tx pins). Then I have another computer (B) connected to the Leonardo by the USB. Computer B has notepad running and the cursor focused on it and that's all. Computer A is sending characters every once in a while. Here is the code I am using, slimmed down to the bare minimum.
#include <avr/wdt.h>
void setup() {
wdt_disable();
Serial1.begin(115200);
while(!Serial1){;}
//Keyboard.end();
Keyboard.begin();
delay(1000);
Serial1.println("setup complete");
}
char inChar;
void loop() {
if(Serial1.available() > 0) {
inChar = Serial1.read();
if(inChar == 'R') {
hardReset();
}
else if (inChar == 'r'){
softReset();
}
else {
Serial1.println(inChar);
Keyboard.print(inChar);
}
}
}
void softReset(){
Serial1.println("soft reset");
delay(1000);
asm volatile(" jmp 0");
}
void hardReset(){
Serial1.println("hard reset");
delay(1000);
cli();
wdt_enable(WDTO_1S);
while(1);
}
Send a few characters first, like 123. You'll note that on computer B notepad will say 123 and on computer A it will also say 123. Perfect. now send an r (The hard reset isn't quite working, but that's a separate issue). You'll see that on computer A it will say "soft reset" followed a couple seconds later by "setup complete". Now send characters again. If you send 456, then computer A will show 456 on the serial line, but computer B will NOT have any new characters. It will sit there stupid and though it says a HID keyboard is plugged in, it won't have any new characters, and the only way to get it to resume correct behavior is to unplug/plug the computer B USB cable, which in this installation is not an option.