Skip to content

Commit

Permalink
dynamic type for serialconfig (#1)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Seidt <robert.seidt@gmail.com>
  • Loading branch information
rseidt and Robert Seidt authored Apr 3, 2024
1 parent 1993679 commit 9692cbc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/RS485.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ void RS485Class::begin(unsigned long baudrate, int predelay, int postdelay)
begin(baudrate, SERIAL_8N1, predelay, postdelay);
}

void RS485Class::begin(unsigned long baudrate, uint16_t config)
void RS485Class::begin(unsigned long baudrate, RS485_SER_CONF_TYPE config)
{
begin(baudrate, config, RS485_DEFAULT_PRE_DELAY, RS485_DEFAULT_POST_DELAY);
}

void RS485Class::begin(unsigned long baudrate, uint16_t config, int predelay, int postdelay)
void RS485Class::begin(unsigned long baudrate, RS485_SER_CONF_TYPE config, int predelay, int postdelay)
{
_baudrate = baudrate;
_config = config;
Expand Down
16 changes: 13 additions & 3 deletions src/RS485.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
#define SERIAL_PORT_HARDWARE Serial1
#define RS485_DEFAULT_DE_PIN 8
#define RS485_DEFAULT_RE_PIN 7
#elif defined(ESP32) || defined(ESP8266)
#define RS485_DEFAULT_DE_PIN 12
#define RS485_DEFAULT_RE_PIN 13

#else
#ifndef RS485_DEFAULT_DE_PIN
#define RS485_DEFAULT_DE_PIN A6
Expand All @@ -61,6 +65,12 @@
#define RS485_DEFAULT_PRE_DELAY 50
#define RS485_DEFAULT_POST_DELAY 50

#if defined(ESP32) || defined(ESP8266)
#define RS485_SER_CONF_TYPE SerialConfig
#else
#define RS485_SER_CONF_TYPE uint16_t
#endif

class RS485Class : public Stream {
public:
#ifdef __MBED__
Expand All @@ -69,9 +79,9 @@ class RS485Class : public Stream {
RS485Class(HardwareSerial& hwSerial, int txPin, int dePin, int rePin);

virtual void begin(unsigned long baudrate);
virtual void begin(unsigned long baudrate, uint16_t config);
virtual void begin(unsigned long baudrate, RS485_SER_CONF_TYPE config);
virtual void begin(unsigned long baudrate, int predelay, int postdelay);
virtual void begin(unsigned long baudrate, uint16_t config, int predelay, int postdelay);
virtual void begin(unsigned long baudrate, RS485_SER_CONF_TYPE config, int predelay, int postdelay);
virtual void end();
virtual int available();
virtual int peek();
Expand Down Expand Up @@ -103,7 +113,7 @@ class RS485Class : public Stream {

bool _transmisionBegun;
unsigned long _baudrate;
uint16_t _config;
RS485_SER_CONF_TYPE _config;
};

extern RS485Class RS485;
Expand Down

0 comments on commit 9692cbc

Please # to comment.