浏览代码

Fixed clear and add alerts

tags/v1.2.0
Bertrand Lemasle 6 年前
父节点
当前提交
aa1761ed04
共有 1 个文件被更改,包括 11 次插入5 次删除
  1. +11
    -5
      Alerts.cpp

+ 11
- 5
Alerts.cpp 查看文件

@@ -22,23 +22,29 @@ namespace alerts {
} }


void add(uint8_t mask) { 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_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(); config::main::save();
} }


void clear(PositionEntryMetadata &metadata) { void clear(PositionEntryMetadata &metadata) {
config_t* config = &config::main::value; config_t* config = &config::main::value;
uint8_t clearMask = 0; 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.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 (metadata.temperature != ALERT_SUSPICIOUS_RTC_TEMPERATURE) bitSet(clearMask, ALERT_RTC_TEMPERATURE_FAILURE);
if (rtc::isAccurate()) bitSet(clearMask, ALERT_RTC_CLOCK_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(); config::main::save();
} }
} }

正在加载...
取消
保存