From 3c725afab4cf67dd564786e4cdca095b6b86839c Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sat, 28 Dec 2024 15:45:27 +0100 Subject: [PATCH] Less confusion and simpler code around the RCN213 defines --- DCCEXParser.cpp | 3 ++- Turnouts.cpp | 11 ++++------- Turnouts.h | 2 -- config.example.h | 5 +++-- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index ea56e52..ad577ff 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -402,7 +402,8 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) || (p[activep] > 1) || (p[activep] < 0) // invalid activate 0|1 ) break; // Honour the configuration option (config.h) which allows the command to be reversed -#ifdef DCC_ACCESSORY_COMMAND_REVERSE + // Because of earlier confusion we need to do the same thing under both defines +#if defined(DCC_ACCESSORY_COMMAND_REVERSE) || defined(DCC_ACCESSORY_RCN_213) DCC::setAccessory(address, subaddress,p[activep]==0,onoff); #else DCC::setAccessory(address, subaddress,p[activep]==1,onoff); diff --git a/Turnouts.cpp b/Turnouts.cpp index ffc5e93..8e212ed 100644 --- a/Turnouts.cpp +++ b/Turnouts.cpp @@ -312,12 +312,6 @@ * *************************************************************************************/ -#if defined(DCC_TURNOUTS_RCN_213) - const bool DCCTurnout::rcn213Compliant = true; -#else - const bool DCCTurnout::rcn213Compliant = false; -#endif - // DCCTurnoutData contains data specific to this subclass that is // written to EEPROM when the turnout is saved. struct DCCTurnoutData { @@ -385,7 +379,10 @@ // DCC++ Classic behaviour is that Throw writes a 1 in the packet, // and Close writes a 0. // RCN-213 specifies that Throw is 0 and Close is 1. - DCC::setAccessory(_dccTurnoutData.address, _dccTurnoutData.subAddress, close ^ !rcn213Compliant); +#if defined(DCC_TURNOUTS_RCN_213) + close = !close; +#endif + DCC::setAccessory(_dccTurnoutData.address, _dccTurnoutData.subAddress, close); return true; } diff --git a/Turnouts.h b/Turnouts.h index 56b7f82..82baf0a 100644 --- a/Turnouts.h +++ b/Turnouts.h @@ -245,8 +245,6 @@ public: // Load a VPIN turnout definition from EEPROM. The common Turnout data has already been read at this point. static Turnout *load(struct TurnoutData *turnoutData); void print(Print *stream) override; - // Flag whether DCC Accessory packets are to contain 1=close/0=throw(RCN-213) or 1=throw/0-close (DCC++ Classic) - static const bool rcn213Compliant; protected: bool setClosedInternal(bool close) override; diff --git a/config.example.h b/config.example.h index d7dab5e..97de2ce 100644 --- a/config.example.h +++ b/config.example.h @@ -269,9 +269,10 @@ The configuration file for DCC-EX Command Station // over DCC++. This #define likewise inverts the behaviour of the command // for triggering DCC Accessory Decoders, so that generates a // DCC packet with D=1 (close turnout) and generates D=0 -// (throw turnout). +// (throw turnout). This is the same as DCC_ACCESSORY_COMMAND_REVERSE //#define DCC_ACCESSORY_RCN_213 -// + + // HANDLING MULTIPLE SERIAL THROTTLES // The command station always operates with the default Serial port. // Diagnostics are only emitted on the default serial port and not broadcast.