mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-27 01:56:14 +01:00
move call to CommandDistributor::broadcastPower() into the TrackManager::setTrackPower(*) functions
This commit is contained in:
parent
a1accec79a
commit
18116a391c
|
@ -283,7 +283,7 @@ void CommandDistributor::broadcastPower() {
|
||||||
//DIAG(F("m=%d p=%d j=%d"), main, prog, join);
|
//DIAG(F("m=%d p=%d j=%d"), main, prog, join);
|
||||||
const FSH * reason=F("");
|
const FSH * reason=F("");
|
||||||
if (join) {
|
if (join) {
|
||||||
reason = F("JOIN");
|
reason = F(" JOIN"); // with space at start so we can append without space
|
||||||
broadcastReply(COMMAND_TYPE, F("<p1 %S>\n"),reason);
|
broadcastReply(COMMAND_TYPE, F("<p1 %S>\n"),reason);
|
||||||
} else {
|
} else {
|
||||||
if (main) {
|
if (main) {
|
||||||
|
@ -303,7 +303,7 @@ void CommandDistributor::broadcastPower() {
|
||||||
broadcastReply(WITHROTTLE_TYPE, F("PPA%c\n"), main?'1': state);
|
broadcastReply(WITHROTTLE_TYPE, F("PPA%c\n"), main?'1': state);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LCD(2,F("Power %S %S"),state=='1'?F("On"): ( state=='0'? F("Off") : F("SC") ),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) {
|
||||||
|
|
|
@ -587,7 +587,6 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||||
}
|
}
|
||||||
else break; // will reply <X>
|
else break; // will reply <X>
|
||||||
}
|
}
|
||||||
CommandDistributor::broadcastPower();
|
|
||||||
//TrackManager::streamTrackState(NULL,t);
|
//TrackManager::streamTrackState(NULL,t);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -619,7 +618,6 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||||
}
|
}
|
||||||
else break; // will reply <X>
|
else break; // will reply <X>
|
||||||
}
|
}
|
||||||
CommandDistributor::broadcastPower();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -414,7 +414,6 @@ void RMFT2::driveLoco(byte speed) {
|
||||||
power on appropriate track if DC or main if dcc
|
power on appropriate track if DC or main if dcc
|
||||||
if (TrackManager::getMainPowerMode()==POWERMODE::OFF) {
|
if (TrackManager::getMainPowerMode()==POWERMODE::OFF) {
|
||||||
TrackManager::setMainPower(POWERMODE::ON);
|
TrackManager::setMainPower(POWERMODE::ON);
|
||||||
CommandDistributor::broadcastPower();
|
|
||||||
}
|
}
|
||||||
**********/
|
**********/
|
||||||
|
|
||||||
|
@ -642,7 +641,6 @@ void RMFT2::loop2() {
|
||||||
case OPCODE_POWEROFF:
|
case OPCODE_POWEROFF:
|
||||||
TrackManager::setPower(POWERMODE::OFF);
|
TrackManager::setPower(POWERMODE::OFF);
|
||||||
TrackManager::setJoin(false);
|
TrackManager::setJoin(false);
|
||||||
CommandDistributor::broadcastPower();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPCODE_SET_POWER:
|
case OPCODE_SET_POWER:
|
||||||
|
@ -837,12 +835,10 @@ void RMFT2::loop2() {
|
||||||
case OPCODE_JOIN:
|
case OPCODE_JOIN:
|
||||||
TrackManager::setPower(POWERMODE::ON);
|
TrackManager::setPower(POWERMODE::ON);
|
||||||
TrackManager::setJoin(true);
|
TrackManager::setJoin(true);
|
||||||
CommandDistributor::broadcastPower();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPCODE_UNJOIN:
|
case OPCODE_UNJOIN:
|
||||||
TrackManager::setJoin(false);
|
TrackManager::setJoin(false);
|
||||||
CommandDistributor::broadcastPower();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPCODE_READ_LOCO1: // READ_LOCO is implemented as 2 separate opcodes
|
case OPCODE_READ_LOCO1: // READ_LOCO is implemented as 2 separate opcodes
|
||||||
|
@ -870,7 +866,6 @@ void RMFT2::loop2() {
|
||||||
case OPCODE_POWERON:
|
case OPCODE_POWERON:
|
||||||
TrackManager::setMainPower(POWERMODE::ON);
|
TrackManager::setMainPower(POWERMODE::ON);
|
||||||
TrackManager::setJoin(false);
|
TrackManager::setJoin(false);
|
||||||
CommandDistributor::broadcastPower();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPCODE_START:
|
case OPCODE_START:
|
||||||
|
|
|
@ -489,10 +489,13 @@ std::vector<MotorDriver *>TrackManager::getMainDrivers() {
|
||||||
|
|
||||||
// Set track power for all tracks with this mode
|
// Set track power for all tracks with this mode
|
||||||
void TrackManager::setTrackPower(TRACK_MODE trackmodeToMatch, POWERMODE powermode) {
|
void TrackManager::setTrackPower(TRACK_MODE trackmodeToMatch, POWERMODE powermode) {
|
||||||
|
bool didChange=false;
|
||||||
FOR_EACH_TRACK(t) {
|
FOR_EACH_TRACK(t) {
|
||||||
MotorDriver *driver=track[t];
|
MotorDriver *driver=track[t];
|
||||||
TRACK_MODE trackmodeOfTrack = driver->getMode();
|
TRACK_MODE trackmodeOfTrack = driver->getMode();
|
||||||
if (trackmodeToMatch & trackmodeOfTrack) {
|
if (trackmodeToMatch & trackmodeOfTrack) {
|
||||||
|
if (powermode != driver->getPower())
|
||||||
|
didChange=true;
|
||||||
if (powermode == POWERMODE::ON) {
|
if (powermode == POWERMODE::ON) {
|
||||||
if (trackmodeOfTrack & TRACK_MODE_DC) {
|
if (trackmodeOfTrack & TRACK_MODE_DC) {
|
||||||
driver->setBrake(true); // DC starts with brake on
|
driver->setBrake(true); // DC starts with brake on
|
||||||
|
@ -507,12 +510,15 @@ void TrackManager::setTrackPower(TRACK_MODE trackmodeToMatch, POWERMODE powermod
|
||||||
driver->setPower(powermode);
|
driver->setPower(powermode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (didChange)
|
||||||
|
CommandDistributor::broadcastPower();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set track power for this track, inependent of mode
|
// Set track power for this track, inependent of mode
|
||||||
void TrackManager::setTrackPower(POWERMODE powermode, byte t) {
|
void TrackManager::setTrackPower(POWERMODE powermode, byte t) {
|
||||||
MotorDriver *driver=track[t];
|
MotorDriver *driver=track[t];
|
||||||
TRACK_MODE trackmode = driver->getMode();
|
TRACK_MODE trackmode = driver->getMode();
|
||||||
|
POWERMODE oldpower = driver->getPower();
|
||||||
if (trackmode & TRACK_MODE_NONE) {
|
if (trackmode & TRACK_MODE_NONE) {
|
||||||
driver->setBrake(true); // Track is unused. Brake is good to have.
|
driver->setBrake(true); // Track is unused. Brake is good to have.
|
||||||
powermode = POWERMODE::OFF; // Track is unused. Force it to OFF
|
powermode = POWERMODE::OFF; // Track is unused. Force it to OFF
|
||||||
|
@ -530,6 +536,8 @@ void TrackManager::setTrackPower(POWERMODE powermode, byte t) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
driver->setPower(powermode);
|
driver->setPower(powermode);
|
||||||
|
if (oldpower != driver->getPower())
|
||||||
|
CommandDistributor::broadcastPower();
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns state of the one and only prog track
|
// returns state of the one and only prog track
|
||||||
|
|
|
@ -150,7 +150,6 @@ void WiThrottle::parse(RingStream * stream, byte * cmdx) {
|
||||||
DCCWaveform::progTrack.setPowerMode(cmd[3]=='1'?POWERMODE::ON:POWERMODE::OFF);
|
DCCWaveform::progTrack.setPowerMode(cmd[3]=='1'?POWERMODE::ON:POWERMODE::OFF);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CommandDistributor::broadcastPower();
|
|
||||||
}
|
}
|
||||||
#if defined(EXRAIL_ACTIVE)
|
#if defined(EXRAIL_ACTIVE)
|
||||||
else if (cmd[1]=='R' && cmd[2]=='A' && cmd[3]=='2' ) { // Route activate
|
else if (cmd[1]=='R' && cmd[2]=='A' && cmd[3]=='2' ) { // Route activate
|
||||||
|
@ -496,7 +495,6 @@ void WiThrottle::getLocoCallback(int16_t locoid) {
|
||||||
TrackManager::setJoin(true); // <1 JOIN> so we can drive loco away
|
TrackManager::setJoin(true); // <1 JOIN> so we can drive loco away
|
||||||
DIAG(F("LocoCallback commit success"));
|
DIAG(F("LocoCallback commit success"));
|
||||||
stashStream->commit();
|
stashStream->commit();
|
||||||
CommandDistributor::broadcastPower();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiThrottle::sendIntro(Print* stream) {
|
void WiThrottle::sendIntro(Print* stream) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user