From 94a2839bcab397661887ea9e0bd3976861f5f8dc Mon Sep 17 00:00:00 2001 From: Asbelos Date: Thu, 16 Dec 2021 12:11:38 +0000 Subject: [PATCH 1/2] simplify LCD power state --- CommandDistributor.cpp | 18 ++++++++++-------- CommandStation-EX.ino | 1 + DCCEX.h | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index 8405eb9..5e107df 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -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("\nPPA%c\n"),reason, main?'1':'0'); - LCD(2,F("Power %S"),reason); + F("\nPPA%c\n"),state,reason, main?'1':'0'); + LCD(2,F("Power %S%S"),state=='1'?F("On"):F("Off"),reason); broadcast(); } diff --git a/CommandStation-EX.ino b/CommandStation-EX.ino index 689804b..d619e86 100644 --- a/CommandStation-EX.ino +++ b/CommandStation-EX.ino @@ -104,6 +104,7 @@ void setup() #endif LCD(3,F("Ready")); + CommandDistributor::broadcastPower(); } void loop() diff --git a/DCCEX.h b/DCCEX.h index 2906dae..568f2d3 100644 --- a/DCCEX.h +++ b/DCCEX.h @@ -43,6 +43,6 @@ #include "Sensors.h" #include "Outputs.h" #include "RMFT.h" - +#include "CommandDistributor.h" #endif From f755c291d52f0703efda4cc4b90e665214bd90bf Mon Sep 17 00:00:00 2001 From: Asbelos Date: Thu, 16 Dec 2021 12:32:14 +0000 Subject: [PATCH 2/2] Turnout typos and power broadcast --- Turnouts.h | 2 +- WiThrottle.cpp | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Turnouts.h b/Turnouts.h index cce0190..8666250 100644 --- a/Turnouts.h +++ b/Turnouts.h @@ -165,7 +165,7 @@ public: #endif static void printAll(Print *stream) { for (Turnout *tt = _firstTurnout; tt != 0; tt = tt->_nextTurnout) - StringFormatter::send(stream, F("\n"),tt->getId(), tt->isThrown()); + StringFormatter::send(stream, F("\n"),tt->getId(), tt->isThrown()); } diff --git a/WiThrottle.cpp b/WiThrottle.cpp index b3cc0a8..b9fef3f 100644 --- a/WiThrottle.cpp +++ b/WiThrottle.cpp @@ -50,6 +50,7 @@ #include "GITHUB_SHA.h" #include "version.h" #include "RMFT2.h" +#include "CommandDistributor.h" #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) @@ -113,12 +114,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")); @@ -148,10 +143,9 @@ void WiThrottle::parse(RingStream * stream, byte * cmdx) { case 'P': if (cmd[1]=='P' && cmd[2]=='A' ) { //PPA power mode 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 + if (MotorDriver::commonFaultPin) // commonFaultPin prevents individual track handling + DCCWaveform::progTrack.setPowerMode(cmd[3]=='1'?POWERMODE::ON:POWERMODE::OFF); + CommandDistributor::broadcastPower(); } #if defined(RMFT_ACTIVE) else if (cmd[1]=='R' && cmd[2]=='A' && cmd[3]=='2' ) { // Route activate @@ -202,7 +196,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; }