From aa1761ed04d99434cb75bcc3fbbe82fdb786898a Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Mon, 6 Aug 2018 19:11:07 +1200 Subject: [PATCH] Fixed clear and add alerts --- Alerts.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Alerts.cpp b/Alerts.cpp index 33bab8c..d9c8e9a 100644 --- a/Alerts.cpp +++ b/Alerts.cpp @@ -22,23 +22,29 @@ namespace alerts { } void add(uint8_t mask) { - if (!mask) return; //save a write to eeprom if there is no change - config_t* config = &config::main::value; - config->activeAlerts |= mask; + uint8_t active = config->activeAlerts; + + active |= mask; + if (config->activeAlerts == active) return; //save a write to eeprom if there is no change + + config->activeAlerts = active; config::main::save(); } void clear(PositionEntryMetadata &metadata) { config_t* config = &config::main::value; uint8_t clearMask = 0; + uint8_t active = config->activeAlerts; if (metadata.batteryLevel >= config->alertBatteryLevelClear) clearMask |= _BV(ALERT_BATTERY_LEVEL_1) | _BV(ALERT_BATTERY_LEVEL_2); if (metadata.temperature != ALERT_SUSPICIOUS_RTC_TEMPERATURE) bitSet(clearMask, ALERT_RTC_TEMPERATURE_FAILURE); if (rtc::isAccurate()) bitSet(clearMask, ALERT_RTC_CLOCK_FAILURE); - if (!config->activeAlerts || !clearMask) return; //save a write to eeprom if there is no change - config->activeAlerts &= ~clearMask; + active &= ~clearMask; + if (config->activeAlerts == active) return; //save a write to eeprom if there is no change + + config->activeAlerts = active; config::main::save(); } }