Repeat all received bytes to serial host.

This commit is contained in:
Maxwell Pray
2023-02-21 01:44:19 -08:00
parent f020b78a52
commit 4b96df400b
2 changed files with 16 additions and 32 deletions
+16 -30
View File
@@ -1,7 +1,6 @@
#define COMMAND_PING 'x'
#define COMMAND_QUERY '?'
#define COMMAND_TRANSMIT 'U'
#define COMMAND_QUERY_PAYLOAD "?107\r M764 rev 764100"
#define COMMAND_QUERY_PAYLOAD "107\r M764 rev 764100"
#define DATA_MODE_TIMEOUT_MS 1000
@@ -11,40 +10,27 @@ namespace NotebookAdapter {
unsigned long last_data_ms = 0;
bool command_mode = true;
void emulate_command_mode(uint8_t serial_byte) {
switch(serial_byte) {
case COMMAND_PING:
Serial.write(COMMAND_PING);
break;
case COMMAND_QUERY:
Serial.print(COMMAND_QUERY_PAYLOAD);
Serial.write(0);
break;
case COMMAND_TRANSMIT:
Serial.write(COMMAND_TRANSMIT);
command_mode = false;
break;
}
}
void emulate_data_mode(uint8_t serial_byte) {
void emulate(uint8_t serial_byte) {
if (millis() - last_data_ms > DATA_MODE_TIMEOUT_MS) {
command_mode = true;
}
Serial.write(serial_byte);
switch(serial_byte) {
case COMMAND_QUERY:
if (command_mode) {
Serial.print(COMMAND_QUERY_PAYLOAD);
Serial.write(0);
}
break;
case COMMAND_TRANSMIT:
command_mode = true;
break;
}
last_data_ms = millis();
}
void emulate(uint8_t serial_byte) {
void(*function)(uint8_t) = command_mode ? emulate_command_mode : emulate_data_mode;
function(serial_byte);
}
}
-2
View File
@@ -4,8 +4,6 @@
#include <Arduino.h>
namespace NotebookAdapter {
void emulate_command_mode(uint8_t serial_byte);
void emulate_data_mode(uint8_t serial_byte);
void emulate(uint8_t serial_byte);
}