libstp
Robotics library for Botball
Loading...
Searching...
No Matches
Digital.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <vector>
5
7
9{
20 {
21#ifdef SAFETY_CHECKS_ENABLED
22 static inline detail::PortRegistry registry_{};
23 static void registerDigitalPort(int port);
24 static void unregisterDigitalPort(int port);
25#endif
26 public:
27 int port;
28
30 explicit DigitalSensor(int port);
31
32 virtual ~DigitalSensor();
33
35 virtual bool read() const;
36 };
37
47 class ButtonGroup final : public DigitalSensor
48 {
49 public:
51 explicit ButtonGroup(std::vector<int> ports);
52
54 bool read() const override;
55
57 const std::vector<int>& ports() const { return ports_; }
58
59 private:
60 std::vector<int> ports_;
61 // Owns sensors for ports_[1..]; ports_[0] is the inherited base.
62 std::vector<std::unique_ptr<DigitalSensor>> extra_;
63 };
64}
ButtonGroup(std::vector< int > ports)
Construct from one or more platform port indices (must be non-empty).
bool read() const override
True when any member port reads pressed.
const std::vector< int > & ports() const
The configured member ports.
Definition Digital.hpp:57
virtual bool read() const
Return the current boolean state for the configured input.
DigitalSensor(int port)
Create a digital input bound to a platform-defined port index.