Skip to content

Instantly share code, notes, and snippets.

@loginov-rocks
Last active January 8, 2022 19:38
Show Gist options
  • Save loginov-rocks/041f81c4351a6c8e26f3fedd84651e93 to your computer and use it in GitHub Desktop.
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
#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