1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-24 13:21:23 +01:00

sync power state and turnout list/states to all clients

This commit is contained in:
SteveT 2020-08-14 21:10:02 -04:00
parent a7da30b236
commit b03776c6f8
2 changed files with 22 additions and 12 deletions

View File

@ -71,7 +71,14 @@ bool WiThrottle::areYouUsingThrottle(int cab) {
} }
return false; return false;
} }
void WiThrottle::setSendPowerState() {
for (WiThrottle* wt=firstThrottle; wt!=NULL ; wt=wt->nextThrottle)
wt->sendPowerState = true;
}
void WiThrottle::setSendTurnoutList() {
for (WiThrottle* wt=firstThrottle; wt!=NULL ; wt=wt->nextThrottle)
wt->sendTurnoutList = true;
}
// One instance of WiThrottle per connected client, so we know what the locos are // One instance of WiThrottle per connected client, so we know what the locos are
@ -140,6 +147,7 @@ void WiThrottle::parse(Print & stream, byte * cmdx) {
if (cmd[1]=='P' && cmd[2]=='A' ) { //PPA power mode if (cmd[1]=='P' && cmd[2]=='A' ) { //PPA power mode
DCCWaveform::mainTrack.setPowerMode(cmd[3]=='1'?POWERMODE::ON:POWERMODE::OFF); DCCWaveform::mainTrack.setPowerMode(cmd[3]=='1'?POWERMODE::ON:POWERMODE::OFF);
StringFormatter::send(stream,F("PPA%x\n"),DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON); StringFormatter::send(stream,F("PPA%x\n"),DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON);
setSendPowerState(); //tell all WiThrottle instances to send power state at next heartbeat
} }
else if (cmd[1]=='T' && cmd[2]=='A') { // PTA accessory toggle else if (cmd[1]=='T' && cmd[2]=='A') { // PTA accessory toggle
int id=getInt(cmd+4); int id=getInt(cmd+4);
@ -159,7 +167,7 @@ void WiThrottle::parse(Print & stream, byte * cmdx) {
} }
Turnout::activate(id,newstate); Turnout::activate(id,newstate);
StringFormatter::send(stream, F("PTA%c%d\n"),newstate?'4':'2',id ); StringFormatter::send(stream, F("PTA%c%d\n"),newstate?'4':'2',id );
sendTurnoutList = true; setSendTurnoutList(); //tell all WiThrottle instances to send turnout list at next heartbeat
} }
break; break;
case 'N': // Heartbeat (2) case 'N': // Heartbeat (2)
@ -267,16 +275,16 @@ void WiThrottle::locoAction(Print & stream, byte* aval, char throttleChar, int c
} }
break; break;
case 'F': //F onOff function case 'F': //F onOff function
{ {
bool funcstate; bool funcstate;
bool pressed=aval[1]=='1'; bool pressed=aval[1]=='1';
int fKey = getInt(aval+2); int fKey = getInt(aval+2);
LOOPLOCOS(throttleChar, cab) { LOOPLOCOS(throttleChar, cab) {
funcstate = DCC::changeFn(myLocos[loco].cab, fKey, pressed); funcstate = DCC::changeFn(myLocos[loco].cab, fKey, pressed);
if(funcstate==0 || funcstate==1) if(funcstate==0 || funcstate==1)
StringFormatter::send(stream,F("M%cA%c%d<;>F%d%d\n"), throttleChar, LorS(myLocos[loco].cab), StringFormatter::send(stream,F("M%cA%c%d<;>F%d%d\n"), throttleChar, LorS(myLocos[loco].cab),
myLocos[loco].cab, funcstate, fKey); myLocos[loco].cab, funcstate, fKey);
} }
} }
break; break;
case 'q': case 'q':

View File

@ -42,6 +42,8 @@ class WiThrottle {
static int getLocoId(byte * cmd); static int getLocoId(byte * cmd);
static char LorS(int cab); static char LorS(int cab);
static bool isThrottleInUse(int cab); static bool isThrottleInUse(int cab);
static void setSendTurnoutList();
static void setSendPowerState();
bool areYouUsingThrottle(int cab); bool areYouUsingThrottle(int cab);
WiThrottle* nextThrottle; WiThrottle* nextThrottle;
int clientid; int clientid;