roo_control
API Documentation for roo_control
Loading...
Searching...
No Matches
switch.h
Go to the documentation of this file.
1#pragma once
2
5#include "roo_logging.h"
6
7namespace roo_control {
8
9/// An abstraction of a multi-state settable switch.
10///
11/// This can represent GPIO relays, port extenders, or software switches.
12///
13/// This abstraction serves two main purposes:
14/// 1) it makes it easy to swap the implementation of a switch, without
15/// changing the code that uses it. For example, you can start by
16/// connecting a simple relay to a GPIO port, but eventually upgrade to a
17/// port extender. You will not need to update the calling code (just the
18/// setup logic).
19/// 2) it allows building higher-level abstractions that are
20/// implementation-independent. For example, the InertSwitch (and its
21/// materialization, InertBinarySwitch) can be used to add debouncing
22/// on top of any switch implementation.
23template <typename State>
24class Switch : public Selector<State> {
25 public:
26 virtual ~Switch() = default;
27
28 /// Updates the state of the switch. Returns true on success.
29 virtual bool setState(State state) = 0;
30};
31
32/// Materialization for a two-state switch, usually driven by digital logic.
34
35} // namespace roo_control
An abstraction of a multi-state device.
Definition selector.h:23
An abstraction of a multi-state settable switch.
Definition switch.h:24
virtual bool setState(State state)=0
Updates the state of the switch. Returns true on success.
virtual ~Switch()=default