diff --git a/example/advanced/Power_Measurements/Display/Display.ino b/example/advanced/Power_Measurements/Display/Display.ino new file mode 100644 index 0000000..c455fc4 --- /dev/null +++ b/example/advanced/Power_Measurements/Display/Display.ino @@ -0,0 +1,26 @@ +#include "Dezibot.h" + +Dezibot dezibot = Dezibot(); + +// How many times to run a command on the display consecutively; +const uint16_t iterations = 5000; + +void setup() { + dezibot.begin(); +} + +void loop() { + //Typical output + dezibot.display.println("Typical output"); + for(uint16_t iter=0; iterfree_power_budget = this->total_power_budget; +} + +bool Power::tryAccquirePowerAllowance(uint16_t neededPower) +{ + if (this->free_power_budget >= neededPower) + { + this->free_power_budget -= neededPower; + return true; + } + else + { + return false; + } +} + +void Power::releasePower(uint16_t power) +{ + if (this->free_power_budget + power <= this->total_power_budget) + { + this->free_power_budget += power; + } + else // TODO: Maybe we should actually throw an error here, since obviouslsy someone used us wrong. + { + this->free_power_budget = this->total_power_budget; + } +} diff --git a/src/power/Power.h b/src/power/Power.h new file mode 100644 index 0000000..b4b64f9 --- /dev/null +++ b/src/power/Power.h @@ -0,0 +1,35 @@ +/** + * @file Power.h + * @author Phillip Kühne + * @brief This component provides utilities for keeping track of power usage + * consumption. + * @version 0.1 + * @date 2024-11-23 + */ + +#include + +#ifndef Power_h +#define Power_h + +#define TOTAL_POWER_MILLIWATTS 700 + +class Power { + protected: + static const uint16_t total_power_budget = TOTAL_POWER_MILLIWATTS; + uint16_t free_power_budget; + + public: + Power(); + uint16_t getFreePowerBudget(void); + /// @brief Request an allowance of a certain number of milliwatts from the power scheduler + /// @param neededPower the amount of power we want to be accounted for (in mW) + /// @return whether the power could be successfully allocated + bool tryAccquirePowerAllowance(uint16_t neededPower); + /// @brief "Return" a certain amount of power when it is no longer needed + /// @param power the amount of power to return (in mW) + /// @return whether the power + void releasePower(uint16_t power); +}; + +#endif //Power \ No newline at end of file