diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 5588243..a9ab348 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "devel-202404051830Z" +#define GITHUB_SHA "devel-202404061747Z" diff --git a/TrackManager.cpp b/TrackManager.cpp index 06b6a18..d66b999 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -38,8 +38,8 @@ if (track[t]->getMode()==findmode) \ track[t]->function; -MotorDriver * TrackManager::track[MAX_TRACKS]; -int16_t TrackManager::trackDCAddr[MAX_TRACKS]; +MotorDriver * TrackManager::track[MAX_TRACKS] = { NULL }; +int16_t TrackManager::trackDCAddr[MAX_TRACKS] = { 0 }; int8_t TrackManager::lastTrack=-1; bool TrackManager::progTrackSyncMain=false; @@ -251,7 +251,6 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr } else { track[trackToSet]->makeProgTrack(false); // only the prog track knows it's type } - track[trackToSet]->setMode(mode); // When a track is switched, we must clear any side effects of its previous // state, otherwise trains run away or just dont move. @@ -259,8 +258,13 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr // This can be done BEFORE the PWM-Timer evaluation (methinks) if (mode & TRACK_MODE_DC) { if (trackDCAddr[trackToSet] != dcAddr) { - // if we change dcAddr, detach first old signal - track[trackToSet]->detachDCSignal(); + // new or changed DC Addr, run the new setup + if (trackDCAddr[trackToSet] != 0) { + // if we change dcAddr and not only + // change from another mode, + // first detach old DC signal + track[trackToSet]->detachDCSignal(); + } #ifdef ARDUINO_ARCH_ESP32 int trackfound = -1; FOR_EACH_TRACK(t) { @@ -285,7 +289,9 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr // DCC tracks need to have set the PWM to zero or they will not work. track[trackToSet]->detachDCSignal(); track[trackToSet]->setBrake(false); + trackDCAddr[trackToSet]=0; // clear that an addr is set for DC as this is not a DC track } + track[trackToSet]->setMode(mode); // BOOST: // Leave it as is diff --git a/version.h b/version.h index 6f25b47..2af0a55 100644 --- a/version.h +++ b/version.h @@ -3,8 +3,9 @@ #include "StringFormatter.h" -#define VERSION "5.2.44" -// 5.2.44 - ESP32 fix PWM LEDC inverted pin mode +#define VERSION "5.2.45" +// 5.2.45 - ESP32 Trackmanager reset cab number to 0 when track is not DC +// ESP32 fix PWM LEDC inverted pin mode // ESP32 rewrite PWM LEDC to use pin mux // 5.2.42 - ESP32 Bugfix: Uninitialized stack variable // 5.2.41 - Update rotary encoder default address to 0x67