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