RBCX
Library for the RB3204-RBCX board with the ESP32 by RoboticsBrno.
Loading...
Searching...
No Matches
RBCXButtons.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <mutex>
5#include <vector>
6
7#include "RBCXUtil.h"
8
9#include "rbcx.pb.h"
10
11// Arduino defines B1...
12#ifdef B1
13#undef B1
14#endif
15
16namespace rb {
17
22enum ButtonId : uint32_t {
23 Off = CoprocStat_ButtonsEnum_BOFF,
24 On = CoprocStat_ButtonsEnum_BON,
25
26 B1 = CoprocStat_ButtonsEnum_B1,
27 B2 = CoprocStat_ButtonsEnum_B2,
28 B3 = CoprocStat_ButtonsEnum_B3,
29 B4 = CoprocStat_ButtonsEnum_B4,
30
31 Up = B1,
35};
36
38
39class Buttons {
40 friend class Manager;
41
42public:
43 typedef std::function<bool(ButtonId, bool)> callback_t;
44
45 static constexpr uint32_t Count = 6;
46
47
48 inline bool byId(ButtonId id) const { return (m_buttonsSet & id) != 0; };
49 inline bool up() const { return byId(ButtonId::Up); }
50 inline bool down() const { return byId(ButtonId::Down); }
51 inline bool left() const { return byId(ButtonId::Left); }
52 inline bool right() const { return byId(ButtonId::Right); }
53 inline bool on() const { return byId(ButtonId::On); }
54 inline bool off() const { return byId(ButtonId::Off); }
55
61 void onChange(callback_t callback);
62
63private:
64 Buttons();
65 Buttons(const Buttons&) = delete;
66 ~Buttons();
67
68 void setState(const CoprocStat_ButtonsStat& msg);
69
70 std::vector<callback_t> m_callbacks;
71 std::recursive_mutex m_mutex;
72 ButtonId m_buttonsSet;
73};
74};
#define RBCX_ENUM_IMPL_MASK_OPERATORS(T)
Definition: RBCXUtil.h:33
Definition: RBCXButtons.h:39
bool down() const
Returns true if the down button is pressed.
Definition: RBCXButtons.h:50
bool byId(ButtonId id) const
Definition: RBCXButtons.h:48
bool left() const
Returns true if the left button is pressed.
Definition: RBCXButtons.h:51
std::function< bool(ButtonId, bool)> callback_t
Definition: RBCXButtons.h:43
bool right() const
Returns true if the right button is pressed.
Definition: RBCXButtons.h:52
bool up() const
Returns true if the button ButtonId is pressed.
Definition: RBCXButtons.h:49
bool off() const
Returns true if the off button is pressed.
Definition: RBCXButtons.h:54
bool on() const
Returns true if the on button is pressed.
Definition: RBCXButtons.h:53
The main library class for working with the RBCX board. Call the install() method at the start of you...
Definition: RBCXManager.h:61
Definition: RBCXAngle.cpp:3
ButtonId
Helper class for controlling the LEDs connected to the expander.
Definition: RBCXButtons.h:22
@ B4
Definition: RBCXButtons.h:29
@ B3
Definition: RBCXButtons.h:28
@ Off
Definition: RBCXButtons.h:23
@ B1
Definition: RBCXButtons.h:26
@ Left
Definition: RBCXButtons.h:33
@ Right
Definition: RBCXButtons.h:34
@ Down
Definition: RBCXButtons.h:32
@ B2
Definition: RBCXButtons.h:27
@ On
Definition: RBCXButtons.h:24
@ Up
Definition: RBCXButtons.h:31