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

clear progTrackSyncMain (join flag) when prog track is removed 2nd fix

This commit is contained in:
Harald Barth 2024-12-22 23:12:45 +01:00
parent 84bc098157
commit cafd53a0e5
2 changed files with 21 additions and 10 deletions

View File

@ -72,15 +72,19 @@ void DCCACK::Setup(int cv, byte byteValueOrBitnum, ackOp const program[], ACK_C
// then unjoin if necessary. This requires that the joined flag is // then unjoin if necessary. This requires that the joined flag is
// cleared when the prog track is removed. // cleared when the prog track is removed.
ackManagerRejoin=TrackManager::isJoined(); ackManagerRejoin=TrackManager::isJoined();
//DIAG(F("Joined is %d"), ackManagerRejoin);
if (ackManagerRejoin) { if (ackManagerRejoin) {
// Change from JOIN must zero resets packet. // Change from JOIN must zero resets packet.
TrackManager::setJoin(false); TrackManager::setJoin(false);
DCCWaveform::progTrack.clearResets(); DCCWaveform::progTrack.clearResets();
} }
progDriver=TrackManager::getProgDriver(); progDriver=TrackManager::getProgDriver();
//DIAG(F("Progdriver is %d"), progDriver);
if (progDriver==NULL) { if (progDriver==NULL) {
TrackManager::setJoin(ackManagerRejoin); if (ackManagerRejoin) {
DIAG(F("Joined but no Prog track"));
TrackManager::setJoin(false);
}
callback(-3); // we dont have a prog track! callback(-3); // we dont have a prog track!
return; return;
} }

View File

@ -356,17 +356,24 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
applyDCSpeed(trackToSet); applyDCSpeed(trackToSet);
} }
// Turn off power if we changed the mode of this track #ifdef ARDUINO_ARCH_ESP32
if (mode != oldmode)
track[trackToSet]->setPower(POWERMODE::OFF);
streamTrackState(NULL,trackToSet);
#ifndef DISABLE_PROG #ifndef DISABLE_PROG
// If no prog track exists, the join flag should not say that if (tempProgTrack == trackToSet && oldmode & TRACK_MODE_MAIN && !(mode & TRACK_MODE_PROG)) {
// the prog track is joined either, so clear flag here // If we just take away the prog track, the join should not
if (getProgDriver() == NULL) progTrackSyncMain=false; // be active either. So do in effect an unjoin
DIAG(F("Unsync"));
tempProgTrack = MAX_TRACKS+1;
progTrackSyncMain=false;
if (joinRelay!=UNUSED_PIN) digitalWrite(joinRelay,LOW);
}
#endif #endif
#endif
// Turn off power if we changed the mode of this track
if (mode != oldmode) {
track[trackToSet]->setPower(POWERMODE::OFF);
}
streamTrackState(NULL,trackToSet);
//DIAG(F("TrackMode=%d"),mode); //DIAG(F("TrackMode=%d"),mode);
return true; return true;
} }