diff --git a/Turnouts.cpp b/Turnouts.cpp index f30abdd..5578905 100644 --- a/Turnouts.cpp +++ b/Turnouts.cpp @@ -21,6 +21,7 @@ #include "StringFormatter.h" #include "Hardware.h" #include "PWMServoDriver.h" +//#include "DIAG.h" // uncomment if you need DIAG below bool Turnout::activate(int n,bool state){ //DIAG(F("\nTurnout::activate(%d,%d)\n"),n,state); diff --git a/WiThrottle.cpp b/WiThrottle.cpp index 0310cb9..3a97e74 100644 --- a/WiThrottle.cpp +++ b/WiThrottle.cpp @@ -133,14 +133,19 @@ void WiThrottle::parse(Print & stream, byte * cmdx) { else if (cmd[1]=='T' && cmd[2]=='A') { // PTA accessory toggle // TODO... if we are given an address that is not a known Turnout... // should we create one or just send the DCC message. - int id=getInt(cmd+6); + int id=getInt(cmd+4); bool newstate=false; switch (cmd[3]) { case 'T': newstate=true; break; case 'C': newstate=false; break; case '2': newstate=!Turnout::isActive(id); } - Turnout::activate(id,newstate); + if (Turnout::activate(id,newstate) == false) { + int addr = ((id - 1) / 4) + 1; + int subaddr = (id - 1) % 4; + Turnout::create(id,addr,subaddr); + Turnout::activate(id,newstate); + } StringFormatter::send(stream, F("PTA%cDT%d\n"),newstate?'4':'2',id ); } break;