27 lines
740 B
C++
27 lines
740 B
C++
#pragma once
|
|
|
|
#include <Arduino.h>
|
|
#include "../sensors/BatterySensor.h"
|
|
#include "../ui/Display.h"
|
|
|
|
class PowerManager {
|
|
public:
|
|
void begin(unsigned long bootMs);
|
|
void setBatteryAwakeWindowMs(unsigned long windowMs);
|
|
void loop(const BatterySensor& battery);
|
|
|
|
bool isPluggedIn() const { return _pluggedIn; }
|
|
bool batteryWindowElapsed(unsigned long nowMs) const;
|
|
|
|
void deepSleepForSeconds(uint32_t seconds, const char* reason, Display* display = nullptr) const;
|
|
|
|
private:
|
|
bool detectPluggedIn(const BatterySensor& battery) const;
|
|
|
|
bool _pluggedIn = true;
|
|
bool _plugStateInitialized = false;
|
|
unsigned long _bootMs = 0;
|
|
unsigned long _onBatterySinceMs = 0;
|
|
unsigned long _batteryAwakeWindowMs = 2UL * 60UL * 1000UL;
|
|
};
|