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(); } }