mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-24 16:46:13 +01:00
Compare commits
No commits in common. "1af5132e6aca4dea56636ba5df9f2533d538f17a" and "148d4d30f8544c0afb91338f011a15615da73dfe" have entirely different histories.
1af5132e6a
...
148d4d30f8
|
@ -248,11 +248,6 @@ void CommandDistributor::broadcastLoco(byte slot) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandDistributor::broadcastPower() {
|
void CommandDistributor::broadcastPower() {
|
||||||
char pstr[] = "? x";
|
|
||||||
for(byte t=0; t<TrackManager::MAX_TRACKS; t++)
|
|
||||||
if (TrackManager::getPower(t, pstr))
|
|
||||||
broadcastReply(COMMAND_TYPE, F("<p%s>\n"),pstr);
|
|
||||||
|
|
||||||
bool main=TrackManager::getMainPower()==POWERMODE::ON;
|
bool main=TrackManager::getMainPower()==POWERMODE::ON;
|
||||||
bool prog=TrackManager::getProgPower()==POWERMODE::ON;
|
bool prog=TrackManager::getProgPower()==POWERMODE::ON;
|
||||||
bool join=TrackManager::isJoined();
|
bool join=TrackManager::isJoined();
|
||||||
|
|
101
DCCEXParser.cpp
101
DCCEXParser.cpp
|
@ -553,66 +553,131 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||||
|
|
||||||
case '1': // POWERON <1 [MAIN|PROG|JOIN]>
|
case '1': // POWERON <1 [MAIN|PROG|JOIN]>
|
||||||
{
|
{
|
||||||
|
bool main=false;
|
||||||
|
bool prog=false;
|
||||||
|
bool join=false;
|
||||||
|
bool singletrack=false;
|
||||||
|
//byte t=0;
|
||||||
if (params > 1) break;
|
if (params > 1) break;
|
||||||
if (params==0) { // All
|
if (params==0) { // All
|
||||||
TrackManager::setTrackPower(TRACK_MODE_ALL, POWERMODE::ON);
|
main=true;
|
||||||
|
prog=true;
|
||||||
}
|
}
|
||||||
if (params==1) {
|
if (params==1) {
|
||||||
if (p[0]==HASH_KEYWORD_MAIN) { // <1 MAIN>
|
if (p[0]==HASH_KEYWORD_MAIN) { // <1 MAIN>
|
||||||
TrackManager::setTrackPower(TRACK_MODE_MAIN, POWERMODE::ON);
|
main=true;
|
||||||
}
|
}
|
||||||
#ifndef DISABLE_PROG
|
#ifndef DISABLE_PROG
|
||||||
else if (p[0] == HASH_KEYWORD_JOIN) { // <1 JOIN>
|
else if (p[0] == HASH_KEYWORD_JOIN) { // <1 JOIN>
|
||||||
TrackManager::setJoin(true);
|
main=true;
|
||||||
TrackManager::setTrackPower(TRACK_MODE_MAIN|TRACK_MODE_PROG, POWERMODE::ON);
|
prog=true;
|
||||||
|
join=true;
|
||||||
}
|
}
|
||||||
else if (p[0]==HASH_KEYWORD_PROG) { // <1 PROG>
|
else if (p[0]==HASH_KEYWORD_PROG) { // <1 PROG>
|
||||||
TrackManager::setJoin(false);
|
prog=true;
|
||||||
TrackManager::setTrackPower(TRACK_MODE_PROG, POWERMODE::ON);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
//else if (p[0] >= 'A' && p[0] <= 'H') { // <1 A-H>
|
||||||
else if (p[0] >= HASH_KEYWORD_A && p[0] <= HASH_KEYWORD_H) { // <1 A-H>
|
else if (p[0] >= HASH_KEYWORD_A && p[0] <= HASH_KEYWORD_H) { // <1 A-H>
|
||||||
byte t = (p[0] - 'A');
|
byte t = (p[0] - 'A');
|
||||||
TrackManager::setTrackPower(POWERMODE::ON, t);
|
//DIAG(F("Processing track - %d "), t);
|
||||||
//StringFormatter::send(stream, F("<p1 %c>\n"), t+'A');
|
if (TrackManager::isProg(t)) {
|
||||||
|
main = false;
|
||||||
|
prog = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
main=true;
|
||||||
|
prog=false;
|
||||||
|
}
|
||||||
|
singletrack=true;
|
||||||
|
if (main) TrackManager::setTrackPower(false, false, POWERMODE::ON, t);
|
||||||
|
if (prog) TrackManager::setTrackPower(true, false, POWERMODE::ON, t);
|
||||||
|
|
||||||
|
StringFormatter::send(stream, F("<1 %c>\n"), t+'A');
|
||||||
|
//CommandDistributor::broadcastPower();
|
||||||
|
//TrackManager::streamTrackState(NULL,t);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
else break; // will reply <X>
|
else break; // will reply <X>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!singletrack) {
|
||||||
|
TrackManager::setJoin(join);
|
||||||
|
if (join) TrackManager::setJoinPower(POWERMODE::ON);
|
||||||
|
else {
|
||||||
|
if (main) TrackManager::setMainPower(POWERMODE::ON);
|
||||||
|
if (prog) TrackManager::setProgPower(POWERMODE::ON);
|
||||||
|
}
|
||||||
CommandDistributor::broadcastPower();
|
CommandDistributor::broadcastPower();
|
||||||
//TrackManager::streamTrackState(NULL,t);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
case '0': // POWEROFF <0 [MAIN | PROG] >
|
case '0': // POWEROFF <0 [MAIN | PROG] >
|
||||||
{
|
{
|
||||||
|
bool main=false;
|
||||||
|
bool prog=false;
|
||||||
|
bool singletrack=false;
|
||||||
|
//byte t=0;
|
||||||
if (params > 1) break;
|
if (params > 1) break;
|
||||||
if (params==0) { // All
|
if (params==0) { // All
|
||||||
TrackManager::setJoin(false);
|
main=true;
|
||||||
TrackManager::setTrackPower(TRACK_MODE_ALL, POWERMODE::OFF);
|
prog=true;
|
||||||
}
|
}
|
||||||
if (params==1) {
|
if (params==1) {
|
||||||
if (p[0]==HASH_KEYWORD_MAIN) { // <0 MAIN>
|
if (p[0]==HASH_KEYWORD_MAIN) { // <0 MAIN>
|
||||||
TrackManager::setJoin(false);
|
main=true;
|
||||||
TrackManager::setTrackPower(TRACK_MODE_MAIN, POWERMODE::OFF);
|
|
||||||
}
|
}
|
||||||
#ifndef DISABLE_PROG
|
#ifndef DISABLE_PROG
|
||||||
else if (p[0]==HASH_KEYWORD_PROG) { // <0 PROG>
|
else if (p[0]==HASH_KEYWORD_PROG) { // <0 PROG>
|
||||||
TrackManager::progTrackBoosted=false; // Prog track boost mode will not outlive prog track off
|
prog=true;
|
||||||
TrackManager::setTrackPower(TRACK_MODE_PROG, POWERMODE::OFF);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
//else if (p[0] >= 'A' && p[0] <= 'H') { // <1 A-H>
|
||||||
else if (p[0] >= HASH_KEYWORD_A && p[0] <= HASH_KEYWORD_H) { // <1 A-H>
|
else if (p[0] >= HASH_KEYWORD_A && p[0] <= HASH_KEYWORD_H) { // <1 A-H>
|
||||||
byte t = (p[0] - 'A');
|
byte t = (p[0] - 'A');
|
||||||
TrackManager::setJoin(false);
|
//DIAG(F("Processing track - %d "), t);
|
||||||
TrackManager::setTrackPower(POWERMODE::OFF, t);
|
if (TrackManager::isProg(t)) {
|
||||||
//StringFormatter::send(stream, F("<p0 %c>\n"), t+'A');
|
main = false;
|
||||||
|
prog = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
main=true;
|
||||||
|
prog=false;
|
||||||
|
}
|
||||||
|
singletrack=true;
|
||||||
|
TrackManager::setJoin(false);
|
||||||
|
if (main) TrackManager::setTrackPower(false, false, POWERMODE::OFF, t);
|
||||||
|
if (prog) {
|
||||||
|
TrackManager::progTrackBoosted=false; // Prog track boost mode will not outlive prog track off
|
||||||
|
TrackManager::setTrackPower(true, false, POWERMODE::OFF, t);
|
||||||
|
}
|
||||||
|
StringFormatter::send(stream, F("<0 %c>\n"), t+'A');
|
||||||
|
//CommandDistributor::broadcastPower();
|
||||||
|
//TrackManager::streamTrackState(NULL, t);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
else break; // will reply <X>
|
else break; // will reply <X>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!singletrack) {
|
||||||
|
TrackManager::setJoin(false);
|
||||||
|
|
||||||
|
if (main) TrackManager::setMainPower(POWERMODE::OFF);
|
||||||
|
if (prog) {
|
||||||
|
TrackManager::progTrackBoosted=false; // Prog track boost mode will not outlive prog track off
|
||||||
|
TrackManager::setProgPower(POWERMODE::OFF);
|
||||||
|
}
|
||||||
CommandDistributor::broadcastPower();
|
CommandDistributor::broadcastPower();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case '!': // ESTOP ALL <!>
|
case '!': // ESTOP ALL <!>
|
||||||
DCC::setThrottle(0,1,1); // this broadcasts speed 1(estop) and sets all reminders to speed 1.
|
DCC::setThrottle(0,1,1); // this broadcasts speed 1(estop) and sets all reminders to speed 1.
|
||||||
|
|
|
@ -636,10 +636,10 @@ void RMFT2::loop2() {
|
||||||
//byte thistrack=getOperand(1);
|
//byte thistrack=getOperand(1);
|
||||||
switch (operand) {
|
switch (operand) {
|
||||||
case TRACK_POWER_0:
|
case TRACK_POWER_0:
|
||||||
TrackManager::setTrackPower(POWERMODE::OFF, getOperand(1));
|
TrackManager::setTrackPower(TrackManager::isProg(getOperand(1)), false, POWERMODE::OFF, getOperand(1));
|
||||||
break;
|
break;
|
||||||
case TRACK_POWER_1:
|
case TRACK_POWER_1:
|
||||||
TrackManager::setTrackPower(POWERMODE::ON, getOperand(1));
|
TrackManager::setTrackPower(TrackManager::isProg(getOperand(1)), false, POWERMODE::ON, getOperand(1));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -650,7 +650,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) ? loco : 0;
|
int16_t cab=(mode==TRACK_MODE_DC || mode==TRACK_MODE_DCX) ? loco : 0;
|
||||||
TrackManager::setTrackMode(operand & 0x0F, mode, cab);
|
TrackManager::setTrackMode(operand & 0x0F, mode, cab);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
#define GITHUB_SHA "devel-202311141013Z"
|
#define GITHUB_SHA "devel-202310230944Z"
|
||||||
|
|
|
@ -605,10 +605,6 @@ 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))){
|
|
||||||
DIAG(F("TRACK %c INVERT"), trackno + 'A');
|
|
||||||
invertOutput();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// all well
|
// all well
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* © 2021 Mike S
|
* © 2021 Mike S
|
||||||
* © 2021 Fred Decker
|
* © 2021 Fred Decker
|
||||||
* © 2020 Chris Harlow
|
* © 2020 Chris Harlow
|
||||||
* © 2022,2023 Harald Barth
|
* © 2022 Harald Barth
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This file is part of CommandStation-EX
|
* This file is part of CommandStation-EX
|
||||||
|
@ -28,15 +28,8 @@
|
||||||
#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_EXT = 16, TRACK_MODE_BOOST = 32,
|
TRACK_MODE_DC = 8, TRACK_MODE_DCX = 16, TRACK_MODE_EXT = 32};
|
||||||
TRACK_MODE_ALL = 62, // only to operate all tracks
|
|
||||||
TRACK_MODE_INV = 64, TRACK_MODE_DCX = 72 /*DC + INV*/, 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
|
||||||
|
@ -156,8 +149,6 @@ class MotorDriver {
|
||||||
// from outside interrupt
|
// from outside interrupt
|
||||||
void setBrake( bool on, bool interruptContext=false);
|
void setBrake( bool on, bool interruptContext=false);
|
||||||
__attribute__((always_inline)) inline void setSignal( bool high) {
|
__attribute__((always_inline)) inline void setSignal( bool high) {
|
||||||
if (invertPhase)
|
|
||||||
high = !high;
|
|
||||||
if (trackPWM) {
|
if (trackPWM) {
|
||||||
DCCTimer::setPWM(signalPin,high);
|
DCCTimer::setPWM(signalPin,high);
|
||||||
}
|
}
|
||||||
|
@ -177,12 +168,6 @@ class MotorDriver {
|
||||||
pinMode(signalPin, OUTPUT);
|
pinMode(signalPin, OUTPUT);
|
||||||
else
|
else
|
||||||
pinMode(signalPin, INPUT);
|
pinMode(signalPin, INPUT);
|
||||||
if (signalPin2 != UNUSED_PIN) {
|
|
||||||
if (on)
|
|
||||||
pinMode(signalPin2, OUTPUT);
|
|
||||||
else
|
|
||||||
pinMode(signalPin2, INPUT);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
inline pinpair getSignalPin() { return pinpair(signalPin,signalPin2); };
|
inline pinpair getSignalPin() { return pinpair(signalPin,signalPin2); };
|
||||||
void setDCSignal(byte speedByte);
|
void setDCSignal(byte speedByte);
|
||||||
|
@ -247,32 +232,6 @@ 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);
|
|
||||||
};
|
|
||||||
inline void invertOutput() { // toggles output inversion
|
|
||||||
invertPhase = !invertPhase;
|
|
||||||
invertOutput(invertPhase);
|
|
||||||
};
|
|
||||||
inline void invertOutput(bool b) { // sets output inverted or not
|
|
||||||
if (b)
|
|
||||||
invertPhase = 1;
|
|
||||||
else
|
|
||||||
invertPhase = 0;
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
|
||||||
pinpair p = getSignalPin();
|
|
||||||
uint32_t *outreg = (uint32_t *)(GPIO_FUNC0_OUT_SEL_CFG_REG + 4*p.pin);
|
|
||||||
if (invertPhase) // set or clear the invert bit in the gpio out register
|
|
||||||
*outreg |= ((uint32_t)0x1 << GPIO_FUNC0_OUT_INV_SEL_S);
|
|
||||||
else
|
|
||||||
*outreg &= ~((uint32_t)0x1 << GPIO_FUNC0_OUT_INV_SEL_S);
|
|
||||||
if (p.invpin != UNUSED_PIN) {
|
|
||||||
outreg = (uint32_t *)(GPIO_FUNC0_OUT_SEL_CFG_REG + 4*p.invpin);
|
|
||||||
if (invertPhase) // clear or set the invert bit in the gpio out register
|
|
||||||
*outreg &= ~((uint32_t)0x1 << GPIO_FUNC0_OUT_INV_SEL_S);
|
|
||||||
else
|
|
||||||
*outreg |= ((uint32_t)0x1 << GPIO_FUNC0_OUT_INV_SEL_S);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
inline TRACK_MODE getMode() {
|
inline TRACK_MODE getMode() {
|
||||||
return trackMode;
|
return trackMode;
|
||||||
|
@ -304,7 +263,7 @@ class MotorDriver {
|
||||||
bool invertBrake; // brake pin passed as negative means pin is inverted
|
bool invertBrake; // brake pin passed as negative means pin is inverted
|
||||||
bool invertPower; // power pin passed as negative means pin is inverted
|
bool invertPower; // power pin passed as negative means pin is inverted
|
||||||
bool invertFault; // fault pin passed as negative means pin is inverted
|
bool invertFault; // fault pin passed as negative means pin is inverted
|
||||||
bool invertPhase = 0; // phase of out pin is inverted
|
|
||||||
// Raw to milliamp conversion factors avoiding float data types.
|
// Raw to milliamp conversion factors avoiding float data types.
|
||||||
// Milliamps=rawADCreading * sensefactorInternal / senseScale
|
// Milliamps=rawADCreading * sensefactorInternal / senseScale
|
||||||
//
|
//
|
||||||
|
|
241
TrackManager.cpp
241
TrackManager.cpp
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* © 2022 Chris Harlow
|
* © 2022 Chris Harlow
|
||||||
* © 2022,2023 Harald Barth
|
* © 2022 Harald Barth
|
||||||
* © 2023 Colin Murdoch
|
* © 2023 Colin Murdoch
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
|
@ -45,11 +45,6 @@ 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;
|
|
||||||
#ifdef BOOSTER_INPUT
|
|
||||||
const int16_t HASH_KEYWORD_BOOST = 11269;
|
|
||||||
#endif
|
|
||||||
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];
|
||||||
|
@ -92,7 +87,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_BOOST|TRACK_MODE_EXT )) {
|
if (track[tr]->getMode() & ( TRACK_MODE_MAIN|TRACK_MODE_PROG|TRACK_MODE_DC|TRACK_MODE_DCX|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;
|
||||||
|
@ -202,8 +197,8 @@ 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)
|
if (track[t]->getMode()==TRACK_MODE_DC) track[t]->setDCSignal(speedbyte);
|
||||||
track[t]->setDCSignal(speedbyte);
|
else if (track[t]->getMode()==TRACK_MODE_DCX) track[t]->setDCSignal(speedbyte ^ 128);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +207,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) {
|
if (mode==TRACK_MODE_DC || mode==TRACK_MODE_DCX) {
|
||||||
#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;
|
||||||
|
@ -228,37 +223,21 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
||||||
pinpair p = track[trackToSet]->getSignalPin();
|
pinpair p = track[trackToSet]->getSignalPin();
|
||||||
//DIAG(F("Track=%c remove pin %d"),trackToSet+'A', p.pin);
|
//DIAG(F("Track=%c remove pin %d"),trackToSet+'A', p.pin);
|
||||||
gpio_reset_pin((gpio_num_t)p.pin);
|
gpio_reset_pin((gpio_num_t)p.pin);
|
||||||
|
pinMode(p.pin, OUTPUT); // gpio_reset_pin may reset to input
|
||||||
if (p.invpin != UNUSED_PIN) {
|
if (p.invpin != UNUSED_PIN) {
|
||||||
//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);
|
||||||
|
pinMode(p.invpin, OUTPUT); // gpio_reset_pin may reset to input
|
||||||
}
|
}
|
||||||
#ifdef BOOSTER_INPUT
|
|
||||||
if (mode & TRACK_MODE_BOOST) {
|
|
||||||
//DIAG(F("Track=%c mode boost pin %d"),trackToSet+'A', p.pin);
|
|
||||||
pinMode(BOOSTER_INPUT, INPUT);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
} else // elseif clause continues
|
|
||||||
#endif
|
|
||||||
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
|
||||||
|
@ -276,20 +255,16 @@ 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)) {
|
if (!(mode==TRACK_MODE_DC || mode==TRACK_MODE_DCX)) {
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
if (!(mode & TRACK_MODE_BOOST))
|
track[trackToSet]->enableSignal(mode != TRACK_MODE_EXT);
|
||||||
track[trackToSet]->enableSignal(!(mode & TRACK_MODE_EXT));
|
|
||||||
|
|
||||||
#ifndef ARDUINO_ARCH_ESP32
|
#ifndef ARDUINO_ARCH_ESP32
|
||||||
// re-evaluate HighAccuracy mode
|
// re-evaluate HighAccuracy mode
|
||||||
|
@ -299,7 +274,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) {
|
if (track[t]->getMode()==TRACK_MODE_DC || track[t]->getMode()==TRACK_MODE_DCX) {
|
||||||
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
|
||||||
|
@ -307,7 +282,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_MODE_PROG)) {
|
} else if (track[t]->getMode()==TRACK_MODE_MAIN || track[t]->getMode()==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;
|
||||||
|
@ -325,12 +300,10 @@ 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) {
|
if (mode==TRACK_MODE_DC || mode==TRACK_MODE_DCX) {
|
||||||
// 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
|
||||||
|
@ -339,7 +312,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 | TRACK_MODE_DC | TRACK_MODE_EXT | TRACK_MODE_BOOST)) ?
|
(mode==TRACK_MODE_MAIN || mode==TRACK_MODE_DC || mode==TRACK_MODE_DCX || mode==TRACK_MODE_EXT) ?
|
||||||
mainPowerGuess : POWERMODE::OFF);
|
mainPowerGuess : POWERMODE::OFF);
|
||||||
//DIAG(F("TrackMode=%d"),mode);
|
//DIAG(F("TrackMode=%d"),mode);
|
||||||
return true;
|
return true;
|
||||||
|
@ -347,6 +320,8 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
||||||
|
|
||||||
void TrackManager::applyDCSpeed(byte t) {
|
void TrackManager::applyDCSpeed(byte t) {
|
||||||
uint8_t speedByte=DCC::getThrottleSpeedByte(trackDCAddr[t]);
|
uint8_t speedByte=DCC::getThrottleSpeedByte(trackDCAddr[t]);
|
||||||
|
if (track[t]->getMode()==TRACK_MODE_DCX)
|
||||||
|
speedByte = speedByte ^ 128; // reverse direction bit
|
||||||
track[t]->setDCSignal(speedByte);
|
track[t]->setDCSignal(speedByte);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,21 +353,12 @@ 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);
|
||||||
#ifdef BOOSTER_INPUT
|
|
||||||
if (params==2 && p[1]==HASH_KEYWORD_BOOST) // <= id BOOST>
|
|
||||||
return setTrackMode(p[0],TRACK_MODE_BOOST);
|
|
||||||
#endif
|
|
||||||
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_DC|TRACK_MODE_INV,p[2]);
|
return setTrackMode(p[0],TRACK_MODE_DCX,p[2]);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -400,43 +366,36 @@ bool TrackManager::parseJ(Print *stream, int16_t params, int16_t p[])
|
||||||
void TrackManager::streamTrackState(Print* stream, byte t) {
|
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("<= %d XXX>\n");
|
auto format=F("");
|
||||||
TRACK_MODE tm = track[t]->getMode();
|
bool pstate = TrackManager::isPowerOn(t);
|
||||||
if (tm & TRACK_MODE_MAIN) {
|
|
||||||
if(tm & TRACK_MODE_AUTOINV)
|
switch(track[t]->getMode()) {
|
||||||
format=F("<= %c MAIN A>\n");
|
case TRACK_MODE_MAIN:
|
||||||
else if (tm & TRACK_MODE_INV)
|
if (pstate) {format=F("<= %c MAIN ON>\n");} else {format = F("<= %c MAIN OFF>\n");}
|
||||||
format=F("<= %c MAIN I>\n");
|
break;
|
||||||
else
|
|
||||||
format=F("<= %c MAIN>\n");
|
|
||||||
}
|
|
||||||
#ifndef DISABLE_PROG
|
#ifndef DISABLE_PROG
|
||||||
else if (tm & TRACK_MODE_PROG)
|
case TRACK_MODE_PROG:
|
||||||
format=F("<= %c PROG>\n");
|
if (pstate) {format=F("<= %c PROG ON>\n");} else {format=F("<= %c PROG OFF>\n");}
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
else if (tm & TRACK_MODE_NONE)
|
case TRACK_MODE_NONE:
|
||||||
format=F("<= %c NONE>\n");
|
if (pstate) {format=F("<= %c NONE ON>\n");} else {format=F("<= %c NONE OFF>\n");}
|
||||||
else if(tm & TRACK_MODE_EXT)
|
break;
|
||||||
format=F("<= %c EXT>\n");
|
case TRACK_MODE_EXT:
|
||||||
else if(tm & TRACK_MODE_BOOST) {
|
if (pstate) {format=F("<= %c EXT ON>\n");} else {format=F("<= %c EXT OFF>\n");}
|
||||||
if(tm & TRACK_MODE_AUTOINV)
|
break;
|
||||||
format=F("<= %c B A>\n");
|
case TRACK_MODE_DC:
|
||||||
else if (tm & TRACK_MODE_INV)
|
if (pstate) {format=F("<= %c DC %d ON>\n");} else {format=F("<= %c DC %d OFF>\n");}
|
||||||
format=F("<= %c B I>\n");
|
break;
|
||||||
else
|
case TRACK_MODE_DCX:
|
||||||
format=F("<= %c B>\n");
|
if (pstate) {format=F("<= %c DCX %d ON>\n");} else {format=F("<= %c DCX %d OFF>\n");}
|
||||||
}
|
break;
|
||||||
else if (tm & TRACK_MODE_DC) {
|
default:
|
||||||
if (tm & TRACK_MODE_INV)
|
break; // unknown, dont care
|
||||||
format=F("<= %c DCX %d>\n");
|
|
||||||
else
|
|
||||||
format=F("<= %c DC %d>\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stream)
|
if (stream) StringFormatter::send(stream,format,'A'+t, trackDCAddr[t]);
|
||||||
StringFormatter::send(stream,format,'A'+t, trackDCAddr[t]);
|
else CommandDistributor::broadcastTrackState(format,'A'+t, trackDCAddr[t]);
|
||||||
else
|
|
||||||
CommandDistributor::broadcastTrackState(format,'A'+t, trackDCAddr[t]);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,13 +411,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 : (bool)(track[nextCycleTrack]->getMode() & TRACK_MODE_PROG);
|
bool useProgLimit=dontLimitProg? false: 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,50 +425,60 @@ 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
|
||||||
|
|
||||||
// Set track power for all tracks with this mode
|
void TrackManager::setPower2(bool setProg,bool setJoin, POWERMODE mode) {
|
||||||
void TrackManager::setTrackPower(TRACK_MODE trackmode, POWERMODE powermode) {
|
if (!setProg) mainPowerGuess=mode;
|
||||||
FOR_EACH_TRACK(t) {
|
FOR_EACH_TRACK(t) {
|
||||||
MotorDriver *driver=track[t];
|
|
||||||
if (trackmode & driver->getMode()) {
|
TrackManager::setTrackPower(setProg, setJoin, mode, t);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set track power for this track, inependent of mode
|
void TrackManager::setTrackPower(bool setProg, bool setJoin, POWERMODE mode, byte thistrack) {
|
||||||
void TrackManager::setTrackPower(POWERMODE powermode, byte t) {
|
|
||||||
MotorDriver *driver=track[t];
|
//DIAG(F("SetTrackPower Processing Track %d"), thistrack);
|
||||||
TRACK_MODE trackmode = driver->getMode();
|
MotorDriver * driver=track[thistrack];
|
||||||
if (trackmode & TRACK_MODE_DC) {
|
if (!driver) return;
|
||||||
if (powermode == POWERMODE::ON) {
|
|
||||||
driver->setBrake(true); // DC starts with brake on
|
switch (track[thistrack]->getMode()) {
|
||||||
applyDCSpeed(t); // speed match DCC throttles
|
case TRACK_MODE_MAIN:
|
||||||
}
|
if (setProg) break;
|
||||||
} else {
|
|
||||||
if (powermode == POWERMODE::ON) {
|
|
||||||
// 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
|
||||||
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);
|
||||||
|
break;
|
||||||
|
case TRACK_MODE_DC:
|
||||||
|
case TRACK_MODE_DCX:
|
||||||
|
//DIAG(F("Processing track - %d setProg %d"), thistrack, setProg);
|
||||||
|
if (setProg || setJoin) break;
|
||||||
|
driver->setBrake(true); // DC starts with brake on
|
||||||
|
applyDCSpeed(thistrack); // speed match DCC throttles
|
||||||
|
driver->setPower(mode);
|
||||||
|
break;
|
||||||
|
case TRACK_MODE_PROG:
|
||||||
|
if (!setProg && !setJoin) break;
|
||||||
|
driver->setBrake(true);
|
||||||
|
driver->setBrake(false);
|
||||||
|
driver->setPower(mode);
|
||||||
|
break;
|
||||||
|
case TRACK_MODE_EXT:
|
||||||
|
driver->setBrake(true);
|
||||||
|
driver->setBrake(false);
|
||||||
|
driver->setPower(mode);
|
||||||
|
break;
|
||||||
|
case TRACK_MODE_NONE:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
driver->setPower(powermode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackManager::reportPowerChange(Print* stream, byte thistrack) {
|
void TrackManager::reportPowerChange(Print* stream, byte thistrack) {
|
||||||
|
@ -521,41 +490,13 @@ void TrackManager::reportPowerChange(Print* stream, byte thistrack) {
|
||||||
track[0]->raw2mA(track[0]->getCurrentRaw(false)), maxCurrent, maxCurrent);
|
track[0]->raw2mA(track[0]->getCurrentRaw(false)), maxCurrent, maxCurrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns state of the one and only prog track
|
|
||||||
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(); // optimize: there is max one prog track
|
return track[t]->getPower();
|
||||||
return POWERMODE::OFF;
|
return POWERMODE::OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TrackManager::getPower(byte t, char s[]) {
|
|
||||||
if (t > lastTrack)
|
|
||||||
return false;
|
|
||||||
if (track[t]) {
|
|
||||||
s[0] = track[t]->getPower() == POWERMODE::ON ? '1' : '0';
|
|
||||||
s[2] = t + 'A';
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TrackManager::reportObsoleteCurrent(Print* stream) {
|
void TrackManager::reportObsoleteCurrent(Print* stream) {
|
||||||
// This function is for backward JMRI compatibility only
|
// This function is for backward JMRI compatibility only
|
||||||
// It reports the first track only, as main, regardless of track settings.
|
// It reports the first track only, as main, regardless of track settings.
|
||||||
|
@ -596,7 +537,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;
|
||||||
|
@ -625,7 +566,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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,19 +65,20 @@ class TrackManager {
|
||||||
static std::vector<MotorDriver *>getMainDrivers();
|
static std::vector<MotorDriver *>getMainDrivers();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void setPower2(bool progTrack,bool joinTrack,POWERMODE mode);
|
||||||
static void setPower(POWERMODE mode) {setMainPower(mode); setProgPower(mode);}
|
static void setPower(POWERMODE mode) {setMainPower(mode); setProgPower(mode);}
|
||||||
static void setTrackPower(POWERMODE mode, byte t);
|
static void setMainPower(POWERMODE mode) {setPower2(false,false,mode);}
|
||||||
static void setTrackPower(TRACK_MODE trackmode, POWERMODE powermode);
|
static void setProgPower(POWERMODE mode) {setPower2(true,false,mode);}
|
||||||
static void setMainPower(POWERMODE mode) {setTrackPower(TRACK_MODE_MAIN, mode);}
|
static void setJoinPower(POWERMODE mode) {setPower2(false,true,mode);}
|
||||||
static void setProgPower(POWERMODE mode) {setTrackPower(TRACK_MODE_PROG, mode);}
|
static void setTrackPower(bool setProg, bool setJoin, POWERMODE mode, byte thistrack);
|
||||||
|
|
||||||
|
|
||||||
static const int16_t MAX_TRACKS=8;
|
static const int16_t MAX_TRACKS=8;
|
||||||
static bool setTrackMode(byte track, TRACK_MODE mode, int16_t DCaddr=0);
|
static bool setTrackMode(byte track, TRACK_MODE mode, int16_t DCaddr=0);
|
||||||
static bool parseJ(Print * stream, int16_t params, int16_t p[]);
|
static bool parseJ(Print * stream, int16_t params, int16_t p[]);
|
||||||
static void loop();
|
static void loop();
|
||||||
static POWERMODE getMainPower();
|
static POWERMODE getMainPower() {return mainPowerGuess;}
|
||||||
static POWERMODE getProgPower();
|
static POWERMODE getProgPower();
|
||||||
static bool getPower(byte t, char s[]);
|
|
||||||
static void setJoin(bool join);
|
static void setJoin(bool join);
|
||||||
static bool isJoined() { return progTrackSyncMain;}
|
static bool isJoined() { return progTrackSyncMain;}
|
||||||
static void setJoinRelayPin(byte joinRelayPin);
|
static void setJoinRelayPin(byte joinRelayPin);
|
||||||
|
@ -111,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
|
static int16_t trackDCAddr[MAX_TRACKS]; // dc address if TRACK_MODE_DC or TRACK_MODE_DCX
|
||||||
#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
|
||||||
|
|
|
@ -266,12 +266,6 @@ The configuration file for DCC-EX Command Station
|
||||||
//
|
//
|
||||||
//#define SERIAL_BT_COMMANDS
|
//#define SERIAL_BT_COMMANDS
|
||||||
|
|
||||||
// BOOSTER PIN INPUT ON ESP32
|
|
||||||
// On ESP32 you have the possibility to define a pin as booster input
|
|
||||||
// Arduio pin D2 is GPIO 26 on ESPDuino32
|
|
||||||
//
|
|
||||||
//#define BOOSTER_INPUT 26
|
|
||||||
|
|
||||||
// SABERTOOTH
|
// SABERTOOTH
|
||||||
//
|
//
|
||||||
// This is a very special option and only useful if you happen to have a
|
// This is a very special option and only useful if you happen to have a
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
|
|
||||||
#include "StringFormatter.h"
|
#include "StringFormatter.h"
|
||||||
|
|
||||||
#define VERSION "5.2.1"
|
#define VERSION "5.1.21"
|
||||||
// 5.2.1 - Trackmanager rework for simpler structure
|
|
||||||
// 5.2.0 - ESP32: Autoreverse and booster mode support
|
|
||||||
// 5.1.21 - EXRAIL invoke multiple ON handlers for same event
|
// 5.1.21 - EXRAIL invoke multiple ON handlers for same event
|
||||||
// 5.1.20 - EXRAIL Tidy and ROUTE_STATE, ROUTE_CAPTION
|
// 5.1.20 - EXRAIL Tidy and ROUTE_STATE, ROUTE_CAPTION
|
||||||
// 5.1.19 - Only flag 2.2.0.0-dev as broken, not 2.2.0.0
|
// 5.1.19 - Only flag 2.2.0.0-dev as broken, not 2.2.0.0
|
||||||
|
|
Loading…
Reference in New Issue
Block a user