mirror of
https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
synced 2025-08-24 10:48:37 +02:00
Add existing code: Power consumption test cases and Semaphore power scheduler skeleton
This commit is contained in:
40
src/power/Power.cpp
Normal file
40
src/power/Power.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @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 "Power.h"
|
||||
|
||||
Power::Power()
|
||||
{
|
||||
this->free_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;
|
||||
}
|
||||
}
|
35
src/power/Power.h
Normal file
35
src/power/Power.h
Normal file
@@ -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 <Arduino.h>
|
||||
|
||||
#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
|
Reference in New Issue
Block a user