-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathAlerts.cpp
More file actions
49 lines (37 loc) · 1.64 KB
/
Alerts.cpp
File metadata and controls
49 lines (37 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include "Alerts.h"
#include "Config.h"
#include "Rtc.h"
#include "Logging.h"
namespace alerts {
#define CURRENT_LOGGER "alerts"
uint8_t getTriggered(PositionEntryMetadata &metadata) {
config_t* config = &config::main::value;
uint8_t active = 0;
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);
return config->activeAlerts ^ active;
}
void add(uint8_t mask) {
config_t* config = &config::main::value;
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);
active &= ~clearMask;
if (config->activeAlerts == active) return; //save a write to eeprom if there is no change
config->activeAlerts = active;
config::main::save();
}
}