dezibot/src/power/Power.cpp

51 lines
1.2 KiB
C++

/**
* @file Power.h
* @author Phillip Kühne
* @brief This component provides utilities for keeping track of power usage
* consumption.
* @version 0.1
* @date 2024-11-23
*/
#include "Power.h"
static portMUX_TYPE mux;
void Power::begin()
{
// Check if another instance of us already initialized the power scheduler,
// if not, we will do it.
if (powerScheduler == nullptr)
{
powerScheduler = PowerScheduler::getPowerScheduler();
if (!(powerScheduler->tryAccquirePowerAllowance(CONSUMPTION_ESP_BASE)))
{
Serial.println("Alledgedly not enough power available to reserve the ESP32s base power consumption. Something is wrong.");
return;
}
}
}
uint16_t Power::getFreePowerBudget(void)
{
return powerScheduler->getFreePowerBudget();
}
bool Power::tryAccquirePowerAllowance(uint16_t neededPower)
{
return powerScheduler->tryAccquirePowerAllowance(neededPower);
}
bool Power::waitForPowerAllowance(uint16_t neededPower, TickType_t TicksToWait)
{
return powerScheduler->waitForPowerAllowance(neededPower, TicksToWait);
}
void Power::beginPermanentDeepSleep(void)
{
return powerScheduler->beginPermanentDeepSleep();
}
void Power::releasePower(uint16_t power)
{
}