diff --git a/MotorDriver.h b/MotorDriver.h index db229d5..6c39058 100644 --- a/MotorDriver.h +++ b/MotorDriver.h @@ -118,12 +118,12 @@ class MotorDriver { inline byte getFaultPin() { return faultPin; } - inline void setResetCounterPointer(byte *bp) { // load resetPacketCounter pointer + inline void setResetCounterPointer(volatile byte *bp) { // load resetPacketCounter pointer resetsCounterP = bp; } void checkPowerOverload(bool useProgLimit, byte trackno); private: - byte *resetsCounterP = NULL; // points to the resetPacketCounter if this is a prog track + volatile byte *resetsCounterP = NULL; // points to the resetPacketCounter if this is a prog track void getFastPin(const FSH* type,int pin, bool input, FASTPIN & result); void getFastPin(const FSH* type,int pin, FASTPIN & result) { getFastPin(type, pin, 0, result); diff --git a/TrackManager.cpp b/TrackManager.cpp index 0c5117b..ccbed6f 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -78,11 +78,11 @@ void TrackManager::Setup(const FSH * shieldname, } void TrackManager::addTrack(byte t, MotorDriver* driver) { - track[t]=driver; trackMode[t]=TRACK_MODE_OFF; + track[t]=driver; if (driver) { - lastTrack=t; track[t]->setPower(POWERMODE::OFF); + lastTrack=t; } } @@ -167,9 +167,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.