libstp
Robotics library for Botball
Loading...
Searching...
No Matches
button.hpp
Go to the documentation of this file.
1//
2// Created by eternalRose on 11/17/25.
3//
4
5#pragma once
6
7#ifdef SAFETY_CHECKS_ENABLED
8#include <set>
9#endif
10#include <memory>
11#include "hal/Digital.hpp"
12
13namespace libstp::button {
14
16 class Button final {
17 public:
19 static Button& instance();
20
21 // Set up the digital sensor using a port number (creates the sensor internally).
22 void setDigital(int port);
23 // Share an already-created sensor instance (e.g. the one from robot
24 // defs). The dynamic type is preserved, so a ButtonGroup keeps its
25 // OR-over-ports behaviour — no copy, no reconstruction.
26 void setDigital(std::shared_ptr<hal::digital::DigitalSensor> sensor);
27
29 bool isPressed() const;
30
32 void waitForButtonPress() const;
33
34 Button(const Button&) = delete;
35 Button& operator=(const Button&) = delete;
36 Button(Button&&) = delete;
37 Button& operator=(Button&&) = delete;
38
39 private:
40 Button() = default;
41 ~Button();
42
43 std::shared_ptr<hal::digital::DigitalSensor> digital_sensor_;
44 };
45} // namespace libstp::button
bool isPressed() const
Button & operator=(const Button &)=delete
Button(const Button &)=delete
Button & operator=(Button &&)=delete
void setDigital(std::shared_ptr< hal::digital::DigitalSensor > sensor)
void waitForButtonPress() const
Button(Button &&)=delete
void setDigital(int port)
static Button & instance()