|
@@ -1,23 +1,18 @@ |
|
|
#pragma once |
|
|
#pragma once |
|
|
|
|
|
|
|
|
|
|
|
#include "Debug.h" |
|
|
#include "Alerts.h" |
|
|
#include "Alerts.h" |
|
|
#include "Config.h" |
|
|
#include "Config.h" |
|
|
#include "Rtc.h" |
|
|
#include "Rtc.h" |
|
|
|
|
|
|
|
|
|
|
|
#define LOGGER_NAME "Alerts" |
|
|
|
|
|
|
|
|
namespace alerts { |
|
|
namespace alerts { |
|
|
|
|
|
|
|
|
uint8_t getTriggered(PositionEntryMetadata &metadata) { |
|
|
uint8_t getTriggered(PositionEntryMetadata &metadata) { |
|
|
config_t* config = &config::main::value; |
|
|
config_t* config = &config::main::value; |
|
|
uint8_t result = 0; |
|
|
uint8_t result = 0; |
|
|
|
|
|
|
|
|
if (!rtc::isAccurate() && !bitRead(config->activeAlerts, ALERT_RTC_CLOCK_FAILURE)) { |
|
|
|
|
|
bitSet(result, ALERT_RTC_CLOCK_FAILURE); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (metadata.temperature == ALERT_SUSPICIOUS_RTC_TEMPERATURE && !bitRead(config->activeAlerts, ALERT_RTC_TEMPERATURE_FAILURE)) { |
|
|
|
|
|
bitSet(result, ALERT_RTC_TEMPERATURE_FAILURE); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (metadata.batteryLevel <= config->alertBatteryLevel1 && !bitRead(config->activeAlerts, ALERT_BATTERY_LEVEL_1)) { |
|
|
if (metadata.batteryLevel <= config->alertBatteryLevel1 && !bitRead(config->activeAlerts, ALERT_BATTERY_LEVEL_1)) { |
|
|
bitSet(result, ALERT_BATTERY_LEVEL_1); |
|
|
bitSet(result, ALERT_BATTERY_LEVEL_1); |
|
|
} |
|
|
} |
|
@@ -26,6 +21,14 @@ namespace alerts { |
|
|
bitSet(result, 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 result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -41,16 +44,16 @@ namespace alerts { |
|
|
config_t* config = &config::main::value; |
|
|
config_t* config = &config::main::value; |
|
|
uint8_t clearMask = 0; |
|
|
uint8_t clearMask = 0; |
|
|
|
|
|
|
|
|
if (bitRead(config->activeAlerts, ALERT_RTC_CLOCK_FAILURE) && rtc::isAccurate()) { |
|
|
|
|
|
bitSet(clearMask, ALERT_RTC_CLOCK_FAILURE); |
|
|
|
|
|
|
|
|
if ((config->activeAlerts & (_BV(ALERT_BATTERY_LEVEL_1) | _BV(ALERT_BATTERY_LEVEL_2))) && metadata.temperature >= 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) { |
|
|
if (bitRead(config->activeAlerts, ALERT_RTC_TEMPERATURE_FAILURE) && metadata.temperature != ALERT_SUSPICIOUS_RTC_TEMPERATURE) { |
|
|
bitSet(clearMask, ALERT_RTC_TEMPERATURE_FAILURE); |
|
|
bitSet(clearMask, ALERT_RTC_TEMPERATURE_FAILURE); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ((config->activeAlerts & (_BV(ALERT_BATTERY_LEVEL_1) | _BV(ALERT_BATTERY_LEVEL_2))) && metadata.temperature >= config->alertBatteryLevelClear) { |
|
|
|
|
|
clearMask |= _BV(ALERT_BATTERY_LEVEL_1) | _BV(ALERT_BATTERY_LEVEL_2); |
|
|
|
|
|
|
|
|
if (bitRead(config->activeAlerts, ALERT_RTC_CLOCK_FAILURE) && rtc::isAccurate()) { |
|
|
|
|
|
bitSet(clearMask, ALERT_RTC_CLOCK_FAILURE); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!clearMask) return; //save a write to eeprom if there is no change |
|
|
if (!clearMask) return; //save a write to eeprom if there is no change |
|
|