mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-30 03:26:13 +01:00
Bugfix: Do not turn off all tracks on change ; give better power messages
This commit is contained in:
parent
ef47257d67
commit
784934024e
|
@ -254,21 +254,56 @@ void CommandDistributor::broadcastPower() {
|
||||||
if (TrackManager::getPower(t, pstr))
|
if (TrackManager::getPower(t, pstr))
|
||||||
broadcastReply(COMMAND_TYPE, F("<p%s>\n"),pstr);
|
broadcastReply(COMMAND_TYPE, F("<p%s>\n"),pstr);
|
||||||
|
|
||||||
|
byte trackcount=0;
|
||||||
|
byte oncount=0;
|
||||||
|
byte offcount=0;
|
||||||
|
for(byte t=0; t<TrackManager::MAX_TRACKS; t++) {
|
||||||
|
if (TrackManager::isActive(t)) {
|
||||||
|
trackcount++;
|
||||||
|
// do not call getPower(t) unless isActive(t)!
|
||||||
|
if (TrackManager::getPower(t) == POWERMODE::ON)
|
||||||
|
oncount++;
|
||||||
|
else
|
||||||
|
offcount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//DIAG(F("t=%d on=%d off=%d"), trackcount, oncount, offcount);
|
||||||
|
|
||||||
|
char state='2';
|
||||||
|
if (oncount==0 || offcount == trackcount)
|
||||||
|
state = '0';
|
||||||
|
else if (oncount == trackcount) {
|
||||||
|
state = '1';
|
||||||
|
}
|
||||||
|
|
||||||
|
// additional info about MAIN, PROG and JOIN
|
||||||
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();
|
||||||
|
//DIAG(F("m=%d p=%d j=%d"), main, prog, join);
|
||||||
const FSH * reason=F("");
|
const FSH * reason=F("");
|
||||||
char state='1';
|
if (join) {
|
||||||
if (main && prog && join) reason=F(" JOIN");
|
reason = F("JOIN");
|
||||||
else if (main && prog);
|
broadcastReply(COMMAND_TYPE, F("<p1 %S>\n"),reason);
|
||||||
else if (main) reason=F(" MAIN");
|
} else {
|
||||||
else if (prog) reason=F(" PROG");
|
if (main) {
|
||||||
else state='0';
|
//reason = F("MAIN");
|
||||||
broadcastReply(COMMAND_TYPE, F("<p%c%S>\n"),state,reason);
|
broadcastReply(COMMAND_TYPE, F("<p1 MAIN>\n"));
|
||||||
|
}
|
||||||
|
if (prog) {
|
||||||
|
//reason = F("PROG");
|
||||||
|
broadcastReply(COMMAND_TYPE, F("<p1 PROG>\n"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state != '2')
|
||||||
|
broadcastReply(COMMAND_TYPE, F("<p%c>\n"),state);
|
||||||
#ifdef CD_HANDLE_RING
|
#ifdef CD_HANDLE_RING
|
||||||
broadcastReply(WITHROTTLE_TYPE, F("PPA%c\n"), main?'1':'0');
|
// send '1' if all main are on, otherwise global state (which in that case is '0' or '2')
|
||||||
|
broadcastReply(WITHROTTLE_TYPE, F("PPA%c\n"), main?'1': state);
|
||||||
#endif
|
#endif
|
||||||
LCD(2,F("Power %S%S"),state=='1'?F("On"):F("Off"),reason);
|
|
||||||
|
LCD(2,F("Power %S %S"),state=='1'?F("On"): ( state=='0'? F("Off") : F("SC") ),reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandDistributor::broadcastRaw(clientType type, char * msg) {
|
void CommandDistributor::broadcastRaw(clientType type, char * msg) {
|
||||||
|
|
|
@ -54,7 +54,6 @@ 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];
|
||||||
|
|
||||||
POWERMODE TrackManager::mainPowerGuess=POWERMODE::OFF;
|
|
||||||
byte TrackManager::lastTrack=0;
|
byte TrackManager::lastTrack=0;
|
||||||
bool TrackManager::progTrackSyncMain=false;
|
bool TrackManager::progTrackSyncMain=false;
|
||||||
bool TrackManager::progTrackBoosted=false;
|
bool TrackManager::progTrackBoosted=false;
|
||||||
|
@ -210,6 +209,9 @@ void TrackManager::setDCSignal(int16_t cab, byte speedbyte) {
|
||||||
bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr) {
|
bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr) {
|
||||||
if (trackToSet>lastTrack || track[trackToSet]==NULL) return false;
|
if (trackToSet>lastTrack || track[trackToSet]==NULL) return false;
|
||||||
|
|
||||||
|
// Remember track mode we came from for later
|
||||||
|
TRACK_MODE oldmode = track[trackToSet]->getMode();
|
||||||
|
|
||||||
//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) {
|
||||||
|
@ -270,7 +272,6 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
||||||
}
|
}
|
||||||
track[trackToSet]->setMode(mode);
|
track[trackToSet]->setMode(mode);
|
||||||
trackDCAddr[trackToSet]=dcAddr;
|
trackDCAddr[trackToSet]=dcAddr;
|
||||||
streamTrackState(NULL,trackToSet);
|
|
||||||
|
|
||||||
// When a track is switched, we must clear any side effects of its previous
|
// When a track is switched, we must clear any side effects of its previous
|
||||||
// state, otherwise trains run away or just dont move.
|
// state, otherwise trains run away or just dont move.
|
||||||
|
@ -337,10 +338,11 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
||||||
applyDCSpeed(trackToSet);
|
applyDCSpeed(trackToSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normal running tracks are set to the global power state
|
// Turn off power if we changed the mode of this track
|
||||||
track[trackToSet]->setPower(
|
if (mode != oldmode)
|
||||||
(mode & (TRACK_MODE_MAIN | TRACK_MODE_DC | TRACK_MODE_EXT | TRACK_MODE_BOOST)) ?
|
track[trackToSet]->setPower(POWERMODE::OFF);
|
||||||
mainPowerGuess : POWERMODE::OFF);
|
streamTrackState(NULL,trackToSet);
|
||||||
|
|
||||||
//DIAG(F("TrackMode=%d"),mode);
|
//DIAG(F("TrackMode=%d"),mode);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,9 +77,13 @@ class TrackManager {
|
||||||
static void loop();
|
static void loop();
|
||||||
static POWERMODE getMainPower();
|
static POWERMODE getMainPower();
|
||||||
static POWERMODE getProgPower();
|
static POWERMODE getProgPower();
|
||||||
|
static inline POWERMODE getPower(byte t) { return track[t]->getPower(); }
|
||||||
static bool getPower(byte t, char s[]);
|
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 inline bool isActive (byte tr) {
|
||||||
|
if (tr > lastTrack) return false;
|
||||||
|
return track[tr]->getMode() & (TRACK_MODE_MAIN|TRACK_MODE_PROG|TRACK_MODE_DC|TRACK_MODE_BOOST|TRACK_MODE_EXT);}
|
||||||
static void setJoinRelayPin(byte joinRelayPin);
|
static void setJoinRelayPin(byte joinRelayPin);
|
||||||
static void sampleCurrent();
|
static void sampleCurrent();
|
||||||
static void reportGauges(Print* stream);
|
static void reportGauges(Print* stream);
|
||||||
|
@ -108,7 +112,6 @@ class TrackManager {
|
||||||
static void addTrack(byte t, MotorDriver* driver);
|
static void addTrack(byte t, MotorDriver* driver);
|
||||||
static byte lastTrack;
|
static byte lastTrack;
|
||||||
static byte nextCycleTrack;
|
static byte nextCycleTrack;
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user