diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index a133a2e..0400ae0 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -577,7 +577,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) { if (params > 1) break; if (params==0) { // All - TrackManager::setTrackPower(TRACK_MODE_ALL, POWERMODE::ON); + TrackManager::setTrackPower(TRACK_ALL, POWERMODE::ON); } if (params==1) { if (p[0]=="MAIN"_hk) { // <1 MAIN> @@ -610,7 +610,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) if (params > 1) break; if (params==0) { // All TrackManager::setJoin(false); - TrackManager::setTrackPower(TRACK_MODE_ALL, POWERMODE::OFF); + TrackManager::setTrackPower(TRACK_ALL, POWERMODE::OFF); } if (params==1) { if (p[0]=="MAIN"_hk) { // <0 MAIN> diff --git a/MotorDriver.cpp b/MotorDriver.cpp index 749c425..39ec08d 100644 --- a/MotorDriver.cpp +++ b/MotorDriver.cpp @@ -576,7 +576,7 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) { DIAG(F("TRACK %c ALERT FAULT"), trackno + 'A'); } setPower(POWERMODE::ALERT); - if ((trackMode & TRACK_MODE_AUTOINV) && (trackMode & (TRACK_MODE_MAIN|TRACK_MODE_EXT|TRACK_MODE_BOOST))){ + if ((trackMode & TRACK_MODIFIER_AUTO) && (trackMode & (TRACK_MODE_MAIN|TRACK_MODE_EXT|TRACK_MODE_BOOST))){ DIAG(F("TRACK %c INVERT"), trackno + 'A'); invertOutput(); } diff --git a/MotorDriver.h b/MotorDriver.h index 3438c05..269fee7 100644 --- a/MotorDriver.h +++ b/MotorDriver.h @@ -29,21 +29,33 @@ #include // use powers of two so we can do logical and/or on the track modes in if clauses. -// RACK_MODE_DCX is (TRACK_MODE_DC|TRACK_MODE_INV) +// 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 {TRACK_MODE_NONE = 1, TRACK_MODE_MAIN = 2, TRACK_MODE_PROG = 4, - TRACK_MODE_DC = 8, TRACK_MODE_EXT = 16, +enum TRACK_MODE : byte { + // main modes + TRACK_MODE_NONE = 1, TRACK_MODE_MAIN = 2, TRACK_MODE_PROG = 4, + TRACK_MODE_DC = 8, TRACK_MODE_EXT = 16, + // modifiers + TRACK_MODIFIER_INV = 64, TRACK_MODIFIER_AUTO = 128, #ifdef ARDUINO_ARCH_ESP32 - TRACK_MODE_BOOST = 32, + TRACK_MODE_BOOST = 32, + TRACK_MODE_BOOST_INV = TRACK_MODE_BOOST|TRACK_MODIFIER_INV, + TRACK_MODE_BOOST_AUTO = TRACK_MODE_BOOST|TRACK_MODIFIER_AUTO, #else - TRACK_MODE_BOOST = 0, + TRACK_MODE_BOOST = 0, + TRACK_MODE_BOOST_INV = 0, + TRACK_MODE_BOOST_AUTO = 0, #endif - TRACK_MODE_ALL = TRACK_MODE_MAIN|TRACK_MODE_PROG|TRACK_MODE_DC|TRACK_MODE_EXT|TRACK_MODE_BOOST, - TRACK_MODE_INV = 64, - TRACK_MODE_DCX = TRACK_MODE_DC|TRACK_MODE_INV, TRACK_MODE_AUTOINV = 128}; + // derived modes; TRACK_ALL is calles that so it does not match TRACK_MODE_* + TRACK_ALL = TRACK_MODE_MAIN|TRACK_MODE_PROG|TRACK_MODE_DC|TRACK_MODE_EXT|TRACK_MODE_BOOST, + TRACK_MODE_MAIN_INV = TRACK_MODE_MAIN|TRACK_MODIFIER_INV, + TRACK_MODE_MAIN_AUTO = TRACK_MODE_MAIN|TRACK_MODIFIER_AUTO, + TRACK_MODE_DC_INV = TRACK_MODE_DC|TRACK_MODIFIER_INV, + TRACK_MODE_DCX = TRACK_MODE_DC_INV // DCX is other name for historical reasons +}; #define setHIGH(fastpin) *fastpin.inout |= fastpin.maskHIGH #define setLOW(fastpin) *fastpin.inout &= fastpin.maskLOW @@ -273,7 +285,7 @@ class MotorDriver { #endif inline void setMode(TRACK_MODE m) { trackMode = m; - invertOutput(trackMode & TRACK_MODE_INV); + invertOutput(trackMode & TRACK_MODIFIER_INV); }; inline void invertOutput() { // toggles output inversion invertPhase = !invertPhase; diff --git a/TrackManager.cpp b/TrackManager.cpp index ba9776b..a164142 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -387,11 +387,15 @@ bool TrackManager::parseEqualSign(Print *stream, int16_t params, int16_t p[]) if (params>1 && (p[0]<0 || p[0]>=MAX_TRACKS)) return false; - if (params==2 && p[1]=="MAIN"_hk) // <= id MAIN> + if (params==2 && p[1]=="MAIN"_hk) // <= id MAIN> return setTrackMode(p[0],TRACK_MODE_MAIN); + if (params==2 && p[1]=="MAIN_INV"_hk) // <= id MAIN_INV> + return setTrackMode(p[0],TRACK_MODE_MAIN_INV); + if (params==2 && p[1]=="MAIN_AUTO"_hk) // <= id MAIN_AUTO> + return setTrackMode(p[0],TRACK_MODE_MAIN_AUTO); #ifndef DISABLE_PROG - if (params==2 && p[1]=="PROG"_hk) // <= id PROG> + if (params==2 && p[1]=="PROG"_hk) // <= id PROG> return setTrackMode(p[0],TRACK_MODE_PROG); #endif @@ -402,20 +406,27 @@ bool TrackManager::parseEqualSign(Print *stream, int16_t params, int16_t p[]) return setTrackMode(p[0],TRACK_MODE_EXT); #ifdef BOOSTER_INPUT if (TRACK_MODE_BOOST != 0 && // compile time optimization - params==2 && p[1]=="BOOST"_hk) // <= id BOOST> + params==2 && p[1]=="BOOST"_hk) // <= id BOOST> return setTrackMode(p[0],TRACK_MODE_BOOST); + if (TRACK_MODE_BOOST_INV != 0 && // compile time optimization + params==2 && p[1]=="BOOST_INV"_hk) // <= id BOOST_INV> + return setTrackMode(p[0],TRACK_MODE_BOOST_INV); + if (TRACK_MODE_BOOST_AUTO != 0 && // compile time optimization + params==2 && p[1]=="BOOST_AUTO"_hk) // <= id BOOST_AUTO> + return setTrackMode(p[0],TRACK_MODE_BOOST_AUTO); #endif - if (params==2 && p[1]=="AUTO"_hk) // <= id AUTO> - return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODE_AUTOINV); + if (params==2 && p[1]=="AUTO"_hk) // <= id AUTO> + return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODIFIER_AUTO); - if (params==2 && p[1]=="INV"_hk) // <= id INV> - return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODE_INV); + if (params==2 && p[1]=="INV"_hk) // <= id INV> + return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODIFIER_INV); - if (params==3 && p[1]=="DC"_hk && p[2]>0) // <= id DC cab> + if (params==3 && p[1]=="DC"_hk && p[2]>0) // <= id DC cab> return setTrackMode(p[0],TRACK_MODE_DC,p[2]); - if (params==3 && p[1]=="DCX"_hk && p[2]>0) // <= id DCX cab> - return setTrackMode(p[0],TRACK_MODE_DC|TRACK_MODE_INV,p[2]); + if (params==3 && (p[1]=="DC_INV"_hk || // <= id DC_INV cab> + p[1]=="DCX"_hk) && p[2]>0) // <= id DCX cab> + return setTrackMode(p[0],TRACK_MODE_DC_INV,p[2]); return false; } @@ -424,9 +435,9 @@ const FSH* TrackManager::getModeName(TRACK_MODE tm) { const FSH *modename=F("---"); if (tm & TRACK_MODE_MAIN) { - if(tm & TRACK_MODE_AUTOINV) + if(tm & TRACK_MODIFIER_AUTO) modename=F("MAIN A"); - else if (tm & TRACK_MODE_INV) + else if (tm & TRACK_MODIFIER_INV) modename=F("MAIN I>\n"); else modename=F("MAIN"); @@ -440,15 +451,15 @@ const FSH* TrackManager::getModeName(TRACK_MODE tm) { else if(tm & TRACK_MODE_EXT) modename=F("EXT"); else if(tm & TRACK_MODE_BOOST) { - if(tm & TRACK_MODE_AUTOINV) + if(tm & TRACK_MODIFIER_AUTO) modename=F("BOOST A"); - else if (tm & TRACK_MODE_INV) + else if (tm & TRACK_MODIFIER_INV) modename=F("BOOST I"); else modename=F("BOOST"); } else if (tm & TRACK_MODE_DC) { - if (tm & TRACK_MODE_INV) + if (tm & TRACK_MODIFIER_INV) modename=F("DCX"); else modename=F("DC");