diff --git a/DCC.cpp b/DCC.cpp index 0c5148a..ed2a803 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -278,6 +278,22 @@ void DCC::setAccessory(int address, byte port, bool gate, byte onoff /*= 2*/) { } } +void DCC::setExtendedAccessory(int16_t address, int16_t value, byte repeats) { + + // format is 10AAAAAA, 0AAA0AA1, 000XXXXX + if (address != (address & 0x7F)) return; + if (value != (value & 0x1F)) return; + + byte b[3]; + b[0]= 0x80 | ((address & 0x7FF)>>5); + b[1]= 0x01 | ((address & 0x1c)<<2) | (address & 0x03)<<1; + b[2]=value & 0x1F; + DCCWaveform::mainTrack.schedulePacket(b, sizeof(b), repeats); // Repeat on packet three times +#if defined(EXRAIL_ACTIVE) + // TODO RMFT2::activateExtendedEvent(address,value); +#endif +} + // // writeCVByteMain: Write a byte with PoM on main. This writes // the 5 byte sized packet to implement this DCC function diff --git a/DCC.h b/DCC.h index 3bf0cf5..e1aeae6 100644 --- a/DCC.h +++ b/DCC.h @@ -71,6 +71,7 @@ public: static uint32_t getFunctionMap(int cab); static void updateGroupflags(byte &flags, int16_t functionNumber); static void setAccessory(int address, byte port, bool gate, byte onoff = 2); + static void setExtendedAccessory(int16_t address, int16_t value, byte repeats=3); static bool writeTextPacket(byte *b, int nBytes); // ACKable progtrack calls bitresults callback 0,0 or -1, cv returns value or -1 diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 6deb34f..a3aa1c4 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -384,6 +384,15 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) #endif } return; + + case 'A': // EXTENDED ACCESSORY + { + if (params!=2) break; + if (p[0] != (p[0] & 0x7F)) break; + if (p[1] != (p[1] & 0x1F)) break; + DCC::setExtendedAccessory(p[0],p[1],3); + } + return; case 'T': // TURNOUT if (parseT(stream, params, p))