From 6d382fa0f454096f79420ea9436ea7292301f65d Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Thu, 12 May 2022 20:56:23 +0200 Subject: [PATCH] TackManager: Make OFF=zero and when DCC then HA must be off --- TrackManager.cpp | 15 ++++++++++++--- TrackManager.h | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/TrackManager.cpp b/TrackManager.cpp index 74b3a7d..39ec185 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -149,9 +149,18 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr // re-evaluate HighAccuracy mode // We can only do this is all main and prog tracks agree bool canDo=true; - FOR_EACH_TRACK(t) - if (trackMode[t]==TRACK_MODE_MAIN ||trackMode[t]==TRACK_MODE_PROG) - canDo &= track[t]->isPWMCapable(); + FOR_EACH_TRACK(t) { + // DC tracks must not have the DCC PWM switched on + // so we globally turn it off if one of the PWM + // capable tracks is now DC or DCX. + if (trackMode[t]==TRACK_MODE_DC || trackMode[t]==TRACK_MODE_DCX) { + if (track[t]->isPWMCapable()) { + canDo=false; + break; + } + } else if (trackMode[t]==TRACK_MODE_MAIN || trackMode[t]==TRACK_MODE_PROG) + canDo &= track[t]->isPWMCapable(); + } //DIAG(F("HAMode=%d"),canDo); if (!canDo) { DCCTimer::clearPWM(); diff --git a/TrackManager.h b/TrackManager.h index 8b12f86..fcbda17 100644 --- a/TrackManager.h +++ b/TrackManager.h @@ -23,7 +23,7 @@ #include "MotorDriver.h" // Virtualised Motor shield multi-track hardware Interface -enum TRACK_MODE : byte {TRACK_MODE_MAIN, TRACK_MODE_PROG, TRACK_MODE_OFF, +enum TRACK_MODE : byte {TRACK_MODE_OFF, TRACK_MODE_MAIN, TRACK_MODE_PROG, TRACK_MODE_DC, TRACK_MODE_DCX}; // These constants help EXRAIL macros say SET_TRACK(2,mode) OR SET_TRACK(C,mode) etc.