|
|
@@ -11,25 +11,14 @@ namespace alerts { |
|
|
|
|
|
|
|
uint8_t getTriggered(PositionEntryMetadata &metadata) { |
|
|
|
config_t* config = &config::main::value; |
|
|
|
uint8_t result = 0; |
|
|
|
uint8_t active = 0; |
|
|
|
|
|
|
|
if (metadata.batteryLevel <= config->alertBatteryLevel1 && !bitRead(config->activeAlerts, ALERT_BATTERY_LEVEL_1)) { |
|
|
|
bitSet(result, ALERT_BATTERY_LEVEL_1); |
|
|
|
} |
|
|
|
if (metadata.batteryLevel <= config->alertBatteryLevel1) bitSet(active, ALERT_BATTERY_LEVEL_1); |
|
|
|
if (metadata.batteryLevel <= config->alertBatteryLevel2) bitSet(active, ALERT_BATTERY_LEVEL_2); |
|
|
|
if (metadata.temperature == ALERT_SUSPICIOUS_RTC_TEMPERATURE) bitSet(active, ALERT_RTC_TEMPERATURE_FAILURE); |
|
|
|
if (!rtc::isAccurate()) bitSet(active, ALERT_RTC_CLOCK_FAILURE); |
|
|
|
|
|
|
|
if (metadata.batteryLevel <= config->alertBatteryLevel2 && !bitRead(config->activeAlerts, ALERT_BATTERY_LEVEL_2)) { |
|
|
|
bitSet(result, ALERT_BATTERY_LEVEL_2); |
|
|
|
} |
|
|
|
|
|
|
|
if (metadata.temperature == ALERT_SUSPICIOUS_RTC_TEMPERATURE && !bitRead(config->activeAlerts, ALERT_RTC_TEMPERATURE_FAILURE)) { |
|
|
|
bitSet(result, ALERT_RTC_TEMPERATURE_FAILURE); |
|
|
|
} |
|
|
|
|
|
|
|
if (!rtc::isAccurate() && !bitRead(config->activeAlerts, ALERT_RTC_CLOCK_FAILURE)) { |
|
|
|
bitSet(result, ALERT_RTC_CLOCK_FAILURE); |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
return config->activeAlerts ^ active; |
|
|
|
} |
|
|
|
|
|
|
|
void add(uint8_t mask) { |
|
|
@@ -44,19 +33,11 @@ namespace alerts { |
|
|
|
config_t* config = &config::main::value; |
|
|
|
uint8_t clearMask = 0; |
|
|
|
|
|
|
|
if ((config->activeAlerts & (_BV(ALERT_BATTERY_LEVEL_1) | _BV(ALERT_BATTERY_LEVEL_2))) && metadata.batteryLevel >= config->alertBatteryLevelClear) { |
|
|
|
clearMask |= _BV(ALERT_BATTERY_LEVEL_1) | _BV(ALERT_BATTERY_LEVEL_2); |
|
|
|
} |
|
|
|
|
|
|
|
if (bitRead(config->activeAlerts, ALERT_RTC_TEMPERATURE_FAILURE) && metadata.temperature != ALERT_SUSPICIOUS_RTC_TEMPERATURE) { |
|
|
|
bitSet(clearMask, ALERT_RTC_TEMPERATURE_FAILURE); |
|
|
|
} |
|
|
|
|
|
|
|
if (bitRead(config->activeAlerts, ALERT_RTC_CLOCK_FAILURE) && rtc::isAccurate()) { |
|
|
|
bitSet(clearMask, ALERT_RTC_CLOCK_FAILURE); |
|
|
|
} |
|
|
|
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 (!clearMask) return; //save a write to eeprom if there is no change |
|
|
|
if (!config->activeAlerts || !clearMask) return; //save a write to eeprom if there is no change |
|
|
|
config->activeAlerts &= ~clearMask; |
|
|
|
config::main::save(); |
|
|
|
} |
|
|
|