fix: infinite loop of rebooting
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
|
# should be in /etc/udev/rules.d/
|
||||||
ACTION=="add", ATTRS{idProduct}=="7523", ATTRS{idVendor}=="1a86", NAME="watchdog"
|
ACTION=="add", ATTRS{idProduct}=="7523", ATTRS{idVendor}=="1a86", NAME="watchdog"
|
||||||
|
|||||||
@@ -1,48 +1,53 @@
|
|||||||
const int HEARTBEAT_REBOOT_DELAY_MILLIS = 20000; //this is coupled to the HEARTBEAT_INTERVAL in src/main.rs
|
const int HEARTBEAT_REBOOT_DELAY_MILLIS = 2000; //this is coupled to the HEARTBEAT_INTERVAL in src/main.rs
|
||||||
const int HEARTBEAT_BOOT_DELAY_MILLIS = 60000;
|
const int HEARTBEAT_BOOT_DELAY_MILLIS = 9000;
|
||||||
const int PIN_REBOOT = 2;
|
const int PIN_REBOOT = 2;
|
||||||
const int PIN_BOOT = 3;
|
const int PIN_BOOT = 3;
|
||||||
|
|
||||||
|
bool rebooted = false;
|
||||||
|
|
||||||
unsigned long startTimeMillis;
|
unsigned long startTimeMillis;
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
pinMode(PIN_REBOOT, OUTPUT);
|
pinMode(PIN_REBOOT, OUTPUT);
|
||||||
pinMode(PIN_BOOT, OUTPUT);
|
pinMode(PIN_BOOT, OUTPUT);
|
||||||
waitForSerial();
|
|
||||||
//NOTE might want to replace this initialization with a check in the first loop, so we dont instantly reboot
|
//NOTE might want to replace this initialization with a check in the first loop, so we dont instantly reboot
|
||||||
startTimeMillis = millis();
|
startTimeMillis = millis();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
if (millis() - startTimeMillis > HEARTBEAT_REBOOT_DELAY_MILLIS){pin_switch(PIN_REBOOT);}
|
|
||||||
if (Serial.available() > 0) { // if something has been written to the serial port
|
if (Serial.available() > 0) { // if something has been written to the serial port
|
||||||
startTimeMillis = millis();
|
startTimeMillis = millis();
|
||||||
clearSerial();
|
clearSerial();
|
||||||
|
rebooted = false;
|
||||||
|
Serial.println("read serial");
|
||||||
}
|
}
|
||||||
|
unsigned long timeElapsed = millis() - startTimeMillis;
|
||||||
|
if (timeElapsed > HEARTBEAT_REBOOT_DELAY_MILLIS && not rebooted){
|
||||||
|
pin_switch(PIN_REBOOT);
|
||||||
|
startTimeMillis = millis();
|
||||||
|
rebooted = true;
|
||||||
|
Serial.println("reboot");
|
||||||
|
|
||||||
|
}
|
||||||
|
if (timeElapsed > HEARTBEAT_BOOT_DELAY_MILLIS){
|
||||||
|
pin_switch(PIN_BOOT);
|
||||||
|
startTimeMillis = millis();
|
||||||
|
Serial.println("boot");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void pin_switch(int pin){
|
void pin_switch(int pin){
|
||||||
//TODO connect the RST pins on the motherboard
|
//TODO connect the RST pins on the motherboard
|
||||||
Serial.println("Error!");
|
|
||||||
digitalWrite(pin, LOW);
|
digitalWrite(pin, LOW);
|
||||||
delay(500);
|
delay(500);
|
||||||
digitalWrite(pin, HIGH);
|
digitalWrite(pin, HIGH);
|
||||||
waitForSerial();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
busy wait for first serial input
|
|
||||||
*/
|
|
||||||
void waitForSerial(){
|
|
||||||
while(Serial.available() == 0){
|
|
||||||
//check if we may need to initiate a normal boot instead of a reboot, e.g. after a power outage
|
|
||||||
if (millis() - startTimeMillis > HEARTBEAT_BOOT_DELAY_MILLIS){
|
|
||||||
pin_switch(PIN_BOOT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void clearSerial(){
|
void clearSerial(){
|
||||||
while (Serial.available()>0){
|
while (Serial.available()>0){
|
||||||
|
|||||||
Reference in New Issue
Block a user