wip: testing
This commit is contained in:
@@ -12,43 +12,43 @@ void setup() {
|
|||||||
pinMode(PIN_BOOT, OUTPUT);
|
pinMode(PIN_BOOT, OUTPUT);
|
||||||
//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 (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();
|
startTimeMillis = millis();
|
||||||
clearSerial();
|
clearSerial();
|
||||||
rebooted = false;
|
rebooted = false;
|
||||||
Serial.println("read serial");
|
Serial.println("read serial");
|
||||||
}
|
}
|
||||||
unsigned long timeElapsed = millis() - startTimeMillis;
|
unsigned long timeElapsed = millis() - startTimeMillis;
|
||||||
|
|
||||||
|
// TODO fix instant reboot
|
||||||
|
// reboot?
|
||||||
if (timeElapsed > HEARTBEAT_REBOOT_DELAY_MILLIS && not rebooted){
|
if (timeElapsed > HEARTBEAT_REBOOT_DELAY_MILLIS && not rebooted){
|
||||||
pin_switch(PIN_REBOOT);
|
pin_switch(PIN_REBOOT);
|
||||||
startTimeMillis = millis();
|
startTimeMillis = millis();
|
||||||
rebooted = true;
|
rebooted = true;
|
||||||
Serial.println("reboot");
|
Serial.println("reboot");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// boot?
|
||||||
if (timeElapsed > HEARTBEAT_BOOT_DELAY_MILLIS){
|
if (timeElapsed > HEARTBEAT_BOOT_DELAY_MILLIS){
|
||||||
pin_switch(PIN_BOOT);
|
pin_switch(PIN_BOOT);
|
||||||
startTimeMillis = millis();
|
startTimeMillis = millis();
|
||||||
Serial.println("boot");
|
Serial.println("boot");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void pin_switch(int pin){
|
void pin_switch(int pin){
|
||||||
//TODO connect the RST pins on the motherboard
|
|
||||||
digitalWrite(pin, LOW);
|
digitalWrite(pin, LOW);
|
||||||
delay(500);
|
delay(500);
|
||||||
digitalWrite(pin, HIGH);
|
digitalWrite(pin, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void clearSerial(){
|
void clearSerial(){
|
||||||
while (Serial.available()>0){
|
while (Serial.available()>0){
|
||||||
char t = Serial.read();
|
char t = Serial.read();
|
||||||
|
|||||||
Reference in New Issue
Block a user