1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-23 08:06:13 +01:00

Autocreate turnouts

This commit is contained in:
Harald Barth 2020-07-25 18:50:23 +02:00
parent deec8b7e8c
commit b886a09f82
2 changed files with 8 additions and 2 deletions

View File

@ -21,6 +21,7 @@
#include "StringFormatter.h" #include "StringFormatter.h"
#include "Hardware.h" #include "Hardware.h"
#include "PWMServoDriver.h" #include "PWMServoDriver.h"
//#include "DIAG.h" // uncomment if you need DIAG below
bool Turnout::activate(int n,bool state){ bool Turnout::activate(int n,bool state){
//DIAG(F("\nTurnout::activate(%d,%d)\n"),n,state); //DIAG(F("\nTurnout::activate(%d,%d)\n"),n,state);

View File

@ -133,14 +133,19 @@ void WiThrottle::parse(Print & stream, byte * cmdx) {
else if (cmd[1]=='T' && cmd[2]=='A') { // PTA accessory toggle else if (cmd[1]=='T' && cmd[2]=='A') { // PTA accessory toggle
// TODO... if we are given an address that is not a known Turnout... // TODO... if we are given an address that is not a known Turnout...
// should we create one or just send the DCC message. // should we create one or just send the DCC message.
int id=getInt(cmd+6); int id=getInt(cmd+4);
bool newstate=false; bool newstate=false;
switch (cmd[3]) { switch (cmd[3]) {
case 'T': newstate=true; break; case 'T': newstate=true; break;
case 'C': newstate=false; break; case 'C': newstate=false; break;
case '2': newstate=!Turnout::isActive(id); 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 ); StringFormatter::send(stream, F("PTA%cDT%d\n"),newstate?'4':'2',id );
} }
break; break;