diff --git a/Universal_Serial_Adapter/Config.cpp b/Universal_Serial_Adapter/Config.cpp index 42add7d..75e7b1d 100644 --- a/Universal_Serial_Adapter/Config.cpp +++ b/Universal_Serial_Adapter/Config.cpp @@ -148,3 +148,38 @@ void Config::setDefaults() { setMode(ttl); setTimeout(thirtyseconds); } + +void Config::processSerialData() { + switch (currentMode) { + case 1: // ttl + if (Serial1.available()) { + int inByte = Serial1.read(); + Serial.write(inByte); + } + if (Serial.available()) { + int inByte = Serial.read(); + Serial1.write(inByte); + } + break; + case 2: // db9_null + if (Serial2.available()) { + int inByte = Serial2.read(); + Serial.write(inByte); + } + if (Serial.available()) { + int inByte = Serial.read(); + Serial2.write(inByte); + } + break; + case 3: // cisco + if (Serial3.available()) { + int inByte = Serial3.read(); + Serial.write(inByte); + } + if (Serial.available()) { + int inByte = Serial.read(); + Serial3.write(inByte); + } + break; + } +} \ No newline at end of file diff --git a/Universal_Serial_Adapter/Config.h b/Universal_Serial_Adapter/Config.h index db27c9f..2fae59a 100644 --- a/Universal_Serial_Adapter/Config.h +++ b/Universal_Serial_Adapter/Config.h @@ -43,6 +43,7 @@ public: void disableUI(); void enableUI(); bool isUIEnabled(); + void processSerialData(); }; #endif diff --git a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino index f314a74..56f5efa 100644 --- a/Universal_Serial_Adapter/Universal_Serial_Adapter.ino +++ b/Universal_Serial_Adapter/Universal_Serial_Adapter.ino @@ -33,7 +33,12 @@ void setup() { } void loop() { + // Serial data is processed at multiple points to prevent + // UI code from interfering with communication + config->processSerialData(); ui->processInputEvents(); + config->processSerialData(); ui->processTimeoutEvents(); + config->processSerialData(); }