From 4f16091670d1cf8187f659d6c1a3d4e7a1025343 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sat, 21 Dec 2024 15:19:23 +0100 Subject: [PATCH 1/7] take whole if clause out when DISABLE_PROG is active --- TrackManager.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/TrackManager.cpp b/TrackManager.cpp index b4863bc..0727956 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -246,9 +246,6 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr #endif #ifndef DISABLE_PROG if (mode & TRACK_MODE_PROG) { -#else - if (false) { -#endif // only allow 1 track to be prog FOR_EACH_TRACK(t) if ( (track[t]->getMode() & TRACK_MODE_PROG) && t != trackToSet) { @@ -261,6 +258,7 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr } else { track[trackToSet]->makeProgTrack(false); // only the prog track knows it's type } +#endif // When a track is switched, we must clear any side effects of its previous // state, otherwise trains run away or just dont move. From 8329fd83ceff5efb38e516ffd4a92f78a0ac51df Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sat, 21 Dec 2024 15:42:15 +0100 Subject: [PATCH 2/7] clear progTrackSyncMain (join flag) when prog track is removed --- DCCACK.cpp | 4 ++++ TrackManager.cpp | 6 ++++++ 2 files changed, 10 insertions(+) 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; } From 84bc098157c3c542e08a7fb54f5f655a7cdd16d9 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sat, 21 Dec 2024 16:08:57 +0100 Subject: [PATCH 3/7] seperate out the templates that make it possible to use bitwise operations on enums --- IODevice.h | 1 + MotorDriver.h | 5 +---- TemplateForEnums.h | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 TemplateForEnums.h diff --git a/IODevice.h b/IODevice.h index 7be84fd..08b7370 100644 --- a/IODevice.h +++ b/IODevice.h @@ -38,6 +38,7 @@ #include "FSH.h" #include "I2CManager.h" #include "inttypes.h" +#include "TemplateForEnums.h" typedef uint16_t VPIN; // Limit VPIN number to max 32767. Above this number, printing often gives negative values. diff --git a/MotorDriver.h b/MotorDriver.h index 269fee7..f1d52f7 100644 --- a/MotorDriver.h +++ b/MotorDriver.h @@ -28,12 +28,9 @@ #include "DCCTimer.h" #include +#include "TemplateForEnums.h" // use powers of two so we can do logical and/or on the track modes in if clauses. // For example TRACK_MODE_DC_INV is (TRACK_MODE_DC|TRACK_MODIFIER_INV) -template inline T operator~ (T a) { return (T)~(int)a; } -template inline T operator| (T a, T b) { return (T)((int)a | (int)b); } -template inline T operator& (T a, T b) { return (T)((int)a & (int)b); } -template inline T operator^ (T a, T b) { return (T)((int)a ^ (int)b); } enum TRACK_MODE : byte { // main modes TRACK_MODE_NONE = 1, TRACK_MODE_MAIN = 2, TRACK_MODE_PROG = 4, diff --git a/TemplateForEnums.h b/TemplateForEnums.h new file mode 100644 index 0000000..459568d --- /dev/null +++ b/TemplateForEnums.h @@ -0,0 +1,26 @@ +/* + * © 2024, Harald Barth. All rights reserved. + * + * This file is part of DCC-EX + * + * This is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * It is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with CommandStation. If not, see . + */ +#ifndef TemplateForEnums +#define TemplateForEnums +template inline T operator~ (T a) { return (T)~(int)a; } +template inline T operator| (T a, T b) { return (T)((int)a | (int)b); } +template inline T operator& (T a, T b) { return (T)((int)a & (int)b); } +template inline T operator^ (T a, T b) { return (T)((int)a ^ (int)b); } +#endif + From d4a99b5db5b03114d063c14890965e1d1d741a0f Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sun, 22 Dec 2024 13:59:21 +0100 Subject: [PATCH 4/7] version 5.2.93 --- GITHUB_SHA.h | 2 +- version.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 9dd9282..7969083 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "devel-202411091200Z" +#define GITHUB_SHA "devel-202412221258Z" diff --git a/version.h b/version.h index db69609..44a33f9 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,8 @@ #include "StringFormatter.h" -#define VERSION "5.2.92" +#define VERSION "5.2.93" +// 5.2.93 - Bugfix ESP32: clear progTrackSyncMain (join flag) when prog track is removed // 5.2.92 - Bugfix: FADE power off fix, EXRAIL power diagnostic fix. // 5.2.91 - Bugfix: Neopixel I2C overlap check // 5.2.90 - Bugfix: EXRAIL EXTT_TURNTABLE() now has description as optional in line with ocumentation (also fixed DCC_TURNTABLE) From cafd53a0e569ebb2ae143a4ea4ae4cbba6d203ff Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sun, 22 Dec 2024 23:12:45 +0100 Subject: [PATCH 5/7] clear progTrackSyncMain (join flag) when prog track is removed 2nd fix --- DCCACK.cpp | 8 ++++++-- TrackManager.cpp | 23 +++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/DCCACK.cpp b/DCCACK.cpp index d6b070e..7a43cd1 100644 --- a/DCCACK.cpp +++ b/DCCACK.cpp @@ -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 // cleared when the prog track is removed. ackManagerRejoin=TrackManager::isJoined(); + //DIAG(F("Joined is %d"), ackManagerRejoin); if (ackManagerRejoin) { // Change from JOIN must zero resets packet. TrackManager::setJoin(false); DCCWaveform::progTrack.clearResets(); } - progDriver=TrackManager::getProgDriver(); + //DIAG(F("Progdriver is %d"), progDriver); 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! return; } diff --git a/TrackManager.cpp b/TrackManager.cpp index 5ada17b..74e67de 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -356,17 +356,24 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr applyDCSpeed(trackToSet); } - // Turn off power if we changed the mode of this track - if (mode != oldmode) - track[trackToSet]->setPower(POWERMODE::OFF); - streamTrackState(NULL,trackToSet); - +#ifdef ARDUINO_ARCH_ESP32 #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; + if (tempProgTrack == trackToSet && oldmode & TRACK_MODE_MAIN && !(mode & TRACK_MODE_PROG)) { + // If we just take away the prog track, the join should not + // 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 + // 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); return true; } From 43fe772661baa85f3a4e00b6633b818411338919 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sun, 22 Dec 2024 23:13:53 +0100 Subject: [PATCH 6/7] remove diag --- TrackManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TrackManager.cpp b/TrackManager.cpp index 74e67de..72e8fad 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -361,7 +361,7 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr if (tempProgTrack == trackToSet && oldmode & TRACK_MODE_MAIN && !(mode & TRACK_MODE_PROG)) { // If we just take away the prog track, the join should not // be active either. So do in effect an unjoin - DIAG(F("Unsync")); + //DIAG(F("Unsync")); tempProgTrack = MAX_TRACKS+1; progTrackSyncMain=false; if (joinRelay!=UNUSED_PIN) digitalWrite(joinRelay,LOW); From 13488e1e93f1ddeaf55027b52e0cd27c1a55c26b Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sun, 22 Dec 2024 23:22:24 +0100 Subject: [PATCH 7/7] version tag --- GITHUB_SHA.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 7969083..c59512d 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "devel-202412221258Z" +#define GITHUB_SHA "devel-202412222121Z"