From 2a79f67308033a859fdcfd546433a991c447110a Mon Sep 17 00:00:00 2001 From: Neil McKechnie Date: Thu, 12 Aug 2021 11:59:32 +0100 Subject: [PATCH] Fix EEPROM handling for outputs. Output definitions in EEPROM were being lost once the output was activated or deactivated. The handling has been corrected and tested. --- Outputs.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Outputs.cpp b/Outputs.cpp index 5910172..7287446 100644 --- a/Outputs.cpp +++ b/Outputs.cpp @@ -105,7 +105,7 @@ void Output::activate(uint16_t s){ // Update EEPROM if output has been stored. if(EEStore::eeStore->data.nOutputs > 0 && num > 0) - EEPROM.put(num, data.flags); + EEPROM.put(num, data.oStatus); } /////////////////////////////////////////////////////////////////////////////// @@ -149,7 +149,9 @@ void Output::load(){ for(uint16_t i=0;idata.nOutputs;i++){ EEPROM.get(EEStore::pointer(),data); // Create new object, set current state to default or to saved state from eeprom. - tt=create(data.id, data.pin, data.flags, data.setDefault ? data.defaultValue : data.active); + tt=create(data.id, data.pin, data.flags); + uint8_t state = data.setDefault ? data.defaultValue : data.active; + tt->activate(state); if (tt) tt->num=EEStore::pointer() + offsetof(OutputData, oStatus); // Save pointer to flags within EEPROM EEStore::advance(sizeof(tt->data)); @@ -177,6 +179,8 @@ void Output::store(){ /////////////////////////////////////////////////////////////////////////////// // Static function to create an Output object +// The obscurely named parameter 'v' is 0 if called from the load() function +// and 1 if called from the command processing. Output *Output::create(uint16_t id, VPIN pin, int iFlag, int v){ Output *tt;