diff --git a/DCC.cpp b/DCC.cpp index 7051d35..97564be 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -157,7 +157,9 @@ void DCC::writeCVBitMain(int cab, int cv, byte bNum, bool bValue) { DCCWaveform::mainTrack.schedulePacket(b, nB, 4); } - +void DCC::setProgTrackSyncMain(bool on) { + DCCWaveform::progTrackSyncMain=on; +} const ackOp PROGMEM WRITE_BIT0_PROG[] = { BASELINE, @@ -347,10 +349,12 @@ bool DCC::issueReminder(int reg) { case 4: // remind function group 4 F13-F20 if (flags & FN_GROUP_4) setFunctionInternal(loco,222, ((functions>>13)& 0xFF)); + flags&= ~FN_GROUP_4; // dont send them again break; case 5: // remind function group 5 F21-F28 if (flags & FN_GROUP_5) setFunctionInternal(loco,223, ((functions>>21)& 0xFF)); + flags&= ~FN_GROUP_5; // dont send them again break; } loopStatus++; @@ -390,7 +394,7 @@ int DCC::lookupSpeedTable(int locoId) { } if (reg==firstEmpty){ speedTable[reg].loco = locoId; - speedTable[reg].speedCode=0; + speedTable[reg].speedCode=128; // default direction forward speedTable[reg].groupFlags=0; speedTable[reg].functions=0; } @@ -452,9 +456,10 @@ void DCC::ackManagerLoop() { case W1: // write 1 bit { if (resetsnextThrottle) if (wt->clientid==wifiClient) return wt; - return new WiThrottle(stream, wifiClient); + return new WiThrottle( wifiClient); } // One instance of WiTHrottle per connected client, so we know what the locos are -WiThrottle::WiThrottle(Print & stream, int wificlientid) { +WiThrottle::WiThrottle( int wificlientid) { DIAG(F("\nCreating new WiThrottle for client %d\n"),wificlientid); nextThrottle=firstThrottle; firstThrottle= this; clientid=wificlientid; - for (int loco=0;loconextTurnout){ - StringFormatter::send(stream,F("]\\[LT&d}|{%d}|{%d"), tt->data.id, tt->data.id, (bool)(tt->data.tStatus & STATUS_ACTIVE)); - } - StringFormatter::send(stream,F("\n*10\n")); - heartBeatEnable=false; // until client turns it on + heartBeatEnable=false; // until client turns it on + firstCall=true; + for (int loco=0;loconextTurnout){ + StringFormatter::send(stream,F("]\\[LT&d}|{%d}|{%d"), tt->data.id, tt->data.id, (bool)(tt->data.tStatus & STATUS_ACTIVE)); + } + StringFormatter::send(stream,F("\n*10\n")); + } + + while (cmd[0]) { switch (cmd[0]) { case '*': // heartbeat control if (cmd[1]=='+') heartBeatEnable=true; @@ -119,6 +137,10 @@ void WiThrottle::parse(Print & stream, byte * cmd) { DIAG(F("\nWiThrottle Quit")); delete this; break; + } + // skip over cmd until 0 or past \r or \n + while(*cmd !='\0' && *cmd != '\r' && *cmd !='\n') cmd++; + if (*cmd!='\0') cmd++; // skip \r or \n } } int WiThrottle::getInt(byte * cmd) { @@ -196,12 +218,12 @@ void WiThrottle::locoAction(Print & stream, byte* aval, char throttleChar, int c case 'q': if (aval[1]=='V') { //qV LOOPLOCOS(throttleChar, cab) { - StringFormatter::send(stream,F("M%cAL%d<;>V%d"), throttleChar, myLocos[loco].cab, DCC::getThrottleSpeed(myLocos[loco].cab)); + StringFormatter::send(stream,F("M%cAL%d<;>V%d\n"), throttleChar, myLocos[loco].cab, DCC::getThrottleSpeed(myLocos[loco].cab)); } } else if (aval[1]=='R') { // qR LOOPLOCOS(throttleChar, cab) { - StringFormatter::send(stream,F("M%cAL%d<;>R%d"), throttleChar, myLocos[loco].cab, DCC::getThrottleDirection(myLocos[loco].cab)); + StringFormatter::send(stream,F("M%cAL%d<;>R%d\n"), throttleChar, myLocos[loco].cab, DCC::getThrottleDirection(myLocos[loco].cab)); } } break; diff --git a/WiThrottle.h b/WiThrottle.h index 94cf3c0..d0c3f4b 100644 --- a/WiThrottle.h +++ b/WiThrottle.h @@ -29,10 +29,10 @@ class WiThrottle { public: static void loop(); void parse(Print & stream, byte * cmd); - static WiThrottle* getThrottle(Print & stream, int wifiClient); + static WiThrottle* getThrottle( int wifiClient); private: - WiThrottle(Print & stream, int wifiClientId); + WiThrottle( int wifiClientId); ~WiThrottle(); static const int MAX_MY_LOCO=10; @@ -46,6 +46,7 @@ class WiThrottle { MYLOCO myLocos[MAX_MY_LOCO]; bool heartBeatEnable; + bool firstCall; unsigned long heartBeat; void multithrottle(Print & stream, byte * cmd); diff --git a/WifiInterface.cpp b/WifiInterface.cpp index 6cbefaf..1a1196c 100644 --- a/WifiInterface.cpp +++ b/WifiInterface.cpp @@ -172,12 +172,12 @@ void WifiInterface::loop(Stream & wifiStream) { } else if (buffer[0]=='<') parser.parse(streamer,buffer, true); // tell JMRI parser that callbacks are diallowed because we dont want to handle the async - else WiThrottle::getThrottle(streamer, connectionId)->parse(streamer, buffer); + else WiThrottle::getThrottle(connectionId)->parse(streamer, buffer); if (streamer.available()) { // there is a reply to send streamer.write('\0'); - DIAG(F("WiFiInterface Responding client (%d) l(%d) %e\n"),connectionId,streamer.available()-1,buffer); + DIAG(F("\nWiFiInterface reply c(%d) l(%d) [%e]\n"),connectionId,streamer.available()-1,buffer); StringFormatter::send(wifiStream,F("AT+CIPSEND=%d,%d\r\n"),connectionId,streamer.available()-1); if (checkForOK(wifiStream,1000,PROMPT_SEARCH,true)) wifiStream.print((char *) buffer);