23 #include "microui_event_decoder.h"
25 #ifdef MICROUIEVENTDECODER_ENABLED
34 #define DESCRIBE_EVENT_GENERATOR(event) (LLUI_DEBUG_TRACE(" (event generator %u)", EVENT_GENERATOR_ID(event)))
35 #define DESCRIBE_EOL() (LLUI_DEBUG_TRACE("\n"))
40 #define EVENT_DATA(event) ((uint16_t)(event))
41 #define EVENT_GENERATOR_ID(event) ((uint8_t)((event) >> 16))
46 #define COMMAND_GET(event) EVENT_DATA(event)
51 #define BUTTON_ACTION_PRESSED 0
52 #define BUTTON_ACTION_RELEASED 1
53 #define BUTTON_ACTION_LONG 2
54 #define BUTTON_ACTION_REPEATED 3
55 #define BUTTON_ACTION_CLICK 4
56 #define BUTTON_ACTION_DOUBLECLICK 5
57 #define BUTTON_ACTION(event) ((uint8_t)((event) >> 8))
58 #define BUTTON_ID(event) ((uint8_t)(event))
63 #define POINTER_ACTION_MOVE 6
64 #define POINTER_ACTION_DRAG 7
65 #define POINTER_X(data) (((data) >> 16) & 0xfff)
66 #define POINTER_Y(data) ((data) & 0xfff)
67 #define POINTER_TYPE(data) (((data) >> 31) & 0x1)
72 #define USEREVENT_SIZE(event) EVENT_DATA(event)
78 static void decode_event_command(uint32_t event, uint32_t index,
79 MICROUI_EVENT_DECODER_decode_event_data *fct_data_decoder) {
81 (void)fct_data_decoder;
83 LLUI_DEBUG_TRACE(
"Command ");
85 uint8_t command = (uint8_t)COMMAND_GET(event);
89 LLUI_DEBUG_TRACE(
"ESC");
93 LLUI_DEBUG_TRACE(
"BACK");
97 LLUI_DEBUG_TRACE(
"UP");
101 LLUI_DEBUG_TRACE(
"DOWN");
105 LLUI_DEBUG_TRACE(
"LEFT");
109 LLUI_DEBUG_TRACE(
"RIGHT");
113 LLUI_DEBUG_TRACE(
"SELECT");
117 LLUI_DEBUG_TRACE(
"CANCEL");
121 LLUI_DEBUG_TRACE(
"HELP");
125 LLUI_DEBUG_TRACE(
"MENU");
129 LLUI_DEBUG_TRACE(
"EXIT");
133 LLUI_DEBUG_TRACE(
"START");
137 LLUI_DEBUG_TRACE(
"STOP");
141 LLUI_DEBUG_TRACE(
"PAUSE");
145 LLUI_DEBUG_TRACE(
"RESUME");
149 LLUI_DEBUG_TRACE(
"COPY");
153 LLUI_DEBUG_TRACE(
"CUT");
157 LLUI_DEBUG_TRACE(
"PASTE");
161 LLUI_DEBUG_TRACE(
"CLOCKWISE");
165 LLUI_DEBUG_TRACE(
"ANTICLOCKWISE");
169 LLUI_DEBUG_TRACE(
"PREVIOUS");
173 LLUI_DEBUG_TRACE(
"NEXT");
177 LLUI_DEBUG_TRACE(
"0x%02x", command);
181 DESCRIBE_EVENT_GENERATOR(event);
185 static void decode_event_button(uint32_t event, uint32_t index,
186 MICROUI_EVENT_DECODER_decode_event_data *fct_data_decoder) {
188 (void)fct_data_decoder;
190 LLUI_DEBUG_TRACE(
"Button %u ", BUTTON_ID(event));
191 uint8_t action = BUTTON_ACTION(event);
194 case BUTTON_ACTION_PRESSED:
195 LLUI_DEBUG_TRACE(
"pressed");
198 case BUTTON_ACTION_RELEASED:
199 LLUI_DEBUG_TRACE(
"released");
202 case BUTTON_ACTION_LONG:
203 LLUI_DEBUG_TRACE(
"long");
206 case BUTTON_ACTION_REPEATED:
207 LLUI_DEBUG_TRACE(
"repeated");
210 case BUTTON_ACTION_CLICK:
211 LLUI_DEBUG_TRACE(
"click");
214 case BUTTON_ACTION_DOUBLECLICK:
215 LLUI_DEBUG_TRACE(
"double-click");
219 LLUI_DEBUG_TRACE(
"unknown action: %u", action);
223 DESCRIBE_EVENT_GENERATOR(event);
227 #ifdef MICROUIEVENTDECODER_EVENTGEN_TOUCH
231 static void decode_event_pointer_data(uint32_t event, uint32_t data, uint32_t index) {
234 LLUI_DEBUG_TRACE(
"[%02u: 0x%08x] at %u,%u (", index, data, POINTER_X(data), POINTER_Y(data));
235 if (0 == POINTER_TYPE(data)) {
236 LLUI_DEBUG_TRACE(
"absolute)");
238 LLUI_DEBUG_TRACE(
"relative)");
246 static void decode_event_pointer(uint32_t event, uint32_t index,
247 MICROUI_EVENT_DECODER_decode_event_data *fct_data_decoder) {
249 (void)fct_data_decoder;
251 LLUI_DEBUG_TRACE(
"Pointer ");
252 uint8_t action = BUTTON_ACTION(event);
255 case BUTTON_ACTION_PRESSED:
256 LLUI_DEBUG_TRACE(
"pressed");
259 case BUTTON_ACTION_RELEASED:
260 LLUI_DEBUG_TRACE(
"released");
263 case BUTTON_ACTION_LONG:
264 LLUI_DEBUG_TRACE(
"long");
267 case BUTTON_ACTION_REPEATED:
268 LLUI_DEBUG_TRACE(
"repeated");
271 case BUTTON_ACTION_CLICK:
272 LLUI_DEBUG_TRACE(
"click");
275 case BUTTON_ACTION_DOUBLECLICK:
276 LLUI_DEBUG_TRACE(
"double-click");
279 case POINTER_ACTION_MOVE:
280 LLUI_DEBUG_TRACE(
"moved");
283 case POINTER_ACTION_DRAG:
284 LLUI_DEBUG_TRACE(
"dragged");
288 LLUI_DEBUG_TRACE(
"unknown action: %u", action);
292 DESCRIBE_EVENT_GENERATOR(event);
296 static void decode_event_state(uint32_t event, uint32_t index,
297 MICROUI_EVENT_DECODER_decode_event_data *fct_data_decoder) {
299 (void)fct_data_decoder;
301 LLUI_DEBUG_TRACE(
"TODO %s 0x%08x\n", __FUNCTION__, event);
311 static void decode_event_input(uint32_t event, uint32_t index,
312 MICROUI_EVENT_DECODER_decode_event_data *fct_data_decoder) {
313 LLUI_DEBUG_TRACE(
"Input event: ");
315 uint8_t generator_id = EVENT_GENERATOR_ID(event);
317 switch (generator_id) {
318 #ifdef MICROUIEVENTDECODER_EVENTGEN_COMMAND
319 case MICROUI_EVENTGEN_COMMANDS:
320 decode_event_command(event, index, fct_data_decoder);
324 #ifdef MICROUIEVENTDECODER_EVENTGEN_BUTTONS
325 case MICROUIEVENTDECODER_EVENTGEN_BUTTONS:
326 decode_event_button(event, index, fct_data_decoder);
330 #ifdef MICROUIEVENTDECODER_EVENTGEN_TOUCH
331 case MICROUIEVENTDECODER_EVENTGEN_TOUCH:
332 *fct_data_decoder = decode_event_pointer_data;
333 decode_event_pointer(event, index, fct_data_decoder);
338 LLUI_DEBUG_TRACE(
"unknown ");
339 DESCRIBE_EVENT_GENERATOR(event);
345 static void decode_event_user_data(uint32_t event, uint32_t data, uint32_t index) {
347 LLUI_DEBUG_TRACE(
" [%02u] 0x%08x\n", index, data);
350 static void decode_event_user(uint32_t event, uint32_t index,
351 MICROUI_EVENT_DECODER_decode_event_data *fct_data_decoder) {
353 LLUI_DEBUG_TRACE(
"User input event");
355 uint8_t size = (uint8_t)USEREVENT_SIZE(event);
356 if (size > (uint32_t)1) {
357 LLUI_DEBUG_TRACE(
"s (size = %u)", size);
359 DESCRIBE_EVENT_GENERATOR(event);
360 LLUI_DEBUG_TRACE(
": ");
362 *fct_data_decoder = decode_event_user_data;
369 void MICROUI_EVENT_DECODER_describe_dump_start(
void) {
370 LLUI_DEBUG_TRACE(
"============================== MicroUI FIFO Dump ===============================\n");
373 void MICROUI_EVENT_DECODER_describe_dump_past(
void) {
374 LLUI_DEBUG_TRACE(
"---------------------------------- Old Events ----------------------------------\n");
377 void MICROUI_EVENT_DECODER_describe_dump_future(
void) {
378 LLUI_DEBUG_TRACE(
"---------------------------------- New Events ----------------------------------\n");
381 void MICROUI_EVENT_DECODER_describe_dump_events_objects(
void) {
382 LLUI_DEBUG_TRACE(
"--------------------------- New Events' Java objects ---------------------------\n");
385 void MICROUI_EVENT_DECODER_describe_dump_end(
void) {
386 LLUI_DEBUG_TRACE(
"================================================================================\n");
389 void MICROUI_EVENT_DECODER_drop_data(uint32_t data, uint32_t index) {
390 LLUI_DEBUG_TRACE(
"[%02u: 0x%08x] garbage\n", index, data);
393 void MICROUI_EVENT_DECODER_decode_event(uint32_t event, uint32_t index,
394 MICROUI_EVENT_DECODER_decode_event_data *fct_data_decoder) {
395 LLUI_DEBUG_TRACE(
"[%02u: 0x%08x] ", index, event);
397 uint8_t event_type = (uint8_t)(event >> 24);
399 switch (event_type) {
401 decode_event_command(event, index, fct_data_decoder);
405 decode_event_button(event, index, fct_data_decoder);
409 decode_event_pointer(event, index, fct_data_decoder);
413 decode_event_state(event, index, fct_data_decoder);
421 LLUI_DEBUG_TRACE(
"Call serially (Runnable index = %u)\n", EVENT_DATA(event));
425 LLUI_DEBUG_TRACE(
"MicroUI STOP\n");
429 decode_event_input(event, index, fct_data_decoder);
433 LLUI_DEBUG_TRACE(
"Display SHOW Displayable (Displayable index = %u)\n", EVENT_DATA(event));
437 LLUI_DEBUG_TRACE(
"Display HIDE Displayable (Displayable index = %u)\n", EVENT_DATA(event));
445 LLUI_DEBUG_TRACE(
"Display FLUSH\n");
449 LLUI_DEBUG_TRACE(
"Display FORCE FLUSH\n");
453 LLUI_DEBUG_TRACE(
"Display REPAINT Displayable (Displayable index = %u)\n", EVENT_DATA(event));
457 LLUI_DEBUG_TRACE(
"Display REPAINT Current Displayable\n");
461 LLUI_DEBUG_TRACE(
"Display KF SWITCH Display\n");
465 decode_event_user(event, index, fct_data_decoder);