Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
alerts.h
Go to the documentation of this file.
1
5#ifndef ALERTS_H
6#define ALERTS_H
7
8#include <cstdint>
9
10namespace lampda {
11namespace logic {
13namespace alerts {
14
16enum class Type : uint32_t
17{
18 // 0 means no errors
19
20 // always sort them by importance
21 MAIN_LOOP_FREEZE = 1 << 0, // main loop does not respond
22 BATTERY_READINGS_INCOHERENT = 1 << 1, // the pin that reads the battery value is not coherent with
23 // it's givent min and max
24 BATTERY_CRITICAL = 1 << 2, // battery is too low, shutdown immediatly
25 BATTERY_LOW = 1 << 3, // battery is dangerously low
26 LONG_LOOP_UPDATE = 1 << 4, // the main loop is taking too long to execute
27 // (bugs when reading button inputs)
28 TEMP_TOO_HIGH = 1 << 5, // Processor temperature is too high
29 TEMP_CRITICAL = 1 << 6, // Processor temperature is critical
30
31 BLUETOOTH_ADVERT = 1 << 7, // bluetooth is advertising
32
33 HARDWARE_ALERT = 1 << 8, // any hardware alert
34
35 FAVORITE_SET = 1 << 9, // user favorite mode is set
36
37 OTG_FAILED = 1 << 10, // OTG activation failed
38
39 SYSTEM_OFF_FAILED = 1 << 11, // system failed to go to sleep, big trouble here
40 SYSTEM_IN_ERROR_STATE = 1 << 12, // system is locked in an error state
41
42 SYSTEM_IN_LOCKOUT = 1 << 13, // system lockout, the lamp should not output any light
43
44 SUNSET_TIMER_ENABLED = 1 << 14, // active sunset timer, system will auto turn off
45
46 SYSTEM_SLEEP_SKIPPED = 1 << 15, // the system skipped the sleep clean phase (crash ? new flash ?)
47
48 USB_PORT_SHORT = 1 << 16, // the usb port is dirty, or wet
49
50 BATTERY_MISSING = 1 << 17, // no battery plugged in the system
51
52 CHARGER_ERROR = 1 << 18, // the charger signaled an error
53};
54
60{
61public:
63 void raise(const Type type);
64
66 void clear(const Type type);
67
69 bool is_raised(const Type type) const { return (_current & static_cast<uint32_t>(type)) != 0x00; }
70
72 bool is_clear() const { return _current == 0x00; }
73
76 uint32_t get_time_since_raised(const Type type) const;
77
79 bool can_use_output_power() const;
80
82 bool can_charge_battery() const;
83
85 bool can_use_usb_port() const;
86
87private:
89 uint32_t _current;
90};
91
93extern AlertManager_t manager;
94
97
99void handle_all(const bool shouldIgnoreAlerts);
100
102void show_all();
103
106
107} // namespace alerts
108} // namespace logic
109} // namespace lampda
110
111#endif
Handle the whole alerts logic. Use this to raise and clear alerts, and make decisions based on those ...
Definition: alerts.h:60
uint32_t get_time_since_raised(const Type type) const
the time in milliseconds since this alert was raised, or zero if it's not. This raise time is updated...
Definition: alerts.cpp:890
bool is_clear() const
Return true if no alerts are raised.
Definition: alerts.h:72
bool can_charge_battery() const
Return true if a raised alert prevents battery charging.
Definition: alerts.cpp:921
bool can_use_usb_port() const
Return true if no raised alerts block the use of power through USB port.
Definition: alerts.cpp:936
bool can_use_output_power() const
Return true if a raised alert prevents power set to output.
Definition: alerts.cpp:906
void clear(const Type type)
Clear an alert.
Definition: alerts.cpp:882
void raise(const Type type)
Raise an alert.
Definition: alerts.cpp:858
bool is_raised(const Type type) const
Return true if the target alert is raised.
Definition: alerts.h:69
Type
Alert types : 31 errors max.
Definition: alerts.h:17
void signal_wake_up_from_charger()
Signal slot that the system just powered up from charger.
Definition: alerts.cpp:748
AlertManager_t manager
Instanciation of the AlertManager.
Definition: alerts.cpp:27
bool is_request_shutdown()
Return true if an alert requested an immediate shutdown. Handling this is urgent or dammages can happ...
Definition: alerts.cpp:856
void handle_all(const bool shouldIgnoreAlerts)
handle the behavior for all alerts. Must be called often
Definition: alerts.cpp:750
void show_all()
show all the raised alerts in Serial debug
Definition: alerts.cpp:837
Program scope.
Definition: control_fixed_modes.hpp:12