re-use existing enum
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
Robin Müller 2022-05-02 22:55:39 +02:00
parent 9449919b2b
commit 1f8a68dabe
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
3 changed files with 15 additions and 21 deletions

View File

@ -3,8 +3,8 @@
#include <cstdint>
namespace heaterSwitches {
enum switcherList: uint8_t {
namespace heater {
enum Switchers: uint8_t {
HEATER_0,
HEATER_1,
HEATER_2,

View File

@ -71,7 +71,7 @@ ReturnValue_t HeaterHandler::initialize() {
}
ReturnValue_t HeaterHandler::initializeHeaterMap() {
for (power::Switch_t switchNr = 0; switchNr < heaterSwitches::NUMBER_OF_SWITCHES; switchNr++) {
for (power::Switch_t switchNr = 0; switchNr < heater::NUMBER_OF_SWITCHES; switchNr++) {
heaterVec.push_back(HeaterWrapper(helper.heaters[switchNr]));
}
return RETURN_OK;
@ -159,14 +159,14 @@ ReturnValue_t HeaterHandler::sendSwitchCommand(uint8_t switchNr, ReturnValue_t o
}
void HeaterHandler::handleActiveCommands() {
for (uint8_t idx = 0; idx < heater::NUMBER_OF_HEATERS; idx++) {
for (uint8_t idx = 0; idx < heater::NUMBER_OF_SWITCHES; idx++) {
if (heaterVec[idx].active) {
switch (heaterVec[idx].action) {
case SET_SWITCH_ON:
handleSwitchOnCommand(idx);
handleSwitchOnCommand(static_cast<heater::Switchers>(idx));
break;
case SET_SWITCH_OFF:
handleSwitchOffCommand(idx);
handleSwitchOffCommand(static_cast<heater::Switchers>(idx));
break;
default:
sif::error << "HeaterHandler::handleActiveCommands: Invalid action commanded"
@ -177,7 +177,7 @@ void HeaterHandler::handleActiveCommands() {
}
}
void HeaterHandler::handleSwitchOnCommand(uint8_t heaterIdx) {
void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) {
ReturnValue_t result = RETURN_OK;
auto& heater = heaterVec.at(heaterIdx);
/* Check if command waits for main switch being set on and whether the timeout has expired */
@ -238,7 +238,7 @@ void HeaterHandler::handleSwitchOnCommand(uint8_t heaterIdx) {
}
}
void HeaterHandler::handleSwitchOffCommand(uint8_t heaterIdx) {
void HeaterHandler::handleSwitchOffCommand(heater::Switchers heaterIdx) {
ReturnValue_t result = RETURN_OK;
auto& heater = heaterVec.at(heaterIdx);
// Check whether switch is already off
@ -271,14 +271,14 @@ void HeaterHandler::handleSwitchOffCommand(uint8_t heaterIdx) {
heater.active = false;
}
HeaterHandler::SwitchState HeaterHandler::checkSwitchState(uint8_t switchNr) {
HeaterHandler::SwitchState HeaterHandler::checkSwitchState(heater::Switchers switchNr) {
return heaterVec.at(switchNr).switchState;
}
bool HeaterHandler::allSwitchesOff() {
bool allSwitchesOrd = false;
/* Or all switches. As soon one switch is on, allSwitchesOrd will be true */
for (power::Switch_t switchNr = 0; switchNr < heaterSwitches::NUMBER_OF_SWITCHES; switchNr++) {
for (power::Switch_t switchNr = 0; switchNr < heater::NUMBER_OF_SWITCHES; switchNr++) {
allSwitchesOrd = allSwitchesOrd || heaterVec.at(switchNr).switchState;
}
return !allSwitchesOrd;

View File

@ -21,18 +21,12 @@
class PowerSwitchIF;
class HealthTableIF;
namespace heater {
static constexpr uint8_t NUMBER_OF_HEATERS = 8;
}
using HeaterPair = std::pair<HealthDevice*, gpioId_t>;
struct HeaterHelper {
public:
HeaterHelper(std::array<HeaterPair, heater::NUMBER_OF_HEATERS> heaters) : heaters(heaters) {}
std::array<HeaterPair, heater::NUMBER_OF_HEATERS> heaters = {};
HeaterHelper(std::array<HeaterPair, heater::NUMBER_OF_SWITCHES> heaters) : heaters(heaters) {}
std::array<HeaterPair, heater::NUMBER_OF_SWITCHES> heaters = {};
};
/**
* @brief This class intends the control of heaters.
@ -144,7 +138,7 @@ class HeaterHandler : public ExecutableObjectIF,
* @brief Returns the state of a switch (ON - true, or OFF - false).
* @param switchNr The number of the switch to check.
*/
SwitchState checkSwitchState(power::Switch_t switchNr);
SwitchState checkSwitchState(heater::Switchers switchNr);
/**
* @brief This function runs commands waiting for execution.
@ -158,9 +152,9 @@ class HeaterHandler : public ExecutableObjectIF,
*/
void setInitialSwitchStates();
void handleSwitchOnCommand(uint8_t heaterIdx);
void handleSwitchOnCommand(heater::Switchers heaterIdx);
void handleSwitchOffCommand(uint8_t heaterIdx);
void handleSwitchOffCommand(heater::Switchers heaterIdx);
/**
* @brief Checks if all switches are off.