Add special case for small power requests

This commit is contained in:
Phillip Kühne 2025-02-12 16:27:54 +01:00
parent c63935a413
commit 8617f420a2
Signed by: phillip
GPG Key ID: E4C1C4D2F90902AA
2 changed files with 24 additions and 5 deletions

View File

@ -79,6 +79,13 @@ namespace PowerParameters {
static constexpr float CURRENT_UV_LED = 200; static constexpr float CURRENT_UV_LED = 200;
}; };
/*
* Single consumer current limit up to which requests are granted no matter what.
* The idea is, that this will allow Sensors (with their miniscule power draw)
* to always be granted power, which should massively improve behaviour.
*/
static constexpr float CURRENT_INSIGNIFICANT = 1;
struct PinConfig { struct PinConfig {
static constexpr int BAT_ADC = 10; static constexpr int BAT_ADC = 10;
static constexpr int BAT_ADC_EN = 9; static constexpr int BAT_ADC_EN = 9;

View File

@ -18,8 +18,13 @@ bool PowerScheduler::tryAccquireCurrentAllowance(
uint16_t requestedDurationMs) { uint16_t requestedDurationMs) {
portENTER_CRITICAL(&mux); portENTER_CRITICAL(&mux);
float existingConsumption = getConsumerCurrent(consumer); float existingConsumption = getConsumerCurrent(consumer);
if ((this->freeLimitCurrentBudget + existingConsumption) > 0 && const bool currentAvailableBelowLimit =
(this->freeMaximumCurrentBudget + existingConsumption) >= neededCurrent) { this->freeLimitCurrentBudget + existingConsumption > 0;
const bool currentAvailableBelowMaximum =
this->freeMaximumCurrentBudget + existingConsumption >= neededCurrent;
const bool currentIsInsignificant = neededCurrent < 0.1;
if (currentIsInsignificant ||
(currentAvailableBelowLimit && currentAvailableBelowMaximum)) {
if (existingConsumption > 0) { if (existingConsumption > 0) {
releaseCurrent(consumer); releaseCurrent(consumer);
} }
@ -85,10 +90,17 @@ bool PowerScheduler::waitForCurrentAllowance(
PowerScheduler::PowerWakeupReasons::POWER_AVAILABLE) { PowerScheduler::PowerWakeupReasons::POWER_AVAILABLE) {
// We were woken up because new power is available, check if it is // We were woken up because new power is available, check if it is
// enough // enough
// Exclude existing consumption from the same consumer, as it will be
// gone if this is granted
float existingConsumption = getConsumerCurrent(consumer); float existingConsumption = getConsumerCurrent(consumer);
if ((this->freeLimitCurrentBudget + existingConsumption) > 0 && const bool currentAvailableBelowLimit =
(this->freeMaximumCurrentBudget + existingConsumption) >= this->freeLimitCurrentBudget + existingConsumption > 0;
neededCurrent) { const bool currentAvailableBelowMaximum =
this->freeMaximumCurrentBudget + existingConsumption >=
neededCurrent;
const bool currentIsInsignificant = neededCurrent < 0.1;
if (currentIsInsignificant ||
(currentAvailableBelowLimit && currentAvailableBelowMaximum)) {
// TODO Check if there is a currently active allowance for this // TODO Check if there is a currently active allowance for this
// consumer and if so, replace it with the new one // consumer and if so, replace it with the new one
if (existingConsumption > 0) { if (existingConsumption > 0) {