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:
parent
7842166722
commit
575b5da606
|
@ -31,6 +31,12 @@
|
|||
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
|
||||
void Turnout::activate(bool state) {
|
||||
//DIAG(F("\nTurnout::activate\n"));
|
||||
|
|
|
@ -41,6 +41,7 @@ class Turnout {
|
|||
static bool activate(int n, bool state);
|
||||
static Turnout* get(int);
|
||||
static bool remove(int);
|
||||
static bool isActive(int);
|
||||
static void load();
|
||||
static void store();
|
||||
static Turnout *create(int id , int address , int subAddress);
|
||||
|
|
|
@ -65,7 +65,7 @@ WiThrottle::WiThrottle( int wificlientid) {
|
|||
firstThrottle= this;
|
||||
clientid=wificlientid;
|
||||
heartBeatEnable=false; // until client turns it on
|
||||
firstCall=true;
|
||||
callState=0;
|
||||
for (int loco=0;loco<MAX_MY_LOCO; loco++) myLocos[loco].throttle='\0';
|
||||
}
|
||||
|
||||
|
@ -96,16 +96,24 @@ void WiThrottle::parse(Print & stream, byte * cmdx) {
|
|||
|
||||
heartBeat=millis();
|
||||
DIAG(F("\nWiThrottle(%d) [%e]"),clientid, cmd);
|
||||
|
||||
if (firstCall) {
|
||||
firstCall=false;
|
||||
StringFormatter::send(stream,F("VN2.0\nHTDCC++EX\nRL0\nPPA%x\nPTT]\\[Turnouts}|{Turnout]\\[Closed}|{2]\\[Thrown}|{4\\PTL"),
|
||||
switch (callState) {
|
||||
case 0: // first call in
|
||||
callState++;
|
||||
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);
|
||||
|
||||
break;
|
||||
case 1: // second call... send the turnout table if we have one
|
||||
callState++;
|
||||
if (Turnout::firstTurnout) {
|
||||
StringFormatter::send(stream,F("PTL"));
|
||||
for(Turnout *tt=Turnout::firstTurnout;tt!=NULL;tt=tt->nextTurnout){
|
||||
StringFormatter::send(stream,F("]\\[LT%d}|{%d}|{%d"), tt->data.id, tt->data.id, (bool)(tt->data.tStatus & STATUS_ACTIVE));
|
||||
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*10\n"));
|
||||
StringFormatter::send(stream,F("\n"));
|
||||
}
|
||||
break;
|
||||
default: // no more special headers required
|
||||
break;
|
||||
}
|
||||
|
||||
while (cmd[0]) {
|
||||
|
@ -122,7 +130,15 @@ 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.
|
||||
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;
|
||||
case 'N': // Heartbeat (2)
|
||||
|
|
|
@ -46,7 +46,7 @@ class WiThrottle {
|
|||
|
||||
MYLOCO myLocos[MAX_MY_LOCO];
|
||||
bool heartBeatEnable;
|
||||
bool firstCall;
|
||||
byte callState; // 0=first, 1=second, 3=third, 4=fourth call... >4=rest.
|
||||
unsigned long heartBeat;
|
||||
|
||||
void multithrottle(Print & stream, byte * cmd);
|
||||
|
|
Loading…
Reference in New Issue
Block a user