libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
UiEventQueue.h
Go to the documentation of this file.
1#pragma once
2#include <stdint.h>
3#include "../util/FIFO.h"
4#include "../util/scopedirqblocker.h"
5
6namespace daisy
7{
18{
19 public:
22
25
27 static constexpr uint16_t invalidPotId = UINT16_MAX;
28
30 struct __attribute__((packed)) Event
31 {
33 enum class EventType : uint8_t
34 {
36 invalid,
49 };
50
52 enum class ActivityType : uint8_t
53 {
57 active
58 };
59
61 EventType type;
62
63 union
64 {
65 struct __attribute__((packed))
66 {
73 bool isRetriggering;
75 struct __attribute__((packed))
76 {
80 struct __attribute__((packed))
81 {
89 struct __attribute__((packed))
90 {
96 struct __attribute__((packed))
97 {
101 float newPosition;
102 } asPotMoved;
103 struct __attribute__((packed))
104 {
106 uint16_t id;
110 };
111 };
112
115
119 bool isRetriggering = false)
120 {
121 Event e;
122 e.type = Event::EventType::buttonPressed;
123 e.asButtonPressed.id = buttonID;
124 e.asButtonPressed.numSuccessivePresses = numSuccessivePresses;
125 e.asButtonPressed.isRetriggering = isRetriggering;
127 events_.PushBack(e);
128 }
129
132 {
133 Event m;
134 m.type = Event::EventType::buttonReleased;
135 m.asButtonReleased.id = buttonID;
137 events_.PushBack(m);
138 }
139
144 {
145 Event e;
146 e.type = Event::EventType::encoderTurned;
147 e.asEncoderTurned.id = encoderID;
148 e.asEncoderTurned.increments = increments;
149 e.asEncoderTurned.stepsPerRev = stepsPerRev;
151 events_.PushBack(e);
152 }
153
156 {
157 Event e;
158 e.type = Event::EventType::encoderActivityChanged;
159 e.asEncoderActivityChanged.id = encoderId;
160 e.asEncoderActivityChanged.newActivityType
161 = isActive ? Event::ActivityType::active
162 : Event::ActivityType::inactive;
164 events_.PushBack(e);
165 }
166
169 {
170 Event e;
171 e.type = Event::EventType::potMoved;
172 e.asPotMoved.id = potId;
173 e.asPotMoved.newPosition = newPosition;
175 events_.PushBack(e);
176 }
177
180 {
181 Event e;
182 e.type = Event::EventType::potActivityChanged;
183 e.asPotActivityChanged.id = potId;
184 e.asPotActivityChanged.newActivityType
185 = isActive ? Event::ActivityType::active
186 : Event::ActivityType::inactive;
188 events_.PushBack(e);
189 }
190
193 {
195 if(events_.IsEmpty())
196 {
197 Event m;
198 m.type = Event::EventType::invalid;
199 return m;
200 }
201 else
202 {
203 return events_.PopFront();
204 }
205 }
206
209 {
211 return events_.IsEmpty();
212 }
213
214 private:
215 FIFO<Event, 256> events_;
216};
217
218} // namespace daisy
bool PushBack(const T &elementToAdd)
Definition FIFO.h:49
T PopFront()
Definition FIFO.h:101
bool IsEmpty() const
Definition FIFO.h:165
Definition leddriver.h:33
struct __attribute__((packed)) PCA9685TransmitBuffer
Definition leddriver.h:36
Definition scopedirqblocker.h:15
A queue that holds user input events in the UI system.
Definition UiEventQueue.h:18
static constexpr uint16_t invalidPotId
Definition UiEventQueue.h:27
struct __attribute__((packed)) Event
Definition UiEventQueue.h:30
void AddEncoderActivityChanged(uint16_t encoderId, bool isActive)
Definition UiEventQueue.h:155
~UiEventQueue()
Definition UiEventQueue.h:114
void AddEncoderTurned(uint16_t encoderID, int16_t increments, uint16_t stepsPerRev)
Definition UiEventQueue.h:141
bool IsQueueEmpty()
Definition UiEventQueue.h:208
void AddButtonReleased(uint16_t buttonID)
Definition UiEventQueue.h:131
void AddPotMoved(uint16_t potId, float newPosition)
Definition UiEventQueue.h:168
Event GetAndRemoveNextEvent()
Definition UiEventQueue.h:192
static constexpr uint16_t invalidEncoderId
Definition UiEventQueue.h:24
UiEventQueue()
Definition UiEventQueue.h:113
static constexpr uint16_t invalidButtonId
Definition UiEventQueue.h:21
void AddPotActivityChanged(uint16_t potId, bool isActive)
Definition UiEventQueue.h:179
void AddButtonPressed(uint16_t buttonID, uint16_t numSuccessivePresses, bool isRetriggering=false)
Definition UiEventQueue.h:117
Hardware defines and helpers for daisy field platform.
Definition index.h:2