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

WiThrottle turnout improvement

This commit is contained in:
Asbelos 2020-07-23 17:34:35 +01:00
parent 7842166722
commit 575b5da606
4 changed files with 38 additions and 15 deletions

View File

@ -31,6 +31,12 @@
return true; return true;
} }
bool Turnout::isActive(int n){
Turnout * tt=get(n);
if (tt==NULL) return false;
return tt->data.tStatus & STATUS_ACTIVE;
}
// activate is virtual here so that it can be overridden by a non-DCC turnout mechanism // activate is virtual here so that it can be overridden by a non-DCC turnout mechanism
void Turnout::activate(bool state) { void Turnout::activate(bool state) {
//DIAG(F("\nTurnout::activate\n")); //DIAG(F("\nTurnout::activate\n"));

View File

@ -41,6 +41,7 @@ class Turnout {
static bool activate(int n, bool state); static bool activate(int n, bool state);
static Turnout* get(int); static Turnout* get(int);
static bool remove(int); static bool remove(int);
static bool isActive(int);
static void load(); static void load();
static void store(); static void store();
static Turnout *create(int id , int address , int subAddress); static Turnout *create(int id , int address , int subAddress);

View File

@ -65,7 +65,7 @@ WiThrottle::WiThrottle( int wificlientid) {
firstThrottle= this; firstThrottle= this;
clientid=wificlientid; clientid=wificlientid;
heartBeatEnable=false; // until client turns it on heartBeatEnable=false; // until client turns it on
firstCall=true; callState=0;
for (int loco=0;loco<MAX_MY_LOCO; loco++) myLocos[loco].throttle='\0'; for (int loco=0;loco<MAX_MY_LOCO; loco++) myLocos[loco].throttle='\0';
} }
@ -96,17 +96,25 @@ void WiThrottle::parse(Print & stream, byte * cmdx) {
heartBeat=millis(); heartBeat=millis();
DIAG(F("\nWiThrottle(%d) [%e]"),clientid, cmd); DIAG(F("\nWiThrottle(%d) [%e]"),clientid, cmd);
switch (callState) {
if (firstCall) { case 0: // first call in
firstCall=false; callState++;
StringFormatter::send(stream,F("VN2.0\nHTDCC++EX\nRL0\nPPA%x\nPTT]\\[Turnouts}|{Turnout]\\[Closed}|{2]\\[Thrown}|{4\\PTL"), StringFormatter::send(stream,F("VN2.0\nHTDCC++EX\nRL0\nPPA%x\nPTT]\\[Turnouts}|{Turnout]\\[Closed}|{2]\\[Thrown}|{4\n*10\n"),
DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON); DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON);
break;
for(Turnout *tt=Turnout::firstTurnout;tt!=NULL;tt=tt->nextTurnout){ case 1: // second call... send the turnout table if we have one
StringFormatter::send(stream,F("]\\[LT%d}|{%d}|{%d"), tt->data.id, tt->data.id, (bool)(tt->data.tStatus & STATUS_ACTIVE)); callState++;
} if (Turnout::firstTurnout) {
StringFormatter::send(stream,F("\n*10\n")); StringFormatter::send(stream,F("PTL"));
} for(Turnout *tt=Turnout::firstTurnout;tt!=NULL;tt=tt->nextTurnout){
StringFormatter::send(stream,F("]\\[DT%d}|{T%d}|{%d"), tt->data.id, tt->data.id, (bool)(tt->data.tStatus & STATUS_ACTIVE));
}
StringFormatter::send(stream,F("\n"));
}
break;
default: // no more special headers required
break;
}
while (cmd[0]) { while (cmd[0]) {
switch (cmd[0]) { switch (cmd[0]) {
@ -122,7 +130,15 @@ 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.
Turnout::activate(getInt(cmd+4),cmd[3]=='T'); int id=getInt(cmd+6);
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);
StringFormatter::send(stream, F("PTA%cDT%d\n"),newstate?'4':'2',id );
} }
break; break;
case 'N': // Heartbeat (2) case 'N': // Heartbeat (2)

View File

@ -46,7 +46,7 @@ class WiThrottle {
MYLOCO myLocos[MAX_MY_LOCO]; MYLOCO myLocos[MAX_MY_LOCO];
bool heartBeatEnable; bool heartBeatEnable;
bool firstCall; byte callState; // 0=first, 1=second, 3=third, 4=fourth call... >4=rest.
unsigned long heartBeat; unsigned long heartBeat;
void multithrottle(Print & stream, byte * cmd); void multithrottle(Print & stream, byte * cmd);