feat: watchdog now restarts pc successfully
This commit is contained in:
1
heartbeat.rules
Normal file
1
heartbeat.rules
Normal file
@@ -0,0 +1 @@
|
||||
ACTION=="add", ATTRS{idProduct}=="7523", ATTRS{idVendor}=="1a86", NAME="watchdog"
|
||||
@@ -1,5 +1,5 @@
|
||||
const int HEARTBEAT_MAX_DELAY_MILLIS = 20000; //this is coupled to the HEARTBEAT_INTERVAL in src/main.rs
|
||||
const int PIN_SWITCH = 13;
|
||||
const int PIN_SWITCH = 2;
|
||||
|
||||
unsigned long startTimeMillis;
|
||||
void setup() {
|
||||
@@ -17,6 +17,7 @@ void loop(){
|
||||
if (tickMillis > HEARTBEAT_MAX_DELAY_MILLIS){rst();}
|
||||
if (Serial.available() > 0) { // if something has been written to the serial port
|
||||
startTimeMillis = millis();
|
||||
clearSerial();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +25,7 @@ void loop(){
|
||||
void rst(){
|
||||
//TODO connect the RST pins on the motherboard
|
||||
Serial.println("Error!");
|
||||
digialWrite(PIN_SWITCH, LOW);
|
||||
digitalWrite(PIN_SWITCH, LOW);
|
||||
delay(500);
|
||||
digitalWrite(PIN_SWITCH, HIGH);
|
||||
waitForSerial();
|
||||
@@ -37,3 +38,8 @@ void waitForSerial(){
|
||||
while(Serial.available() == 0){}
|
||||
}
|
||||
|
||||
void clearSerial(){
|
||||
while (Serial.available()>0){
|
||||
char t = Serial.read();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
use std::{thread, io};
|
||||
use std::time::Duration;
|
||||
use serialport::{available_ports, SerialPort, SerialPortType};
|
||||
use serialport::SerialPort;
|
||||
|
||||
const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5);
|
||||
const HEARTBEAT_MESSAGE: &str = "OK";
|
||||
const WATCHDOG_DEVICE: &str = "/dev/watchdog";
|
||||
|
||||
|
||||
fn main() {
|
||||
@@ -12,7 +13,7 @@ fn main() {
|
||||
|
||||
fn setup() -> Box<dyn SerialPort>{
|
||||
//TODO find serial port of microcontroller
|
||||
let port = serialport::new("/dev/pts/4", 9600)
|
||||
let port = serialport::new(WATCHDOG_DEVICE, 9600)
|
||||
.open()
|
||||
.expect("Failed to open port");
|
||||
return port;
|
||||
|
||||
Reference in New Issue
Block a user