24 #include "microui_event_decoder.h"
26 #ifdef MICROUIEVENTDECODER_ENABLED
35 #define DESCRIBE_EVENT_GENERATOR(event) (LLUI_DEBUG_TRACE(" (event generator %u)", EVENT_GENERATOR_ID(event)))
36 #define DESCRIBE_EOL() (LLUI_DEBUG_TRACE("\n"))
41 #define EVENT_DATA(event) ((uint16_t)(event))
42 #define EVENT_GENERATOR_ID(event) ((uint8_t)((event) >> 16))
47 #define COMMAND_GET(event) EVENT_DATA(event)
52 #define BUTTON_ACTION_PRESSED 0
53 #define BUTTON_ACTION_RELEASED 1
54 #define BUTTON_ACTION_LONG 2
55 #define BUTTON_ACTION_REPEATED 3
56 #define BUTTON_ACTION_CLICK 4
57 #define BUTTON_ACTION_DOUBLECLICK 5
58 #define BUTTON_ACTION(event) ((uint8_t)((event) >> 8))
59 #define BUTTON_ID(event) ((uint8_t)(event))
64 #define POINTER_ACTION_MOVE 6
65 #define POINTER_ACTION_DRAG 7
66 #define POINTER_X(data) (((data) >> 16) & 0xfff)
67 #define POINTER_Y(data) ((data) & 0xfff)
68 #define POINTER_TYPE(data) (((data) >> 31) & 0x1)
73 #define USEREVENT_SIZE(event) EVENT_DATA(event)
79 static void decode_event_command(uint32_t event, uint32_t index, 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");
92 LLUI_DEBUG_TRACE(
"BACK");
95 LLUI_DEBUG_TRACE(
"UP");
98 LLUI_DEBUG_TRACE(
"DOWN");
101 LLUI_DEBUG_TRACE(
"LEFT");
104 LLUI_DEBUG_TRACE(
"RIGHT");
107 LLUI_DEBUG_TRACE(
"SELECT");
110 LLUI_DEBUG_TRACE(
"CANCEL");
113 LLUI_DEBUG_TRACE(
"HELP");
116 LLUI_DEBUG_TRACE(
"MENU");
119 LLUI_DEBUG_TRACE(
"EXIT");
122 LLUI_DEBUG_TRACE(
"START");
125 LLUI_DEBUG_TRACE(
"STOP");
128 LLUI_DEBUG_TRACE(
"PAUSE");
131 LLUI_DEBUG_TRACE(
"RESUME");
134 LLUI_DEBUG_TRACE(
"COPY");
137 LLUI_DEBUG_TRACE(
"CUT");
140 LLUI_DEBUG_TRACE(
"PASTE");
143 LLUI_DEBUG_TRACE(
"CLOCKWISE");
146 LLUI_DEBUG_TRACE(
"ANTICLOCKWISE");
149 LLUI_DEBUG_TRACE(
"PREVIOUS");
152 LLUI_DEBUG_TRACE(
"NEXT");
155 LLUI_DEBUG_TRACE(
"0x%02x", command);
159 DESCRIBE_EVENT_GENERATOR(event);
163 static void decode_event_button(uint32_t event, uint32_t index, MICROUI_EVENT_DECODER_decode_event_data* fct_data_decoder) {
165 (void)fct_data_decoder;
167 LLUI_DEBUG_TRACE(
"Button %u ", BUTTON_ID(event));
168 uint8_t action = BUTTON_ACTION(event);
171 case BUTTON_ACTION_PRESSED:
172 LLUI_DEBUG_TRACE(
"pressed");
174 case BUTTON_ACTION_RELEASED:
175 LLUI_DEBUG_TRACE(
"released");
177 case BUTTON_ACTION_LONG:
178 LLUI_DEBUG_TRACE(
"long");
180 case BUTTON_ACTION_REPEATED:
181 LLUI_DEBUG_TRACE(
"repeated");
183 case BUTTON_ACTION_CLICK:
184 LLUI_DEBUG_TRACE(
"click");
186 case BUTTON_ACTION_DOUBLECLICK:
187 LLUI_DEBUG_TRACE(
"double-click");
190 LLUI_DEBUG_TRACE(
"unknown action: %u", action);
194 DESCRIBE_EVENT_GENERATOR(event);
198 #ifdef MICROUIEVENTDECODER_EVENTGEN_TOUCH
202 static void decode_event_pointer_data(uint32_t event, uint32_t data, uint32_t index) {
205 LLUI_DEBUG_TRACE(
"[%02u: 0x%08x] at %u,%u (", index, data, POINTER_X(data), POINTER_Y(data));
206 if (0 == POINTER_TYPE(data)) {
207 LLUI_DEBUG_TRACE(
"absolute)");
210 LLUI_DEBUG_TRACE(
"relative)");
217 static void decode_event_pointer(uint32_t event, uint32_t index, MICROUI_EVENT_DECODER_decode_event_data* fct_data_decoder) {
219 (void)fct_data_decoder;
221 LLUI_DEBUG_TRACE(
"Pointer ");
222 uint8_t action = BUTTON_ACTION(event);
225 case BUTTON_ACTION_PRESSED:
226 LLUI_DEBUG_TRACE(
"pressed");
228 case BUTTON_ACTION_RELEASED:
229 LLUI_DEBUG_TRACE(
"released");
231 case BUTTON_ACTION_LONG:
232 LLUI_DEBUG_TRACE(
"long");
234 case BUTTON_ACTION_REPEATED:
235 LLUI_DEBUG_TRACE(
"repeated");
237 case BUTTON_ACTION_CLICK:
238 LLUI_DEBUG_TRACE(
"click");
240 case BUTTON_ACTION_DOUBLECLICK:
241 LLUI_DEBUG_TRACE(
"double-click");
243 case POINTER_ACTION_MOVE:
244 LLUI_DEBUG_TRACE(
"moved");
246 case POINTER_ACTION_DRAG:
247 LLUI_DEBUG_TRACE(
"dragged");
250 LLUI_DEBUG_TRACE(
"unknown action: %u", action);
254 DESCRIBE_EVENT_GENERATOR(event);
258 static void decode_event_state(uint32_t event, uint32_t index, MICROUI_EVENT_DECODER_decode_event_data* fct_data_decoder) {
260 (void)fct_data_decoder;
262 LLUI_DEBUG_TRACE(
"TODO %s 0x%08x\n", __FUNCTION__, event);
272 static void decode_event_input(uint32_t event, uint32_t index, MICROUI_EVENT_DECODER_decode_event_data* fct_data_decoder) {
273 LLUI_DEBUG_TRACE(
"Input event: ");
275 uint8_t generator_id = EVENT_GENERATOR_ID(event);
277 switch(generator_id) {
279 #ifdef MICROUIEVENTDECODER_EVENTGEN_COMMAND
280 case MICROUI_EVENTGEN_COMMANDS:
281 decode_event_command(event, index, fct_data_decoder);
285 #ifdef MICROUIEVENTDECODER_EVENTGEN_BUTTONS
286 case MICROUIEVENTDECODER_EVENTGEN_BUTTONS:
287 decode_event_button(event, index, fct_data_decoder);
291 #ifdef MICROUIEVENTDECODER_EVENTGEN_TOUCH
292 case MICROUIEVENTDECODER_EVENTGEN_TOUCH:
293 *fct_data_decoder = decode_event_pointer_data;
294 decode_event_pointer(event, index, fct_data_decoder);
299 LLUI_DEBUG_TRACE(
"unknown ");
300 DESCRIBE_EVENT_GENERATOR(event);
306 static void decode_event_user_data(uint32_t event, uint32_t data, uint32_t index) {
308 LLUI_DEBUG_TRACE(
" [%02u] 0x%08x\n", index, data);
311 static void decode_event_user(uint32_t event, uint32_t index, MICROUI_EVENT_DECODER_decode_event_data* fct_data_decoder) {
313 LLUI_DEBUG_TRACE(
"User input event");
315 uint8_t size = (uint8_t)USEREVENT_SIZE(event);
316 if (size > (uint32_t)1) {
317 LLUI_DEBUG_TRACE(
"s (size = %u)", size);
319 DESCRIBE_EVENT_GENERATOR(event);
320 LLUI_DEBUG_TRACE(
": ");
322 *fct_data_decoder = decode_event_user_data;
330 void MICROUI_EVENT_DECODER_describe_dump_start(
void) {
331 LLUI_DEBUG_TRACE(
"============================== MicroUI FIFO Dump ===============================\n");
334 void MICROUI_EVENT_DECODER_describe_dump_past(
void) {
335 LLUI_DEBUG_TRACE(
"---------------------------------- Old Events ----------------------------------\n");
338 void MICROUI_EVENT_DECODER_describe_dump_future(
void) {
339 LLUI_DEBUG_TRACE(
"---------------------------------- New Events ----------------------------------\n");
342 void MICROUI_EVENT_DECODER_describe_dump_events_objects(
void) {
343 LLUI_DEBUG_TRACE(
"--------------------------- New Events' Java objects ---------------------------\n");
346 void MICROUI_EVENT_DECODER_describe_dump_end(
void) {
347 LLUI_DEBUG_TRACE(
"================================================================================\n");
350 void MICROUI_EVENT_DECODER_drop_data(uint32_t data, uint32_t index) {
351 LLUI_DEBUG_TRACE(
"[%02u: 0x%08x] garbage\n", index, data);
354 void MICROUI_EVENT_DECODER_decode_event(uint32_t event, uint32_t index, MICROUI_EVENT_DECODER_decode_event_data* fct_data_decoder) {
355 LLUI_DEBUG_TRACE(
"[%02u: 0x%08x] ", index, event);
357 uint8_t event_type = (uint8_t)(event >> 24);
361 decode_event_command(event, index, fct_data_decoder);
364 decode_event_button(event, index, fct_data_decoder);
367 decode_event_pointer(event, index, fct_data_decoder);
370 decode_event_state(event, index, fct_data_decoder);
376 LLUI_DEBUG_TRACE(
"Call serially (Runnable index = %u)\n", EVENT_DATA(event));
379 LLUI_DEBUG_TRACE(
"MicroUI STOP\n");
382 decode_event_input(event, index, fct_data_decoder);
385 LLUI_DEBUG_TRACE(
"Display SHOW Displayable (Displayable index = %u)\n", EVENT_DATA(event));
388 LLUI_DEBUG_TRACE(
"Display HIDE Displayable (Displayable index = %u)\n", EVENT_DATA(event));
394 LLUI_DEBUG_TRACE(
"Display FLUSH\n");
397 LLUI_DEBUG_TRACE(
"Display FORCE FLUSH\n");
400 LLUI_DEBUG_TRACE(
"Display REPAINT Displayable (Displayable index = %u)\n", EVENT_DATA(event));
403 LLUI_DEBUG_TRACE(
"Display REPAINT Current Displayable\n");
406 LLUI_DEBUG_TRACE(
"Display KF SWITCH Display\n");
409 decode_event_user(event, index, fct_data_decoder);