From 1ec378281b5e8d6e7900d2ffe058b23f84cfd8d2 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sat, 25 Mar 2023 12:14:58 +0100 Subject: [PATCH] do not broadcast a turnout state that has not changed --- GITHUB_SHA.h | 2 +- Turnouts.cpp | 35 +++++++++++++---------------------- version.h | 3 ++- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 46d55b9..9a36e4a 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "devel-202303202024Z" +#define GITHUB_SHA "devel-202303251113Z" diff --git a/Turnouts.cpp b/Turnouts.cpp index 582ea7d..c02e97c 100644 --- a/Turnouts.cpp +++ b/Turnouts.cpp @@ -110,15 +110,16 @@ /* static */ bool Turnout::setClosedStateOnly(uint16_t id, bool closeFlag) { Turnout *tt = get(id); if (!tt) return false; - tt->_turnoutData.closed = closeFlag; - // I know it says setClosedStateOnly, but we need to tell others - // that the state has changed too. - #if defined(EXRAIL_ACTIVE) - RMFT2::turnoutEvent(id, closeFlag); - #endif - - CommandDistributor::broadcastTurnout(id, closeFlag); + // that the state has changed too. But we only broadcast if there + // really has been a change. + if (tt->_turnoutData.closed != closeFlag) { + tt->_turnoutData.closed = closeFlag; + CommandDistributor::broadcastTurnout(id, closeFlag); + } +#if defined(EXRAIL_ACTIVE) + RMFT2::turnoutEvent(id, closeFlag); +#endif return true; } @@ -128,31 +129,21 @@ // type should be placed in the virtual function setClosedInternal(bool) which is // called from here. /* static */ bool Turnout::setClosed(uint16_t id, bool closeFlag) { - #if defined(DIAG_IO) - if (closeFlag) - DIAG(F("Turnout::close(%d)"), id); - else - DIAG(F("Turnout::throw(%d)"), id); - #endif +#if defined(DIAG_IO) + DIAG(F("Turnout(%d,%c)"), id, closeFlag ? 'c':'t'); +#endif Turnout *tt = Turnout::get(id); if (!tt) return false; bool ok = tt->setClosedInternal(closeFlag); if (ok) { - + tt->setClosedStateOnly(id, closeFlag); #ifndef DISABLE_EEPROM // Write byte containing new closed/thrown state to EEPROM if required. Note that eepromAddress // is always zero for LCN turnouts. if (EEStore::eeStore->data.nTurnouts > 0 && tt->_eepromAddress > 0) EEPROM.put(tt->_eepromAddress, tt->_turnoutData.flags); #endif - - #if defined(EXRAIL_ACTIVE) - RMFT2::turnoutEvent(id, closeFlag); - #endif - - // Send message to JMRI etc. - CommandDistributor::broadcastTurnout(id, closeFlag); } return ok; } diff --git a/version.h b/version.h index 25867b1..6a597fe 100644 --- a/version.h +++ b/version.h @@ -4,7 +4,8 @@ #include "StringFormatter.h" -#define VERSION "4.2.35" +#define VERSION "4.2.36rc1" +// 4.2.36 - do not broadcast a turnout state that has not changed // 4.2.35 - add direct pin manipulation command // 4.2.34 - Completely fix EX-IOExpander analogue inputs // 4.2.33 - Fix EX-IOExpander non-working analogue inputs