arduino dev

This commit is contained in:
Jonatan Nilsson 2024-02-14 00:06:49 +00:00
parent 9b2bf554b1
commit c1fcd3a47d

View file

@ -22,7 +22,6 @@ String vfd_line_bottom = "Waiting for stream. ";
unsigned int vfd_line_position = 0; unsigned int vfd_line_position = 0;
bool vfd_line_print = false; bool vfd_line_print = false;
unsigned long millis_last_incoming_ping = 0; unsigned long millis_last_incoming_ping = 0;
unsigned long millis_last_outgoing_ping = 0;
// the setup function runs once when you press reset or power the board // the setup function runs once when you press reset or power the board
void setup() { void setup() {
@ -49,6 +48,9 @@ void check_serial() {
millis_last_incoming_ping = millis(); millis_last_incoming_ping = millis();
int incomingByte = Serial.read(); int incomingByte = Serial.read();
if (incomingByte == 0 || incomingByte == '^') { if (incomingByte == 0 || incomingByte == '^') {
if (Serial.availableForWrite()) {
Serial.write("pong^");
}
incomingByte = vfd_line_position = 0; incomingByte = vfd_line_position = 0;
} }
if (incomingByte < 32) { if (incomingByte < 32) {
@ -71,27 +73,20 @@ void check_serial() {
// the loop function runs over and over again forever // the loop function runs over and over again forever
void loop() { void loop() {
// We've been running for over 50 days and wrapped to zero. Reset all our timers // We've been running for over 50 days and wrapped to zero. Reset all our timers
if (millis() < 10000 && (millis_last_outgoing_ping > 10000 || millis_last_incoming_ping > 10000)) { if (millis() < 10000 && millis_last_incoming_ping > 10000) {
millis_last_outgoing_ping = 0;
millis_last_incoming_ping = 0; millis_last_incoming_ping = 0;
} }
check_serial(); check_serial();
// If it's been 10 seconds since last incoming data // If it's been 30 seconds since last incoming data
if (millis() - millis_last_incoming_ping > 30000) { if (millis() - millis_last_incoming_ping > 30000) {
// |12345678901234567890| // |12345678901234567890|
vfd_line_top = "Error stream is down"; vfd_line_top = "Stream is down! Try ";
vfd_line_bottom = "Verify or restart..."; vfd_line_bottom = "restarting computer.";
vfd_line_print = true; vfd_line_print = true;
millis_last_incoming_ping = millis(); millis_last_incoming_ping = millis();
} }
// Send outgoing ping every 5 seconds if we can.
if (millis() - millis_last_outgoing_ping > 30000 && Serial.availableForWrite()) {
Serial.write('^');
millis_last_outgoing_ping = millis();
}
// If we have something to print, print it // If we have something to print, print it
if (vfd_line_print) { if (vfd_line_print) {