fixed serial timeout logic

pico-fc-test
alanbjohnston 3 years ago committed by GitHub
parent 517d93bb28
commit bd1b577720
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -213,19 +213,20 @@ void loop() {
bool timeout = false;
bool take_photo = false;
Serial.println("Checking for serial input before sleeping");
unsigned long timer_ms = millis();
while ((Serial.available() < 0) || !timeout) {
while ((Serial.available() < 0) && !timeout) {
if ((millis() - timer_ms) > 10000) timeout = true; // poll serial for 10 seconds
}
if (Serial.available() > 0) {
char result = Serial.read();
if ((result == 'f') || (result == 'F')) SPIFFS.format();
take_photo = true;
Serial.println("Serial input received!");
}
if (!take_photo) {
Serial.println("No serial input received!");
esp_sleep_enable_timer_wakeup(5 * 1000000); // sleep for 10 seconds
Serial.println("Going to sleep now for 5 seconds");
Serial.flush();
esp_deep_sleep_start();

Loading…
Cancel
Save

Powered by TurnKey Linux.