Complete proxy functions in Power.h and refactor (mainly reorder) for clarity.

This commit is contained in:
Phillip Kühne 2025-02-12 17:42:22 +01:00
parent 8617f420a2
commit d64579eca4
Signed by: phillip
GPG Key ID: E4C1C4D2F90902AA
4 changed files with 68 additions and 39 deletions

View File

@ -26,8 +26,12 @@ void Power::begin() {
} }
} }
uint16_t Power::getFreeCurrentBudget(void) { float Power::getFreeLimitCurrentBudget() {
return powerScheduler->getFreeCurrentBudget(); return powerScheduler->getFreeLimitCurrentBudget();
}
float Power::getFreeMaximumCurrentBudget() {
return powerScheduler->getFreeMaximumCurrentBudget();
} }
bool Power::tryAccquireCurrentAllowance( bool Power::tryAccquireCurrentAllowance(
@ -37,20 +41,32 @@ bool Power::tryAccquireCurrentAllowance(
requestedDurationMs); requestedDurationMs);
} }
void Power::releaseCurrent(PowerParameters::PowerConsumers consumer) {
powerScheduler->releaseCurrent(consumer);
}
bool Power::waitForCurrentAllowance(PowerParameters::PowerConsumers consumer, bool Power::waitForCurrentAllowance(PowerParameters::PowerConsumers consumer,
uint16_t neededCurrent, uint16_t neededCurrent,
TickType_t TicksToWait, uint16_t maxSlackTimeMs,
uint16_t requestedDurationMs) { uint16_t requestedDurationMs) {
return powerScheduler->waitForCurrentAllowance( return powerScheduler->waitForCurrentAllowance(
consumer, neededCurrent, TicksToWait, requestedDurationMs); consumer, neededCurrent, maxSlackTimeMs, requestedDurationMs);
} }
void Power::beginPermanentDeepSleep(void) { void Power::beginPermanentDeepSleep(void) {
return powerScheduler->beginPermanentDeepSleep(); return powerScheduler->beginPermanentDeepSleep();
} }
void Power::releaseCurrent(PowerParameters::PowerConsumers consumer) { float Power::getCurrentCurrent(void) {
powerScheduler->releaseCurrent(consumer); return powerScheduler->getCurrentCurrent();
}
void Power::recalculateCurrentBudgets(void) {
return powerScheduler->recalculateCurrentBudgets();
}
float Power::getConsumerCurrent(PowerParameters::PowerConsumers consumer) {
return powerScheduler->getConsumerCurrent(consumer);
} }
float Power::getBatteryVoltage() { float Power::getBatteryVoltage() {
@ -73,19 +89,13 @@ float Power::getBatteryVoltage() {
return batteryVoltage; return batteryVoltage;
} }
int Power::getBatteryChargePercent() { int Power::getBatteryChargePercent() { return percentRemaining; }
return percentRemaining;
}
float Power::getBatteryChargeCoulombs() {
return coloumbsRemaining;
}
float Power::getBatteryChargeCoulombs() { return coloumbsRemaining; }
int Power::getBatteryVoltageChargePercent() { int Power::getBatteryVoltageChargePercent() {
// Get the battery voltage and calculate the charge state based on the // Directly get the battery voltage and calculate the charge state based on
// discharge curve. // the discharge curve.
float batteryVoltage = getBatteryVoltage(); float batteryVoltage = getBatteryVoltage();
float chargeState = 0; float chargeState = 0;
// Clamp edge cases // Clamp edge cases
@ -161,7 +171,6 @@ void Power::updatePowerStateHandler() {
powerScheduler->recalculateCurrentBudgets(); powerScheduler->recalculateCurrentBudgets();
return; return;
} }
float Power::getMax3V3Current() { float Power::getMax3V3Current() {
@ -173,7 +182,8 @@ float Power::getMax3V3Current() {
} }
void Power::addSoCSample(float soc) { void Power::addSoCSample(float soc) {
latestSoCIndex = (latestSoCIndex + 1) % PowerParameters::Battery::AVERAGING_SAMPLES; latestSoCIndex =
(latestSoCIndex + 1) % PowerParameters::Battery::AVERAGING_SAMPLES;
lastSOC[latestSoCIndex] = soc; lastSOC[latestSoCIndex] = soc;
} }

View File

@ -18,33 +18,52 @@ class Power {
public: public:
static void begin(void); static void begin(void);
Power(); Power();
uint16_t getFreeCurrentBudget(void); /// @brief Get the current free current budget (to C1 discharge)
/// @brief Request an allowance of a certain number of milliwatts from the /// @return the amount of power that is currently available (in mA)
/// power scheduler static float getFreeLimitCurrentBudget(void);
/// @param neededPower the amount of power we want to be accounted for (in mW) /// @brief Get the current hard maximum free current (to C2 discharge)
/// @return whether the power could be successfully allocated /// @return the maximum amount of power that can be allocated (in mA)
static bool static float getFreeMaximumCurrentBudget(void);
tryAccquireCurrentAllowance(PowerParameters::PowerConsumers consumer,
uint16_t neededCurrent, /// @brief Request an allowance of a certain number of milliamperes from the
uint16_t requestedDurationMs); /// power scheduler without waiting for it (meaning it will not be scheduled
/// @brief "Return" the power consumed by an active consumer /// for future allocation). Only one can be active per consumer.
/// @param neededPower the amount of power to return (in mW) /// @param neededCurrent the amount of current we want to be accounted for (in
/// @return whether the power /// mA)
/// @return whether the current could be successfully allocated
static bool tryAccquireCurrentAllowance(PowerParameters::PowerConsumers consumer,
uint16_t neededcurrent,
uint16_t requestedDurationMs = 0);
/// @brief "Return" the current currently allocated to a consumer
/// @param consumer the active consumer to release the current for
static void releaseCurrent(PowerParameters::PowerConsumers consumer); static void releaseCurrent(PowerParameters::PowerConsumers consumer);
/// @brief Wait for a certain amount of power to be available /// @brief Wait for a certain amount of current to be available. This will
/// @param neededPower the amount of power we want to be accounted for (in mW) /// "reseve a spot in the queue". Only one can be active per consumer.
/// @param neededCurrent 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 /// @param TicksToWait the amount of time to wait for the power to become
/// available /// available
/// @return whether the power could be successfully allocatedy /// @return whether the power could be successfully allocatedy
static bool waitForCurrentAllowance(PowerParameters::PowerConsumers consumer, static bool waitForCurrentAllowance(PowerParameters::PowerConsumers consumer,
uint16_t neededCurrent, uint16_t neededCurrent,
TickType_t TicksToWait, uint16_t maxSlackTimeMs,
uint16_t requestedDurationMs); uint16_t requestedDurationMs);
/// @brief Put the ESP32 into deep sleep mode, without a method to wake up /// @brief Put the ESP32 into deep sleep mode, without a method to wake up
/// again. Basically this is a shutdown. /// again. Basically this is a shutdown.
static void beginPermanentDeepSleep(void); static void beginPermanentDeepSleep(void);
//// @brief Get currently granted power
/// @return the amount of power that is currently allocated (in mA)
static float getCurrentCurrent(void);
// @brief Responsible for recalculating the current budgets
static void recalculateCurrentBudgets(void);
// @brief Get current consumption of a consumer
static float getConsumerCurrent(PowerParameters::PowerConsumers consumer);
/// @brief Get battery voltage measurement. /// @brief Get battery voltage measurement.
/// @return Battery Terminal Voltage in Volts /// @return Battery Terminal Voltage in Volts
static float getBatteryVoltage(); static float getBatteryVoltage();

View File

@ -230,11 +230,11 @@ float PowerScheduler::getCurrentCurrent(void) {
return currentSum; return currentSum;
} }
float PowerScheduler::getFreeCurrentBudget(void) { float PowerScheduler::getFreeLimitCurrentBudget(void) {
return this->freeLimitCurrentBudget; return this->freeLimitCurrentBudget;
} }
float PowerScheduler::getFreeHardMaxCurrent(void) { float PowerScheduler::getFreeMaximumCurrentBudget(void) {
return this->freeMaximumCurrentBudget; return this->freeMaximumCurrentBudget;
} }

View File

@ -32,10 +32,10 @@ public:
float i_max_ma = 0); float i_max_ma = 0);
/// @brief Get the current free current budget (to C1 discharge) /// @brief Get the current free current budget (to C1 discharge)
/// @return the amount of power that is currently available (in mA) /// @return the amount of power that is currently available (in mA)
float getFreeCurrentBudget(void); float getFreeLimitCurrentBudget(void);
/// @brief Get the current hard maximum free current (to C2 discharge) /// @brief Get the current hard maximum free current (to C2 discharge)
/// @return the maximum amount of power that can be allocated (in mA) /// @return the maximum amount of power that can be allocated (in mA)
float getFreeHardMaxCurrent(void); float getFreeMaximumCurrentBudget(void);
/// @brief Request an allowance of a certain number of milliamperes from the /// @brief Request an allowance of a certain number of milliamperes from the
/// power scheduler without waiting for it (meaning it will not be scheduled /// power scheduler without waiting for it (meaning it will not be scheduled