mirror of
				https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
				synced 2025-10-31 15:20:01 +01:00 
			
		
		
		
	Rename Power.* to PowerManager.* for clarity
This commit is contained in:
		| @@ -19,7 +19,7 @@ | |||||||
| #include "infraredLight/InfraredLight.h" | #include "infraredLight/InfraredLight.h" | ||||||
| #include "communication/Communication.h" | #include "communication/Communication.h" | ||||||
| #include "display/Display.h" | #include "display/Display.h" | ||||||
| #include "power/Power.h" | #include "power/PowerManager.h" | ||||||
|  |  | ||||||
|  |  | ||||||
| class Dezibot { | class Dezibot { | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| #include "ColorDetection.h" | #include "ColorDetection.h" | ||||||
|  |  | ||||||
| void ColorDetection::begin(void) { | void ColorDetection::begin(void) { | ||||||
|   if (!Power::waitForCurrentAllowance( |   if (!PowerManager::waitForCurrentAllowance( | ||||||
|           PowerParameters::PowerConsumers::RGBW_SENSOR, |           PowerParameters::PowerConsumers::RGBW_SENSOR, | ||||||
|           PowerParameters::CurrentConsumptions::CURRENT_SENSOR_RGBW, |           PowerParameters::CurrentConsumptions::CURRENT_SENSOR_RGBW, | ||||||
|           COLOR_DETECTION_MAX_EXECUTION_DELAY_MS, NULL)) { |           COLOR_DETECTION_MAX_EXECUTION_DELAY_MS, NULL)) { | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ | |||||||
|  |  | ||||||
| #ifndef ColorDetection_h | #ifndef ColorDetection_h | ||||||
| #define ColorDetection_h | #define ColorDetection_h | ||||||
| #include "../power/Power.h" | #include "../power/PowerManager.h" | ||||||
| #include <Arduino.h> | #include <Arduino.h> | ||||||
| #include <Wire.h> | #include <Wire.h> | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
|   | |||||||
| @@ -45,7 +45,7 @@ void nodeTimeAdjustedCallback(int32_t offset) { | |||||||
|  |  | ||||||
| void vTaskUpdate(void *pvParameters) { | void vTaskUpdate(void *pvParameters) { | ||||||
|   for (;;) { |   for (;;) { | ||||||
|     if (Power::waitForCurrentAllowance( |     if (PowerManager::waitForCurrentAllowance( | ||||||
|             PowerParameters::PowerConsumers::WIFI, |             PowerParameters::PowerConsumers::WIFI, | ||||||
|             PowerParameters::CurrentConsumptions::CURRENT_WIFI_PEAK + |             PowerParameters::CurrentConsumptions::CURRENT_WIFI_PEAK + | ||||||
|                 PowerParameters::CurrentConsumptions::CURRENT_WIFI_BASE, |                 PowerParameters::CurrentConsumptions::CURRENT_WIFI_BASE, | ||||||
| @@ -54,7 +54,7 @@ void vTaskUpdate(void *pvParameters) { | |||||||
|     } else { |     } else { | ||||||
|       ESP_LOGW(TAG, "Skipping mesh update after not being granted power"); |       ESP_LOGW(TAG, "Skipping mesh update after not being granted power"); | ||||||
|     } |     } | ||||||
|     Power::waitForCurrentAllowance( |     PowerManager::waitForCurrentAllowance( | ||||||
|         PowerParameters::PowerConsumers::WIFI, |         PowerParameters::PowerConsumers::WIFI, | ||||||
|         PowerParameters::CurrentConsumptions::CURRENT_WIFI_BASE, |         PowerParameters::CurrentConsumptions::CURRENT_WIFI_BASE, | ||||||
|         MESH_MAX_EXECUTION_DELAY_MS, NULL); |         MESH_MAX_EXECUTION_DELAY_MS, NULL); | ||||||
| @@ -76,7 +76,7 @@ void Communication::begin(void) { | |||||||
|   mesh.setDebugMsgTypes( |   mesh.setDebugMsgTypes( | ||||||
|       ERROR | |       ERROR | | ||||||
|       STARTUP); // set before init() so that you can see startup messages |       STARTUP); // set before init() so that you can see startup messages | ||||||
|   if (!Power::waitForCurrentAllowance( |   if (!PowerManager::waitForCurrentAllowance( | ||||||
|           PowerParameters::PowerConsumers::WIFI, |           PowerParameters::PowerConsumers::WIFI, | ||||||
|           PowerParameters::CurrentConsumptions::CURRENT_WIFI_BASE, |           PowerParameters::CurrentConsumptions::CURRENT_WIFI_BASE, | ||||||
|           MESH_MAX_EXECUTION_DELAY_MS, NULL)) { |           MESH_MAX_EXECUTION_DELAY_MS, NULL)) { | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
|  |  | ||||||
| #ifndef Communication_h | #ifndef Communication_h | ||||||
| #define Communication_h | #define Communication_h | ||||||
| #include "../power/Power.h" | #include "../power/PowerManager.h" | ||||||
| #include <Arduino.h> | #include <Arduino.h> | ||||||
| #include <painlessMesh.h> | #include <painlessMesh.h> | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ | |||||||
|  |  | ||||||
|  |  | ||||||
| void Display::begin(void){ | void Display::begin(void){ | ||||||
|     if(!Power::waitForCurrentAllowance( |     if(!PowerManager::waitForCurrentAllowance( | ||||||
|         PowerParameters::PowerConsumers::DISPLAY_OLED, PowerParameters::CurrentConsumptions::CURRENT_DISPLAY |         PowerParameters::PowerConsumers::DISPLAY_OLED, PowerParameters::CurrentConsumptions::CURRENT_DISPLAY | ||||||
|         ,DISPLAY_MAX_EXECUTION_DELAY_MS, NULL)){ |         ,DISPLAY_MAX_EXECUTION_DELAY_MS, NULL)){ | ||||||
|             ESP_LOGE(TAG,"Could not get power for Display"); |             ESP_LOGE(TAG,"Could not get power for Display"); | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ | |||||||
|  |  | ||||||
| #ifndef Display_h | #ifndef Display_h | ||||||
| #define Display_h | #define Display_h | ||||||
| #include "../power/Power.h" | #include "../power/PowerManager.h" | ||||||
| #include "DisplayCMDs.h" | #include "DisplayCMDs.h" | ||||||
| #include <Arduino.h> | #include <Arduino.h> | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
|   | |||||||
| @@ -47,7 +47,7 @@ void InfraredLED::setState(bool state){ | |||||||
|     ledc_set_freq(pwmSpeedMode,timer,1); |     ledc_set_freq(pwmSpeedMode,timer,1); | ||||||
|     if (state) { |     if (state) { | ||||||
|       if (this->ledPin == IR_BOTTOM_PIN) { |       if (this->ledPin == IR_BOTTOM_PIN) { | ||||||
|         if (!Power::waitForCurrentAllowance( |         if (!PowerManager::waitForCurrentAllowance( | ||||||
|                 PowerParameters::PowerConsumers::LED_IR_BOTTOM, |                 PowerParameters::PowerConsumers::LED_IR_BOTTOM, | ||||||
|                 PowerParameters::CurrentConsumptions::CURRENT_LED_IR_BOTTOM, |                 PowerParameters::CurrentConsumptions::CURRENT_LED_IR_BOTTOM, | ||||||
|                 IR_LED_MAX_EXECUTION_DELAY_MS, NULL)) { |                 IR_LED_MAX_EXECUTION_DELAY_MS, NULL)) { | ||||||
| @@ -56,7 +56,7 @@ void InfraredLED::setState(bool state){ | |||||||
|           return; |           return; | ||||||
|         } |         } | ||||||
|       } else if (this->ledPin == IR_FRONT_PIN) { |       } else if (this->ledPin == IR_FRONT_PIN) { | ||||||
|         if (!Power::waitForCurrentAllowance( |         if (!PowerManager::waitForCurrentAllowance( | ||||||
|                 PowerParameters::PowerConsumers::LED_IR_FRONT, |                 PowerParameters::PowerConsumers::LED_IR_FRONT, | ||||||
|                 PowerParameters::CurrentConsumptions::CURRENT_LED_IR_FRONT, |                 PowerParameters::CurrentConsumptions::CURRENT_LED_IR_FRONT, | ||||||
|                 IR_LED_MAX_EXECUTION_DELAY_MS, NULL)) { |                 IR_LED_MAX_EXECUTION_DELAY_MS, NULL)) { | ||||||
| @@ -68,9 +68,9 @@ void InfraredLED::setState(bool state){ | |||||||
|         ledc_set_duty(pwmSpeedMode,channel,1023); |         ledc_set_duty(pwmSpeedMode,channel,1023); | ||||||
|     } else { |     } else { | ||||||
|       if (this->ledPin == IR_BOTTOM_PIN) { |       if (this->ledPin == IR_BOTTOM_PIN) { | ||||||
|         Power::releaseCurrent(PowerParameters::PowerConsumers::LED_IR_BOTTOM); |         PowerManager::releaseCurrent(PowerParameters::PowerConsumers::LED_IR_BOTTOM); | ||||||
|       } else { |       } else { | ||||||
|         Power::releaseCurrent(PowerParameters::PowerConsumers::LED_IR_FRONT); |         PowerManager::releaseCurrent(PowerParameters::PowerConsumers::LED_IR_FRONT); | ||||||
|       } |       } | ||||||
|         ledc_set_duty(pwmSpeedMode,channel,0); |         ledc_set_duty(pwmSpeedMode,channel,0); | ||||||
|     } |     } | ||||||
| @@ -83,12 +83,12 @@ void InfraredLED::sendFrequency(uint16_t frequency){ | |||||||
|   // Float to force float division without casting |   // Float to force float division without casting | ||||||
|   constexpr float resolution = 1 << DUTY_RESOLUTION; |   constexpr float resolution = 1 << DUTY_RESOLUTION; | ||||||
|   if (this->ledPin == IR_BOTTOM_PIN) { |   if (this->ledPin == IR_BOTTOM_PIN) { | ||||||
|     Power::waitForCurrentAllowance( |     PowerManager::waitForCurrentAllowance( | ||||||
|         PowerParameters::PowerConsumers::LED_IR_BOTTOM, |         PowerParameters::PowerConsumers::LED_IR_BOTTOM, | ||||||
|         this->modelCurrentConsumption(duty), IR_LED_MAX_EXECUTION_DELAY_MS, |         this->modelCurrentConsumption(duty), IR_LED_MAX_EXECUTION_DELAY_MS, | ||||||
|         NULL); |         NULL); | ||||||
|   } else if (this->ledPin == IR_FRONT_PIN) { |   } else if (this->ledPin == IR_FRONT_PIN) { | ||||||
|     Power::waitForCurrentAllowance( |     PowerManager::waitForCurrentAllowance( | ||||||
|         PowerParameters::PowerConsumers::LED_IR_FRONT, |         PowerParameters::PowerConsumers::LED_IR_FRONT, | ||||||
|         this->modelCurrentConsumption(duty), IR_LED_MAX_EXECUTION_DELAY_MS, |         this->modelCurrentConsumption(duty), IR_LED_MAX_EXECUTION_DELAY_MS, | ||||||
|         NULL); |         NULL); | ||||||
|   | |||||||
| @@ -10,7 +10,7 @@ | |||||||
|  */ |  */ | ||||||
| #ifndef InfraredLight_h | #ifndef InfraredLight_h | ||||||
| #define InfraredLight_h | #define InfraredLight_h | ||||||
| #include "../power/Power.h" | #include "../power/PowerManager.h" | ||||||
| #include "driver/ledc.h" | #include "driver/ledc.h" | ||||||
| #include <Arduino.h> | #include <Arduino.h> | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
|   | |||||||
| @@ -64,7 +64,7 @@ uint32_t LightDetection::getAverageValue(photoTransistors sensor, uint32_t measu | |||||||
| }; | }; | ||||||
|  |  | ||||||
| void LightDetection::beginInfrared(void){ | void LightDetection::beginInfrared(void){ | ||||||
|     if(!Power::waitForCurrentAllowance( |     if(!PowerManager::waitForCurrentAllowance( | ||||||
|         PowerParameters::PowerConsumers::PT_IR, |         PowerParameters::PowerConsumers::PT_IR, | ||||||
|         PowerParameters::CurrentConsumptions::CURRENT_PT * 4, |         PowerParameters::CurrentConsumptions::CURRENT_PT * 4, | ||||||
|         LIGHT_DETECTION_MAX_EXECUTION_DELAY_MS, NULL)) { |         LIGHT_DETECTION_MAX_EXECUTION_DELAY_MS, NULL)) { | ||||||
| @@ -80,7 +80,7 @@ void LightDetection::beginInfrared(void){ | |||||||
| }; | }; | ||||||
|  |  | ||||||
| void LightDetection::beginDaylight(void){ | void LightDetection::beginDaylight(void){ | ||||||
|     if(!Power::waitForCurrentAllowance( |     if(!PowerManager::waitForCurrentAllowance( | ||||||
|         PowerParameters::PowerConsumers::PT_DL, |         PowerParameters::PowerConsumers::PT_DL, | ||||||
|         PowerParameters::CurrentConsumptions::CURRENT_PT * 2, |         PowerParameters::CurrentConsumptions::CURRENT_PT * 2, | ||||||
|         LIGHT_DETECTION_MAX_EXECUTION_DELAY_MS, NULL)) { |         LIGHT_DETECTION_MAX_EXECUTION_DELAY_MS, NULL)) { | ||||||
| @@ -113,7 +113,7 @@ uint16_t LightDetection::readIRPT(photoTransistors sensor){ | |||||||
|     default: |     default: | ||||||
|         break; |         break; | ||||||
|     } |     } | ||||||
|     //Power::releaseCurrent(PowerParameters::PowerConsumers::PT_IR); |     //PowerManager::releaseCurrent(PowerParameters::PowerConsumers::PT_IR); | ||||||
|     //digitalWrite(IR_PT_ENABLE,LOW); |     //digitalWrite(IR_PT_ENABLE,LOW); | ||||||
|     return result; |     return result; | ||||||
| }; | }; | ||||||
| @@ -132,7 +132,7 @@ uint16_t LightDetection::readDLPT(photoTransistors sensor){ | |||||||
|     default: |     default: | ||||||
|         break; |         break; | ||||||
|     } |     } | ||||||
|     Power::releaseCurrent(PowerParameters::PowerConsumers::PT_DL); |     PowerManager::releaseCurrent(PowerParameters::PowerConsumers::PT_DL); | ||||||
|     digitalWrite(DL_PT_ENABLE,LOW); |     digitalWrite(DL_PT_ENABLE,LOW); | ||||||
|     return result; |     return result; | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ | |||||||
|  |  | ||||||
| #ifndef LightDetection_h | #ifndef LightDetection_h | ||||||
| #define LightDetection_h | #define LightDetection_h | ||||||
| #include "../power/Power.h" | #include "../power/PowerManager.h" | ||||||
| #include <Arduino.h> | #include <Arduino.h> | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
|  |  | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ | |||||||
| #include <freertos/task.h> | #include <freertos/task.h> | ||||||
| #include "driver/ledc.h" | #include "driver/ledc.h" | ||||||
| #include "motionDetection/MotionDetection.h" | #include "motionDetection/MotionDetection.h" | ||||||
| #include "../power/Power.h" | #include "../power/PowerManager.h" | ||||||
| #define LEDC_MODE          LEDC_LOW_SPEED_MODE | #define LEDC_MODE          LEDC_LOW_SPEED_MODE | ||||||
| #define TIMER              LEDC_TIMER_2 | #define TIMER              LEDC_TIMER_2 | ||||||
| #define CHANNEL_LEFT       LEDC_CHANNEL_3  | #define CHANNEL_LEFT       LEDC_CHANNEL_3  | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| #include "Motion.h" | #include "Motion.h" | ||||||
| #include "power/Power.h" | #include "power/PowerManager.h" | ||||||
|  |  | ||||||
| #define MOTOR_LEFT_PIN 12 | #define MOTOR_LEFT_PIN 12 | ||||||
| #define MOTOR_RIGHT_PIN 11 | #define MOTOR_RIGHT_PIN 11 | ||||||
| @@ -30,7 +30,7 @@ void Motor::begin(void){ | |||||||
| bool Motor::setSpeed(uint16_t duty) { | bool Motor::setSpeed(uint16_t duty) { | ||||||
|   const float current = this->modelCurrentConsumption(duty); |   const float current = this->modelCurrentConsumption(duty); | ||||||
|   if (this->pin == MOTOR_LEFT_PIN) { |   if (this->pin == MOTOR_LEFT_PIN) { | ||||||
|     if (!Power::waitForCurrentAllowance( |     if (!PowerManager::waitForCurrentAllowance( | ||||||
|             PowerParameters::PowerConsumers::MOTOR_LEFT, current, |             PowerParameters::PowerConsumers::MOTOR_LEFT, current, | ||||||
|             MOTOR_MAX_EXECUTION_DELAY_MS, NULL)) { |             MOTOR_MAX_EXECUTION_DELAY_MS, NULL)) { | ||||||
|       ESP_LOGW(TAG, |       ESP_LOGW(TAG, | ||||||
| @@ -40,7 +40,7 @@ bool Motor::setSpeed(uint16_t duty) { | |||||||
|       return false; |       return false; | ||||||
|     } |     } | ||||||
|   } else { |   } else { | ||||||
|     if (!Power::waitForCurrentAllowance( |     if (!PowerManager::waitForCurrentAllowance( | ||||||
|             PowerParameters::PowerConsumers::MOTOR_RIGHT, current, |             PowerParameters::PowerConsumers::MOTOR_RIGHT, current, | ||||||
|             MOTOR_MAX_EXECUTION_DELAY_MS, NULL)) { |             MOTOR_MAX_EXECUTION_DELAY_MS, NULL)) { | ||||||
|       ESP_LOGW(TAG, |       ESP_LOGW(TAG, | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ MotionDetection::MotionDetection(){ | |||||||
| }; | }; | ||||||
|  |  | ||||||
| void MotionDetection::begin(void){ | void MotionDetection::begin(void){ | ||||||
|   if (!Power::waitForCurrentAllowance( |   if (!PowerManager::waitForCurrentAllowance( | ||||||
|           PowerParameters::PowerConsumers::IMU, |           PowerParameters::PowerConsumers::IMU, | ||||||
|           PowerParameters::CurrentConsumptions::CURRENT_IMU, |           PowerParameters::CurrentConsumptions::CURRENT_IMU, | ||||||
|           IMU_MAX_EXECUTION_DELAY_MS, NULL)) { |           IMU_MAX_EXECUTION_DELAY_MS, NULL)) { | ||||||
|   | |||||||
| @@ -10,7 +10,7 @@ | |||||||
|  */ |  */ | ||||||
| #ifndef MotionDetection_h | #ifndef MotionDetection_h | ||||||
| #define MotionDetection_h | #define MotionDetection_h | ||||||
| #include "../power/Power.h" | #include "../power/PowerManager.h" | ||||||
| #include "IMU_CMDs.h" | #include "IMU_CMDs.h" | ||||||
| #include <Arduino.h> | #include <Arduino.h> | ||||||
| #include <SPI.h> | #include <SPI.h> | ||||||
|   | |||||||
| @@ -6,15 +6,15 @@ MultiColorLight::MultiColorLight() | |||||||
|       }; |       }; | ||||||
|  |  | ||||||
| void MultiColorLight::begin(void) { | void MultiColorLight::begin(void) { | ||||||
|   if (!Power::waitForCurrentAllowance( |   if (!PowerManager::waitForCurrentAllowance( | ||||||
|           PowerParameters::PowerConsumers::LED_RGB_TOP_LEFT, |           PowerParameters::PowerConsumers::LED_RGB_TOP_LEFT, | ||||||
|           PowerParameters::CurrentConsumptions::CURRENT_LED_RGB_BASE, |           PowerParameters::CurrentConsumptions::CURRENT_LED_RGB_BASE, | ||||||
|           MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL) && |           MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL) && | ||||||
|       Power::waitForCurrentAllowance( |       PowerManager::waitForCurrentAllowance( | ||||||
|           PowerParameters::PowerConsumers::LED_RGB_TOP_RIGHT, |           PowerParameters::PowerConsumers::LED_RGB_TOP_RIGHT, | ||||||
|           PowerParameters::CurrentConsumptions::CURRENT_LED_RGB_BASE, |           PowerParameters::CurrentConsumptions::CURRENT_LED_RGB_BASE, | ||||||
|           MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL) && |           MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL) && | ||||||
|       Power::waitForCurrentAllowance( |       PowerManager::waitForCurrentAllowance( | ||||||
|           PowerParameters::PowerConsumers::LED_RGB_BOTTOM, |           PowerParameters::PowerConsumers::LED_RGB_BOTTOM, | ||||||
|           PowerParameters::CurrentConsumptions::CURRENT_LED_RGB_BASE, |           PowerParameters::CurrentConsumptions::CURRENT_LED_RGB_BASE, | ||||||
|           MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL)) { |           MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL)) { | ||||||
| @@ -33,7 +33,7 @@ void MultiColorLight::setLed(uint8_t index, uint32_t color) { | |||||||
|   float totalConsumption = modelCurrentConsumption(normalizedColor); |   float totalConsumption = modelCurrentConsumption(normalizedColor); | ||||||
|   switch (index) { |   switch (index) { | ||||||
|   case 0: |   case 0: | ||||||
|     if (!Power::waitForCurrentAllowance( |     if (!PowerManager::waitForCurrentAllowance( | ||||||
|             PowerParameters::PowerConsumers::LED_RGB_TOP_RIGHT, |             PowerParameters::PowerConsumers::LED_RGB_TOP_RIGHT, | ||||||
|             totalConsumption, MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL)) { |             totalConsumption, MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL)) { | ||||||
|       ESP_LOGW(TAG, |       ESP_LOGW(TAG, | ||||||
| @@ -44,7 +44,7 @@ void MultiColorLight::setLed(uint8_t index, uint32_t color) { | |||||||
|     } |     } | ||||||
|     break; |     break; | ||||||
|   case 1: |   case 1: | ||||||
|     if (!Power::waitForCurrentAllowance( |     if (!PowerManager::waitForCurrentAllowance( | ||||||
|             PowerParameters::PowerConsumers::LED_RGB_TOP_LEFT, totalConsumption, |             PowerParameters::PowerConsumers::LED_RGB_TOP_LEFT, totalConsumption, | ||||||
|             MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL)) { |             MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL)) { | ||||||
|       ESP_LOGW(TAG, |       ESP_LOGW(TAG, | ||||||
| @@ -55,7 +55,7 @@ void MultiColorLight::setLed(uint8_t index, uint32_t color) { | |||||||
|     } |     } | ||||||
|     break; |     break; | ||||||
|   case 2: |   case 2: | ||||||
|     if (!Power::waitForCurrentAllowance( |     if (!PowerManager::waitForCurrentAllowance( | ||||||
|             PowerParameters::PowerConsumers::LED_RGB_BOTTOM, totalConsumption, |             PowerParameters::PowerConsumers::LED_RGB_BOTTOM, totalConsumption, | ||||||
|             MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL)) { |             MULTI_COLOR_LIGHT_MAX_EXECUTION_DELAY_MS, NULL)) { | ||||||
|       ESP_LOGW(TAG, |       ESP_LOGW(TAG, | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ | |||||||
|  */ |  */ | ||||||
| #ifndef MultiColorLight_h | #ifndef MultiColorLight_h | ||||||
| #define MultiColorLight_h | #define MultiColorLight_h | ||||||
| #include "../power/Power.h" | #include "../power/PowerManager.h" | ||||||
| #include "ColorConstants.h" | #include "ColorConstants.h" | ||||||
| #include <Adafruit_NeoPixel.h> | #include <Adafruit_NeoPixel.h> | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| /**
 | /**
 | ||||||
|  * @file Power.h |  * @file PowerManager.h | ||||||
|  * @author Phillip Kühne |  * @author Phillip Kühne | ||||||
|  * @brief This component provides utilities for keeping track of power usage |  * @brief This component provides utilities for keeping track of power usage | ||||||
|  * consumption. |  * consumption. | ||||||
| @@ -7,19 +7,19 @@ | |||||||
|  * @date 2024-11-23 |  * @date 2024-11-23 | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include "Power.h" | #include "PowerManager.h" | ||||||
| 
 | 
 | ||||||
| SemaphoreHandle_t Power::powerMutex = NULL; | SemaphoreHandle_t PowerManager::powerMutex = NULL; | ||||||
| 
 | 
 | ||||||
| void vTaskUpdatePowerState(void *pvParameters) { | void vTaskUpdatePowerState(void *pvParameters) { | ||||||
|   for (;;) { |   for (;;) { | ||||||
|     ESP_LOGV(TAG, "Updating Power State..."); |     ESP_LOGV(TAG, "Updating Power State..."); | ||||||
|     Power::updatePowerStateHandler(); |     PowerManager::updatePowerStateHandler(); | ||||||
|     vTaskDelay(pdMS_TO_TICKS(10)); |     vTaskDelay(pdMS_TO_TICKS(10)); | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Power::begin() { | void PowerManager::begin() { | ||||||
|   // Check if another instance of us already initialized the power scheduler,
 |   // Check if another instance of us already initialized the power scheduler,
 | ||||||
|   // if not, we will do it.
 |   // if not, we will do it.
 | ||||||
|   ESP_LOGI(TAG, "Initializing Power Management"); |   ESP_LOGI(TAG, "Initializing Power Management"); | ||||||
| @@ -38,8 +38,8 @@ void Power::begin() { | |||||||
|     powerScheduler = &PowerScheduler::getPowerScheduler( |     powerScheduler = &PowerScheduler::getPowerScheduler( | ||||||
|         PowerParameters::Battery::CELL_CURRENT_1C_MA, |         PowerParameters::Battery::CELL_CURRENT_1C_MA, | ||||||
|         PowerParameters::Battery::CELL_CURRENT_2C_MA); |         PowerParameters::Battery::CELL_CURRENT_2C_MA); | ||||||
|     Power::initPowerState(); |     PowerManager::initPowerState(); | ||||||
|     Power::recalculateCurrentBudgets(); |     PowerManager::recalculateCurrentBudgets(); | ||||||
|     TaskHandle_t xHandle = NULL; |     TaskHandle_t xHandle = NULL; | ||||||
|     xTaskCreate(vTaskUpdatePowerState, "vTaskPowerStateUpdate", 4096, NULL, |     xTaskCreate(vTaskUpdatePowerState, "vTaskPowerStateUpdate", 4096, NULL, | ||||||
|                 tskIDLE_PRIORITY, &xHandle); |                 tskIDLE_PRIORITY, &xHandle); | ||||||
| @@ -54,26 +54,26 @@ void Power::begin() { | |||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| float Power::getFreeLimitCurrentBudget() { | float PowerManager::getFreeLimitCurrentBudget() { | ||||||
|   return powerScheduler->getFreeLimitCurrentBudget(); |   return powerScheduler->getFreeLimitCurrentBudget(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| float Power::getFreeMaximumCurrentBudget() { | float PowerManager::getFreeMaximumCurrentBudget() { | ||||||
|   return powerScheduler->getFreeMaximumCurrentBudget(); |   return powerScheduler->getFreeMaximumCurrentBudget(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool Power::tryAccquireCurrentAllowance( | bool PowerManager::tryAccquireCurrentAllowance( | ||||||
|     PowerParameters::PowerConsumers consumer, uint16_t neededCurrent, |     PowerParameters::PowerConsumers consumer, uint16_t neededCurrent, | ||||||
|     uint16_t requestedDurationMs) { |     uint16_t requestedDurationMs) { | ||||||
|   return powerScheduler->tryAccquireCurrentAllowance(consumer, neededCurrent, |   return powerScheduler->tryAccquireCurrentAllowance(consumer, neededCurrent, | ||||||
|                                                      requestedDurationMs); |                                                      requestedDurationMs); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Power::releaseCurrent(PowerParameters::PowerConsumers consumer) { | void PowerManager::releaseCurrent(PowerParameters::PowerConsumers consumer) { | ||||||
|   powerScheduler->releaseCurrent(consumer); |   powerScheduler->releaseCurrent(consumer); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool Power::waitForCurrentAllowance(PowerParameters::PowerConsumers consumer, | bool PowerManager::waitForCurrentAllowance(PowerParameters::PowerConsumers consumer, | ||||||
|                                     uint16_t neededCurrent, |                                     uint16_t neededCurrent, | ||||||
|                                     uint16_t maxSlackTimeMs, |                                     uint16_t maxSlackTimeMs, | ||||||
|                                     uint16_t requestedDurationMs) { |                                     uint16_t requestedDurationMs) { | ||||||
| @@ -81,15 +81,15 @@ bool Power::waitForCurrentAllowance(PowerParameters::PowerConsumers consumer, | |||||||
|       consumer, neededCurrent, maxSlackTimeMs, requestedDurationMs); |       consumer, neededCurrent, maxSlackTimeMs, requestedDurationMs); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Power::beginPermanentDeepSleep(void) { | void PowerManager::beginPermanentDeepSleep(void) { | ||||||
|   return powerScheduler->beginPermanentDeepSleep(); |   return powerScheduler->beginPermanentDeepSleep(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| float Power::getCurrentCurrent(void) { | float PowerManager::getCurrentCurrent(void) { | ||||||
|   return powerScheduler->getCurrentCurrent(); |   return powerScheduler->getCurrentCurrent(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| float Power::getBatteryCurrent(void) { | float PowerManager::getBatteryCurrent(void) { | ||||||
|   const float i_3v3 = getCurrentCurrent(); |   const float i_3v3 = getCurrentCurrent(); | ||||||
|   const float u_3v3 = 3.3; |   const float u_3v3 = 3.3; | ||||||
|   const float u_bat = getBatteryVoltage(); |   const float u_bat = getBatteryVoltage(); | ||||||
| @@ -97,15 +97,15 @@ float Power::getBatteryCurrent(void) { | |||||||
|   return (u_3v3 * i_3v3) / (u_bat * eta); |   return (u_3v3 * i_3v3) / (u_bat * eta); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Power::recalculateCurrentBudgets(void) { | void PowerManager::recalculateCurrentBudgets(void) { | ||||||
|   return powerScheduler->recalculateCurrentBudgets(); |   return powerScheduler->recalculateCurrentBudgets(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| float Power::getConsumerCurrent(PowerParameters::PowerConsumers consumer) { | float PowerManager::getConsumerCurrent(PowerParameters::PowerConsumers consumer) { | ||||||
|   return powerScheduler->getConsumerCurrent(consumer); |   return powerScheduler->getConsumerCurrent(consumer); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| float Power::getBatteryVoltage() { | float PowerManager::getBatteryVoltage() { | ||||||
|   // Get the battery voltage from the ADC and convert it to a voltage
 |   // Get the battery voltage from the ADC and convert it to a voltage
 | ||||||
|   // using the voltage divider.
 |   // using the voltage divider.
 | ||||||
|   pinMode(PowerParameters::PinConfig::BAT_ADC_EN, OUTPUT); |   pinMode(PowerParameters::PinConfig::BAT_ADC_EN, OUTPUT); | ||||||
| @@ -127,14 +127,14 @@ float Power::getBatteryVoltage() { | |||||||
|   return batteryVoltage; |   return batteryVoltage; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| float Power::getBatteryChargePercent() { return percentRemaining; } | float PowerManager::getBatteryChargePercent() { return percentRemaining; } | ||||||
| 
 | 
 | ||||||
| float Power::getBatteryChargeCoulombs() { return coloumbsRemaining; } | float PowerManager::getBatteryChargeCoulombs() { return coloumbsRemaining; } | ||||||
| 
 | 
 | ||||||
| float Power::getBatteryVoltageChargePercent() { | float PowerManager::getBatteryVoltageChargePercent() { | ||||||
|   // Directly get the battery voltage, correct the curve with an offset and
 |   // Directly get the battery voltage, correct the curve with an offset and
 | ||||||
|   // calculate the charge state based on the discharge curve.
 |   // calculate the charge state based on the discharge curve.
 | ||||||
|   float batteryVoltage = getBatteryVoltage() + Power::fullVoltageOffset; |   float batteryVoltage = getBatteryVoltage() + PowerManager::fullVoltageOffset; | ||||||
|   float chargeState = 0; |   float chargeState = 0; | ||||||
|   // Clamp edge cases
 |   // Clamp edge cases
 | ||||||
|   if (batteryVoltage >= |   if (batteryVoltage >= | ||||||
| @@ -163,16 +163,16 @@ float Power::getBatteryVoltageChargePercent() { | |||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Power::updatePowerStateHandler() { | void PowerManager::updatePowerStateHandler() { | ||||||
| 
 | 
 | ||||||
|   // Update supply and charge state flags
 |   // Update supply and charge state flags
 | ||||||
|   Power::busPowered = !digitalRead(PowerParameters::PinConfig::VUSB_SENS); |   PowerManager::busPowered = !digitalRead(PowerParameters::PinConfig::VUSB_SENS); | ||||||
|   Power::chargingState = digitalRead(PowerParameters::PinConfig::BAT_CHG_STAT); |   PowerManager::chargingState = digitalRead(PowerParameters::PinConfig::BAT_CHG_STAT); | ||||||
| 
 | 
 | ||||||
|   // If the battery is charging and fully charged
 |   // If the battery is charging and fully charged
 | ||||||
|   if (Power::busPowered && !Power::chargingState) { |   if (PowerManager::busPowered && !PowerManager::chargingState) { | ||||||
|     // Calibrate voltage offset on full Battery
 |     // Calibrate voltage offset on full Battery
 | ||||||
|     Power::fullVoltageOffset = PowerParameters::Battery::DISCHARGE_CURVE::VOLTAGES[0] - getBatteryVoltage(); |     PowerManager::fullVoltageOffset = PowerParameters::Battery::DISCHARGE_CURVE::VOLTAGES[0] - getBatteryVoltage(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   ESP_LOGD(TAG, "Bus Powered: %d, Charging: %d", busPowered, chargingState); |   ESP_LOGD(TAG, "Bus Powered: %d, Charging: %d", busPowered, chargingState); | ||||||
| @@ -184,7 +184,7 @@ void Power::updatePowerStateHandler() { | |||||||
|   float coloumbsConsumedSinceLastUpdate; |   float coloumbsConsumedSinceLastUpdate; | ||||||
| 
 | 
 | ||||||
|   // Calculate remaining battery charge in Coulombs based on current and time
 |   // Calculate remaining battery charge in Coulombs based on current and time
 | ||||||
|   if (!Power::busPowered) { |   if (!PowerManager::busPowered) { | ||||||
|     coloumbsConsumedSinceLastUpdate = |     coloumbsConsumedSinceLastUpdate = | ||||||
|         (currentCurrent / 1000) * |         (currentCurrent / 1000) * | ||||||
|         ((pdTICKS_TO_MS(xTaskGetTickCount() - lastPowerStateUpdate)) / 1000.0); |         ((pdTICKS_TO_MS(xTaskGetTickCount() - lastPowerStateUpdate)) / 1000.0); | ||||||
| @@ -196,7 +196,7 @@ void Power::updatePowerStateHandler() { | |||||||
| 
 | 
 | ||||||
|   // If current flow is close enough to reference, get battery charge state via
 |   // If current flow is close enough to reference, get battery charge state via
 | ||||||
|   // voltage curve
 |   // voltage curve
 | ||||||
|   if (!Power::busPowered) { |   if (!PowerManager::busPowered) { | ||||||
|     if ((currentCurrent > (referenceCurrentMa * 0.6)) && |     if ((currentCurrent > (referenceCurrentMa * 0.6)) && | ||||||
|         (currentCurrent < (referenceCurrentMa * 1.4))) { |         (currentCurrent < (referenceCurrentMa * 1.4))) { | ||||||
|       // Get battery charge state from voltage curve
 |       // Get battery charge state from voltage curve
 | ||||||
| @@ -233,21 +233,21 @@ void Power::updatePowerStateHandler() { | |||||||
|   for (int i = 0; i < PowerParameters::Battery::AVERAGING_SAMPLES; i++) { |   for (int i = 0; i < PowerParameters::Battery::AVERAGING_SAMPLES; i++) { | ||||||
|     sampleSum += lastSOC[i]; |     sampleSum += lastSOC[i]; | ||||||
|   } |   } | ||||||
|   Power::percentRemaining = |   PowerManager::percentRemaining = | ||||||
|       sampleSum / PowerParameters::Battery::AVERAGING_SAMPLES; |       sampleSum / PowerParameters::Battery::AVERAGING_SAMPLES; | ||||||
| 
 | 
 | ||||||
|   // Update last update time
 |   // Update last update time
 | ||||||
|   Power::lastPowerStateUpdate = xTaskGetTickCount(); |   PowerManager::lastPowerStateUpdate = xTaskGetTickCount(); | ||||||
| 
 | 
 | ||||||
|   // Update the available current (changes based on battery state of charge)
 |   // Update the available current (changes based on battery state of charge)
 | ||||||
|   Power::powerScheduler->recalculateCurrentBudgets(); |   PowerManager::powerScheduler->recalculateCurrentBudgets(); | ||||||
|   ESP_LOGD(TAG, "Current: %f mA, Charge: %f Coulombs, %f %%", currentCurrent, |   ESP_LOGD(TAG, "Current: %f mA, Charge: %f Coulombs, %f %%", currentCurrent, | ||||||
|            coloumbsRemaining, percentRemaining); |            coloumbsRemaining, percentRemaining); | ||||||
| 
 | 
 | ||||||
|   return; |   return; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| float Power::getMax3V3Current() { | float PowerManager::getMax3V3Current() { | ||||||
|   // Conversion from Thesis
 |   // Conversion from Thesis
 | ||||||
|   float u_bat = getBatteryVoltage(); |   float u_bat = getBatteryVoltage(); | ||||||
|   float i_bat = PowerParameters::Battery::CELL_CURRENT_1C_MA; |   float i_bat = PowerParameters::Battery::CELL_CURRENT_1C_MA; | ||||||
| @@ -256,7 +256,7 @@ float Power::getMax3V3Current() { | |||||||
|   return (u_bat * i_bat * eta) / u_3v3; |   return (u_bat * i_bat * eta) / u_3v3; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Power::addSoCSample(float soc) { | void PowerManager::addSoCSample(float soc) { | ||||||
|   PowerMutex lock(powerMutex); |   PowerMutex lock(powerMutex); | ||||||
|   if (!lock.isLocked()) { |   if (!lock.isLocked()) { | ||||||
|     ESP_LOGE(TAG, "Could not take power to add SoC sample"); |     ESP_LOGE(TAG, "Could not take power to add SoC sample"); | ||||||
| @@ -267,7 +267,7 @@ void Power::addSoCSample(float soc) { | |||||||
|   lastSOC[latestSoCIndex] = soc; |   lastSOC[latestSoCIndex] = soc; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Power::initPowerState(void) { | void PowerManager::initPowerState(void) { | ||||||
|   // Initialize the power state
 |   // Initialize the power state
 | ||||||
|   lastPowerStateUpdate = xTaskGetTickCount(); |   lastPowerStateUpdate = xTaskGetTickCount(); | ||||||
|   // TODO: Get initial battery charge state based on voltage, set coloumbs based
 |   // TODO: Get initial battery charge state based on voltage, set coloumbs based
 | ||||||
| @@ -288,88 +288,88 @@ void Power::initPowerState(void) { | |||||||
|   chargingState = digitalRead(PowerParameters::PinConfig::BAT_CHG_STAT); |   chargingState = digitalRead(PowerParameters::PinConfig::BAT_CHG_STAT); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Power::dumpPowerStatistics() { | void PowerManager::dumpPowerStatistics() { | ||||||
|   Serial.printf("======== Dezibot Power Statistics ========\r\n"); |   Serial.printf("======== Dezibot Power Statistics ========\r\n"); | ||||||
|   Serial.printf("Current: %f mA\r\n", Power::getCurrentCurrent()); |   Serial.printf("Current: %f mA\r\n", PowerManager::getCurrentCurrent()); | ||||||
|   Serial.printf("Battery Voltage: %f V\r\n", Power::getBatteryVoltage()); |   Serial.printf("Battery Voltage: %f V\r\n", PowerManager::getBatteryVoltage()); | ||||||
|   Serial.printf("Battery Charge: %f %%\r\n", Power::getBatteryChargePercent()); |   Serial.printf("Battery Charge: %f %%\r\n", PowerManager::getBatteryChargePercent()); | ||||||
|   Serial.printf("Battery Charge: %f Coulombs\r\n", |   Serial.printf("Battery Charge: %f Coulombs\r\n", | ||||||
|                 Power::getBatteryChargeCoulombs()); |                 PowerManager::getBatteryChargeCoulombs()); | ||||||
|   Serial.printf("Max 3.3V Current in this state (1C, 2C): %f mA, %f mA \r\n", |   Serial.printf("Max 3.3V Current in this state (1C, 2C): %f mA, %f mA \r\n", | ||||||
|                 Power::getMax3V3Current(), Power::getMax3V3Current() * 2); |                 PowerManager::getMax3V3Current(), PowerManager::getMax3V3Current() * 2); | ||||||
|   Serial.printf("=========================================\r\n"); |   Serial.printf("=========================================\r\n"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Power::dumpConsumerStatistics() { | void PowerManager::dumpConsumerStatistics() { | ||||||
|   Serial.printf("======== Dezibot Consumer Statistics ========\r\n"); |   Serial.printf("======== Dezibot Consumer Statistics ========\r\n"); | ||||||
|   Serial.printf("ESP: %f mA\r\n", Power::getConsumerCurrent( |   Serial.printf("ESP: %f mA\r\n", PowerManager::getConsumerCurrent( | ||||||
|                                       PowerParameters::PowerConsumers::ESP)); |                                       PowerParameters::PowerConsumers::ESP)); | ||||||
|   Serial.printf("WIFI: %f mA\r\n", Power::getConsumerCurrent( |   Serial.printf("WIFI: %f mA\r\n", PowerManager::getConsumerCurrent( | ||||||
|                                        PowerParameters::PowerConsumers::WIFI)); |                                        PowerParameters::PowerConsumers::WIFI)); | ||||||
|   Serial.printf("LED_RGB_TOP_LEFT: %f mA\r\n", |   Serial.printf("LED_RGB_TOP_LEFT: %f mA\r\n", | ||||||
|                 Power::getConsumerCurrent( |                 PowerManager::getConsumerCurrent( | ||||||
|                     PowerParameters::PowerConsumers::LED_RGB_TOP_LEFT)); |                     PowerParameters::PowerConsumers::LED_RGB_TOP_LEFT)); | ||||||
|   Serial.printf("LED_RGB_TOP_RIGHT: %f mA\r\n", |   Serial.printf("LED_RGB_TOP_RIGHT: %f mA\r\n", | ||||||
|                 Power::getConsumerCurrent( |                 PowerManager::getConsumerCurrent( | ||||||
|                     PowerParameters::PowerConsumers::LED_RGB_TOP_RIGHT)); |                     PowerParameters::PowerConsumers::LED_RGB_TOP_RIGHT)); | ||||||
|   Serial.printf("LED_RGB_BOTTOM: %f mA\r\n", |   Serial.printf("LED_RGB_BOTTOM: %f mA\r\n", | ||||||
|                 Power::getConsumerCurrent( |                 PowerManager::getConsumerCurrent( | ||||||
|                     PowerParameters::PowerConsumers::LED_RGB_BOTTOM)); |                     PowerParameters::PowerConsumers::LED_RGB_BOTTOM)); | ||||||
|   Serial.printf( |   Serial.printf( | ||||||
|       "RGBW_SENSOR: %f mA\r\n", |       "RGBW_SENSOR: %f mA\r\n", | ||||||
|       Power::getConsumerCurrent(PowerParameters::PowerConsumers::RGBW_SENSOR)); |       PowerManager::getConsumerCurrent(PowerParameters::PowerConsumers::RGBW_SENSOR)); | ||||||
|   Serial.printf("LED_IR_BOTTOM: %f mA\r\n", |   Serial.printf("LED_IR_BOTTOM: %f mA\r\n", | ||||||
|                 Power::getConsumerCurrent( |                 PowerManager::getConsumerCurrent( | ||||||
|                     PowerParameters::PowerConsumers::LED_IR_BOTTOM)); |                     PowerParameters::PowerConsumers::LED_IR_BOTTOM)); | ||||||
|   Serial.printf( |   Serial.printf( | ||||||
|       "LED_IR_FRONT: %f mA\r\n", |       "LED_IR_FRONT: %f mA\r\n", | ||||||
|       Power::getConsumerCurrent(PowerParameters::PowerConsumers::LED_IR_FRONT)); |       PowerManager::getConsumerCurrent(PowerParameters::PowerConsumers::LED_IR_FRONT)); | ||||||
|   Serial.printf( |   Serial.printf( | ||||||
|       "PT_IR: %f mA\r\n", |       "PT_IR: %f mA\r\n", | ||||||
|       Power::getConsumerCurrent(PowerParameters::PowerConsumers::PT_IR)); |       PowerManager::getConsumerCurrent(PowerParameters::PowerConsumers::PT_IR)); | ||||||
|   Serial.printf( |   Serial.printf( | ||||||
|       "PT_DL: %f mA\r\n", |       "PT_DL: %f mA\r\n", | ||||||
|       Power::getConsumerCurrent(PowerParameters::PowerConsumers::PT_DL)); |       PowerManager::getConsumerCurrent(PowerParameters::PowerConsumers::PT_DL)); | ||||||
|   Serial.printf( |   Serial.printf( | ||||||
|       "LED_UV: %f mA\r\n", |       "LED_UV: %f mA\r\n", | ||||||
|       Power::getConsumerCurrent(PowerParameters::PowerConsumers::LED_UV)); |       PowerManager::getConsumerCurrent(PowerParameters::PowerConsumers::LED_UV)); | ||||||
|   Serial.printf( |   Serial.printf( | ||||||
|       "DISPLAY_OLED: %f mA\r\n", |       "DISPLAY_OLED: %f mA\r\n", | ||||||
|       Power::getConsumerCurrent(PowerParameters::PowerConsumers::DISPLAY_OLED)); |       PowerManager::getConsumerCurrent(PowerParameters::PowerConsumers::DISPLAY_OLED)); | ||||||
|   Serial.printf( |   Serial.printf( | ||||||
|       "MOTOR_LEFT: %f mA\r\n", |       "MOTOR_LEFT: %f mA\r\n", | ||||||
|       Power::getConsumerCurrent(PowerParameters::PowerConsumers::MOTOR_LEFT)); |       PowerManager::getConsumerCurrent(PowerParameters::PowerConsumers::MOTOR_LEFT)); | ||||||
|   Serial.printf( |   Serial.printf( | ||||||
|       "MOTOR_RIGHT: %f mA\r\n", |       "MOTOR_RIGHT: %f mA\r\n", | ||||||
|       Power::getConsumerCurrent(PowerParameters::PowerConsumers::MOTOR_RIGHT)); |       PowerManager::getConsumerCurrent(PowerParameters::PowerConsumers::MOTOR_RIGHT)); | ||||||
|   Serial.printf("IMU: %f mA\r\n", Power::getConsumerCurrent( |   Serial.printf("IMU: %f mA\r\n", PowerManager::getConsumerCurrent( | ||||||
|                                       PowerParameters::PowerConsumers::IMU)); |                                       PowerParameters::PowerConsumers::IMU)); | ||||||
|   Serial.printf("=============================================\r\n"); |   Serial.printf("=============================================\r\n"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool Power::isUSBPowered() { return busPowered; } | bool PowerManager::isUSBPowered() { return busPowered; } | ||||||
| 
 | 
 | ||||||
| bool Power::isBatteryPowered() { return !busPowered; } | bool PowerManager::isBatteryPowered() { return !busPowered; } | ||||||
| 
 | 
 | ||||||
| bool Power::isBatteryCharging() { return chargingState && busPowered; } | bool PowerManager::isBatteryCharging() { return chargingState && busPowered; } | ||||||
| 
 | 
 | ||||||
| bool Power::isBatteryDischarging() { return !chargingState && !busPowered; } | bool PowerManager::isBatteryDischarging() { return !chargingState && !busPowered; } | ||||||
| 
 | 
 | ||||||
| bool Power::isBatteryFullyCharged() { return !chargingState && busPowered; } | bool PowerManager::isBatteryFullyCharged() { return !chargingState && busPowered; } | ||||||
| int Power::latestSoCIndex = 0; | int PowerManager::latestSoCIndex = 0; | ||||||
| float Power::lastSOC[PowerParameters::Battery::AVERAGING_SAMPLES] = {0}; | float PowerManager::lastSOC[PowerParameters::Battery::AVERAGING_SAMPLES] = {0}; | ||||||
| TickType_t Power::lastPowerStateUpdate = 0; | TickType_t PowerManager::lastPowerStateUpdate = 0; | ||||||
| float Power::coloumbsRemaining = | float PowerManager::coloumbsRemaining = | ||||||
|     PowerParameters::Battery::CELL_CHARGE_FULL_COLOUMB; |     PowerParameters::Battery::CELL_CHARGE_FULL_COLOUMB; | ||||||
| float Power::percentRemaining = 100.0; | float PowerManager::percentRemaining = 100.0; | ||||||
| PowerScheduler *Power::powerScheduler = nullptr; | PowerScheduler *PowerManager::powerScheduler = nullptr; | ||||||
| 
 | 
 | ||||||
| bool Power::busPowered = false; | bool PowerManager::busPowered = false; | ||||||
| 
 | 
 | ||||||
| bool Power::chargingState = false; | bool PowerManager::chargingState = false; | ||||||
| 
 | 
 | ||||||
| float Power::fullVoltageOffset = 0; | float PowerManager::fullVoltageOffset = 0; | ||||||
| 
 | 
 | ||||||
| Power::Power() {} | PowerManager::PowerManager() {} | ||||||
| 
 | 
 | ||||||
| Power::~Power() {} | PowerManager::~PowerManager() {} | ||||||
| @@ -1,5 +1,5 @@ | |||||||
| /**
 | /**
 | ||||||
|  * @file Power.h |  * @file PowerManager.h | ||||||
|  * @author Phillip Kühne |  * @author Phillip Kühne | ||||||
|  * @brief This component provides utilities for keeping track of power usage |  * @brief This component provides utilities for keeping track of power usage | ||||||
|  * consumption. |  * consumption. | ||||||
| @@ -21,7 +21,7 @@ | |||||||
| 
 | 
 | ||||||
| enum TaskResumptionReason { POWER_AVAILABLE, TIMEOUT }; | enum TaskResumptionReason { POWER_AVAILABLE, TIMEOUT }; | ||||||
| 
 | 
 | ||||||
| class Power { | class PowerManager { | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|   static SemaphoreHandle_t powerMutex; |   static SemaphoreHandle_t powerMutex; | ||||||
| @@ -86,8 +86,8 @@ protected: | |||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
|   static void begin(void); |   static void begin(void); | ||||||
|   Power(); |   PowerManager(); | ||||||
|   ~Power(); |   ~PowerManager(); | ||||||
|   /// @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)
 | ||||||
|   static float getFreeLimitCurrentBudget(void); |   static float getFreeLimitCurrentBudget(void); | ||||||
| @@ -193,6 +193,6 @@ public: | |||||||
| 
 | 
 | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| extern Power power; | extern PowerManager power; | ||||||
| 
 | 
 | ||||||
| #endif // Power
 | #endif // Power
 | ||||||
| @@ -11,7 +11,7 @@ | |||||||
|  */ |  */ | ||||||
|  |  | ||||||
| #include "PowerScheduler.h" | #include "PowerScheduler.h" | ||||||
| #include "Power.h" | #include "PowerManager.h" | ||||||
|  |  | ||||||
| bool PowerScheduler::tryAccquireCurrentAllowance( | bool PowerScheduler::tryAccquireCurrentAllowance( | ||||||
|     PowerParameters::PowerConsumers consumer, float neededCurrent, |     PowerParameters::PowerConsumers consumer, float neededCurrent, | ||||||
| @@ -192,9 +192,9 @@ void PowerScheduler::recalculateCurrentBudgets(void) { | |||||||
|  |  | ||||||
|   // Get the respective maximums and subtract currently flowing currents |   // Get the respective maximums and subtract currently flowing currents | ||||||
|   ESP_LOGI(TAG, "Recalculating current budgets..."); |   ESP_LOGI(TAG, "Recalculating current budgets..."); | ||||||
|   float tempFreeLimitCurrentBudget = Power::getMax3V3Current(); |   float tempFreeLimitCurrentBudget = PowerManager::getMax3V3Current(); | ||||||
|   ESP_LOGI(TAG, "Got max 3V3 current: %.2f", tempFreeLimitCurrentBudget); |   ESP_LOGI(TAG, "Got max 3V3 current: %.2f", tempFreeLimitCurrentBudget); | ||||||
|   float tempFreeMaximumCurrentBudget = Power::getMax3V3Current() * 2; |   float tempFreeMaximumCurrentBudget = PowerManager::getMax3V3Current() * 2; | ||||||
|   PowerSchedulerMutex lock(powerSchedulerMutex); |   PowerSchedulerMutex lock(powerSchedulerMutex); | ||||||
|   if (lock.isLocked() == false) { |   if (lock.isLocked() == false) { | ||||||
|     return; |     return; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user