Skip to content

Commit

Permalink
Merge pull request #13 from manchoz/mnx_setdelays
Browse files Browse the repository at this point in the history
Add ::setDelays method
  • Loading branch information
facchinm authored Aug 25, 2021
2 parents 2990dd4 + 0ffb72c commit d88a9af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/RS485.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ void RS485Class::begin(unsigned long baudrate, uint16_t config, int predelay, in
{
_baudrate = baudrate;
_config = config;
_predelay = predelay;
_postdelay = postdelay;

// Set only if not already initialized with ::setDelays
_predelay = _predelay == 0 ? predelay : _predelay;
_postdelay = _postdelay == 0 ? postdelay : _postdelay;

if (_dePin > -1) {
pinMode(_dePin, OUTPUT);
Expand Down Expand Up @@ -178,4 +180,10 @@ void RS485Class::setPins(int txPin, int dePin, int rePin)
_rePin = rePin;
}

void RS485Class::setDelays(int predelay, int postdelay)
{
_predelay = predelay;
_postdelay = postdelay;
}

RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN);
2 changes: 2 additions & 0 deletions src/RS485.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class RS485Class : public Stream {

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

void setDelays(int predelay, int postdelay);

private:
HardwareSerial* _serial;
int _txPin;
Expand Down

0 comments on commit d88a9af

Please sign in to comment.