Skip to content

Commit d88a9af

Browse files
authored
Merge pull request #13 from manchoz/mnx_setdelays
Add ::setDelays method
2 parents 2990dd4 + 0ffb72c commit d88a9af

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/RS485.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ void RS485Class::begin(unsigned long baudrate, uint16_t config, int predelay, in
4747
{
4848
_baudrate = baudrate;
4949
_config = config;
50-
_predelay = predelay;
51-
_postdelay = postdelay;
50+
51+
// Set only if not already initialized with ::setDelays
52+
_predelay = _predelay == 0 ? predelay : _predelay;
53+
_postdelay = _postdelay == 0 ? postdelay : _postdelay;
5254

5355
if (_dePin > -1) {
5456
pinMode(_dePin, OUTPUT);
@@ -178,4 +180,10 @@ void RS485Class::setPins(int txPin, int dePin, int rePin)
178180
_rePin = rePin;
179181
}
180182

183+
void RS485Class::setDelays(int predelay, int postdelay)
184+
{
185+
_predelay = predelay;
186+
_postdelay = postdelay;
187+
}
188+
181189
RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);

src/RS485.h

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class RS485Class : public Stream {
6767

6868
void setPins(int txPin, int dePin, int rePin);
6969

70+
void setDelays(int predelay, int postdelay);
71+
7072
private:
7173
HardwareSerial* _serial;
7274
int _txPin;

0 commit comments

Comments
 (0)