CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
SleepManager.h
Go to the documentation of this file.
1#pragma once
2
4#include <cstdint>
5
6// Forward declarations
7namespace cdc::ui {
9}
10namespace cdc::hal {
11class IPowerManager;
12}
13
14namespace cdc::ui {
15
16// Light sleep timeout (seconds after which lock screen enters light sleep)
17static constexpr uint32_t LIGHT_SLEEP_TIMEOUT_MS = 120 * 1000;
18
19// Maximum number of sleep inhibitors
20static constexpr uint8_t MAX_SLEEP_INHIBITORS = 8;
21
22// Light sleep management for lock screen
23class SleepManager {
24public:
25 static SleepManager& instance();
26
27 // Initialize with dependencies
28 void init(hal::ISleepController* sleep, hal::IPowerManager* power, LockScreenView* lockScreen);
29
30 // Check if should enter sleep (call from ui_process when on lock screen)
31 void checkLockScreenSleep(uint32_t nowMs);
32
33 // Reset the sleep timer (on key press or activity)
34 void resetTimer(uint32_t nowMs);
35
36 // Reset timer to current time
37 void resetTimer();
38
39 // Check if currently in light sleep
40 bool isInLightSleep() const { return inLightSleep_; }
41
42 // === Sleep Inhibitor API ===
43
49 bool addSleepInhibitor(const char* reason);
50
56 bool removeSleepInhibitor(const char* reason);
57
61 bool isSleepInhibited() const { return inhibitorCount_ > 0; }
62
66 uint8_t getInhibitorCount() const { return inhibitorCount_; }
67
68private:
69 SleepManager() = default;
70
71 void enterLockScreenSleep();
72 bool handleWakeup();
73 void updateCaffeinatedIcon();
74
75 hal::ISleepController* sleep_ = nullptr;
76 hal::IPowerManager* power_ = nullptr;
77 LockScreenView* lockScreen_ = nullptr;
78
79 uint32_t lockScreenEnteredMs_ = 0;
80 bool inLightSleep_ = false;
81
82 // Sleep inhibitors
83 const char* inhibitors_[MAX_SLEEP_INHIBITORS] = {};
84 uint8_t inhibitorCount_ = 0;
85};
86
87} // namespace cdc::ui
bool isSleepInhibited() const
void resetTimer()
Resets lock-screen sleep timer using current system tick.
void checkLockScreenSleep(uint32_t nowMs)
Evaluates whether lock-screen light sleep should be entered.
bool addSleepInhibitor(const char *reason)
Sleep inhibitor API implementation.
static SleepManager & instance()
Returns singleton sleep manager instance.
bool removeSleepInhibitor(const char *reason)
Removes a sleep inhibitor reason.
bool isInLightSleep() const
void init(hal::ISleepController *sleep, hal::IPowerManager *power, LockScreenView *lockScreen)
Initializes sleep-manager dependencies and state.
uint8_t getInhibitorCount() const
Centralized key-code constants for cdc_views.
Definition IModule.h:8
static constexpr uint8_t MAX_SLEEP_INHIBITORS
static constexpr uint32_t LIGHT_SLEEP_TIMEOUT_MS