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

add EXT as a new track mode

This commit is contained in:
Harald Barth 2022-05-18 09:40:53 +02:00
parent f0e8419fea
commit 6d2a9e3b36
3 changed files with 29 additions and 5 deletions

View File

@ -99,6 +99,12 @@ class MotorDriver {
} }
} }
}; };
inline void enableSignal(bool on) {
if (on)
pinMode(signalPin, OUTPUT);
else
pinMode(signalPin, INPUT);
};
virtual void setBrake( bool on); virtual void setBrake( bool on);
virtual void setDCSignal(byte speedByte); virtual void setDCSignal(byte speedByte);
virtual int getCurrentRaw(); virtual int getCurrentRaw();

View File

@ -37,6 +37,7 @@ const int16_t HASH_KEYWORD_MAIN = 11339;
const int16_t HASH_KEYWORD_OFF = 22479; const int16_t HASH_KEYWORD_OFF = 22479;
const int16_t HASH_KEYWORD_DC = 2183; 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_A = 65; // parser makes single chars the ascii. const int16_t HASH_KEYWORD_A = 65; // parser makes single chars the ascii.
MotorDriver * TrackManager::track[MAX_TRACKS]; MotorDriver * TrackManager::track[MAX_TRACKS];
@ -164,6 +165,11 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
track[trackToSet]->setBrake(false); track[trackToSet]->setBrake(false);
} }
// EXT is a special case where the signal pin is
// turned off. So unless that is set, the signal
// pin should be turned on
track[trackToSet]->enableSignal(mode != TRACK_MODE_EXT);
// re-evaluate HighAccuracy mode // re-evaluate HighAccuracy mode
// We can only do this is all main and prog tracks agree // We can only do this is all main and prog tracks agree
bool canDo=true; bool canDo=true;
@ -225,6 +231,9 @@ bool TrackManager::parseJ(Print *stream, int16_t params, int16_t p[])
case TRACK_MODE_OFF: case TRACK_MODE_OFF:
StringFormatter::send(stream,F("OFF")); StringFormatter::send(stream,F("OFF"));
break; break;
case TRACK_MODE_EXT:
StringFormatter::send(stream,F("EXT"));
break;
case TRACK_MODE_DC: case TRACK_MODE_DC:
StringFormatter::send(stream,F("DC %d"),trackDCAddr[t]); StringFormatter::send(stream,F("DC %d"),trackDCAddr[t]);
break; break;
@ -253,6 +262,9 @@ bool TrackManager::parseJ(Print *stream, int16_t params, int16_t p[])
if (params==2 && p[1]==HASH_KEYWORD_OFF) // <= id OFF> if (params==2 && p[1]==HASH_KEYWORD_OFF) // <= id OFF>
return setTrackMode(p[0],TRACK_MODE_OFF); return setTrackMode(p[0],TRACK_MODE_OFF);
if (params==2 && p[1]==HASH_KEYWORD_EXT) // <= id EXT>
return setTrackMode(p[0],TRACK_MODE_EXT);
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]);
@ -292,6 +304,7 @@ void TrackManager::setPower2(bool setProg,POWERMODE mode) {
if (setProg) break; if (setProg) break;
// 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); driver->setPower(mode);
@ -309,6 +322,11 @@ void TrackManager::setPower2(bool setProg,POWERMODE mode) {
driver->setBrake(false); driver->setBrake(false);
driver->setPower(mode); driver->setPower(mode);
break; break;
case TRACK_MODE_EXT:
driver->setBrake(true);
driver->setBrake(false);
driver->setPower(mode);
break;
case TRACK_MODE_OFF: case TRACK_MODE_OFF:
break; break;
} }

View File

@ -24,7 +24,7 @@
// Virtualised Motor shield multi-track hardware Interface // Virtualised Motor shield multi-track hardware Interface
enum TRACK_MODE : byte {TRACK_MODE_OFF, TRACK_MODE_MAIN, TRACK_MODE_PROG, enum TRACK_MODE : byte {TRACK_MODE_OFF, TRACK_MODE_MAIN, TRACK_MODE_PROG,
TRACK_MODE_DC, TRACK_MODE_DCX}; TRACK_MODE_DC, TRACK_MODE_DCX, TRACK_MODE_EXT};
// These constants help EXRAIL macros say SET_TRACK(2,mode) OR SET_TRACK(C,mode) etc. // These constants help EXRAIL macros say SET_TRACK(2,mode) OR SET_TRACK(C,mode) etc.
const byte TRACK_NUMBER_0=0, TRACK_NUMBER_A=0; const byte TRACK_NUMBER_0=0, TRACK_NUMBER_A=0;