133
- EV_1click: The user clicked the e-switch, released it, and
134
enough time passed that no more clicks were detected.
136
- EV_2clicks: The user clicked and released the e-switch twice, then
137
enough time passed that no more clicks were detected.
139
- EV_3clicks: The user clicked and released the e-switch three
140
times, then enough time passed that no more clicks were detected.
142
- EV_4clicks: The user clicked and released the e-switch four times,
143
then enough time passed that no more clicks were detected.
145
- EV_click1_hold: The user pressed the button and is still holding
146
it. The 'arg' indicates how many clock ticks since the "hold"
149
- EV_click1_hold_release: The user pressed the button, held it for a
150
while, and then released it. No timeout is attempted after this.
152
- EV_click2_hold: The user clicked once, then pressed the button and
153
is still holding it. The 'arg' indicates how many clock ticks
154
since the "hold" state started.
156
- EV_click2_hold_release: The user clicked once, then pressed the
157
button, held it for a while, and released it. No timeout is
158
attempted after this.
160
- EV_click1_press: The user pressed the button and it's still down.
161
No time has yet passed.
163
- EV_click1_release: The user quickly pressed and released the
164
button. The click timeout has not yet expired, so they might
167
- EV_click2_press: The user pressed the button, released it, pressed
168
again, and it's still down. No time has yet passed since then.
170
- EV_click2_release: The quickly pressed and released the button
171
twice. The click timeout has not yet expired, so they might still
138
Button events can be referred to either by pre-defined symbols, or
139
by teasing out the flags manually. The structure of a button
142
- Bit 7: 1 for button events, 0 otherwise.
144
- Bit 6: 1 for a "timeout" event (signals the end of a
145
sequence), or 0 otherwise.
147
- Bit 5: 1 for a "hold" event, 0 otherwise. This flag is only
148
necessary because, without it, it would be impossible to
149
distinguish between "click, click, timeout" and "click, hold,
152
- Bit 4: 1 if button is currently pressed, 0 otherwise. Button
153
release events look just like button press events, except this
156
- Bits 0,1,2,3: Counter for how many clicks there have been.
157
The first click is 1, second is 2, and it goes up to 15 clicks
158
in a row. Clicks after 15 are coded as 15.
160
The pre-defined button event symbols are like the following:
162
- EV_click1_press: The user pressed the button, but no time has
165
- EV_click1_release: The user pressed and released the button,
166
but no time has passed since then.
168
- EV_click1_complete: The user clicked the e-switch, released
169
it, and enough time passed that no more clicks were detected.
172
- EV_click1_hold: The user pressed the button, and continued
173
holding it long enough to count as a "hold" event. This event
174
is sent once per timer tick as long as the button is held, and
175
the 'arg' value indicates how many timer ticks since the
176
button state went from 'press' to 'hold'.
178
- EV_click1_hold_release: The button was released at the end of
179
a "hold" event. This is the end of the input sequence,
180
because no timeout period is used after a hold.
182
It's worth noting that a "hold" event can only happen at the
183
end of an input sequence, and the sequence will reset to empty
184
after the hold is released.
186
If the user pressed the button more than once, events follow the
187
same pattern. These are the same as above, except with a full
188
short-press and release first.
192
- EV_click2_complete (a.k.a. EV_2clicks)
194
- EV_click2_hold_release
196
Each of the above patterns continues up to 15 clicks.
198
To match entire categories of events, use the bitmasks provided.
199
For example, to match button events where the button is down or
200
the button is up, the code would look like this:
202
if ((event & (B_CLICK | B_PRESS)) == (B_CLICK | B_PRESS)) {
203
// button is down (can be a press event or a hold event)
205
else if ((event & (B_CLICK | B_PRESS)) == (B_CLICK)) {
206
// button was just released
174
209
In theory, you could also define your own arbitrary event types, and
175
210
emit() them as necessary, and handle them in State functions the same
176
211
as any other event.
178
One thing to note if you create your own Event types: The copy which
179
gets sent to States must be in the 'event_sequences' array, meaning
180
the State gets a const PROGMEM version of the Event. It cannot simply
181
send the dynamic 'current_event' object, because it has probably
182
already changed by the time the callback happens.
185
214
Cooperative multitasking: