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

Improving the binding to the Serial object and fix SoftwareSerial bug #20

Merged
merged 5 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions src/PMserial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ void SerialPM::wake() {

SerialPM::STATUS SerialPM::trigRead()
{
if (hwSerial == false)
static_cast<SoftwareSerial *>(uart)->listen(); // when you want to listen on a port, explicitly select it. (https://www.arduino.cc/en/Tutorial/LibraryExamples/TwoPortReceive)

while (uart->available())
{
uart->read(); // empty the RX buffer
Expand Down
6 changes: 4 additions & 2 deletions src/PMserial.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,18 @@ class SerialPM
float temp, rhum, hcho;
};
};

#ifdef HAS_HW_SERIAL
SerialPM(PMS sensor, HardwareSerial &serial) : pms(sensor)
{
uart = &serial;
hwSerial = true;
}
#endif

#ifdef HAS_SW_SERIAL
SerialPM(PMS sensor, uint8_t rx, uint8_t tx) : pms(sensor)
SerialPM(PMS sensor, Stream &serial) : pms(sensor)
{
SoftwareSerial serial(rx, tx);
uart = &serial;
hwSerial = false;
}
Expand All @@ -98,6 +99,7 @@ class SerialPM
hwSerial = true;
}
#endif

void init();
#define PMS_ERROR_TIMEOUT "Sensor read timeout"
#define PMS_ERROR_PMS_TYPE "Wrong PMSx003 sensor type"
Expand Down