Skip to content

Commit

Permalink
Uart clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
tyeth committed Feb 8, 2024
1 parent d622022 commit 426039c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
21 changes: 5 additions & 16 deletions examples/Wippersnapper_demo/Wippersnapper_demo.ino
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
// Adafruit IO WipperSnapper Beta
//
//
// NOTE: This software is a BETA release and in active development.
// Please report bugs or errors to https://github.com/adafruit/Adafruit_Wippersnapper_Arduino/issues
//
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Brent Rubell for Adafruit Industries, 2021-2022
//
// All text above must be included in any redistribution.
// Adafruit IO WipperSnapper Beta (DEBUG BUILD ONLY!)
// Brent Rubell for Adafruit Industries, 2021 - 2023

#include "Wippersnapper_Networking.h"
Wippersnapper_WiFi wipper;
Expand All @@ -23,11 +11,12 @@ void setup() {
// Provisioning must occur prior to serial init.
wipper.provision();

Serial.begin(115200);
Serial.begin(115200); // wippersnapper serial
// Serial1.begin(115200); // ESP-IDF messages serial
// Serial1.setDebugOutput(true); // Enable ESP-IDF messages over Serial1
//while (!Serial) delay(10);

wipper.connect();

}

void loop() {
Expand Down
33 changes: 32 additions & 1 deletion src/components/uart/drivers/ws_uart_drv_pm25aqi.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,38 @@ class ws_uart_drv_pm25aqi : public ws_uart_drv {
// Attempt to read the PM2.5 Sensor
if (!_aqi->read(&_data)) {
Serial.println("[UART, PM25] Data not available.");
delay(500);
#ifdef USE_SW_UART
if (_swSerial->available()) {
WS_DEBUG_PRINTLN("[UART, PM25] Flushing Software Serial..");
_swSerial->flush();
WS_DEBUG_PRINTLN("[UART, PM25] Uart Available. Attempting to clear write errors");
_swSerial->clearWriteError();
} else {
WS_DEBUG_PRINTLN("[UART, PM25] Uart Unavailable. Attempting to clear write errors");
_swSerial->clearWriteError();
if (!_swSerial->isListening()) {
WS_DEBUG_PRINTLN("[UART, PM25] Re-listening on Software Serial..");
_swSerial->listen();
}
// delay(500);
}
#else
WS_DEBUG_PRINTLN("[UART, PM25] Setting Hardware Serial to debug mode..");
_hwSerial->setDebugOutput(true);
if (_hwSerial->available()) {
WS_DEBUG_PRINTLN("[UART, PM25] Uart available, flushing Hardware Serial..");
_hwSerial->flush();
WS_DEBUG_PRINTLN("[UART, PM25] Uart available, clearing write errors..");
_hwSerial->clearWriteError();
WS_DEBUG_PRINTLN("[UART, PM25] Uart available, resetting event queue..");
_hwSerial->eventQueueReset();
} else {
WS_DEBUG_PRINTLN("[UART, PM25] Uart Unavailable. Attempting to reset event queue...");
_hwSerial->eventQueueReset();
WS_DEBUG_PRINTLN("[UART, PM25] Uart Unavailable. Attempting to clear write errors");
_hwSerial->clearWriteError();
}
#endif
return false;
}
Serial.println("[UART, PM25] Read data OK");
Expand Down

0 comments on commit 426039c

Please sign in to comment.