From 7c68a9de705e9d2351c104b8cbdc92845a3ab8e3 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Mon, 22 Jun 2020 11:58:33 +0100 Subject: [PATCH] virtual turnout activate --- Turnouts.cpp | 13 ++++++++----- Turnouts.h | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Turnouts.cpp b/Turnouts.cpp index a8bbaff..7754a21 100644 --- a/Turnouts.cpp +++ b/Turnouts.cpp @@ -2,16 +2,19 @@ #include "EEStore.h" #include "StringFormatter.h" -bool Turnout::activate(int n,bool state){ + bool Turnout::activate(int n,bool state){ Turnout * tt=get(n); if (tt==NULL) return false; - tt->data.tStatus=state; - DCC::setAccessory(tt->data.address, tt->data.subAddress, tt->data.tStatus); - if(n>0) - EEPROM.put(n,tt->data.tStatus); + tt->activate(state); + if(n>0) EEPROM.put(n,tt->data.tStatus); return true; } +// activate is virtual here so that it can be overridden by a non-DCC turnout mechanism +void Turnout::activate(bool state) { + data.tStatus=state; + DCC::setAccessory(data.address,data.subAddress, data.tStatus); +} /////////////////////////////////////////////////////////////////////////////// Turnout* Turnout::get(int n){ diff --git a/Turnouts.h b/Turnouts.h index 39a67e7..8152c36 100644 --- a/Turnouts.h +++ b/Turnouts.h @@ -16,7 +16,7 @@ struct Turnout{ int num; struct TurnoutData data; Turnout *nextTurnout; - static bool activate(int n, bool state); + static bool activate(int n, bool state); static Turnout* get(int); static bool remove(int); static void load(); @@ -24,6 +24,7 @@ struct Turnout{ static Turnout *create(int, int, int); static void show(Print & stream, int n); static bool showAll(Print & stream); + virtual void activate(bool state); }; // Turnout #endif