diff --git a/DCCACK.cpp b/DCCACK.cpp index 64dafa3..d6b070e 100644 --- a/DCCACK.cpp +++ b/DCCACK.cpp @@ -67,6 +67,10 @@ CALLBACK_STATE DCCACK::callbackState=READY; ACK_CALLBACK DCCACK::ackManagerCallback; void DCCACK::Setup(int cv, byte byteValueOrBitnum, ackOp const program[], ACK_CALLBACK callback) { + // On ESP32 the joined track is hidden from sight (it has type MAIN) + // and because of that we need first check if track was joined and + // then unjoin if necessary. This requires that the joined flag is + // cleared when the prog track is removed. ackManagerRejoin=TrackManager::isJoined(); if (ackManagerRejoin) { // Change from JOIN must zero resets packet. diff --git a/TrackManager.cpp b/TrackManager.cpp index 0727956..5ada17b 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -361,6 +361,12 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr track[trackToSet]->setPower(POWERMODE::OFF); streamTrackState(NULL,trackToSet); +#ifndef DISABLE_PROG + // If no prog track exists, the join flag should not say that + // the prog track is joined either, so clear flag here + if (getProgDriver() == NULL) progTrackSyncMain=false; +#endif + //DIAG(F("TrackMode=%d"),mode); return true; }