Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Uart clearing #5

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading