add option to directly check switch state

This commit is contained in:
Robin Müller 2022-03-22 20:35:04 +01:00
parent bbe21e7e89
commit 4b5e3e70f7
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
2 changed files with 16 additions and 4 deletions

View File

@ -45,12 +45,24 @@ void PowerSwitcher::commandSwitches(ReturnValue_t onOff) {
return;
}
void PowerSwitcher::turnOn() {
void PowerSwitcher::turnOn(bool checkCurrentState) {
if(checkCurrentState) {
if(getStateOfSwitches() == PowerSwitchIF::SWITCH_ON) {
state = SWITCH_IS_ON;
return;
}
}
commandSwitches(PowerSwitchIF::SWITCH_ON);
state = WAIT_ON;
}
void PowerSwitcher::turnOff() {
void PowerSwitcher::turnOff(bool checkCurrentState) {
if(checkCurrentState) {
if(getStateOfSwitches() == PowerSwitchIF::SWITCH_OFF) {
state = SWITCH_IS_OFF;
return;
}
}
commandSwitches(PowerSwitchIF::SWITCH_OFF);
state = WAIT_OFF;
}

View File

@ -20,8 +20,8 @@ class PowerSwitcher : public HasReturnvaluesIF {
static const ReturnValue_t SWITCH_STATE_MISMATCH = MAKE_RETURN_CODE(2);
PowerSwitcher(PowerSwitchIF* switcher, uint8_t setSwitch1, uint8_t setSwitch2 = power::NO_SWITCH,
State_t setStartState = SWITCH_IS_OFF);
void turnOn();
void turnOff();
void turnOn(bool checkCurrentState = true);
void turnOff(bool checkCurrentState = true);
bool active();
void doStateMachine();
State_t getState();