Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
Classes | Enumerations | Functions | Variables
lampda::logic::alerts Namespace Reference

Handle the system alerts, that are displayed on the RGB indicator. More...

Classes

struct  Alert_BatteryCritical
 This alert is raised when the battery level falls below a critical threshold. Falling further will dammage the battery. More...
 
struct  Alert_BatteryLow
 This alert is raised when the battery level gets low. More...
 
struct  Alert_BatteryMissing
 This alert is raised when no connected battery is detected. More...
 
struct  Alert_BatteryReadingIncoherent
 This alert is raised when the battery readings do not fit the battery physical model. More...
 
struct  Alert_BluetoothAdvertisement
 This alert is raised when the Bluetooth advertising is turned on. It is just an informative alert. More...
 
struct  Alert_ChargerError
 This alert is raised when the battery charger signals an error. It is not well handled at the moment, so it does not block anything. More...
 
struct  Alert_FavoriteSet
 This alert is raised when new favorite mode is added. More...
 
struct  Alert_HardwareAlert
 This alert is raised when a problem is detected in the hardware. Usually, it means that an electrical component may have become unresponsive. More...
 
struct  Alert_LongLoopUpdate
 This alert is raised when the main loop becomes slower than the defined behavior. This is not a critical alert, but it sually indicates that the user mode in use is too slow. More...
 
struct  Alert_MainLoopFreeze
 This alert is raised when the main loop becomes unresponsive. More...
 
struct  Alert_OtgFailed
 This alert is raised when the output power fails to start. It can happen with logic bugs, or if the output rail is shorted. More...
 
struct  Alert_OtgOverLimits
 This alert is raised when the output power goes out of the limits : overcurrent or overvoltage. Clear on total reboot. More...
 
struct  Alert_SkippedCleanSleep
 This alert is raised when the system starts without sleeping cleanly first. It appears after updates, crashes, power failures, ... More...
 
struct  Alert_SunsetTimerSet
 This alert is raised when the sunset timer is active. It means that the system will turn off on it's own after a delay. More...
 
struct  Alert_SystemInErrorState
 This alert is raised when the system falls into an unrecoverable state. It can be raised by logic error, or detected bugs at program start. More...
 
struct  Alert_SystemInLockout
 This alert is raised when the user tries to power the system as it is in lockout mode. More...
 
struct  Alert_SystemShutdownFailed
 This alert is raised when the system fails to go to sleep. There is no way to recover from this, as we depend on the low level handlers for this functionality. More...
 
struct  Alert_TempCritical
 This alert is raised when the temperature gets too high. If it keeps climbing, the components will get dammaged. More...
 
struct  Alert_TempTooHigh
 This alert is raised when the internal temperature gets high. If it keeps rising, the battery may get dammaged. More...
 
struct  Alert_UsbPortShort
 This alert is raised when a short circuit is detected in the USB lines. The port should be cleaned before using it again. More...
 
struct  AlertBase
 Base class for all alerts. Must be overloaded to define an alert. More...
 
class  AlertManager_t
 Handle the whole alerts logic. Use this to raise and clear alerts, and make decisions based on those alerts. Alerts can be raised and cleared on their own. More...
 
struct  RaiseTimeLock
 Hold _raiseTimeMutex for the scope. More...
 

Enumerations

enum class  Type : uint32_t {
  MAIN_LOOP_FREEZE = 1 << 0 , BATTERY_READINGS_INCOHERENT = 1 << 1 , BATTERY_CRITICAL = 1 << 2 , BATTERY_LOW = 1 << 3 ,
  LONG_LOOP_UPDATE = 1 << 4 , TEMP_TOO_HIGH = 1 << 5 , TEMP_CRITICAL = 1 << 6 , BLUETOOTH_ADVERT = 1 << 7 ,
  HARDWARE_ALERT = 1 << 8 , FAVORITE_SET = 1 << 9 , OTG_FAILED = 1 << 10 , SYSTEM_OFF_FAILED = 1 << 11 ,
  SYSTEM_IN_ERROR_STATE = 1 << 12 , SYSTEM_IN_LOCKOUT = 1 << 13 , SUNSET_TIMER_ENABLED = 1 << 14 , SYSTEM_SLEEP_SKIPPED = 1 << 15 ,
  USB_PORT_SHORT = 1 << 16 , BATTERY_MISSING = 1 << 17 , CHARGER_ERROR = 1 << 18 , OTG_OVER_LIMITS = 1 << 19
}
 Alert types : 31 errors max. More...
 

Functions

bool is_battery_alert_ready ()
 Return true if we are ready to display battery alerts.
 
const char * AlertsToText (const Type type)
 Convert alerts enums to text.
 
