2022-02-22 02:27:27 +01:00
|
|
|
/*
|
|
|
|
* © 2022 Chris Harlow
|
2023-11-10 23:58:30 +01:00
|
|
|
* © 2022,2023 Harald Barth
|
2023-09-05 13:21:09 +02:00
|
|
|
* © 2023 Colin Murdoch
|
2022-02-22 02:27:27 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2022-03-18 21:03:19 +01:00
|
|
|
* This file is part of DCC++EX
|
2022-02-22 02:27:27 +01:00
|
|
|
*
|
|
|
|
* This is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* It is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "TrackManager.h"
|
|
|
|
#include "FSH.h"
|
2022-02-23 16:44:34 +01:00
|
|
|
#include "DCCWaveform.h"
|
2022-02-28 11:38:26 +01:00
|
|
|
#include "DCC.h"
|
2022-02-22 02:27:27 +01:00
|
|
|
#include "MotorDriver.h"
|
2022-05-10 23:37:24 +02:00
|
|
|
#include "DCCTimer.h"
|
2022-02-22 02:27:27 +01:00
|
|
|
#include "DIAG.h"
|
2023-09-26 19:02:39 +02:00
|
|
|
#include "CommandDistributor.h"
|
|
|
|
#include "DCCEXParser.h"
|
2022-02-22 02:27:27 +01:00
|
|
|
// Virtualised Motor shield multi-track hardware Interface
|
2022-02-28 10:32:26 +01:00
|
|
|
#define FOR_EACH_TRACK(t) for (byte t=0;t<=lastTrack;t++)
|
|
|
|
|
|
|
|
#define APPLY_BY_MODE(findmode,function) \
|
|
|
|
FOR_EACH_TRACK(t) \
|
2023-07-17 02:26:29 +02:00
|
|
|
if (track[t]->getMode()==findmode) \
|
2022-02-22 02:27:27 +01:00
|
|
|
track[t]->function;
|
2023-04-23 20:24:29 +02:00
|
|
|
#ifndef DISABLE_PROG
|
2022-02-22 02:27:27 +01:00
|
|
|
const int16_t HASH_KEYWORD_PROG = -29718;
|
2023-04-23 20:24:29 +02:00
|
|
|
#endif
|
2022-02-22 02:27:27 +01:00
|
|
|
const int16_t HASH_KEYWORD_MAIN = 11339;
|
2022-02-24 12:58:40 +01:00
|
|
|
const int16_t HASH_KEYWORD_OFF = 22479;
|
2023-08-02 10:00:43 +02:00
|
|
|
const int16_t HASH_KEYWORD_NONE = -26550;
|
2022-02-24 12:58:40 +01:00
|
|
|
const int16_t HASH_KEYWORD_DC = 2183;
|
2022-03-19 17:26:29 +01:00
|
|
|
const int16_t HASH_KEYWORD_DCX = 6463; // DC reversed polarity
|
2022-05-18 09:40:53 +02:00
|
|
|
const int16_t HASH_KEYWORD_EXT = 8201; // External DCC signal
|
2022-03-18 17:41:52 +01:00
|
|
|
const int16_t HASH_KEYWORD_A = 65; // parser makes single chars the ascii.
|
2023-11-10 23:58:30 +01:00
|
|
|
const int16_t HASH_KEYWORD_AUTO = -5457;
|
2023-11-11 08:03:59 +01:00
|
|
|
#ifdef BOOSTER_INPUT
|
2023-11-10 23:58:30 +01:00
|
|
|
const int16_t HASH_KEYWORD_BOOST = 11269;
|
2023-11-11 08:03:59 +01:00
|
|
|
#endif
|
2023-11-10 23:58:30 +01:00
|
|
|
const int16_t HASH_KEYWORD_INV = 11857;
|
2022-02-22 02:27:27 +01:00
|
|
|
|
|
|
|
MotorDriver * TrackManager::track[MAX_TRACKS];
|
2022-03-19 17:26:29 +01:00
|
|
|
int16_t TrackManager::trackDCAddr[MAX_TRACKS];
|
|
|
|
|
2022-02-28 10:32:26 +01:00
|
|
|
POWERMODE TrackManager::mainPowerGuess=POWERMODE::OFF;
|
|
|
|
byte TrackManager::lastTrack=0;
|
2022-03-19 12:22:31 +01:00
|
|
|
bool TrackManager::progTrackSyncMain=false;
|
|
|
|
bool TrackManager::progTrackBoosted=false;
|
|
|
|
int16_t TrackManager::joinRelay=UNUSED_PIN;
|
2022-08-17 02:11:51 +02:00
|
|
|
#ifdef ARDUINO_ARCH_ESP32
|
2023-08-25 19:07:57 +02:00
|
|
|
byte TrackManager::tempProgTrack=MAX_TRACKS+1; // MAX_TRACKS+1 is the unused flag
|
2022-08-17 02:11:51 +02:00
|
|
|
#endif
|
2022-03-19 12:22:31 +01:00
|
|
|
|
2022-10-02 22:53:35 +02:00
|
|
|
#ifdef ANALOG_READ_INTERRUPT
|
2022-10-02 00:43:46 +02:00
|
|
|
/*
|
|
|
|
* sampleCurrent() runs from Interrupt
|
|
|
|
*/
|
|
|
|
void TrackManager::sampleCurrent() {
|
|
|
|
static byte tr = 0;
|
2022-10-02 13:40:46 +02:00
|
|
|
byte trAtStart = tr;
|
2022-10-02 00:43:46 +02:00
|
|
|
static bool waiting = false;
|
|
|
|
|
|
|
|
if (waiting) {
|
|
|
|
if (! track[tr]->sampleCurrentFromHW()) {
|
|
|
|
return; // no result, continue to wait
|
|
|
|
}
|
|
|
|
// found value, advance at least one track
|
2022-10-02 13:40:46 +02:00
|
|
|
// for scope debug track[1]->setBrake(0);
|
2022-10-02 00:43:46 +02:00
|
|
|
waiting = false;
|
|
|
|
tr++;
|
2022-10-02 13:40:46 +02:00
|
|
|
if (tr > lastTrack) tr = 0;
|
2023-07-17 02:26:29 +02:00
|
|
|
if (lastTrack < 2 || track[tr]->getMode() & TRACK_MODE_PROG) {
|
2022-10-02 13:40:46 +02:00
|
|
|
return; // We could continue but for prog track we
|
|
|
|
// rather do it in next interrupt beacuse
|
|
|
|
// that gives us well defined sampling point.
|
|
|
|
// For other tracks we care less unless we
|
|
|
|
// have only few (max 2) tracks.
|
|
|
|
}
|
2022-10-02 00:43:46 +02:00
|
|
|
}
|
|
|
|
if (!waiting) {
|
|
|
|
// look for a valid track to sample or until we are around
|
2022-10-02 13:40:46 +02:00
|
|
|
while (true) {
|
2023-11-10 23:58:30 +01:00
|
|
|
if (track[tr]->getMode() & ( TRACK_MODE_MAIN|TRACK_MODE_PROG|TRACK_MODE_DC|TRACK_MODE_BOOST|TRACK_MODE_EXT )) {
|
2022-10-02 00:43:46 +02:00
|
|
|
track[tr]->startCurrentFromHW();
|
2022-10-02 13:40:46 +02:00
|
|
|
// for scope debug track[1]->setBrake(1);
|
2022-10-02 00:43:46 +02:00
|
|
|
waiting = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tr++;
|
2022-10-02 13:40:46 +02:00
|
|
|
if (tr > lastTrack) tr = 0;
|
|
|
|
if (tr == trAtStart) // we are through and nothing found to do
|
|
|
|
return;
|
2022-10-02 00:43:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-02 22:53:35 +02:00
|
|
|
#endif
|
2022-02-23 16:44:34 +01:00
|
|
|
|
2022-02-28 10:32:26 +01:00
|
|
|
// The setup call is done this way so that the tracks can be in a list
|
|
|
|
// from the config... the tracks default to NULL in the declaration
|
2022-02-22 02:27:27 +01:00
|
|
|
void TrackManager::Setup(const FSH * shieldname,
|
|
|
|
MotorDriver * track0, MotorDriver * track1, MotorDriver * track2,
|
|
|
|
MotorDriver * track3, MotorDriver * track4, MotorDriver * track5,
|
2022-03-01 13:52:25 +01:00
|
|
|
MotorDriver * track6, MotorDriver * track7 ) {
|
2022-02-28 10:32:26 +01:00
|
|
|
addTrack(0,track0);
|
|
|
|
addTrack(1,track1);
|
|
|
|
addTrack(2,track2);
|
|
|
|
addTrack(3,track3);
|
|
|
|
addTrack(4,track4);
|
|
|
|
addTrack(5,track5);
|
|
|
|
addTrack(6,track6);
|
|
|
|
addTrack(7,track7);
|
|
|
|
|
2022-03-19 17:26:29 +01:00
|
|
|
// Default the first 2 tracks (which may be null) and perform HA waveform check.
|
2022-02-23 16:44:34 +01:00
|
|
|
setTrackMode(0,TRACK_MODE_MAIN);
|
2023-04-23 20:24:29 +02:00
|
|
|
#ifndef DISABLE_PROG
|
2022-02-23 16:44:34 +01:00
|
|
|
setTrackMode(1,TRACK_MODE_PROG);
|
2023-04-23 20:24:29 +02:00
|
|
|
#else
|
|
|
|
setTrackMode(1,TRACK_MODE_MAIN);
|
|
|
|
#endif
|
2022-02-28 10:32:26 +01:00
|
|
|
|
2023-06-21 10:44:57 +02:00
|
|
|
// Fault pin config for odd motor boards (example pololu)
|
|
|
|
FOR_EACH_TRACK(t) {
|
|
|
|
for (byte s=t+1;s<=lastTrack;s++) {
|
|
|
|
if (track[t]->getFaultPin() != UNUSED_PIN &&
|
|
|
|
track[t]->getFaultPin() == track[s]->getFaultPin()) {
|
|
|
|
track[t]->setCommonFaultPin();
|
|
|
|
track[s]->setCommonFaultPin();
|
|
|
|
DIAG(F("Common Fault pin tracks %c and %c"), t+'A', s+'A');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-22 22:57:59 +02:00
|
|
|
DCC::setShieldName(shieldname);
|
2022-02-22 02:27:27 +01:00
|
|
|
}
|
2022-02-28 10:32:26 +01:00
|
|
|
|
|
|
|
void TrackManager::addTrack(byte t, MotorDriver* driver) {
|
2022-05-12 20:59:31 +02:00
|
|
|
track[t]=driver;
|
2022-03-23 18:06:15 +01:00
|
|
|
if (driver) {
|
|
|
|
track[t]->setPower(POWERMODE::OFF);
|
2023-08-02 10:00:43 +02:00
|
|
|
track[t]->setMode(TRACK_MODE_NONE);
|
2023-03-20 21:22:48 +01:00
|
|
|
track[t]->setTrackLetter('A'+t);
|
2022-05-12 20:59:31 +02:00
|
|
|
lastTrack=t;
|
2022-03-23 18:06:15 +01:00
|
|
|
}
|
2022-05-13 00:05:25 +02:00
|
|
|
}
|
|
|
|
|
2022-06-06 23:14:35 +02:00
|
|
|
// setDCCSignal(), called from interrupt context
|
|
|
|
// does assume ports are shadowed if they can be
|
2022-02-22 02:27:27 +01:00
|
|
|
void TrackManager::setDCCSignal( bool on) {
|
2022-06-13 23:18:10 +02:00
|
|
|
HAVE_PORTA(shadowPORTA=PORTA);
|
|
|
|
HAVE_PORTB(shadowPORTB=PORTB);
|
|
|
|
HAVE_PORTC(shadowPORTC=PORTC);
|
2023-09-28 11:43:22 +02:00
|
|
|
HAVE_PORTD(shadowPORTD=PORTD);
|
|
|
|
HAVE_PORTE(shadowPORTE=PORTE);
|
|
|
|
HAVE_PORTF(shadowPORTF=PORTF);
|
2022-08-23 07:56:56 +02:00
|
|
|
APPLY_BY_MODE(TRACK_MODE_MAIN,setSignal(on));
|
2022-06-13 23:18:10 +02:00
|
|
|
HAVE_PORTA(PORTA=shadowPORTA);
|
|
|
|
HAVE_PORTB(PORTB=shadowPORTB);
|
|
|
|
HAVE_PORTC(PORTC=shadowPORTC);
|
2023-09-28 11:43:22 +02:00
|
|
|
HAVE_PORTD(PORTD=shadowPORTD);
|
|
|
|
HAVE_PORTE(PORTE=shadowPORTE);
|
|
|
|
HAVE_PORTF(PORTF=shadowPORTF);
|
2022-02-22 02:27:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TrackManager::setCutout( bool on) {
|
|
|
|
(void) on;
|
2022-05-10 23:42:21 +02:00
|
|
|
// TODO Cutout needs fake ports as well
|
2022-02-28 10:32:26 +01:00
|
|
|
// TODO APPLY_BY_MODE(TRACK_MODE_MAIN,setCutout(on));
|
2022-02-22 02:27:27 +01:00
|
|
|
}
|
|
|
|
|
2022-06-06 23:14:35 +02:00
|
|
|
// setPROGSignal(), called from interrupt context
|
|
|
|
// does assume ports are shadowed if they can be
|
2022-02-22 02:27:27 +01:00
|
|
|
void TrackManager::setPROGSignal( bool on) {
|
2022-06-13 23:18:10 +02:00
|
|
|
HAVE_PORTA(shadowPORTA=PORTA);
|
|
|
|
HAVE_PORTB(shadowPORTB=PORTB);
|
|
|
|
HAVE_PORTC(shadowPORTC=PORTC);
|
2023-09-28 11:43:22 +02:00
|
|
|
HAVE_PORTD(shadowPORTD=PORTD);
|
|
|
|
HAVE_PORTE(shadowPORTE=PORTE);
|
|
|
|
HAVE_PORTF(shadowPORTF=PORTF);
|
2022-08-23 07:56:56 +02:00
|
|
|
APPLY_BY_MODE(TRACK_MODE_PROG,setSignal(on));
|
2022-06-13 23:18:10 +02:00
|
|
|
HAVE_PORTA(PORTA=shadowPORTA);
|
|
|
|
HAVE_PORTB(PORTB=shadowPORTB);
|
|
|
|
HAVE_PORTC(PORTC=shadowPORTC);
|
2023-09-28 11:43:22 +02:00
|
|
|
HAVE_PORTD(PORTD=shadowPORTD);
|
|
|
|
HAVE_PORTE(PORTE=shadowPORTE);
|
|
|
|
HAVE_PORTF(PORTF=shadowPORTF);
|
2022-02-22 02:27:27 +01:00
|
|
|
}
|
|
|
|
|
2022-06-06 23:14:35 +02:00
|
|
|
// setDCSignal(), called from normal context
|
|
|
|
// MotorDriver::setDCSignal handles shadowed IO port changes.
|
|
|
|
// with interrupts turned off around the critical section
|
2022-02-22 02:27:27 +01:00
|
|
|
void TrackManager::setDCSignal(int16_t cab, byte speedbyte) {
|
2022-05-21 10:19:25 +02:00
|
|
|
FOR_EACH_TRACK(t) {
|
2023-08-04 14:45:05 +02:00
|
|
|
if (trackDCAddr[t]!=cab && cab != 0) continue;
|
2023-11-10 23:58:30 +01:00
|
|
|
if (track[t]->getMode() & TRACK_MODE_DC)
|
2023-11-10 20:33:14 +01:00
|
|
|
track[t]->setDCSignal(speedbyte);
|
2022-05-21 10:19:25 +02:00
|
|
|
}
|
2022-03-19 17:26:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr) {
|
2022-02-28 10:32:26 +01:00
|
|
|
if (trackToSet>lastTrack || track[trackToSet]==NULL) return false;
|
2022-03-28 15:44:41 +02:00
|
|
|
|
2023-07-25 11:23:36 +02:00
|
|
|
//DIAG(F("Track=%c Mode=%d"),trackToSet+'A', mode);
|
2022-03-28 15:44:41 +02:00
|
|
|
// DC tracks require a motorDriver that can set brake!
|
2023-11-10 23:58:30 +01:00
|
|
|
if (mode & TRACK_MODE_DC) {
|
2023-08-02 01:02:46 +02:00
|
|
|
#if defined(ARDUINO_AVR_UNO)
|
|
|
|
DIAG(F("Uno has no PWM timers available for DC"));
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
if (!track[trackToSet]->brakeCanPWM()) {
|
|
|
|
DIAG(F("Brake pin can't PWM: No DC"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2022-03-28 15:44:41 +02:00
|
|
|
|
2022-08-04 01:21:28 +02:00
|
|
|
#ifdef ARDUINO_ARCH_ESP32
|
|
|
|
// remove pin from MUX matrix and turn it off
|
2022-08-13 09:12:53 +02:00
|
|
|
pinpair p = track[trackToSet]->getSignalPin();
|
2022-08-17 02:11:51 +02:00
|
|
|
//DIAG(F("Track=%c remove pin %d"),trackToSet+'A', p.pin);
|
2022-08-13 09:12:53 +02:00
|
|
|
gpio_reset_pin((gpio_num_t)p.pin);
|
|
|
|
if (p.invpin != UNUSED_PIN) {
|
2022-08-17 02:11:51 +02:00
|
|
|
//DIAG(F("Track=%c remove ^pin %d"),trackToSet+'A', p.invpin);
|
2022-08-13 09:12:53 +02:00
|
|
|
gpio_reset_pin((gpio_num_t)p.invpin);
|
2023-11-10 20:33:14 +01:00
|
|
|
}
|
2023-11-11 08:03:59 +01:00
|
|
|
#ifdef BOOSTER_INPUT
|
2023-11-10 23:58:30 +01:00
|
|
|
if (mode & TRACK_MODE_BOOST) {
|
2023-11-11 08:03:59 +01:00
|
|
|
//DIAG(F("Track=%c mode boost pin %d"),trackToSet+'A', p.pin);
|
|
|
|
pinMode(BOOSTER_INPUT, INPUT);
|
2023-11-10 20:33:14 +01:00
|
|
|
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);
|
|
|
|
if (p.invpin != UNUSED_PIN) {
|
|
|
|
gpio_matrix_out(p.invpin, SIG_IN_FUNC228_IDX, true /*inverted*/, false);
|
|
|
|
}
|
2023-11-11 08:03:59 +01:00
|
|
|
} else // elseif clause continues
|
|
|
|
#endif
|
|
|
|
if (mode & (TRACK_MODE_MAIN | TRACK_MODE_PROG | TRACK_MODE_DC)) {
|
2023-11-10 23:58:30 +01:00
|
|
|
// gpio_reset_pin may reset to input
|
|
|
|
pinMode(p.pin, OUTPUT);
|
|
|
|
if (p.invpin != UNUSED_PIN)
|
|
|
|
pinMode(p.invpin, OUTPUT);
|
2022-08-13 09:12:53 +02:00
|
|
|
}
|
2023-11-10 23:58:30 +01:00
|
|
|
|
2022-08-04 01:21:28 +02:00
|
|
|
#endif
|
2023-04-23 20:24:29 +02:00
|
|
|
#ifndef DISABLE_PROG
|
2023-11-10 23:58:30 +01:00
|
|
|
if (mode & TRACK_MODE_PROG) {
|
2023-04-23 20:24:29 +02:00
|
|
|
#else
|
|
|
|
if (false) {
|
|
|
|
#endif
|
2022-08-02 15:36:51 +02:00
|
|
|
// only allow 1 track to be prog
|
|
|
|
FOR_EACH_TRACK(t)
|
2023-11-10 23:58:30 +01:00
|
|
|
if ( (track[t]->getMode() & TRACK_MODE_PROG) && t != trackToSet) {
|
2022-08-02 15:36:51 +02:00
|
|
|
track[t]->setPower(POWERMODE::OFF);
|
2023-08-02 10:00:43 +02:00
|
|
|
track[t]->setMode(TRACK_MODE_NONE);
|
2022-08-02 15:36:51 +02:00
|
|
|
track[t]->makeProgTrack(false); // revoke prog track special handling
|
2023-03-06 12:57:14 +01:00
|
|
|
streamTrackState(NULL,t);
|
2022-08-02 15:36:51 +02:00
|
|
|
}
|
|
|
|
track[trackToSet]->makeProgTrack(true); // set for prog track special handling
|
2022-04-30 23:24:51 +02:00
|
|
|
} else {
|
2022-08-02 15:36:51 +02:00
|
|
|
track[trackToSet]->makeProgTrack(false); // only the prog track knows it's type
|
2022-02-23 16:44:34 +01:00
|
|
|
}
|
2023-07-17 02:26:29 +02:00
|
|
|
track[trackToSet]->setMode(mode);
|
2022-03-19 17:26:29 +01:00
|
|
|
trackDCAddr[trackToSet]=dcAddr;
|
2023-03-06 12:57:14 +01:00
|
|
|
streamTrackState(NULL,trackToSet);
|
|
|
|
|
2022-03-28 15:44:41 +02:00
|
|
|
// When a track is switched, we must clear any side effects of its previous
|
2022-08-23 07:56:56 +02:00
|
|
|
// state, otherwise trains run away or just dont move.
|
|
|
|
|
|
|
|
// This can be done BEFORE the PWM-Timer evaluation (methinks)
|
2023-11-10 23:58:30 +01:00
|
|
|
if (!(mode & TRACK_MODE_DC)) {
|
2022-05-21 10:19:25 +02:00
|
|
|
// DCC tracks need to have set the PWM to zero or they will not work.
|
2022-08-10 00:14:28 +02:00
|
|
|
track[trackToSet]->detachDCSignal();
|
2022-05-24 08:07:33 +02:00
|
|
|
track[trackToSet]->setBrake(false);
|
2022-03-28 15:44:41 +02:00
|
|
|
}
|
2022-05-18 09:40:53 +02:00
|
|
|
|
2023-11-10 23:58:30 +01:00
|
|
|
// BOOST:
|
|
|
|
// Leave it as is
|
|
|
|
// otherwise:
|
|
|
|
// EXT is a special case where the signal pin is
|
|
|
|
// turned off. So unless that is set, the signal
|
|
|
|
// pin should be turned on
|
|
|
|
if (!(mode & TRACK_MODE_BOOST))
|
|
|
|
track[trackToSet]->enableSignal(!(mode & TRACK_MODE_EXT));
|
2022-05-18 09:40:53 +02:00
|
|
|
|
2022-08-04 01:21:28 +02:00
|
|
|
#ifndef ARDUINO_ARCH_ESP32
|
2022-02-22 02:27:27 +01:00
|
|
|
// re-evaluate HighAccuracy mode
|
2022-02-28 10:32:26 +01:00
|
|
|
// We can only do this is all main and prog tracks agree
|
2022-02-22 02:27:27 +01:00
|
|
|
bool canDo=true;
|
2022-05-12 20:56:23 +02:00
|
|
|
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.
|
2023-11-10 23:58:30 +01:00
|
|
|
if (track[t]->getMode() & TRACK_MODE_DC) {
|
2022-05-12 20:56:23 +02:00
|
|
|
if (track[t]->isPWMCapable()) {
|
2022-06-11 19:57:45 +02:00
|
|
|
canDo=false; // this track is capable but can not run PWM
|
|
|
|
break; // in this mode, so abort and prevent globally below
|
|
|
|
} else {
|
|
|
|
track[t]->trackPWM=false; // this track sure can not run with PWM
|
|
|
|
//DIAG(F("Track %c trackPWM 0 (not capable)"), t+'A');
|
2022-05-12 20:56:23 +02:00
|
|
|
}
|
2023-11-10 23:58:30 +01:00
|
|
|
} else if (track[t]->getMode() & (TRACK_MODE_MAIN |TRACK_MODE_PROG)) {
|
2022-06-11 19:57:45 +02:00
|
|
|
track[t]->trackPWM = track[t]->isPWMCapable(); // trackPWM is still a guess here
|
|
|
|
//DIAG(F("Track %c trackPWM %d"), t+'A', track[t]->trackPWM);
|
|
|
|
canDo &= track[t]->trackPWM;
|
|
|
|
}
|
2022-05-12 20:56:23 +02:00
|
|
|
}
|
2022-05-10 23:37:24 +02:00
|
|
|
if (!canDo) {
|
2022-06-11 19:57:45 +02:00
|
|
|
// if we discover that HA mode was globally impossible
|
|
|
|
// we must adjust the trackPWM capabilities
|
|
|
|
FOR_EACH_TRACK(t) {
|
|
|
|
track[t]->trackPWM=false;
|
|
|
|
//DIAG(F("Track %c trackPWM 0 (global override)"), t+'A');
|
|
|
|
}
|
|
|
|
DCCTimer::clearPWM(); // has to be AFTER trackPWM changes because if trackPWM==true this is undone for that track
|
2022-05-10 23:37:24 +02:00
|
|
|
}
|
2022-08-04 01:21:28 +02:00
|
|
|
#else
|
2022-08-23 07:56:56 +02:00
|
|
|
// For ESP32 we just reinitialize the DCC Waveform
|
2022-08-04 01:21:28 +02:00
|
|
|
DCCWaveform::begin();
|
2023-11-10 23:58:30 +01:00
|
|
|
// setMode() again AFTER Waveform::begin() of ESP32 fixes INVERTED signal
|
|
|
|
track[trackToSet]->setMode(mode);
|
2022-08-04 01:21:28 +02:00
|
|
|
#endif
|
2022-08-23 07:56:56 +02:00
|
|
|
|
|
|
|
// This block must be AFTER the PWM-Timer modifications
|
2023-11-10 23:58:30 +01:00
|
|
|
if (mode & TRACK_MODE_DC) {
|
2022-08-23 07:56:56 +02:00
|
|
|
// DC tracks need to be given speed of the throttle for that cab address
|
|
|
|
// otherwise will not match other tracks on same cab.
|
|
|
|
// This also needs to allow for inverted DCX
|
|
|
|
applyDCSpeed(trackToSet);
|
|
|
|
}
|
|
|
|
|
2022-03-23 18:06:15 +01:00
|
|
|
// Normal running tracks are set to the global power state
|
|
|
|
track[trackToSet]->setPower(
|
2023-11-10 23:58:30 +01:00
|
|
|
(mode & (TRACK_MODE_MAIN | TRACK_MODE_DC | TRACK_MODE_EXT | TRACK_MODE_BOOST)) ?
|
2022-03-23 18:06:15 +01:00
|
|
|
mainPowerGuess : POWERMODE::OFF);
|
2022-05-10 23:37:24 +02:00
|
|
|
//DIAG(F("TrackMode=%d"),mode);
|
2022-02-22 02:27:27 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-31 23:19:13 +02:00
|
|
|
void TrackManager::applyDCSpeed(byte t) {
|
2022-06-05 23:07:03 +02:00
|
|
|
uint8_t speedByte=DCC::getThrottleSpeedByte(trackDCAddr[t]);
|
|
|
|
track[t]->setDCSignal(speedByte);
|
2022-03-31 23:19:13 +02:00
|
|
|
}
|
|
|
|
|
2022-02-22 02:27:27 +01:00
|
|
|
bool TrackManager::parseJ(Print *stream, int16_t params, int16_t p[])
|
|
|
|
{
|
|
|
|
|
2022-03-18 17:41:52 +01:00
|
|
|
if (params==0) { // <=> List track assignments
|
2022-02-28 10:32:26 +01:00
|
|
|
FOR_EACH_TRACK(t)
|
2023-03-06 12:57:14 +01:00
|
|
|
streamTrackState(stream,t);
|
2022-02-22 02:27:27 +01:00
|
|
|
return true;
|
2023-09-26 19:02:39 +02:00
|
|
|
|
2022-02-22 02:27:27 +01:00
|
|
|
}
|
|
|
|
|
2022-03-18 17:41:52 +01:00
|
|
|
p[0]-=HASH_KEYWORD_A; // convert A... to 0....
|
|
|
|
|
|
|
|
if (params>1 && (p[0]<0 || p[0]>=MAX_TRACKS))
|
2022-02-22 02:27:27 +01:00
|
|
|
return false;
|
|
|
|
|
2022-03-18 17:41:52 +01:00
|
|
|
if (params==2 && p[1]==HASH_KEYWORD_MAIN) // <= id MAIN>
|
|
|
|
return setTrackMode(p[0],TRACK_MODE_MAIN);
|
2022-02-22 02:27:27 +01:00
|
|
|
|
2023-04-23 20:24:29 +02:00
|
|
|
#ifndef DISABLE_PROG
|
2022-03-18 17:41:52 +01:00
|
|
|
if (params==2 && p[1]==HASH_KEYWORD_PROG) // <= id PROG>
|
|
|
|
return setTrackMode(p[0],TRACK_MODE_PROG);
|
2023-04-23 20:24:29 +02:00
|
|
|
#endif
|
2022-02-22 02:27:27 +01:00
|
|
|
|
2023-08-02 10:00:43 +02:00
|
|
|
if (params==2 && (p[1]==HASH_KEYWORD_OFF || p[1]==HASH_KEYWORD_NONE)) // <= id OFF> <= id NONE>
|
|
|
|
return setTrackMode(p[0],TRACK_MODE_NONE);
|
2022-05-18 09:40:53 +02:00
|
|
|
|
|
|
|
if (params==2 && p[1]==HASH_KEYWORD_EXT) // <= id EXT>
|
|
|
|
return setTrackMode(p[0],TRACK_MODE_EXT);
|
2023-11-11 08:03:59 +01:00
|
|
|
#ifdef BOOSTER_INPUT
|
2023-11-10 23:58:30 +01:00
|
|
|
if (params==2 && p[1]==HASH_KEYWORD_BOOST) // <= id BOOST>
|
|
|
|
return setTrackMode(p[0],TRACK_MODE_BOOST);
|
2023-11-11 08:03:59 +01:00
|
|
|
#endif
|
2023-11-10 23:58:30 +01:00
|
|
|
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);
|
|
|
|
|
2022-03-18 21:03:19 +01:00
|
|
|
if (params==3 && p[1]==HASH_KEYWORD_DC && p[2]>0) // <= id DC cab>
|
2022-03-19 17:26:29 +01:00
|
|
|
return setTrackMode(p[0],TRACK_MODE_DC,p[2]);
|
|
|
|
|
|
|
|
if (params==3 && p[1]==HASH_KEYWORD_DCX && p[2]>0) // <= id DCX cab>
|
2023-11-10 23:58:30 +01:00
|
|
|
return setTrackMode(p[0],TRACK_MODE_DC|TRACK_MODE_INV,p[2]);
|
2022-02-22 02:27:27 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-03-06 12:57:14 +01:00
|
|
|
void TrackManager::streamTrackState(Print* stream, byte t) {
|
|
|
|
// null stream means send to commandDistributor for broadcast
|
|
|
|
if (track[t]==NULL) return;
|
2023-11-13 17:16:58 +01:00
|
|
|
auto format=F("<= %d XXX>\n");
|
2023-11-10 23:58:30 +01:00
|
|
|
TRACK_MODE tm = track[t]->getMode();
|
2023-11-11 08:03:59 +01:00
|
|
|
if (tm & TRACK_MODE_MAIN) {
|
|
|
|
if(tm & TRACK_MODE_AUTOINV)
|
2023-11-13 17:16:58 +01:00
|
|
|
format=F("<= %c MAIN A>\n");
|
2023-11-11 08:03:59 +01:00
|
|
|
else if (tm & TRACK_MODE_INV)
|
2023-11-13 17:16:58 +01:00
|
|
|
format=F("<= %c MAIN I>\n");
|
2023-11-11 08:03:59 +01:00
|
|
|
else
|
2023-11-13 17:16:58 +01:00
|
|
|
format=F("<= %c MAIN>\n");
|
2023-11-11 08:03:59 +01:00
|
|
|
}
|
2023-04-23 20:24:29 +02:00
|
|
|
#ifndef DISABLE_PROG
|
2023-11-10 23:58:30 +01:00
|
|
|
else if (tm & TRACK_MODE_PROG)
|
2023-11-13 17:16:58 +01:00
|
|
|
format=F("<= %c PROG>\n");
|
2023-04-23 20:24:29 +02:00
|
|
|
#endif
|
2023-11-10 23:58:30 +01:00
|
|
|
else if (tm & TRACK_MODE_NONE)
|
2023-11-13 17:16:58 +01:00
|
|
|
format=F("<= %c NONE>\n");
|
2023-11-10 23:58:30 +01:00
|
|
|
else if(tm & TRACK_MODE_EXT)
|
2023-11-13 17:16:58 +01:00
|
|
|
format=F("<= %c EXT>\n");
|
2023-11-11 08:03:59 +01:00
|
|
|
else if(tm & TRACK_MODE_BOOST) {
|
|
|
|
if(tm & TRACK_MODE_AUTOINV)
|
2023-11-13 17:16:58 +01:00
|
|
|
format=F("<= %c B A>\n");
|
2023-11-11 08:03:59 +01:00
|
|
|
else if (tm & TRACK_MODE_INV)
|
2023-11-13 17:16:58 +01:00
|
|
|
format=F("<= %c B I>\n");
|
2023-11-11 08:03:59 +01:00
|
|
|
else
|
2023-11-13 17:16:58 +01:00
|
|
|
format=F("<= %c B>\n");
|
2023-11-11 08:03:59 +01:00
|
|
|
}
|
2023-11-10 23:58:30 +01:00
|
|
|
else if (tm & TRACK_MODE_DC) {
|
|
|
|
if (tm & TRACK_MODE_INV)
|
2023-11-13 17:16:58 +01:00
|
|
|
format=F("<= %c DCX %d>\n");
|
2023-11-10 23:58:30 +01:00
|
|
|
else
|
2023-11-13 17:16:58 +01:00
|
|
|
format=F("<= %c DC %d>\n");
|
2023-03-06 12:57:14 +01:00
|
|
|
}
|
2023-09-26 19:02:39 +02:00
|
|
|
|
2023-11-10 23:58:30 +01:00
|
|
|
if (stream)
|
2023-11-13 17:16:58 +01:00
|
|
|
StringFormatter::send(stream,format,'A'+t, trackDCAddr[t]);
|
2023-11-10 23:58:30 +01:00
|
|
|
else
|
2023-11-13 17:16:58 +01:00
|
|
|
CommandDistributor::broadcastTrackState(format,'A'+t, trackDCAddr[t]);
|
2023-09-26 19:02:39 +02:00
|
|
|
|
2023-03-06 12:57:14 +01:00
|
|
|
}
|
|
|
|
|
2022-02-23 16:44:34 +01:00
|
|
|
byte TrackManager::nextCycleTrack=MAX_TRACKS;
|
|
|
|
|
2022-03-19 12:22:31 +01:00
|
|
|
void TrackManager::loop() {
|
2023-04-23 20:24:29 +02:00
|
|
|
DCCWaveform::loop();
|
|
|
|
#ifndef DISABLE_PROG
|
|
|
|
DCCACK::loop();
|
|
|
|
#endif
|
2022-03-19 12:22:31 +01:00
|
|
|
bool dontLimitProg=DCCACK::isActive() || progTrackSyncMain || progTrackBoosted;
|
2022-02-23 16:44:34 +01:00
|
|
|
nextCycleTrack++;
|
2022-02-28 10:32:26 +01:00
|
|
|
if (nextCycleTrack>lastTrack) nextCycleTrack=0;
|
2022-02-23 16:44:34 +01:00
|
|
|
if (track[nextCycleTrack]==NULL) return;
|
|
|
|
MotorDriver * motorDriver=track[nextCycleTrack];
|
2023-11-10 23:58:30 +01:00
|
|
|
bool useProgLimit=dontLimitProg ? false : (bool)(track[nextCycleTrack]->getMode() & TRACK_MODE_PROG);
|
2022-02-23 16:44:34 +01:00
|
|
|
motorDriver->checkPowerOverload(useProgLimit, nextCycleTrack);
|
|
|
|
}
|
2022-02-22 02:27:27 +01:00
|
|
|
|
2022-02-23 16:44:34 +01:00
|
|
|
MotorDriver * TrackManager::getProgDriver() {
|
2022-02-28 10:32:26 +01:00
|
|
|
FOR_EACH_TRACK(t)
|
2023-11-10 23:58:30 +01:00
|
|
|
if (track[t]->getMode() & TRACK_MODE_PROG) return track[t];
|
2022-02-23 16:44:34 +01:00
|
|
|
return NULL;
|
2022-03-31 23:19:13 +02:00
|
|
|
}
|
|
|
|
|
2022-08-01 22:56:56 +02:00
|
|
|
#ifdef ARDUINO_ARCH_ESP32
|
|
|
|
std::vector<MotorDriver *>TrackManager::getMainDrivers() {
|
|
|
|
std::vector<MotorDriver *> v;
|
|
|
|
FOR_EACH_TRACK(t)
|
2023-11-10 23:58:30 +01:00
|
|
|
if (track[t]->getMode() & TRACK_MODE_MAIN) v.push_back(track[t]);
|
2022-08-01 22:56:56 +02:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-11-14 00:05:18 +01:00
|
|
|
// Set track power for all tracks with this mode
|
|
|
|
void TrackManager::setTrackPower(TRACK_MODE trackmode, POWERMODE powermode) {
|
|
|
|
FOR_EACH_TRACK(t) {
|
|
|
|
MotorDriver *driver=track[t];
|
|
|
|
if (trackmode & driver->getMode()) {
|
|
|
|
if (powermode == POWERMODE::ON) {
|
|
|
|
if (trackmode & TRACK_MODE_DC) {
|
|
|
|
driver->setBrake(true); // DC starts with brake on
|
|
|
|
applyDCSpeed(t); // speed match DCC throttles
|
|
|
|
} else {
|
|
|
|
// toggle brake before turning power on - resets overcurrent error
|
|
|
|
// on the Pololu board if brake is wired to ^D2.
|
|
|
|
driver->setBrake(true);
|
|
|
|
driver->setBrake(false); // DCC runs with brake off
|
|
|
|
}
|
|
|
|
}
|
|
|
|
driver->setPower(powermode);
|
2022-02-23 16:44:34 +01:00
|
|
|
}
|
2023-11-14 00:05:18 +01:00
|
|
|
}
|
2022-02-23 16:44:34 +01:00
|
|
|
}
|
2023-09-25 15:32:54 +02:00
|
|
|
|
2023-11-14 00:05:18 +01:00
|
|
|
// Set track power for this track, inependent of mode
|
|
|
|
void TrackManager::setTrackPower(POWERMODE powermode, byte t) {
|
|
|
|
MotorDriver *driver=track[t];
|
|
|
|
TRACK_MODE trackmode = driver->getMode();
|
|
|
|
if (trackmode & TRACK_MODE_DC) {
|
|
|
|
if (powermode == POWERMODE::ON) {
|
|
|
|
driver->setBrake(true); // DC starts with brake on
|
|
|
|
applyDCSpeed(t); // speed match DCC throttles
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (powermode == POWERMODE::ON) {
|
|
|
|
// toggle brake before turning power on - resets overcurrent error
|
|
|
|
// on the Pololu board if brake is wired to ^D2.
|
|
|
|
driver->setBrake(true);
|
|
|
|
driver->setBrake(false); // DCC runs with brake off
|
|
|
|
}
|
|
|
|
}
|
|
|
|
driver->setPower(powermode);
|
2023-11-10 23:58:30 +01:00
|
|
|
}
|
2023-09-22 18:03:40 +02:00
|
|
|
|
2023-11-14 00:05:18 +01:00
|
|
|
void TrackManager::reportPowerChange(Print* stream, byte thistrack) {
|
2023-09-26 19:02:39 +02:00
|
|
|
// This function is for backward JMRI compatibility only
|
|
|
|
// It reports the first track only, as main, regardless of track settings.
|
|
|
|
// <c MeterName value C/V unit min max res warn>
|
|
|
|
int maxCurrent=track[0]->raw2mA(track[0]->getRawCurrentTripValue());
|
|
|
|
StringFormatter::send(stream, F("<c CurrentMAIN %d C Milli 0 %d 1 %d>\n"),
|
|
|
|
track[0]->raw2mA(track[0]->getCurrentRaw(false)), maxCurrent, maxCurrent);
|
|
|
|
}
|
|
|
|
|
2023-11-14 00:05:18 +01:00
|
|
|
// returns state of the one and only prog track
|
2022-02-28 10:32:26 +01:00
|
|
|
POWERMODE TrackManager::getProgPower() {
|
2023-11-14 00:05:18 +01:00
|
|
|
FOR_EACH_TRACK(t)
|
|
|
|
if (track[t]->getMode() & TRACK_MODE_PROG)
|
|
|
|
return track[t]->getPower(); // optimize: there is max one prog track
|
2023-11-14 11:12:14 +01:00
|
|
|
return POWERMODE::OFF;
|
2023-11-14 00:05:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// returns on if all are on. returns off otherwise
|
|
|
|
POWERMODE TrackManager::getMainPower() {
|
|
|
|
POWERMODE result = POWERMODE::OFF;
|
|
|
|
FOR_EACH_TRACK(t) {
|
|
|
|
if (track[t]->getMode() & TRACK_MODE_MAIN) {
|
|
|
|
POWERMODE p = track[t]->getPower();
|
|
|
|
if (p == POWERMODE::OFF)
|
|
|
|
return POWERMODE::OFF; // done and out
|
|
|
|
if (p == POWERMODE::ON)
|
|
|
|
result = POWERMODE::ON;
|
|
|
|
}
|
2022-02-23 16:44:34 +01:00
|
|
|
}
|
2023-11-14 00:05:18 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TrackManager::getPower(byte t, char s[]) {
|
2023-11-14 11:12:14 +01:00
|
|
|
if (t > lastTrack)
|
|
|
|
return false;
|
2023-11-14 00:05:18 +01:00
|
|
|
if (track[t]) {
|
|
|
|
s[0] = track[t]->getPower() == POWERMODE::ON ? '1' : '0';
|
|
|
|
s[2] = t + 'A';
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-03-02 13:56:30 +01:00
|
|
|
|
|
|
|
void TrackManager::reportObsoleteCurrent(Print* stream) {
|
|
|
|
// This function is for backward JMRI compatibility only
|
|
|
|
// It reports the first track only, as main, regardless of track settings.
|
|
|
|
// <c MeterName value C/V unit min max res warn>
|
|
|
|
int maxCurrent=track[0]->raw2mA(track[0]->getRawCurrentTripValue());
|
|
|
|
StringFormatter::send(stream, F("<c CurrentMAIN %d C Milli 0 %d 1 %d>\n"),
|
|
|
|
track[0]->raw2mA(track[0]->getCurrentRaw(false)), maxCurrent, maxCurrent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrackManager::reportCurrent(Print* stream) {
|
|
|
|
StringFormatter::send(stream,F("<jI"));
|
|
|
|
FOR_EACH_TRACK(t) {
|
|
|
|
StringFormatter::send(stream, F(" %d"),
|
|
|
|
(track[t]->getPower()==POWERMODE::OVERLOAD) ? -1 :
|
|
|
|
track[t]->raw2mA(track[t]->getCurrentRaw(false)));
|
|
|
|
}
|
|
|
|
StringFormatter::send(stream,F(">\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrackManager::reportGauges(Print* stream) {
|
|
|
|
StringFormatter::send(stream,F("<jG"));
|
|
|
|
FOR_EACH_TRACK(t) {
|
|
|
|
StringFormatter::send(stream, F(" %d"),
|
|
|
|
track[t]->raw2mA(track[t]->getRawCurrentTripValue()));
|
|
|
|
}
|
|
|
|
StringFormatter::send(stream,F(">\n"));
|
|
|
|
}
|
|
|
|
|
2022-03-19 12:22:31 +01:00
|
|
|
void TrackManager::setJoinRelayPin(byte joinRelayPin) {
|
|
|
|
joinRelay=joinRelayPin;
|
|
|
|
if (joinRelay!=UNUSED_PIN) {
|
|
|
|
pinMode(joinRelay,OUTPUT);
|
|
|
|
digitalWrite(joinRelay,LOW); // LOW is relay disengaged
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrackManager::setJoin(bool joined) {
|
2022-08-17 02:11:51 +02:00
|
|
|
#ifdef ARDUINO_ARCH_ESP32
|
|
|
|
if (joined) {
|
|
|
|
FOR_EACH_TRACK(t) {
|
2023-11-10 23:58:30 +01:00
|
|
|
if (track[t]->getMode() & TRACK_MODE_PROG) {
|
2022-08-17 02:11:51 +02:00
|
|
|
tempProgTrack = t;
|
|
|
|
setTrackMode(t, TRACK_MODE_MAIN);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (tempProgTrack != MAX_TRACKS+1) {
|
2023-08-25 19:07:57 +02:00
|
|
|
// as setTrackMode with TRACK_MODE_PROG defaults to
|
|
|
|
// power off, we will take the current power state
|
|
|
|
// of our track and then preserve that state.
|
|
|
|
POWERMODE tPTmode = track[tempProgTrack]->getPower(); //get current power status of this track
|
2022-08-17 02:11:51 +02:00
|
|
|
setTrackMode(tempProgTrack, TRACK_MODE_PROG);
|
2023-08-25 19:07:57 +02:00
|
|
|
track[tempProgTrack]->setPower(tPTmode); //set track status as it was before
|
2022-08-17 02:11:51 +02:00
|
|
|
tempProgTrack = MAX_TRACKS+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2022-03-19 12:22:31 +01:00
|
|
|
progTrackSyncMain=joined;
|
|
|
|
if (joinRelay!=UNUSED_PIN) digitalWrite(joinRelay,joined?HIGH:LOW);
|
|
|
|
}
|
2023-09-05 13:21:09 +02:00
|
|
|
|
|
|
|
bool TrackManager::isPowerOn(byte t) {
|
2023-09-05 21:52:18 +02:00
|
|
|
if (track[t]->getPower()!=POWERMODE::ON)
|
|
|
|
return false;
|
|
|
|
return true;
|
2023-09-05 13:21:09 +02:00
|
|
|
}
|
|
|
|
|
2023-09-22 18:03:40 +02:00
|
|
|
bool TrackManager::isProg(byte t) {
|
2023-11-10 23:58:30 +01:00
|
|
|
if (track[t]->getMode() & TRACK_MODE_PROG)
|
2023-09-22 18:03:40 +02:00
|
|
|
return true;
|
|
|
|
return false;
|
2023-10-06 20:11:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
byte TrackManager::returnMode(byte t) {
|
|
|
|
return (track[t]->getMode());
|
|
|
|
}
|
|
|
|
|
2023-10-10 12:52:46 +02:00
|
|
|
int16_t TrackManager::returnDCAddr(byte t) {
|
|
|
|
return (trackDCAddr[t]);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* TrackManager::getModeName(byte Mode) {
|
2023-10-06 20:11:11 +02:00
|
|
|
|
|
|
|
//DIAG(F("PowerMode %d"), Mode);
|
|
|
|
|
|
|
|
switch (Mode)
|
|
|
|
{
|
|
|
|
case 1: return "NONE";
|
|
|
|
case 2: return "MAIN";
|
|
|
|
case 4: return "PROG";
|
|
|
|
case 8: return "DC";
|
|
|
|
case 16: return "DCX";
|
|
|
|
case 32: return "EXT";
|
|
|
|
default: return "----";
|
|
|
|
}
|
|
|
|
}
|