1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-22 23:56:13 +01:00

TrackManager and EXRAIL: Introduce more consistent names for <= ...> and SET_TRACK

This commit is contained in:
Harald Barth 2024-09-30 10:05:47 +02:00
parent 07ab7286ba
commit 01533e2cd2
4 changed files with 50 additions and 27 deletions

View File

@ -577,7 +577,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
{ {
if (params > 1) break; if (params > 1) break;
if (params==0) { // All if (params==0) { // All
TrackManager::setTrackPower(TRACK_MODE_ALL, POWERMODE::ON); TrackManager::setTrackPower(TRACK_ALL, POWERMODE::ON);
} }
if (params==1) { if (params==1) {
if (p[0]=="MAIN"_hk) { // <1 MAIN> 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 > 1) break;
if (params==0) { // All if (params==0) { // All
TrackManager::setJoin(false); TrackManager::setJoin(false);
TrackManager::setTrackPower(TRACK_MODE_ALL, POWERMODE::OFF); TrackManager::setTrackPower(TRACK_ALL, POWERMODE::OFF);
} }
if (params==1) { if (params==1) {
if (p[0]=="MAIN"_hk) { // <0 MAIN> if (p[0]=="MAIN"_hk) { // <0 MAIN>

View File

@ -576,7 +576,7 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
DIAG(F("TRACK %c ALERT FAULT"), trackno + 'A'); DIAG(F("TRACK %c ALERT FAULT"), trackno + 'A');
} }
setPower(POWERMODE::ALERT); 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'); DIAG(F("TRACK %c INVERT"), trackno + 'A');
invertOutput(); invertOutput();
} }

View File

@ -29,21 +29,33 @@
#include <wiring_private.h> #include <wiring_private.h>
// use powers of two so we can do logical and/or on the track modes in if clauses. // 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<class T> inline T operator~ (T a) { return (T)~(int)a; } template<class T> inline T operator~ (T a) { return (T)~(int)a; }
template<class T> inline T operator| (T a, T b) { return (T)((int)a | (int)b); } template<class T> inline T operator| (T a, T b) { return (T)((int)a | (int)b); }
template<class T> inline T operator& (T a, T b) { return (T)((int)a & (int)b); } template<class T> inline T operator& (T a, T b) { return (T)((int)a & (int)b); }
template<class T> inline T operator^ (T a, T b) { return (T)((int)a ^ (int)b); } template<class T> 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, enum TRACK_MODE : byte {
TRACK_MODE_DC = 8, TRACK_MODE_EXT = 16, // 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 #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 #else
TRACK_MODE_BOOST = 0, TRACK_MODE_BOOST = 0,
TRACK_MODE_BOOST_INV = 0,
TRACK_MODE_BOOST_AUTO = 0,
#endif #endif
TRACK_MODE_ALL = TRACK_MODE_MAIN|TRACK_MODE_PROG|TRACK_MODE_DC|TRACK_MODE_EXT|TRACK_MODE_BOOST, // derived modes; TRACK_ALL is calles that so it does not match TRACK_MODE_*
TRACK_MODE_INV = 64, TRACK_ALL = TRACK_MODE_MAIN|TRACK_MODE_PROG|TRACK_MODE_DC|TRACK_MODE_EXT|TRACK_MODE_BOOST,
TRACK_MODE_DCX = TRACK_MODE_DC|TRACK_MODE_INV, TRACK_MODE_AUTOINV = 128}; 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 setHIGH(fastpin) *fastpin.inout |= fastpin.maskHIGH
#define setLOW(fastpin) *fastpin.inout &= fastpin.maskLOW #define setLOW(fastpin) *fastpin.inout &= fastpin.maskLOW
@ -273,7 +285,7 @@ class MotorDriver {
#endif #endif
inline void setMode(TRACK_MODE m) { inline void setMode(TRACK_MODE m) {
trackMode = m; trackMode = m;
invertOutput(trackMode & TRACK_MODE_INV); invertOutput(trackMode & TRACK_MODIFIER_INV);
}; };
inline void invertOutput() { // toggles output inversion inline void invertOutput() { // toggles output inversion
invertPhase = !invertPhase; invertPhase = !invertPhase;

View File

@ -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)) if (params>1 && (p[0]<0 || p[0]>=MAX_TRACKS))
return false; 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); 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 #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); return setTrackMode(p[0],TRACK_MODE_PROG);
#endif #endif
@ -402,20 +406,27 @@ bool TrackManager::parseEqualSign(Print *stream, int16_t params, int16_t p[])
return setTrackMode(p[0],TRACK_MODE_EXT); return setTrackMode(p[0],TRACK_MODE_EXT);
#ifdef BOOSTER_INPUT #ifdef BOOSTER_INPUT
if (TRACK_MODE_BOOST != 0 && // compile time optimization 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); 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 #endif
if (params==2 && p[1]=="AUTO"_hk) // <= id AUTO> if (params==2 && p[1]=="AUTO"_hk) // <= id AUTO>
return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODE_AUTOINV); return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODIFIER_AUTO);
if (params==2 && p[1]=="INV"_hk) // <= id INV> if (params==2 && p[1]=="INV"_hk) // <= id INV>
return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODE_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]); return setTrackMode(p[0],TRACK_MODE_DC,p[2]);
if (params==3 && p[1]=="DCX"_hk && p[2]>0) // <= id DCX cab> if (params==3 && (p[1]=="DC_INV"_hk || // <= id DC_INV cab>
return setTrackMode(p[0],TRACK_MODE_DC|TRACK_MODE_INV,p[2]); p[1]=="DCX"_hk) && p[2]>0) // <= id DCX cab>
return setTrackMode(p[0],TRACK_MODE_DC_INV,p[2]);
return false; return false;
} }
@ -424,9 +435,9 @@ const FSH* TrackManager::getModeName(TRACK_MODE tm) {
const FSH *modename=F("---"); const FSH *modename=F("---");
if (tm & TRACK_MODE_MAIN) { if (tm & TRACK_MODE_MAIN) {
if(tm & TRACK_MODE_AUTOINV) if(tm & TRACK_MODIFIER_AUTO)
modename=F("MAIN A"); modename=F("MAIN A");
else if (tm & TRACK_MODE_INV) else if (tm & TRACK_MODIFIER_INV)
modename=F("MAIN I>\n"); modename=F("MAIN I>\n");
else else
modename=F("MAIN"); modename=F("MAIN");
@ -440,15 +451,15 @@ const FSH* TrackManager::getModeName(TRACK_MODE tm) {
else if(tm & TRACK_MODE_EXT) else if(tm & TRACK_MODE_EXT)
modename=F("EXT"); modename=F("EXT");
else if(tm & TRACK_MODE_BOOST) { else if(tm & TRACK_MODE_BOOST) {
if(tm & TRACK_MODE_AUTOINV) if(tm & TRACK_MODIFIER_AUTO)
modename=F("BOOST A"); modename=F("BOOST A");
else if (tm & TRACK_MODE_INV) else if (tm & TRACK_MODIFIER_INV)
modename=F("BOOST I"); modename=F("BOOST I");
else else
modename=F("BOOST"); modename=F("BOOST");
} }
else if (tm & TRACK_MODE_DC) { else if (tm & TRACK_MODE_DC) {
if (tm & TRACK_MODE_INV) if (tm & TRACK_MODIFIER_INV)
modename=F("DCX"); modename=F("DCX");
else else
modename=F("DC"); modename=F("DC");