1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-23 21:01:25 +01:00

Merge branch 'Broadcast' into EXRAILPlus

This commit is contained in:
Asbelos 2021-12-16 12:37:09 +00:00
commit 2c47c309dc
5 changed files with 17 additions and 21 deletions

View File

@ -105,18 +105,20 @@ void CommandDistributor::broadcastTurnout(int16_t id, bool isClosed ) {
}
void CommandDistributor::broadcastPower() {
const FSH * reason;
bool main=DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON;
bool prog=DCCWaveform::progTrack.getPowerMode()==POWERMODE::ON;
bool join=DCCWaveform::progTrackSyncMain;
if (main && prog && join) reason=F("1 JOIN");
else if (main && prog) reason=F("1");
else if (main) reason=F("1 MAIN");
else if (prog) reason=F("1 PROG");
else reason=F("0");
const FSH * reason=F("");
char state='1';
if (main && prog && join) reason=F(" JOIN");
else if (main && prog);
else if (main) reason=F(" MAIN");
else if (prog) reason=F(" PROG");
else state='0';
StringFormatter::send(broadcastBufferWriter,
F("<p%S>\nPPA%c\n"),reason, main?'1':'0');
LCD(2,F("Power %S"),reason);
F("<p%c%S>\nPPA%c\n"),state,reason, main?'1':'0');
LCD(2,F("Power %S%S"),state=='1'?F("On"):F("Off"),reason);
broadcast();
}

View File

@ -107,6 +107,7 @@ void setup()
#endif
LCD(3,F("Ready"));
CommandDistributor::broadcastPower();
}
void loop()

View File

@ -43,6 +43,6 @@
#include "Sensors.h"
#include "Outputs.h"
#include "RMFT.h"
#include "CommandDistributor.h"
#endif

View File

@ -165,7 +165,7 @@ public:
#endif
static void printAll(Print *stream) {
for (Turnout *tt = _firstTurnout; tt != 0; tt = tt->_nextTurnout)
StringFormatter::send(stream, F("<H %c %c>\n"),tt->getId(), tt->isThrown());
StringFormatter::send(stream, F("<H %d %d>\n"),tt->getId(), tt->isThrown());
}

View File

@ -50,6 +50,7 @@
#include "GITHUB_SHA.h"
#include "version.h"
#include "RMFT2.h"
#include "CommandDistributor.h"
#define LOOPLOCOS(THROTTLECHAR, CAB) for (int loco=0;loco<MAX_MY_LOCO;loco++) \
if ((myLocos[loco].throttle==THROTTLECHAR || '*'==THROTTLECHAR) && (CAB<0 || myLocos[loco].cab==CAB))
@ -110,12 +111,6 @@ void WiThrottle::parse(RingStream * stream, byte * cmdx) {
if (Diag::WITHROTTLE) DIAG(F("%l WiThrottle(%d)<-[%e]"),millis(),clientid,cmd);
if (initSent) {
// Send power state if different than last sent
bool currentPowerState = (DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON);
if (lastPowerState != currentPowerState) {
StringFormatter::send(stream,F("PPA%x\n"),currentPowerState);
lastPowerState = currentPowerState;
}
// Send turnout list if changed since last sent (will replace list on client)
if (turnoutListHash != Turnout::turnoutlistHash) {
StringFormatter::send(stream,F("PTL"));
@ -153,8 +148,7 @@ void WiThrottle::parse(RingStream * stream, byte * cmdx) {
DCCWaveform::mainTrack.setPowerMode(cmd[3]=='1'?POWERMODE::ON:POWERMODE::OFF);
if (MotorDriver::commonFaultPin) // commonFaultPin prevents individual track handling
DCCWaveform::progTrack.setPowerMode(cmd[3]=='1'?POWERMODE::ON:POWERMODE::OFF);
StringFormatter::send(stream,F("PPA%x\n"),DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON);
lastPowerState = (DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON); //remember power state sent for comparison later
CommandDistributor::broadcastPower();
}
#if defined(RMFT_ACTIVE)
else if (cmd[1]=='R' && cmd[2]=='A' && cmd[3]=='2' ) { // Route activate
@ -205,7 +199,6 @@ void WiThrottle::parse(RingStream * stream, byte * cmdx) {
StringFormatter::send(stream,F("HtDCC-EX v%S, %S, %S, %S\n"), F(VERSION), F(ARDUINO_TYPE), DCC::getMotorShieldName(), F(GITHUB_SHA));
StringFormatter::send(stream,F("PTT]\\[Turnouts}|{Turnout]\\[THROW}|{2]\\[CLOSE}|{4\n"));
StringFormatter::send(stream,F("PPA%x\n"),DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON);
lastPowerState = (DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON); //remember power state sent for comparison later
StringFormatter::send(stream,F("*%d\n"),HEARTBEAT_SECONDS);
initSent = true;
}