1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-24 13:21:23 +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() { void CommandDistributor::broadcastPower() {
const FSH * reason;
bool main=DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON; bool main=DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON;
bool prog=DCCWaveform::progTrack.getPowerMode()==POWERMODE::ON; bool prog=DCCWaveform::progTrack.getPowerMode()==POWERMODE::ON;
bool join=DCCWaveform::progTrackSyncMain; bool join=DCCWaveform::progTrackSyncMain;
if (main && prog && join) reason=F("1 JOIN"); const FSH * reason=F("");
else if (main && prog) reason=F("1"); char state='1';
else if (main) reason=F("1 MAIN"); if (main && prog && join) reason=F(" JOIN");
else if (prog) reason=F("1 PROG"); else if (main && prog);
else reason=F("0"); else if (main) reason=F(" MAIN");
else if (prog) reason=F(" PROG");
else state='0';
StringFormatter::send(broadcastBufferWriter, StringFormatter::send(broadcastBufferWriter,
F("<p%S>\nPPA%c\n"),reason, main?'1':'0'); F("<p%c%S>\nPPA%c\n"),state,reason, main?'1':'0');
LCD(2,F("Power %S"),reason); LCD(2,F("Power %S%S"),state=='1'?F("On"):F("Off"),reason);
broadcast(); broadcast();
} }

View File

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

View File

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

View File

@ -165,7 +165,7 @@ public:
#endif #endif
static void printAll(Print *stream) { static void printAll(Print *stream) {
for (Turnout *tt = _firstTurnout; tt != 0; tt = tt->_nextTurnout) 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 "GITHUB_SHA.h"
#include "version.h" #include "version.h"
#include "RMFT2.h" #include "RMFT2.h"
#include "CommandDistributor.h"
#define LOOPLOCOS(THROTTLECHAR, CAB) for (int loco=0;loco<MAX_MY_LOCO;loco++) \ #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)) 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 (Diag::WITHROTTLE) DIAG(F("%l WiThrottle(%d)<-[%e]"),millis(),clientid,cmd);
if (initSent) { 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) // Send turnout list if changed since last sent (will replace list on client)
if (turnoutListHash != Turnout::turnoutlistHash) { if (turnoutListHash != Turnout::turnoutlistHash) {
StringFormatter::send(stream,F("PTL")); 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); DCCWaveform::mainTrack.setPowerMode(cmd[3]=='1'?POWERMODE::ON:POWERMODE::OFF);
if (MotorDriver::commonFaultPin) // commonFaultPin prevents individual track handling if (MotorDriver::commonFaultPin) // commonFaultPin prevents individual track handling
DCCWaveform::progTrack.setPowerMode(cmd[3]=='1'?POWERMODE::ON:POWERMODE::OFF); DCCWaveform::progTrack.setPowerMode(cmd[3]=='1'?POWERMODE::ON:POWERMODE::OFF);
StringFormatter::send(stream,F("PPA%x\n"),DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON); CommandDistributor::broadcastPower();
lastPowerState = (DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON); //remember power state sent for comparison later
} }
#if defined(RMFT_ACTIVE) #if defined(RMFT_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
@ -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("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("PTT]\\[Turnouts}|{Turnout]\\[THROW}|{2]\\[CLOSE}|{4\n"));
StringFormatter::send(stream,F("PPA%x\n"),DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON); 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); StringFormatter::send(stream,F("*%d\n"),HEARTBEAT_SECONDS);
initSent = true; initSent = true;
} }