From ec89ad14eb34609f78ed201e5ec6cd783b8ee583 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Tue, 15 Feb 2022 23:56:36 +0100 Subject: [PATCH 1/4] Make pins configurable for HardwareSerial while keeping existing API for SoftwareSerial --- src/Serials.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Serials.h b/src/Serials.h index 01e503d..4165e0c 100644 --- a/src/Serials.h +++ b/src/Serials.h @@ -17,7 +17,7 @@ namespace Serials { // just to satisfy linker in gcc I needed to add empty parentheses to other virtual methods... class AbstractSerial { public: - virtual void begin(int baudRate) = 0; + virtual void begin(int baudRate, uint32_t config, int pinRx, int pinTx) = 0; virtual Stream *getStream() = 0; virtual ~AbstractSerial() {}; }; @@ -25,8 +25,8 @@ namespace Serials { struct Hardware: public AbstractSerial { Hardware(HardwareSerial &serial): serial(serial) {} - void begin(int baudRate) { - serial.begin(baudRate); + void begin(int baudRate = 9600, uint32_t config = SERIAL_8N1, int pinRx = -1, int pinTx = -1) { + serial.begin(baudRate, config, pinRx, pinTx); } Stream *getStream() { @@ -40,7 +40,7 @@ namespace Serials { struct Software: public AbstractSerial { Software(SoftwareSerial &serial): serial(serial) {} - void begin(int baudRate) { + void begin(int baudRate = 9600, uint32_t config = SERIAL_8N1, int pinRx = -1, int pinTx = -1) { serial.begin(baudRate); } @@ -61,8 +61,8 @@ namespace Serials { } } - void begin(int baudRate) { - serial->begin(baudRate); + void begin(int baudRate = 9600, uint32_t config = SERIAL_8N1, int pinRx = -1, int pinTx = -1) { + serial.begin(baudRate); } Stream *getStream() { From 083d74c92dfd56148c5c4693f1b2a4dc35a757bc Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Tue, 15 Feb 2022 23:58:11 +0100 Subject: [PATCH 2/4] Make rxPin/txPin configurable by begin method --- src/SdsDustSensor.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SdsDustSensor.h b/src/SdsDustSensor.h index a7cf288..adfa865 100644 --- a/src/SdsDustSensor.h +++ b/src/SdsDustSensor.h @@ -72,9 +72,9 @@ class SdsDustSensor { } } - void begin(int baudRate = 9600) { - abstractSerial->begin(baudRate); - } + void begin(int baudRate = 9600, uint32_t config = SERIAL_8N1, int pinRx = -1, int pinTx = -1) { + abstractSerial->begin(baudRate, config, pinRx, pinTx); + } byte *getLastResponse() { return response; From 6d40f58a066a417278f831990d735c74f9ece272 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Wed, 16 Feb 2022 10:34:27 +0100 Subject: [PATCH 3/4] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4e44b24..8dda9cb 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,8 @@ sds.begin(); // you can pass custom baud rate as parameter (9600 by default) ```arduino SdsDustSensor sds(Serial1); // passing HardwareSerial as parameter, you can tune retry mechanism with additional parameters: retryDelayMs and maxRetriesNotAvailable sds.begin(); // you can pass custom baud rate as parameter (9600 by default) +// or you can pass custom rxPin and txPin to HardwareSerial, if your board (e.g. ESP32) supports remapping of GPIOs to Serial +// sds.begin(9600, SERIAL_8N1, SDS_RX, SDS_TX); ``` ## Supported operations From 47bc356748224227065106a3a3f7d8e560bcdde3 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Wed, 16 Feb 2022 12:03:59 +0100 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8dda9cb..70651c0 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ sds.begin(); // you can pass custom baud rate as parameter (9600 by default) SdsDustSensor sds(Serial1); // passing HardwareSerial as parameter, you can tune retry mechanism with additional parameters: retryDelayMs and maxRetriesNotAvailable sds.begin(); // you can pass custom baud rate as parameter (9600 by default) // or you can pass custom rxPin and txPin to HardwareSerial, if your board (e.g. ESP32) supports remapping of GPIOs to Serial -// sds.begin(9600, SERIAL_8N1, SDS_RX, SDS_TX); +// sds.begin(9600, SERIAL_8N1, rxPin, txPin); ``` ## Supported operations