Add Power Scheduler
This commit is contained in:
@@ -13,38 +13,77 @@
|
||||
|
||||
#define TOTAL_POWER_MILLIWATTS POWER_BUDGET
|
||||
|
||||
enum TaskResumptionReason
|
||||
{
|
||||
POWER_AVAILABLE,
|
||||
TIMEOUT
|
||||
};
|
||||
enum TaskResumptionReason { POWER_AVAILABLE, TIMEOUT };
|
||||
|
||||
class Power
|
||||
{
|
||||
class Power {
|
||||
|
||||
public:
|
||||
static void begin();
|
||||
Power();
|
||||
uint16_t getFreePowerBudget(void);
|
||||
/// @brief Request an allowance of a certain number of milliwatts from the power scheduler
|
||||
/// @param neededPower the amount of power we want to be accounted for (in mW)
|
||||
/// @return whether the power could be successfully allocated
|
||||
bool tryAccquirePowerAllowance(uint16_t neededPower);
|
||||
/// @brief "Return" a certain amount of power when it is no longer needed
|
||||
/// @param neededPower the amount of power to return (in mW)
|
||||
/// @return whether the power
|
||||
void releasePower(uint16_t power);
|
||||
static void begin(void);
|
||||
Power();
|
||||
uint16_t getFreeCurrentBudget(void);
|
||||
/// @brief Request an allowance of a certain number of milliwatts from the
|
||||
/// power scheduler
|
||||
/// @param neededPower the amount of power we want to be accounted for (in mW)
|
||||
/// @return whether the power could be successfully allocated
|
||||
static bool
|
||||
tryAccquireCurrentAllowance(PowerParameters::PowerConsumers consumer,
|
||||
uint16_t neededCurrent,
|
||||
uint16_t requestedDurationMs);
|
||||
/// @brief "Return" the power consumed by an active consumer
|
||||
/// @param neededPower the amount of power to return (in mW)
|
||||
/// @return whether the power
|
||||
static void releaseCurrent(PowerParameters::PowerConsumers consumer);
|
||||
|
||||
/// @brief Wait for a certain amount of power to be available
|
||||
/// @param neededPower the amount of power we want to be accounted for (in mW)
|
||||
/// @param TicksToWait the amount of time to wait for the power to become available
|
||||
/// @return whether the power could be successfully allocatedy
|
||||
bool waitForPowerAllowance(uint16_t neededPower, TickType_t TicksToWait);
|
||||
/// @brief Put the ESP32 into deep sleep mode, without a method to wake up again. Basically this is a shutdown.
|
||||
void beginPermanentDeepSleep(void);
|
||||
/// @brief Wait for a certain amount of power to be available
|
||||
/// @param neededPower the amount of power we want to be accounted for (in mW)
|
||||
/// @param TicksToWait the amount of time to wait for the power to become
|
||||
/// available
|
||||
/// @return whether the power could be successfully allocatedy
|
||||
static bool waitForCurrentAllowance(PowerParameters::PowerConsumers consumer,
|
||||
uint16_t neededCurrent,
|
||||
TickType_t TicksToWait,
|
||||
uint16_t requestedDurationMs);
|
||||
/// @brief Put the ESP32 into deep sleep mode, without a method to wake up
|
||||
/// again. Basically this is a shutdown.
|
||||
static void beginPermanentDeepSleep(void);
|
||||
|
||||
/// @brief Get battery voltage measurement.
|
||||
/// @return Battery Terminal Voltage in Volts
|
||||
static float getBatteryVoltage();
|
||||
|
||||
/// @brief Get estimated battery charge state as percentage
|
||||
/// @return Battery charge state in percent
|
||||
static int getBatteryChargePercent();
|
||||
|
||||
/// @brief Get estimated battery charge state as coulombs
|
||||
/// @return Battery charge state in coulombs
|
||||
static float getBatteryChargeCoulombs();
|
||||
|
||||
/// @brief get available current (after voltage conversion and efficiency
|
||||
/// losses, referencing 1C discharge)
|
||||
/// @return available current in milliamps
|
||||
static float getAvailableCurrent();
|
||||
|
||||
protected:
|
||||
static PowerScheduler *powerScheduler;
|
||||
/// @brief PowerScheduler instance to manage power consumption
|
||||
static PowerScheduler *powerScheduler;
|
||||
|
||||
/// @brief update Power State
|
||||
static void updatePowerState();
|
||||
|
||||
/*
|
||||
* Power State
|
||||
*/
|
||||
|
||||
/// @brief remaining Charge in coulombs
|
||||
static int coloumbsRemaining;
|
||||
|
||||
/// @brief remaining Charge in percent
|
||||
static int percentRemaining;
|
||||
|
||||
friend class PowerScheduler;
|
||||
};
|
||||
|
||||
extern Power power;
|
||||
|
||||
#endif // Power
|
||||
Reference in New Issue
Block a user