From 134b3dc51b670f94cffa32de4ed977f73731a01c Mon Sep 17 00:00:00 2001 From: eneller Date: Wed, 25 Jun 2025 00:29:32 +0200 Subject: [PATCH] wip: testing --- mcu-server-watchdog.ino | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mcu-server-watchdog.ino b/mcu-server-watchdog.ino index 35b6c89..a7441c1 100644 --- a/mcu-server-watchdog.ino +++ b/mcu-server-watchdog.ino @@ -12,43 +12,43 @@ void setup() { pinMode(PIN_BOOT, OUTPUT); //NOTE might want to replace this initialization with a check in the first loop, so we dont instantly reboot startTimeMillis = millis(); - } void loop(){ - if (Serial.available() > 0) { // if something has been written to the serial port + // Serial Connection has received data? Reset Timer + if (Serial.available() > 0) { startTimeMillis = millis(); clearSerial(); rebooted = false; Serial.println("read serial"); } unsigned long timeElapsed = millis() - startTimeMillis; + + // TODO fix instant reboot + // reboot? if (timeElapsed > HEARTBEAT_REBOOT_DELAY_MILLIS && not rebooted){ pin_switch(PIN_REBOOT); startTimeMillis = millis(); rebooted = true; Serial.println("reboot"); - } + + // boot? if (timeElapsed > HEARTBEAT_BOOT_DELAY_MILLIS){ pin_switch(PIN_BOOT); startTimeMillis = millis(); Serial.println("boot"); - } } void pin_switch(int pin){ - //TODO connect the RST pins on the motherboard digitalWrite(pin, LOW); delay(500); digitalWrite(pin, HIGH); } - - void clearSerial(){ while (Serial.available()>0){ char t = Serial.read();