void signal_usb_port_fault ()
 Signal a fault of the USB port protection. Safe to call from an interrupt: it only sets a flag. The USB_PORT_SHORT alert is raised (or refreshed) by the next process_interrupt_signals() call.
 
void process_interrupt_signals ()
 Raise the alerts signaled from interrupts since the last call. Called by the alerts loop and the power thread.
 
void update_alerts ()
 
void signal_wake_up_from_charger ()
 Signal slot that the system just powered up from charger.
 
brightness_t get_alerts_max_brightness ()
 Return the max output brightness allowed by the raised alerts (the lowest of their limits)
 
void handle_all (const bool shouldIgnoreAlerts)
 handle the behavior for all alerts. Must be called often
 
void show_all ()
 show all the raised alerts in Serial debug
 
bool is_request_shutdown ()
 Return true if an alert requested an immediate shutdown. Handling this is urgent or dammages can happen.
 

Variables

AlertManager_t manager
 Instanciation of the AlertManager.
 
static hal::mutex::hal_mutex_t _raiseTimeMutex
 Guards the raise times of all alerts (AlertBase::raisedTime): refreshed by raise() from any thread (power thread, BLE, ...), while the main loop takes its timeout decisions on them. The elapsed times are computed under the lock, so a refresh can never be seen as "in the future" of the decision. Not recursive.
 
static const bool _isRaiseTimeMutexInit = (hal::mutex::hal_mutex_init(&_raiseTimeMutex), true)
 Initialized at program start: alerts can be raised before the main setup.
 
bool _request_shutdown = false
 Set to true if an alert requested an emmergency shutdown.
 
uint32_t _startupChargerTime = 0
 Stay at zero in normal operation. Set to the real startup time to ignore the battery alerts while the system starts.
 
static Alert_SystemShutdownFailed alertSystemShutdownFailed {}
 
static Alert_BatteryMissing alertBatteryMissing {}
 
static Alert_HardwareAlert alertHardwareAlert {}
 
static Alert_TempCritical alertTempCritical {}
 
static Alert_UsbPortShort alertUsbPortShort {}
 
static Alert_SkippedCleanSleep alertSkippedCleanSleep {}
 
static Alert_OtgOverLimits alert_OtgOverLimits {}
 
static Alert_BatteryCritical alertBatteryCritical {}
 
static Alert_TempTooHigh alertTempTooHigh {}
 
static Alert_BatteryReadingIncoherent alertBatteryReadingIncoherent {}
 
static Alert_BatteryLow alertBatteryLow {}
 
static Alert_OtgFailed alertOtgFailed {}
 
static Alert_SystemInErrorState alertSystemInErrorState {}
 
static Alert_SystemInLockout alertSystemInLockout {}
 
static Alert_LongLoopUpdate alertLongLoopUpdate {}
 
static Alert_BluetoothAdvertisement alertBluetoothAdvertisement {}
 
static Alert_FavoriteSet alertFavoriteSet {}
 
static Alert_SunsetTimerSet alertSunsetTimerSet {}
 
static Alert_ChargerError alertChargerError {}
 
static AlertBase *const allAlerts []
 Alerts must be sorted by importance, only the first activated one will be shown.
 
static std::atomic< bool > _isUsbPortFaultSignaled {false}
 Set by signal_usb_port_fault(), from the USB fault interrupt. Consumed by process_interrupt_signals()
 

Detailed Description

Handle the system alerts, that are displayed on the RGB indicator.

Enumeration Type Documentation

◆ Type

enum class lampda::logic::alerts::Type : uint32_t
strong

Alert types : 31 errors max.

Enumerator
OTG_OVER_LIMITS 

OTG has gone over the limits (current or voltage)

Variable Documentation

◆ allAlerts

AlertBase* const lampda::logic::alerts::allAlerts[]
inlinestatic
Initial value:
= {
&alertSystemShutdownFailed,
&alertBatteryMissing,
&alertHardwareAlert,
&alertTempCritical,
&alertUsbPortShort,
&alertSkippedCleanSleep,
&alertBatteryCritical,
&alertTempTooHigh,
&alertBatteryReadingIncoherent,
&alertBatteryLow,
&alert_OtgOverLimits,
&alertOtgFailed,
&alertSystemInErrorState,
&alertSystemInLockout,
&alertLongLoopUpdate,
&alertBluetoothAdvertisement,
&alertFavoriteSet,
&alertSunsetTimerSet,
&alertChargerError,
}

Alerts must be sorted by importance, only the first activated one will be shown.

◆ manager

AlertManager_t lampda::logic::alerts::manager

Instanciation of the AlertManager.

external global reference to the AlertManager