Last active
January 8, 2022 19:38
-
-
Save loginov-rocks/041f81c4351a6c8e26f3fedd84651e93 to your computer and use it in GitHub Desktop.
DIY Connected Espresso Machine: Main Class and Indicators (Part 5) - EspressoMachine Implementation, Commands Part
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "EspressoMachine.h" | |
void EspressoMachine::setCommand(EspressoMachineCommand command) | |
{ | |
lastCommand = command; | |
isCommandChanged = true; | |
} | |
EspressoMachineCommand EspressoMachine::getCommand() | |
{ | |
return lastCommand; | |
} | |
// One-time getter to know if the command has been changed. | |
boolean EspressoMachine::getIsCommandChanged() | |
{ | |
if (!isCommandChanged) | |
{ | |
return false; | |
} | |
isCommandChanged = false; | |
return true; | |
} | |
boolean EspressoMachine::command(EspressoMachineCommand command) | |
{ | |
// Deny internal commands usage programmatically. | |
if (command == EspressoMachineCommand::ToggleBoil || | |
command == EspressoMachineCommand::ToggleMakeSteam || | |
command == EspressoMachineCommand::TogglePourWater) | |
{ | |
return false; | |
} | |
// Deny external commands if the toggle is not in the "Off" position. | |
if (getToggleState() != ToggleState::Off) | |
{ | |
return false; | |
} | |
setCommand(command); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment