Fix mistakes

This commit is contained in:
Phillip Kühne 2025-02-16 01:43:19 +01:00
parent 5efa7a5efd
commit 7a7139360c
Signed by: phillip
GPG Key ID: E4C1C4D2F90902AA
8 changed files with 13 additions and 21 deletions

View File

@ -34,7 +34,7 @@ public:
InfraredLight infraredLight; InfraredLight infraredLight;
Communication communication; Communication communication;
Display display; Display display;
Power power; PowerManager power;
void begin(void); void begin(void);
}; };

View File

@ -73,7 +73,7 @@ public:
* *
* @return * @return
*/ */
float modelCurrentConsumption(); static float modelCurrentConsumption();
/** /**
@ -84,7 +84,7 @@ public:
* @param durationMs * @param durationMs
* @return float * @return float
*/ */
float modelChargeConsumption(uint16_t durationMs); static float modelChargeConsumption(uint16_t durationMs);
protected: protected:
uint16_t readDoubleRegister(uint8_t regAddr); uint16_t readDoubleRegister(uint8_t regAddr);

View File

@ -80,8 +80,6 @@ void InfraredLED::setState(bool state){
void InfraredLED::sendFrequency(uint16_t frequency){ void InfraredLED::sendFrequency(uint16_t frequency){
constexpr uint32_t duty = DUTY_CYCLE_FREQUENCY; constexpr uint32_t duty = DUTY_CYCLE_FREQUENCY;
// Float to force float division without casting
constexpr float resolution = 1 << DUTY_RESOLUTION;
if (this->ledPin == IR_BOTTOM_PIN) { if (this->ledPin == IR_BOTTOM_PIN) {
PowerManager::waitForCurrentAllowance( PowerManager::waitForCurrentAllowance(
PowerParameters::PowerConsumers::LED_IR_BOTTOM, PowerParameters::PowerConsumers::LED_IR_BOTTOM,
@ -111,8 +109,6 @@ float InfraredLED::modelCurrentConsumption(uint32_t duty){
}; };
float InfraredLED::modelChargeConsumptionOn(uint16_t durationMs) { float InfraredLED::modelChargeConsumptionOn(uint16_t durationMs) {
// Float to force float division without casting
constexpr float resolution = 1 << DUTY_RESOLUTION;
if (this->ledPin == IR_BOTTOM_PIN) { if (this->ledPin == IR_BOTTOM_PIN) {
return durationMs * return durationMs *
(PowerParameters::CurrentConsumptions::CURRENT_LED_IR_BOTTOM) / 10e6f; (PowerParameters::CurrentConsumptions::CURRENT_LED_IR_BOTTOM) / 10e6f;
@ -124,8 +120,6 @@ float InfraredLED::modelChargeConsumptionOn(uint16_t durationMs) {
} }
float InfraredLED::modelChargeConsumptionSendFrequency(uint16_t durationMs) { float InfraredLED::modelChargeConsumptionSendFrequency(uint16_t durationMs) {
// Float to force float division without casting return (durationMs * this->modelCurrentConsumption(DUTY_CYCLE_FREQUENCY)) /
return (durationMs * this->modelCurrentConsumption(DUTY_CYCLE_FREQUENCY)) /
10e6f; 10e6f;
} }

View File

@ -79,7 +79,6 @@ class Motor{
uint8_t pin; uint8_t pin;
ledc_timer_t timer; ledc_timer_t timer;
ledc_channel_t channel; ledc_channel_t channel;
Power* powerManager;
uint16_t duty; uint16_t duty;
// The phase of the pwm signal, expressed as a number betweeen 0 and // The phase of the pwm signal, expressed as a number betweeen 0 and
// the maximum value representable by the pwm timer resolution. // the maximum value representable by the pwm timer resolution.

View File

@ -31,7 +31,7 @@ class MultiColorLight {
protected: protected:
static const uint16_t ledAmount = 3; static const uint16_t ledAmount = 3;
static const int16_t ledPin = 48; static const int16_t ledPin = 48;
static const uint8_t maxBrightness = 150; static const uint8_t defaultMaxBrightness = 150;
Adafruit_NeoPixel rgbLeds; Adafruit_NeoPixel rgbLeds;
static constexpr int maximumExecutionDelayMs = 10; static constexpr int maximumExecutionDelayMs = 10;
@ -203,7 +203,7 @@ private:
* can be between 0 - maxBrightness * can be between 0 - maxBrightness
*/ */
uint32_t normalizeColor(uint32_t color, uint32_t normalizeColor(uint32_t color,
uint8_t maxBrigthness = maxBrightness); uint8_t maxBrightness = defaultMaxBrightness);
}; };
#endif // MultiColorLight_h #endif // MultiColorLight_h

View File

@ -14,8 +14,8 @@
#include "driver/adc.h" #include "driver/adc.h"
#include "esp_adc/adc_oneshot.h" #include "esp_adc/adc_oneshot.h"
#include "freertos/semphr.h" #include "freertos/semphr.h"
#ifndef Power_h #ifndef PowerManager_h
#define Power_h #define PowerManager_h
#define TAG "Power" #define TAG "Power"
@ -47,7 +47,7 @@ private:
xSemaphoreGive(mutex); xSemaphoreGive(mutex);
} }
} }
bool isLocked() { return locked; } bool isLocked() const { return locked; }
}; };
protected: protected:
@ -103,7 +103,7 @@ public:
/// @return whether the current could be successfully allocated /// @return whether the current could be successfully allocated
static bool static bool
tryAccquireCurrentAllowance(PowerParameters::PowerConsumers consumer, tryAccquireCurrentAllowance(PowerParameters::PowerConsumers consumer,
uint16_t neededcurrent, uint16_t neededCurrent,
uint16_t requestedDurationMs = 0); uint16_t requestedDurationMs = 0);
/// @brief "Return" the current currently allocated to a consumer /// @brief "Return" the current currently allocated to a consumer
/// @param consumer the active consumer to release the current for /// @param consumer the active consumer to release the current for

View File

@ -304,9 +304,8 @@ float PowerScheduler::getConsumerCurrent(
return currentSum; return currentSum;
} }
PowerScheduler::PowerScheduler(float i_limit_ma, float i_max_ma) { PowerScheduler::PowerScheduler(float i_limit_ma, float i_max_ma)
this->limitCurrent = i_limit_ma; : freeLimitCurrentBudget(i_limit_ma), freeMaximumCurrentBudget(i_max_ma) {
this->maximumCurrent = i_max_ma;
this->currentAllowances = std::vector<CurrentAllowance>(); this->currentAllowances = std::vector<CurrentAllowance>();
this->powerSchedulerMutex = xSemaphoreCreateMutex(); this->powerSchedulerMutex = xSemaphoreCreateMutex();
} }

View File

@ -91,7 +91,7 @@ public:
/// account, so requesting the same or less power will always succeed. Also, /// account, so requesting the same or less power will always succeed. Also,
/// small amounts of power (below 1 mA) will always be granted. /// small amounts of power (below 1 mA) will always be granted.
bool tryAccquireCurrentAllowance(PowerParameters::PowerConsumers consumer, bool tryAccquireCurrentAllowance(PowerParameters::PowerConsumers consumer,
float neededcurrent, float neededCurrent,
uint16_t requestedDurationMs = 0); uint16_t requestedDurationMs = 0);
/// @brief "Return" the current currently allocated to a consumer /// @brief "Return" the current currently allocated to a consumer
/// @param consumer the active consumer to release the current for /// @param consumer the active consumer to release the current for