1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-25 05:31:24 +01:00

ESP32: autoreverse and booster prototype

This commit is contained in:
Harald Barth 2023-11-10 23:58:30 +01:00
parent 337af77a03
commit 2f3d489f18
5 changed files with 102 additions and 78 deletions

View File

@ -857,7 +857,7 @@ void RMFT2::loop2() {
// If DC/DCX use my loco for DC address // If DC/DCX use my loco for DC address
{ {
TRACK_MODE mode = (TRACK_MODE)(operand>>8); TRACK_MODE mode = (TRACK_MODE)(operand>>8);
int16_t cab=(mode==TRACK_MODE_DC || mode==TRACK_MODE_DCX) ? loco : 0; int16_t cab=(mode & TRACK_MODE_DC) ? loco : 0;
TrackManager::setTrackMode(operand & 0x0F, mode, cab); TrackManager::setTrackMode(operand & 0x0F, mode, cab);
} }
break; break;

View File

@ -605,7 +605,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_MAIN|TRACK_MODE_EXT)){ // add (&& isAutoreverse) later if ((trackMode & TRACK_MODE_AUTOINV) && (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

@ -3,7 +3,7 @@
* © 2021 Mike S * © 2021 Mike S
* © 2021 Fred Decker * © 2021 Fred Decker
* © 2020 Chris Harlow * © 2020 Chris Harlow
* © 2022 Harald Barth * © 2022,2023 Harald Barth
* All rights reserved. * All rights reserved.
* *
* This file is part of CommandStation-EX * This file is part of CommandStation-EX
@ -28,8 +28,14 @@
#include "DCCTimer.h" #include "DCCTimer.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)
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); }
enum TRACK_MODE : byte {TRACK_MODE_NONE = 1, TRACK_MODE_MAIN = 2, TRACK_MODE_PROG = 4, enum TRACK_MODE : byte {TRACK_MODE_NONE = 1, TRACK_MODE_MAIN = 2, TRACK_MODE_PROG = 4,
TRACK_MODE_DC = 8, TRACK_MODE_DCX = 16, TRACK_MODE_EXT = 32}; TRACK_MODE_DC = 8, TRACK_MODE_EXT = 16, TRACK_MODE_BOOST = 32,
TRACK_MODE_INV = 64, TRACK_MODE_DCX = 72, TRACK_MODE_AUTOINV = 128};
#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
@ -240,7 +246,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_DCX);// change later to TRACK_MODE_INVERTED? invertOutput(trackMode & TRACK_MODE_INV);
}; };
inline void invertOutput() { // toggles output inversion inline void invertOutput() { // toggles output inversion
invertPhase = !invertPhase; invertPhase = !invertPhase;

View File

@ -1,6 +1,6 @@
/* /*
* © 2022 Chris Harlow * © 2022 Chris Harlow
* © 2022 Harald Barth * © 2022,2023 Harald Barth
* © 2023 Colin Murdoch * © 2023 Colin Murdoch
* All rights reserved. * All rights reserved.
* *
@ -45,6 +45,9 @@ const int16_t HASH_KEYWORD_DC = 2183;
const int16_t HASH_KEYWORD_DCX = 6463; // DC reversed polarity const int16_t HASH_KEYWORD_DCX = 6463; // DC reversed polarity
const int16_t HASH_KEYWORD_EXT = 8201; // External DCC signal const int16_t HASH_KEYWORD_EXT = 8201; // External DCC signal
const int16_t HASH_KEYWORD_A = 65; // parser makes single chars the ascii. const int16_t HASH_KEYWORD_A = 65; // parser makes single chars the ascii.
const int16_t HASH_KEYWORD_AUTO = -5457;
const int16_t HASH_KEYWORD_BOOST = 11269;
const int16_t HASH_KEYWORD_INV = 11857;
MotorDriver * TrackManager::track[MAX_TRACKS]; MotorDriver * TrackManager::track[MAX_TRACKS];
int16_t TrackManager::trackDCAddr[MAX_TRACKS]; int16_t TrackManager::trackDCAddr[MAX_TRACKS];
@ -87,7 +90,7 @@ void TrackManager::sampleCurrent() {
if (!waiting) { if (!waiting) {
// look for a valid track to sample or until we are around // look for a valid track to sample or until we are around
while (true) { while (true) {
if (track[tr]->getMode() & ( TRACK_MODE_MAIN|TRACK_MODE_PROG|TRACK_MODE_DC|TRACK_MODE_DCX|TRACK_MODE_EXT )) { if (track[tr]->getMode() & ( TRACK_MODE_MAIN|TRACK_MODE_PROG|TRACK_MODE_DC|TRACK_MODE_BOOST|TRACK_MODE_EXT )) {
track[tr]->startCurrentFromHW(); track[tr]->startCurrentFromHW();
// for scope debug track[1]->setBrake(1); // for scope debug track[1]->setBrake(1);
waiting = true; waiting = true;
@ -197,7 +200,7 @@ void TrackManager::setPROGSignal( bool on) {
void TrackManager::setDCSignal(int16_t cab, byte speedbyte) { void TrackManager::setDCSignal(int16_t cab, byte speedbyte) {
FOR_EACH_TRACK(t) { FOR_EACH_TRACK(t) {
if (trackDCAddr[t]!=cab && cab != 0) continue; if (trackDCAddr[t]!=cab && cab != 0) continue;
if (track[t]->getMode() & (TRACK_MODE_DC|TRACK_MODE_DCX)) if (track[t]->getMode() & TRACK_MODE_DC)
track[t]->setDCSignal(speedbyte); track[t]->setDCSignal(speedbyte);
} }
} }
@ -207,7 +210,7 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
//DIAG(F("Track=%c Mode=%d"),trackToSet+'A', mode); //DIAG(F("Track=%c Mode=%d"),trackToSet+'A', mode);
// DC tracks require a motorDriver that can set brake! // DC tracks require a motorDriver that can set brake!
if (mode==TRACK_MODE_DC || mode==TRACK_MODE_DCX) { if (mode & TRACK_MODE_DC) {
#if defined(ARDUINO_AVR_UNO) #if defined(ARDUINO_AVR_UNO)
DIAG(F("Uno has no PWM timers available for DC")); DIAG(F("Uno has no PWM timers available for DC"));
return false; return false;
@ -227,24 +230,30 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
//DIAG(F("Track=%c remove ^pin %d"),trackToSet+'A', p.invpin); //DIAG(F("Track=%c remove ^pin %d"),trackToSet+'A', p.invpin);
gpio_reset_pin((gpio_num_t)p.invpin); gpio_reset_pin((gpio_num_t)p.invpin);
} }
if (mode & TRACK_MODE_BOOST) {
if (mode == TRACK_MODE_EXT) { DIAG(F("Track=%c mode boost pin %d"),trackToSet+'A', p.pin);
pinMode(26, INPUT); pinMode(26, INPUT); // hardcoded XXX
gpio_matrix_in(26, SIG_IN_FUNC228_IDX, false); //pads 224 to 228 available as loopback gpio_matrix_in(26, SIG_IN_FUNC228_IDX, false); //pads 224 to 228 available as loopback
gpio_matrix_out(p.pin, SIG_IN_FUNC228_IDX, false, false); gpio_matrix_out(p.pin, SIG_IN_FUNC228_IDX, false, false);
if (p.invpin != UNUSED_PIN) { if (p.invpin != UNUSED_PIN) {
gpio_matrix_out(p.invpin, SIG_IN_FUNC228_IDX, true /*inverted*/, false); gpio_matrix_out(p.invpin, SIG_IN_FUNC228_IDX, true /*inverted*/, false);
} }
} else if (mode & (TRACK_MODE_MAIN | TRACK_MODE_PROG | TRACK_MODE_DC)) {
// gpio_reset_pin may reset to input
pinMode(p.pin, OUTPUT);
if (p.invpin != UNUSED_PIN)
pinMode(p.invpin, OUTPUT);
} }
#endif #endif
#ifndef DISABLE_PROG #ifndef DISABLE_PROG
if (mode==TRACK_MODE_PROG) { if (mode & TRACK_MODE_PROG) {
#else #else
if (false) { if (false) {
#endif #endif
// only allow 1 track to be prog // only allow 1 track to be prog
FOR_EACH_TRACK(t) FOR_EACH_TRACK(t)
if (track[t]->getMode()==TRACK_MODE_PROG && t != trackToSet) { if ( (track[t]->getMode() & TRACK_MODE_PROG) && t != trackToSet) {
track[t]->setPower(POWERMODE::OFF); track[t]->setPower(POWERMODE::OFF);
track[t]->setMode(TRACK_MODE_NONE); track[t]->setMode(TRACK_MODE_NONE);
track[t]->makeProgTrack(false); // revoke prog track special handling track[t]->makeProgTrack(false); // revoke prog track special handling
@ -262,18 +271,20 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
// state, otherwise trains run away or just dont move. // state, otherwise trains run away or just dont move.
// This can be done BEFORE the PWM-Timer evaluation (methinks) // This can be done BEFORE the PWM-Timer evaluation (methinks)
if (!(mode==TRACK_MODE_DC || mode==TRACK_MODE_DCX)) { if (!(mode & TRACK_MODE_DC)) {
// DCC tracks need to have set the PWM to zero or they will not work. // DCC tracks need to have set the PWM to zero or they will not work.
track[trackToSet]->detachDCSignal(); track[trackToSet]->detachDCSignal();
track[trackToSet]->setBrake(false); track[trackToSet]->setBrake(false);
} }
#ifndef ARDUINO_ARCH_ESP32 // BOOST:
// Leave it as is
// otherwise:
// EXT is a special case where the signal pin is // EXT is a special case where the signal pin is
// turned off. So unless that is set, the signal // turned off. So unless that is set, the signal
// pin should be turned on // pin should be turned on
track[trackToSet]->enableSignal(mode != TRACK_MODE_EXT); if (!(mode & TRACK_MODE_BOOST))
#endif track[trackToSet]->enableSignal(!(mode & TRACK_MODE_EXT));
#ifndef ARDUINO_ARCH_ESP32 #ifndef ARDUINO_ARCH_ESP32
// re-evaluate HighAccuracy mode // re-evaluate HighAccuracy mode
@ -283,7 +294,7 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
// DC tracks must not have the DCC PWM switched on // DC tracks must not have the DCC PWM switched on
// so we globally turn it off if one of the PWM // so we globally turn it off if one of the PWM
// capable tracks is now DC or DCX. // capable tracks is now DC or DCX.
if (track[t]->getMode()==TRACK_MODE_DC || track[t]->getMode()==TRACK_MODE_DCX) { if (track[t]->getMode() & TRACK_MODE_DC) {
if (track[t]->isPWMCapable()) { if (track[t]->isPWMCapable()) {
canDo=false; // this track is capable but can not run PWM canDo=false; // this track is capable but can not run PWM
break; // in this mode, so abort and prevent globally below break; // in this mode, so abort and prevent globally below
@ -291,7 +302,7 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
track[t]->trackPWM=false; // this track sure can not run with PWM track[t]->trackPWM=false; // this track sure can not run with PWM
//DIAG(F("Track %c trackPWM 0 (not capable)"), t+'A'); //DIAG(F("Track %c trackPWM 0 (not capable)"), t+'A');
} }
} else if (track[t]->getMode()==TRACK_MODE_MAIN || track[t]->getMode()==TRACK_MODE_PROG) { } else if (track[t]->getMode() & (TRACK_MODE_MAIN |TRACK_MODE_PROG)) {
track[t]->trackPWM = track[t]->isPWMCapable(); // trackPWM is still a guess here track[t]->trackPWM = track[t]->isPWMCapable(); // trackPWM is still a guess here
//DIAG(F("Track %c trackPWM %d"), t+'A', track[t]->trackPWM); //DIAG(F("Track %c trackPWM %d"), t+'A', track[t]->trackPWM);
canDo &= track[t]->trackPWM; canDo &= track[t]->trackPWM;
@ -309,10 +320,12 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
#else #else
// For ESP32 we just reinitialize the DCC Waveform // For ESP32 we just reinitialize the DCC Waveform
DCCWaveform::begin(); DCCWaveform::begin();
// setMode() again AFTER Waveform::begin() of ESP32 fixes INVERTED signal
track[trackToSet]->setMode(mode);
#endif #endif
// This block must be AFTER the PWM-Timer modifications // This block must be AFTER the PWM-Timer modifications
if (mode==TRACK_MODE_DC || mode==TRACK_MODE_DCX) { if (mode & TRACK_MODE_DC) {
// DC tracks need to be given speed of the throttle for that cab address // DC tracks need to be given speed of the throttle for that cab address
// otherwise will not match other tracks on same cab. // otherwise will not match other tracks on same cab.
// This also needs to allow for inverted DCX // This also needs to allow for inverted DCX
@ -321,7 +334,7 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
// Normal running tracks are set to the global power state // Normal running tracks are set to the global power state
track[trackToSet]->setPower( track[trackToSet]->setPower(
(mode==TRACK_MODE_MAIN || mode==TRACK_MODE_DC || mode==TRACK_MODE_DCX || mode==TRACK_MODE_EXT) ? (mode & (TRACK_MODE_MAIN | TRACK_MODE_DC | TRACK_MODE_EXT | TRACK_MODE_BOOST)) ?
mainPowerGuess : POWERMODE::OFF); mainPowerGuess : POWERMODE::OFF);
//DIAG(F("TrackMode=%d"),mode); //DIAG(F("TrackMode=%d"),mode);
return true; return true;
@ -361,11 +374,20 @@ bool TrackManager::parseJ(Print *stream, int16_t params, int16_t p[])
if (params==2 && p[1]==HASH_KEYWORD_EXT) // <= id EXT> if (params==2 && p[1]==HASH_KEYWORD_EXT) // <= id EXT>
return setTrackMode(p[0],TRACK_MODE_EXT); return setTrackMode(p[0],TRACK_MODE_EXT);
if (params==2 && p[1]==HASH_KEYWORD_BOOST) // <= id BOOST>
return setTrackMode(p[0],TRACK_MODE_BOOST);
if (params==2 && p[1]==HASH_KEYWORD_AUTO) // <= id AUTO>
return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODE_AUTOINV);
if (params==2 && p[1]==HASH_KEYWORD_INV) // <= id AUTO>
return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODE_INV);
if (params==3 && p[1]==HASH_KEYWORD_DC && p[2]>0) // <= id DC cab> if (params==3 && p[1]==HASH_KEYWORD_DC && 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]==HASH_KEYWORD_DCX && p[2]>0) // <= id DCX cab> if (params==3 && p[1]==HASH_KEYWORD_DCX && p[2]>0) // <= id DCX cab>
return setTrackMode(p[0],TRACK_MODE_DCX,p[2]); return setTrackMode(p[0],TRACK_MODE_DC|TRACK_MODE_INV,p[2]);
return false; return false;
} }
@ -374,35 +396,38 @@ void TrackManager::streamTrackState(Print* stream, byte t) {
// null stream means send to commandDistributor for broadcast // null stream means send to commandDistributor for broadcast
if (track[t]==NULL) return; if (track[t]==NULL) return;
auto format=F(""); auto format=F("");
bool pstate = TrackManager::isPowerOn(t); // bool pstate = TrackManager::isPowerOn(t);
// char *statestr;
switch(track[t]->getMode()) { // if (pstate)
case TRACK_MODE_MAIN: // statestr = (char *)"ON";
if (pstate) {format=F("<= %c MAIN ON>\n");} else {format = F("<= %c MAIN OFF>\n");} // else
break; // statestr = (char *)"OFF";
TRACK_MODE tm = track[t]->getMode();
if (tm & TRACK_MODE_MAIN)
format=F("<= %c MAIN>\n");
#ifndef DISABLE_PROG #ifndef DISABLE_PROG
case TRACK_MODE_PROG: else if (tm & TRACK_MODE_PROG)
if (pstate) {format=F("<= %c PROG ON>\n");} else {format=F("<= %c PROG OFF>\n");} format=F("<= %c PROG>\n");
break;
#endif #endif
case TRACK_MODE_NONE: else if (tm & TRACK_MODE_NONE)
if (pstate) {format=F("<= %c NONE ON>\n");} else {format=F("<= %c NONE OFF>\n");} format=F("<= %c NONE>\n");
break; else if(tm & TRACK_MODE_EXT)
case TRACK_MODE_EXT: format=F("<= %c EXT>\n");
if (pstate) {format=F("<= %c EXT ON>\n");} else {format=F("<= %c EXT OFF>\n");} else if(tm & TRACK_MODE_BOOST)
break; format=F("<= %c BOOST>\n");
case TRACK_MODE_DC: else if (tm & TRACK_MODE_DC) {
if (pstate) {format=F("<= %c DC %d ON>\n");} else {format=F("<= %c DC %d OFF>\n");} if (tm & TRACK_MODE_INV)
break; format=F("<= %c DCX>\n");
case TRACK_MODE_DCX: else
if (pstate) {format=F("<= %c DCX %d ON>\n");} else {format=F("<= %c DCX %d OFF>\n");} format=F("<= %c DC>\n");
break;
default:
break; // unknown, dont care
} }
else
format=F("<= %c XXX>\n");
if (stream) StringFormatter::send(stream,format,'A'+t, trackDCAddr[t]); if (stream)
else CommandDistributor::broadcastTrackState(format,'A'+t, trackDCAddr[t]); StringFormatter::send(stream,format,'A'+t, trackDCAddr[t]);
else
CommandDistributor::broadcastTrackState(format,'A'+t, trackDCAddr[t]);
} }
@ -418,13 +443,13 @@ void TrackManager::loop() {
if (nextCycleTrack>lastTrack) nextCycleTrack=0; if (nextCycleTrack>lastTrack) nextCycleTrack=0;
if (track[nextCycleTrack]==NULL) return; if (track[nextCycleTrack]==NULL) return;
MotorDriver * motorDriver=track[nextCycleTrack]; MotorDriver * motorDriver=track[nextCycleTrack];
bool useProgLimit=dontLimitProg? false: track[nextCycleTrack]->getMode()==TRACK_MODE_PROG; bool useProgLimit=dontLimitProg ? false : (bool)(track[nextCycleTrack]->getMode() & TRACK_MODE_PROG);
motorDriver->checkPowerOverload(useProgLimit, nextCycleTrack); motorDriver->checkPowerOverload(useProgLimit, nextCycleTrack);
} }
MotorDriver * TrackManager::getProgDriver() { MotorDriver * TrackManager::getProgDriver() {
FOR_EACH_TRACK(t) FOR_EACH_TRACK(t)
if (track[t]->getMode()==TRACK_MODE_PROG) return track[t]; if (track[t]->getMode() & TRACK_MODE_PROG) return track[t];
return NULL; return NULL;
} }
@ -432,7 +457,7 @@ MotorDriver * TrackManager::getProgDriver() {
std::vector<MotorDriver *>TrackManager::getMainDrivers() { std::vector<MotorDriver *>TrackManager::getMainDrivers() {
std::vector<MotorDriver *> v; std::vector<MotorDriver *> v;
FOR_EACH_TRACK(t) FOR_EACH_TRACK(t)
if (track[t]->getMode()==TRACK_MODE_MAIN) v.push_back(track[t]); if (track[t]->getMode() & TRACK_MODE_MAIN) v.push_back(track[t]);
return v; return v;
} }
#endif #endif
@ -453,39 +478,32 @@ void TrackManager::setTrackPower(bool setProg, bool setJoin, POWERMODE mode, byt
MotorDriver * driver=track[thistrack]; MotorDriver * driver=track[thistrack];
if (!driver) return; if (!driver) return;
switch (track[thistrack]->getMode()) { TRACK_MODE tm = track[thistrack]->getMode();
case TRACK_MODE_MAIN: if ( (tm & TRACK_MODE_MAIN)
if (setProg) break; && !setProg ){
// toggle brake before turning power on - resets overcurrent error // toggle brake before turning power on - resets overcurrent error
// on the Pololu board if brake is wired to ^D2. // on the Pololu board if brake is wired to ^D2.
// XXX see if we can make this conditional // XXX see if we can make this conditional
driver->setBrake(true); driver->setBrake(true);
driver->setBrake(false); // DCC runs with brake off driver->setBrake(false); // DCC runs with brake off
driver->setPower(mode); driver->setPower(mode);
break; } else if ( (tm & TRACK_MODE_DC)
case TRACK_MODE_DC: && !(setProg || setJoin)){
case TRACK_MODE_DCX:
//DIAG(F("Processing track - %d setProg %d"), thistrack, setProg); //DIAG(F("Processing track - %d setProg %d"), thistrack, setProg);
if (setProg || setJoin) break;
driver->setBrake(true); // DC starts with brake on driver->setBrake(true); // DC starts with brake on
applyDCSpeed(thistrack); // speed match DCC throttles applyDCSpeed(thistrack); // speed match DCC throttles
driver->setPower(mode); driver->setPower(mode);
break; } else if ( (tm & TRACK_MODE_PROG)
case TRACK_MODE_PROG: && (setProg || setJoin) ){
if (!setProg && !setJoin) break;
driver->setBrake(true); driver->setBrake(true);
driver->setBrake(false); driver->setBrake(false);
driver->setPower(mode); driver->setPower(mode);
break; } else if ( (tm & TRACK_MODE_EXT)
case TRACK_MODE_EXT: || (tm & TRACK_MODE_BOOST)){
driver->setBrake(true); driver->setBrake(true);
driver->setBrake(false); driver->setBrake(false);
driver->setPower(mode); driver->setPower(mode);
break;
case TRACK_MODE_NONE:
break;
} }
} }
void TrackManager::reportPowerChange(Print* stream, byte thistrack) { void TrackManager::reportPowerChange(Print* stream, byte thistrack) {
@ -499,7 +517,7 @@ void TrackManager::setTrackPower(bool setProg, bool setJoin, POWERMODE mode, byt
POWERMODE TrackManager::getProgPower() { POWERMODE TrackManager::getProgPower() {
FOR_EACH_TRACK(t) FOR_EACH_TRACK(t)
if (track[t]->getMode()==TRACK_MODE_PROG) if (track[t]->getMode() & TRACK_MODE_PROG)
return track[t]->getPower(); return track[t]->getPower();
return POWERMODE::OFF; return POWERMODE::OFF;
} }
@ -544,7 +562,7 @@ void TrackManager::setJoin(bool joined) {
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
if (joined) { if (joined) {
FOR_EACH_TRACK(t) { FOR_EACH_TRACK(t) {
if (track[t]->getMode()==TRACK_MODE_PROG) { if (track[t]->getMode() & TRACK_MODE_PROG) {
tempProgTrack = t; tempProgTrack = t;
setTrackMode(t, TRACK_MODE_MAIN); setTrackMode(t, TRACK_MODE_MAIN);
break; break;
@ -573,7 +591,7 @@ bool TrackManager::isPowerOn(byte t) {
} }
bool TrackManager::isProg(byte t) { bool TrackManager::isProg(byte t) {
if (track[t]->getMode()==TRACK_MODE_PROG) if (track[t]->getMode() & TRACK_MODE_PROG)
return true; return true;
return false; return false;
} }

View File

@ -112,7 +112,7 @@ class TrackManager {
static POWERMODE mainPowerGuess; static POWERMODE mainPowerGuess;
static void applyDCSpeed(byte t); static void applyDCSpeed(byte t);
static int16_t trackDCAddr[MAX_TRACKS]; // dc address if TRACK_MODE_DC or TRACK_MODE_DCX static int16_t trackDCAddr[MAX_TRACKS]; // dc address if TRACK_MODE_DC
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
static byte tempProgTrack; // holds the prog track number during join static byte tempProgTrack; // holds the prog track number during join
#endif #endif