mirror of
https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
synced 2025-05-19 11:01:46 +02:00
Add special case for small power requests
This commit is contained in:
parent
c63935a413
commit
8617f420a2
@ -79,6 +79,13 @@ namespace PowerParameters {
|
||||
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 {
|
||||
static constexpr int BAT_ADC = 10;
|
||||
static constexpr int BAT_ADC_EN = 9;
|
||||
|
@ -18,8 +18,13 @@ bool PowerScheduler::tryAccquireCurrentAllowance(
|
||||
uint16_t requestedDurationMs) {
|
||||
portENTER_CRITICAL(&mux);
|
||||
float existingConsumption = getConsumerCurrent(consumer);
|
||||
if ((this->freeLimitCurrentBudget + existingConsumption) > 0 &&
|
||||
(this->freeMaximumCurrentBudget + existingConsumption) >= neededCurrent) {
|
||||
const bool currentAvailableBelowLimit =
|
||||
this->freeLimitCurrentBudget + existingConsumption > 0;
|
||||
const bool currentAvailableBelowMaximum =
|
||||
this->freeMaximumCurrentBudget + existingConsumption >= neededCurrent;
|
||||
const bool currentIsInsignificant = neededCurrent < 0.1;
|
||||
if (currentIsInsignificant ||
|
||||
(currentAvailableBelowLimit && currentAvailableBelowMaximum)) {
|
||||
if (existingConsumption > 0) {
|
||||
releaseCurrent(consumer);
|
||||
}
|
||||
@ -85,10 +90,17 @@ bool PowerScheduler::waitForCurrentAllowance(
|
||||
PowerScheduler::PowerWakeupReasons::POWER_AVAILABLE) {
|
||||
// We were woken up because new power is available, check if it is
|
||||
// enough
|
||||
// Exclude existing consumption from the same consumer, as it will be
|
||||
// gone if this is granted
|
||||
float existingConsumption = getConsumerCurrent(consumer);
|
||||
if ((this->freeLimitCurrentBudget + existingConsumption) > 0 &&
|
||||
(this->freeMaximumCurrentBudget + existingConsumption) >=
|
||||
neededCurrent) {
|
||||
const bool currentAvailableBelowLimit =
|
||||
this->freeLimitCurrentBudget + existingConsumption > 0;
|
||||
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
|
||||
// consumer and if so, replace it with the new one
|
||||
if (existingConsumption > 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user