20 #if defined(UI_FEATURE_EVENT_DECODER)
27 #include "microui_event_decoder.h"
36 #define DESCRIBE_EVENT_GENERATOR(event) (UI_DEBUG_PRINT(" (event generator %u)", EVENT_GENERATOR_ID(event)))
37 #define DESCRIBE_EOL() (UI_DEBUG_PRINT("\n"))
42 #define EVENT_DATA(event) ((uint16_t)(event))
43 #define EVENT_GENERATOR_ID(event) ((uint8_t)((event) >> 16))
48 #define COMMAND_GET(event) EVENT_DATA(event)
53 #define BUTTON_ACTION_PRESSED 0
54 #define BUTTON_ACTION_RELEASED 1
55 #define BUTTON_ACTION_LONG 2
56 #define BUTTON_ACTION_REPEATED 3
57 #define BUTTON_ACTION_CLICK 4
58 #define BUTTON_ACTION_DOUBLECLICK 5
59 #define BUTTON_ACTION(event) ((uint8_t)((event) >> 8))
60 #define BUTTON_ID(event) ((uint8_t)(event))
65 #define POINTER_ACTION_MOVE 6
66 #define POINTER_ACTION_DRAG 7
67 #define POINTER_X(data) (((data) >> 16) & 0xfff)
68 #define POINTER_Y(data) ((data) & 0xfff)
69 #define POINTER_TYPE(data) (((data) >> 31) & 0x1)
74 #define USEREVENT_SIZE(event) EVENT_DATA(event)
80 static void decode_event_command(uint32_t event, uint32_t index,
81 MICROUI_EVENT_DECODER_decode_event_data *fct_data_decoder) {
83 (void)fct_data_decoder;
87 uint8_t command = (uint8_t)COMMAND_GET(event);
183 DESCRIBE_EVENT_GENERATOR(event);
187 static void decode_event_button(uint32_t event, uint32_t index,
188 MICROUI_EVENT_DECODER_decode_event_data *fct_data_decoder) {
190 (void)fct_data_decoder;
193 uint8_t action = BUTTON_ACTION(event);
196 case BUTTON_ACTION_PRESSED:
200 case BUTTON_ACTION_RELEASED:
204 case BUTTON_ACTION_LONG:
208 case BUTTON_ACTION_REPEATED:
212 case BUTTON_ACTION_CLICK:
216 case BUTTON_ACTION_DOUBLECLICK:
225 DESCRIBE_EVENT_GENERATOR(event);
229 #ifdef UI_EVENTDECODER_EVENTGEN_TOUCH
233 static void decode_event_pointer_data(uint32_t event, uint32_t data, uint32_t index) {
236 UI_DEBUG_PRINT(
"[%02u: 0x%08x] at %u,%u (", index, data, POINTER_X(data), POINTER_Y(data));
237 if (0 == POINTER_TYPE(data)) {
248 static void decode_event_pointer(uint32_t event, uint32_t index,
249 MICROUI_EVENT_DECODER_decode_event_data *fct_data_decoder) {
251 (void)fct_data_decoder;
254 uint8_t action = BUTTON_ACTION(event);
257 case BUTTON_ACTION_PRESSED:
261 case BUTTON_ACTION_RELEASED:
265 case BUTTON_ACTION_LONG:
269 case BUTTON_ACTION_REPEATED:
273 case BUTTON_ACTION_CLICK:
277 case BUTTON_ACTION_DOUBLECLICK:
281 case POINTER_ACTION_MOVE:
285 case POINTER_ACTION_DRAG:
294 DESCRIBE_EVENT_GENERATOR(event);
298 static void decode_event_state(uint32_t event, uint32_t index,
299 MICROUI_EVENT_DECODER_decode_event_data *fct_data_decoder) {
301 (void)fct_data_decoder;
313 static void decode_event_input(uint32_t event, uint32_t index,
314 MICROUI_EVENT_DECODER_decode_event_data *fct_data_decoder) {
317 uint8_t generator_id = EVENT_GENERATOR_ID(event);
319 switch (generator_id) {
320 #ifdef UI_EVENTDECODER_EVENTGEN_COMMAND
321 case MICROUI_EVENTGEN_COMMANDS:
322 decode_event_command(event, index, fct_data_decoder);
326 #ifdef UI_EVENTDECODER_EVENTGEN_BUTTONS
327 case UI_EVENTDECODER_EVENTGEN_BUTTONS:
328 decode_event_button(event, index, fct_data_decoder);
332 #ifdef UI_EVENTDECODER_EVENTGEN_TOUCH
333 case UI_EVENTDECODER_EVENTGEN_TOUCH:
334 *fct_data_decoder = decode_event_pointer_data;
335 decode_event_pointer(event, index, fct_data_decoder);
341 DESCRIBE_EVENT_GENERATOR(event);
347 static void decode_event_user_data(uint32_t event, uint32_t data, uint32_t index) {
352 static void decode_event_user(uint32_t event, uint32_t index,
353 MICROUI_EVENT_DECODER_decode_event_data *fct_data_decoder) {
357 uint8_t size = (uint8_t)USEREVENT_SIZE(event);
358 if (size > (uint32_t)1) {
361 DESCRIBE_EVENT_GENERATOR(event);
364 *fct_data_decoder = decode_event_user_data;
371 void MICROUI_EVENT_DECODER_describe_dump_start(
void) {
372 UI_DEBUG_PRINT(
"============================== MicroUI FIFO Dump ===============================\n");
375 void MICROUI_EVENT_DECODER_describe_dump_past(
void) {
376 UI_DEBUG_PRINT(
"---------------------------------- Old Events ----------------------------------\n");
379 void MICROUI_EVENT_DECODER_describe_dump_future(
void) {
380 UI_DEBUG_PRINT(
"---------------------------------- New Events ----------------------------------\n");
383 void MICROUI_EVENT_DECODER_describe_dump_events_objects(
void) {
384 UI_DEBUG_PRINT(
"--------------------------- New Events' Java objects ---------------------------\n");
387 void MICROUI_EVENT_DECODER_describe_dump_end(
void) {
388 UI_DEBUG_PRINT(
"================================================================================\n");
391 void MICROUI_EVENT_DECODER_drop_data(uint32_t data, uint32_t index) {
395 void MICROUI_EVENT_DECODER_decode_event(uint32_t event, uint32_t index,
396 MICROUI_EVENT_DECODER_decode_event_data *fct_data_decoder) {
399 uint8_t event_type = (uint8_t)(event >> 24);
401 switch (event_type) {
403 decode_event_command(event, index, fct_data_decoder);
407 decode_event_button(event, index, fct_data_decoder);
411 decode_event_pointer(event, index, fct_data_decoder);
415 decode_event_state(event, index, fct_data_decoder);
423 UI_DEBUG_PRINT(
"Call serially (Runnable index = %u)\n", EVENT_DATA(event));
431 decode_event_input(event, index, fct_data_decoder);
435 UI_DEBUG_PRINT(
"Display SHOW Displayable (Displayable index = %u)\n", EVENT_DATA(event));
439 UI_DEBUG_PRINT(
"Display HIDE Displayable (Displayable index = %u)\n", EVENT_DATA(event));
455 UI_DEBUG_PRINT(
"Display REPAINT Displayable (Displayable index = %u)\n", EVENT_DATA(event));
467 decode_event_user(event, index, fct_data_decoder);
MicroEJ MicroUI library low level API: enable some features according to the hardware capabilities.
#define UI_DEBUG_PRINT
Standard "printf" indirection.