From 7a7139360cae1e5f8dabba8bff8aee3ef91ea923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phillip=20K=C3=BChne?= Date: Sun, 16 Feb 2025 01:43:19 +0100 Subject: [PATCH] Fix mistakes --- src/Dezibot.h | 2 +- src/colorDetection/ColorDetection.h | 4 ++-- src/infraredLight/InfraredLED.cpp | 8 +------- src/motion/Motion.h | 1 - src/multiColorLight/MultiColorLight.h | 4 ++-- src/power/PowerManager.h | 8 ++++---- src/power/PowerScheduler.cpp | 5 ++--- src/power/PowerScheduler.h | 2 +- 8 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/Dezibot.h b/src/Dezibot.h index ef3f691..93353cd 100644 --- a/src/Dezibot.h +++ b/src/Dezibot.h @@ -34,7 +34,7 @@ public: InfraredLight infraredLight; Communication communication; Display display; - Power power; + PowerManager power; void begin(void); }; diff --git a/src/colorDetection/ColorDetection.h b/src/colorDetection/ColorDetection.h index 4323723..4f2a7ce 100644 --- a/src/colorDetection/ColorDetection.h +++ b/src/colorDetection/ColorDetection.h @@ -73,7 +73,7 @@ public: * * @return */ - float modelCurrentConsumption(); + static float modelCurrentConsumption(); /** @@ -84,7 +84,7 @@ public: * @param durationMs * @return float */ - float modelChargeConsumption(uint16_t durationMs); + static float modelChargeConsumption(uint16_t durationMs); protected: uint16_t readDoubleRegister(uint8_t regAddr); diff --git a/src/infraredLight/InfraredLED.cpp b/src/infraredLight/InfraredLED.cpp index a09f1a3..386821d 100644 --- a/src/infraredLight/InfraredLED.cpp +++ b/src/infraredLight/InfraredLED.cpp @@ -80,8 +80,6 @@ void InfraredLED::setState(bool state){ void InfraredLED::sendFrequency(uint16_t 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) { PowerManager::waitForCurrentAllowance( PowerParameters::PowerConsumers::LED_IR_BOTTOM, @@ -111,8 +109,6 @@ float InfraredLED::modelCurrentConsumption(uint32_t duty){ }; 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) { return durationMs * (PowerParameters::CurrentConsumptions::CURRENT_LED_IR_BOTTOM) / 10e6f; @@ -124,8 +120,6 @@ float InfraredLED::modelChargeConsumptionOn(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; } diff --git a/src/motion/Motion.h b/src/motion/Motion.h index e1bb259..eb56d21 100644 --- a/src/motion/Motion.h +++ b/src/motion/Motion.h @@ -79,7 +79,6 @@ class Motor{ uint8_t pin; ledc_timer_t timer; ledc_channel_t channel; - Power* powerManager; uint16_t duty; // The phase of the pwm signal, expressed as a number betweeen 0 and // the maximum value representable by the pwm timer resolution. diff --git a/src/multiColorLight/MultiColorLight.h b/src/multiColorLight/MultiColorLight.h index b526e86..9731145 100644 --- a/src/multiColorLight/MultiColorLight.h +++ b/src/multiColorLight/MultiColorLight.h @@ -31,7 +31,7 @@ class MultiColorLight { protected: static const uint16_t ledAmount = 3; static const int16_t ledPin = 48; - static const uint8_t maxBrightness = 150; + static const uint8_t defaultMaxBrightness = 150; Adafruit_NeoPixel rgbLeds; static constexpr int maximumExecutionDelayMs = 10; @@ -203,7 +203,7 @@ private: * can be between 0 - maxBrightness */ uint32_t normalizeColor(uint32_t color, - uint8_t maxBrigthness = maxBrightness); + uint8_t maxBrightness = defaultMaxBrightness); }; #endif // MultiColorLight_h \ No newline at end of file diff --git a/src/power/PowerManager.h b/src/power/PowerManager.h index c5222ec..362e7b7 100644 --- a/src/power/PowerManager.h +++ b/src/power/PowerManager.h @@ -14,8 +14,8 @@ #include "driver/adc.h" #include "esp_adc/adc_oneshot.h" #include "freertos/semphr.h" -#ifndef Power_h -#define Power_h +#ifndef PowerManager_h +#define PowerManager_h #define TAG "Power" @@ -47,7 +47,7 @@ private: xSemaphoreGive(mutex); } } - bool isLocked() { return locked; } + bool isLocked() const { return locked; } }; protected: @@ -103,7 +103,7 @@ public: /// @return whether the current could be successfully allocated static bool tryAccquireCurrentAllowance(PowerParameters::PowerConsumers consumer, - uint16_t neededcurrent, + 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 diff --git a/src/power/PowerScheduler.cpp b/src/power/PowerScheduler.cpp index 0dbbbef..396e84b 100644 --- a/src/power/PowerScheduler.cpp +++ b/src/power/PowerScheduler.cpp @@ -304,9 +304,8 @@ float PowerScheduler::getConsumerCurrent( return currentSum; } -PowerScheduler::PowerScheduler(float i_limit_ma, float i_max_ma) { - this->limitCurrent = i_limit_ma; - this->maximumCurrent = i_max_ma; +PowerScheduler::PowerScheduler(float i_limit_ma, float i_max_ma) + : freeLimitCurrentBudget(i_limit_ma), freeMaximumCurrentBudget(i_max_ma) { this->currentAllowances = std::vector(); this->powerSchedulerMutex = xSemaphoreCreateMutex(); } diff --git a/src/power/PowerScheduler.h b/src/power/PowerScheduler.h index c32e6a7..aa7e66f 100644 --- a/src/power/PowerScheduler.h +++ b/src/power/PowerScheduler.h @@ -91,7 +91,7 @@ public: /// account, so requesting the same or less power will always succeed. Also, /// small amounts of power (below 1 mA) will always be granted. bool tryAccquireCurrentAllowance(PowerParameters::PowerConsumers consumer, - float neededcurrent, + float neededCurrent, uint16_t requestedDurationMs = 0); /// @brief "Return" the current currently allocated to a consumer /// @param consumer the active consumer to release the current for