|
Ersa Wearable Platform
Embedded smartwatch firmware and application framework
|
#include <power_manager.h>

Public Member Functions | |
| PowerManager (hal::IBattery &battery, events::EventBus &bus=events::EventBus::instance()) | |
| Result< void > | init () |
| void | tick (uint32_t currentUptimeMs) |
| uint32_t | nextBatterySampleDelayMs (uint32_t currentUptimeMs) const |
| WakeLock | acquireWakeLock (const char *tag) |
| bool | acquireWakeLockRaw (const char *tag) |
| bool | releaseWakeLockRaw (const char *tag) |
| size_t | getActiveWakeLockCount () const |
| Return the number of active wake locks. | |
| bool | hasWakeLocks () const |
| Return whether at least one wake lock blocks sleep. | |
| void | noteActivity (uint32_t currentUptimeMs) |
| uint32_t | getIdleTimeMs (uint32_t currentUptimeMs) const |
| uint16_t | getBatteryMv () const |
| Return the latest battery voltage in millivolts. | |
| uint32_t | getBatterySampleAgeMs (uint32_t nowMs) const |
| Return the age of the most recent battery sample in milliseconds. | |
| bool | hasBatterySample () const |
| Return whether at least one battery sample has been recorded. | |
| uint8_t | getBatteryPercent () const |
| Return estimated battery charge as a percentage. | |
| bool | isBatteryConnected () const |
| Return whether a usable battery is connected. | |
| bool | isCharging () const |
| Return whether external charging power is present. | |
| BatteryPowerLevel | getBatteryPowerLevel () const |
| PowerState | getState () const |
| Return the current service-level power state. | |
| void | requestState (PowerState state) |
| Set the service-level power state. | |
| bool | canSleep () const |
| void | enterDeepSleep (uint64_t sleepTimeUs=0) |
Static Public Member Functions | |
| static PowerManager & | instance () |
| Return the installed process-wide power manager. | |
| static void | setInstance (PowerManager *instance) |
| Install the process-wide power manager. | |
Static Public Attributes | |
| static constexpr size_t | MAX_WAKE_LOCKS = 16 |
| static constexpr uint32_t | DEEP_SLEEP_TIMEOUT_MS = 60000 |
| static constexpr uint8_t | LOW_BATTERY_PERCENT = 20 |
| static constexpr uint16_t | LOW_BATTERY_MV = 3600 |
| static constexpr uint8_t | CRITICAL_BATTERY_PERCENT = 3 |
| static constexpr uint16_t | CRITICAL_BATTERY_MV = 3350 |
Private Member Functions | |
| uint32_t | batterySampleIntervalMs () const |
Private Attributes | |
| hal::IBattery & | battery_ |
| events::EventBus & | bus_ |
| PowerState | state_ {PowerState::Active} |
| uint32_t | lastActivityMs_ {0} |
| uint32_t | lastBatterySampleMs_ {0} |
| uint16_t | cachedMv_ {0} |
| uint8_t | cachedPercent_ {100} |
| bool | cachedConnected_ {false} |
| bool | cachedCharging_ {false} |
| BatteryPowerLevel | batteryPowerLevel_ {BatteryPowerLevel::Normal} |
| uint8_t | criticalSampleCount_ {0} |
| const char * | wakeLockTags_ [MAX_WAKE_LOCKS] |
| uint16_t | wakeLockReferences_ [MAX_WAKE_LOCKS] |
| size_t | activeWakeLocks_ {0} |
Applies battery qualification, wake-lock accounting, and sleep eligibility. Product-level policy is kept here while IPowerManagement owns clocks, GPIO wake sources, and chip sleep APIs. This separation makes thresholds and activity decisions host-testable and keeps app code from bypassing radio coordination in the platform layer.
|
explicit |
Bind the battery HAL and event bus; neither is owned by the manager.
| WakeLock ersa::services::PowerManager::acquireWakeLock | ( | const char * | tag | ) |
Prefer this scoped lease when the protected operation has lexical lifetime.
| bool ersa::services::PowerManager::acquireWakeLockRaw | ( | const char * | tag | ) |
Manually acquire a tagged lease for state spanning multiple callbacks.
|
private |
| bool ersa::services::PowerManager::canSleep | ( | ) | const |
True only when no active feature lease blocks automatic sleep.
| void ersa::services::PowerManager::enterDeepSleep | ( | uint64_t | sleepTimeUs = 0 | ) |
Delegate deep sleep; zero timer leaves configured GPIO wakes as sources.
| size_t ersa::services::PowerManager::getActiveWakeLockCount | ( | ) | const |
Return the number of active wake locks.
| uint16_t ersa::services::PowerManager::getBatteryMv | ( | ) | const |
Return the latest battery voltage in millivolts.
| uint8_t ersa::services::PowerManager::getBatteryPercent | ( | ) | const |
Return estimated battery charge as a percentage.
| BatteryPowerLevel ersa::services::PowerManager::getBatteryPowerLevel | ( | ) | const |
Return the filtered battery band used by user alerts and sleep policy.
|
inline |
Return the age of the most recent battery sample in milliseconds.
| uint32_t ersa::services::PowerManager::getIdleTimeMs | ( | uint32_t | currentUptimeMs | ) | const |
Compute wrap-safe idle duration from the last recorded activity.
| PowerState ersa::services::PowerManager::getState | ( | ) | const |
Return the current service-level power state.
|
inline |
Return whether at least one battery sample has been recorded.
| bool ersa::services::PowerManager::hasWakeLocks | ( | ) | const |
Return whether at least one wake lock blocks sleep.
| Result< void > ersa::services::PowerManager::init | ( | ) |
Sample once, seed cached telemetry, and establish initial severity.
|
static |
Return the installed process-wide power manager.
| bool ersa::services::PowerManager::isBatteryConnected | ( | ) | const |
Return whether a usable battery is connected.
| bool ersa::services::PowerManager::isCharging | ( | ) | const |
Return whether external charging power is present.
| uint32_t ersa::services::PowerManager::nextBatterySampleDelayMs | ( | uint32_t | currentUptimeMs | ) | const |
Return the sample deadline so the UI can sleep until useful work is due.
| void ersa::services::PowerManager::noteActivity | ( | uint32_t | currentUptimeMs | ) |
Reset the idle reference point after interaction or foreground work.
| bool ersa::services::PowerManager::releaseWakeLockRaw | ( | const char * | tag | ) |
Release one matching manual lease; false means the tag was not active.
| void ersa::services::PowerManager::requestState | ( | PowerState | state | ) |
Set the service-level power state.
|
static |
Install the process-wide power manager.
| void ersa::services::PowerManager::tick | ( | uint32_t | currentUptimeMs | ) |
Sample when due, apply hysteresis/critical qualification, and publish state transitions. The explicit uptime makes interval behavior testable without a hardware clock.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticconstexpr |
Voltage threshold used to enter the critical battery band.
|
staticconstexpr |
Percentage threshold used to enter the critical battery band.
|
private |
|
staticconstexpr |
Idle interval relevant to legacy service-level deep-sleep transitions.
|
private |
|
private |
|
staticconstexpr |
Voltage threshold used to enter the low battery band.
|
staticconstexpr |
Percentage threshold used to enter the low battery band.
|
staticconstexpr |
Maximum active lock tags tracked without heap allocation.
|
private |
|
private |
|
private |