From fb6ab85c4af5d21a2de4d4391050692439a9979e Mon Sep 17 00:00:00 2001 From: Neil McKechnie Date: Fri, 27 Aug 2021 21:43:24 +0100 Subject: [PATCH] Add flag to invert DCC Accessory command behaviour command puts a D=1 into the DCC packet for a DCC Accessory Decoder. This was previously though to correspond to a 'throw' request and a D=0 to a 'close' request. RCN-213 standard identifies that D=1 is 'close' and D=0 is 'throw', so this change allows CS to be configured to invert the states to conform to the RCN-213 definition. --- DCC.cpp | 3 +++ DCCEXParser.cpp | 7 ++++++- config.example.h | 10 ++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/DCC.cpp b/DCC.cpp index e3dd921..79c5b19 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -239,6 +239,9 @@ void DCC::updateGroupflags(byte & flags, int16_t functionNumber) { } void DCC::setAccessory(int address, byte number, bool activate) { + #ifdef DIAG_IO + DIAG(F("DCC::setAccessory(%d,%d,%d)"), address, number, activate); + #endif // use masks to detect wrong values and do nothing if(address != (address & 511)) return; diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index e4b4d73..91039f7 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -27,6 +27,7 @@ #include "freeMemory.h" #include "GITHUB_SHA.h" #include "version.h" +#include "defines.h" #include "EEStore.h" #include "DIAG.h" @@ -364,8 +365,12 @@ void DCCEXParser::parse(Print *stream, byte *com, RingStream * ringStream) || ((subaddress & 0x03) != subaddress) // invalid subaddress (limit 2 bits ) || ((p[activep] & 0x01) != p[activep]) // invalid activate 0|1 ) break; - // TODO: Trigger configurable range of addresses on local VPins. + // Honour the configuration option (config.h) which allows the command to be reversed +#ifdef DCC_ACCESSORY_RCN_213 + DCC::setAccessory(address, subaddress,p[activep]==0); +#else DCC::setAccessory(address, subaddress,p[activep]==1); +#endif } return; diff --git a/config.example.h b/config.example.h index 6c5c69a..9b1855f 100644 --- a/config.example.h +++ b/config.example.h @@ -134,11 +134,17 @@ The configuration file for DCC-EX Command Station // // According to norm RCN-213 a DCC packet with a 1 is closed/straight // and one with a 0 is thrown/diverging. In DCC++ Classic, and in previous -// versions of DCC++EX, a throw command was implemented in the packet as +// versions of DCC++EX, a turnout throw command was implemented in the packet as // '1' and a close command as '0'. The #define below makes the states // match with the norm. But we don't want to cause havoc on existent layouts, // so we define this only for new installations. If you don't want this, // don't add it to your config.h. -#define DCC_TURNOUTS_RCN_213 +//#define DCC_TURNOUTS_RCN_213 + +// The following #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). +//#define DCC_ACCESSORY_RCN_213 /////////////////////////////////////////////////////////////////////////////////////