diff --git a/examples/others/lv_example_others.h b/examples/others/lv_example_others.h index 346c08e81..eeb97391b 100644 --- a/examples/others/lv_example_others.h +++ b/examples/others/lv_example_others.h @@ -18,6 +18,7 @@ extern "C" { #include "gridnav/lv_example_gridnav.h" #include "fragment/lv_example_fragment.h" #include "imgfont/lv_example_imgfont.h" +#include "msg/lv_example_msg.h" /********************* * DEFINES diff --git a/examples/others/msg/lv_example_msg_1.c b/examples/others/msg/lv_example_msg_1.c index e345ab770..d2cb8a3df 100644 --- a/examples/others/msg/lv_example_msg_1.c +++ b/examples/others/msg/lv_example_msg_1.c @@ -2,7 +2,7 @@ #if LV_USE_MSG && LV_USE_SLIDER && LV_USE_LABEL && LV_BUILD_EXAMPLES /*Define a message ID*/ -#define MSG_NEW_TEMPERATURE 1 +#define MSG_NEW_TEMPERATURE 1 static void slider_event_cb(lv_event_t * e); static void label_event_cb(lv_event_t * e); @@ -29,7 +29,7 @@ void lv_example_msg_1(void) static void slider_event_cb(lv_event_t * e) { - /*Notify all subscribers (only the label now) that the slider value has been changed*/ + /*Notify all subscribers (only the label now) that the slider value has been changed*/ lv_obj_t * slider = lv_event_get_target(e); int32_t v = lv_slider_get_value(slider); lv_msg_send(MSG_NEW_TEMPERATURE, &v); diff --git a/examples/others/msg/lv_example_msg_2.c b/examples/others/msg/lv_example_msg_2.c index c829b607b..f9cf585eb 100644 --- a/examples/others/msg/lv_example_msg_2.c +++ b/examples/others/msg/lv_example_msg_2.c @@ -2,10 +2,10 @@ #if LV_USE_MSG && LV_USE_SLIDER && LV_USE_LABEL && LV_BUILD_EXAMPLES /*Define a message ID*/ -#define MSG_LOGIN_ATTEMPT 1 -#define MSG_LOG_OUT 2 -#define MSG_LOGIN_ERROR 3 -#define MSG_LOGIN_OK 4 +#define MSG_LOGIN_ATTEMPT 1 +#define MSG_LOG_OUT 2 +#define MSG_LOGIN_ERROR 3 +#define MSG_LOGIN_OK 4 static void auth_manager(void * s, lv_msg_t * m); static void textarea_event_cb(lv_event_t * e); @@ -19,7 +19,7 @@ static void info_label_msg_event_cb(lv_event_t * e); */ void lv_example_msg_2(void) { - lv_msg_subsribe(MSG_LOGIN_ATTEMPT, auth_manager, "hello"); + lv_msg_subsribe(MSG_LOGIN_ATTEMPT, auth_manager, "hello"); /*Create a slider in the center of the display*/ lv_obj_t * ta = lv_textarea_create(lv_scr_act()); @@ -74,73 +74,76 @@ void lv_example_msg_2(void) static void auth_manager(void * s, lv_msg_t * m) { - LV_UNUSED(s); - const char * pin_act = lv_msg_get_payload(m); - const char * pin_expexted = lv_msg_get_user_data(m); - if(strcmp(pin_act, pin_expexted) == 0) { - lv_msg_send(MSG_LOGIN_OK, NULL); - } else { - lv_msg_send(MSG_LOGIN_ERROR, "Incorrect PIN"); - } + LV_UNUSED(s); + const char * pin_act = lv_msg_get_payload(m); + const char * pin_expexted = lv_msg_get_user_data(m); + if(strcmp(pin_act, pin_expexted) == 0) { + lv_msg_send(MSG_LOGIN_OK, NULL); + } + else { + lv_msg_send(MSG_LOGIN_ERROR, "Incorrect PIN"); + } } static void textarea_event_cb(lv_event_t * e) { - lv_obj_t * ta = lv_event_get_target(e); - lv_event_code_t code = lv_event_get_code(e); - if(code == LV_EVENT_READY) { - lv_msg_send(MSG_LOGIN_ATTEMPT, lv_textarea_get_text(ta)); - } else if (code == LV_EVENT_MSG_RECEIVED) { - lv_msg_t * m = lv_event_get_msg(e); - switch(lv_msg_get_id(m)) { - case MSG_LOGIN_ERROR: - /*If there was an error, clean the text area*/ - if(strlen(lv_msg_get_payload(m))) lv_textarea_set_text(ta, ""); - break; - case MSG_LOGIN_OK: - lv_obj_add_state(ta, LV_STATE_DISABLED); - lv_obj_clear_state(ta, LV_STATE_FOCUSED | LV_STATE_FOCUS_KEY); - break; - case MSG_LOG_OUT: - lv_textarea_set_text(ta, ""); - lv_obj_clear_state(ta, LV_STATE_DISABLED); - break; - } - } + lv_obj_t * ta = lv_event_get_target(e); + lv_event_code_t code = lv_event_get_code(e); + if(code == LV_EVENT_READY) { + lv_msg_send(MSG_LOGIN_ATTEMPT, lv_textarea_get_text(ta)); + } + else if(code == LV_EVENT_MSG_RECEIVED) { + lv_msg_t * m = lv_event_get_msg(e); + switch(lv_msg_get_id(m)) { + case MSG_LOGIN_ERROR: + /*If there was an error, clean the text area*/ + if(strlen(lv_msg_get_payload(m))) lv_textarea_set_text(ta, ""); + break; + case MSG_LOGIN_OK: + lv_obj_add_state(ta, LV_STATE_DISABLED); + lv_obj_clear_state(ta, LV_STATE_FOCUSED | LV_STATE_FOCUS_KEY); + break; + case MSG_LOG_OUT: + lv_textarea_set_text(ta, ""); + lv_obj_clear_state(ta, LV_STATE_DISABLED); + break; + } + } } static void log_out_event_cb(lv_event_t * e) { - lv_event_code_t code = lv_event_get_code(e); - if(code == LV_EVENT_CLICKED) { - lv_msg_send(MSG_LOG_OUT, NULL); - } else if (code == LV_EVENT_MSG_RECEIVED) { - lv_msg_t * m = lv_event_get_msg(e); - lv_obj_t * btn = lv_event_get_target(e); - switch(lv_msg_get_id(m)) { - case MSG_LOGIN_OK: - lv_obj_clear_state(btn, LV_STATE_DISABLED); - break; - case MSG_LOG_OUT: - lv_obj_add_state(btn, LV_STATE_DISABLED); - break; - } - } + lv_event_code_t code = lv_event_get_code(e); + if(code == LV_EVENT_CLICKED) { + lv_msg_send(MSG_LOG_OUT, NULL); + } + else if(code == LV_EVENT_MSG_RECEIVED) { + lv_msg_t * m = lv_event_get_msg(e); + lv_obj_t * btn = lv_event_get_target(e); + switch(lv_msg_get_id(m)) { + case MSG_LOGIN_OK: + lv_obj_clear_state(btn, LV_STATE_DISABLED); + break; + case MSG_LOG_OUT: + lv_obj_add_state(btn, LV_STATE_DISABLED); + break; + } + } } static void start_engine_msg_event_cb(lv_event_t * e) { - lv_msg_t * m = lv_event_get_msg(e); - lv_obj_t * btn = lv_event_get_target(e); - switch(lv_msg_get_id(m)) { - case MSG_LOGIN_OK: - lv_obj_clear_state(btn, LV_STATE_DISABLED); - break; - case MSG_LOG_OUT: - lv_obj_add_state(btn, LV_STATE_DISABLED); - break; - } + lv_msg_t * m = lv_event_get_msg(e); + lv_obj_t * btn = lv_event_get_target(e); + switch(lv_msg_get_id(m)) { + case MSG_LOGIN_OK: + lv_obj_clear_state(btn, LV_STATE_DISABLED); + break; + case MSG_LOG_OUT: + lv_obj_add_state(btn, LV_STATE_DISABLED); + break; + } } static void info_label_msg_event_cb(lv_event_t * e) @@ -148,20 +151,20 @@ static void info_label_msg_event_cb(lv_event_t * e) lv_obj_t * label = lv_event_get_target(e); lv_msg_t * m = lv_event_get_msg(e); switch(lv_msg_get_id(m)) { - case MSG_LOGIN_ERROR: - lv_label_set_text(label, lv_msg_get_payload(m)); - lv_obj_set_style_text_color(label, lv_palette_main(LV_PALETTE_RED), 0); - break; - case MSG_LOGIN_OK: - lv_label_set_text(label, "Login successful"); - lv_obj_set_style_text_color(label, lv_palette_main(LV_PALETTE_GREEN), 0); - break; - case MSG_LOG_OUT: - lv_label_set_text(label, "Logged out"); - lv_obj_set_style_text_color(label, lv_palette_main(LV_PALETTE_GREY), 0); - break; - default: - break; + case MSG_LOGIN_ERROR: + lv_label_set_text(label, lv_msg_get_payload(m)); + lv_obj_set_style_text_color(label, lv_palette_main(LV_PALETTE_RED), 0); + break; + case MSG_LOGIN_OK: + lv_label_set_text(label, "Login successful"); + lv_obj_set_style_text_color(label, lv_palette_main(LV_PALETTE_GREEN), 0); + break; + case MSG_LOG_OUT: + lv_label_set_text(label, "Logged out"); + lv_obj_set_style_text_color(label, lv_palette_main(LV_PALETTE_GREY), 0); + break; + default: + break; } } diff --git a/examples/others/msg/lv_example_msg_3.c b/examples/others/msg/lv_example_msg_3.c index 266daf39b..dddb4a8c4 100644 --- a/examples/others/msg/lv_example_msg_3.c +++ b/examples/others/msg/lv_example_msg_3.c @@ -2,11 +2,11 @@ #if LV_USE_MSG && LV_USE_SLIDER && LV_USE_LABEL && LV_BUILD_EXAMPLES /*Define a message ID*/ -#define MSG_INC 1 -#define MSG_DEC 2 -#define MSG_SET 3 -#define MSG_UPDATE 4 -#define MSG_UPDATE_REQUEST 5 +#define MSG_INC 1 +#define MSG_DEC 2 +#define MSG_SET 3 +#define MSG_UPDATE 4 +#define MSG_UPDATE_REQUEST 5 static void value_handler(void * s, lv_msg_t * m); static void value_handler(void * s, lv_msg_t * m); @@ -23,130 +23,132 @@ static void slider_event_cb(lv_event_t * e); void lv_example_msg_3(void) { - lv_msg_subsribe(MSG_INC, value_handler, NULL); - lv_msg_subsribe(MSG_DEC, value_handler, NULL); - lv_msg_subsribe(MSG_SET, value_handler, NULL); - lv_msg_subsribe(MSG_UPDATE, value_handler, NULL); - lv_msg_subsribe(MSG_UPDATE_REQUEST, value_handler, NULL); + lv_msg_subsribe(MSG_INC, value_handler, NULL); + lv_msg_subsribe(MSG_DEC, value_handler, NULL); + lv_msg_subsribe(MSG_SET, value_handler, NULL); + lv_msg_subsribe(MSG_UPDATE, value_handler, NULL); + lv_msg_subsribe(MSG_UPDATE_REQUEST, value_handler, NULL); - lv_obj_t * panel = lv_obj_create(lv_scr_act()); - lv_obj_set_size(panel, 250, LV_SIZE_CONTENT); - lv_obj_center(panel); - lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_ROW); - lv_obj_set_flex_align(panel, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START); + lv_obj_t * panel = lv_obj_create(lv_scr_act()); + lv_obj_set_size(panel, 250, LV_SIZE_CONTENT); + lv_obj_center(panel); + lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_ROW); + lv_obj_set_flex_align(panel, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START); - lv_obj_t * btn; - lv_obj_t * label; + lv_obj_t * btn; + lv_obj_t * label; - /*Up button*/ - btn = lv_btn_create(panel); - lv_obj_set_flex_grow(btn, 1); - lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL); - label = lv_label_create(btn); - lv_label_set_text(label, LV_SYMBOL_LEFT); - lv_obj_center(label); + /*Up button*/ + btn = lv_btn_create(panel); + lv_obj_set_flex_grow(btn, 1); + lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL); + label = lv_label_create(btn); + lv_label_set_text(label, LV_SYMBOL_LEFT); + lv_obj_center(label); - /*Current value*/ - label = lv_label_create(panel); - lv_obj_set_flex_grow(label, 2); - lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0); - lv_label_set_text(label, "?"); - lv_msg_subsribe_obj(MSG_UPDATE, label, NULL); - lv_obj_add_event_cb(label, label_event_cb, LV_EVENT_MSG_RECEIVED, NULL); + /*Current value*/ + label = lv_label_create(panel); + lv_obj_set_flex_grow(label, 2); + lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0); + lv_label_set_text(label, "?"); + lv_msg_subsribe_obj(MSG_UPDATE, label, NULL); + lv_obj_add_event_cb(label, label_event_cb, LV_EVENT_MSG_RECEIVED, NULL); - /*Down button*/ - btn = lv_btn_create(panel); - lv_obj_set_flex_grow(btn, 1); - lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL); - label = lv_label_create(btn); - lv_label_set_text(label, LV_SYMBOL_RIGHT); - lv_obj_center(label); + /*Down button*/ + btn = lv_btn_create(panel); + lv_obj_set_flex_grow(btn, 1); + lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL); + label = lv_label_create(btn); + lv_label_set_text(label, LV_SYMBOL_RIGHT); + lv_obj_center(label); - /*Slider*/ - lv_obj_t * slider = lv_slider_create(panel); - lv_obj_set_flex_grow(slider, 1); - lv_obj_add_flag(slider, LV_OBJ_FLAG_FLEX_IN_NEW_TRACK); - lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_ALL, NULL); - lv_msg_subsribe_obj(MSG_UPDATE, slider, NULL); + /*Slider*/ + lv_obj_t * slider = lv_slider_create(panel); + lv_obj_set_flex_grow(slider, 1); + lv_obj_add_flag(slider, LV_OBJ_FLAG_FLEX_IN_NEW_TRACK); + lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_ALL, NULL); + lv_msg_subsribe_obj(MSG_UPDATE, slider, NULL); - /* As there are new UI elements that don't know the system's state - * send an UPDATE REQUEST message which will trigger an UPDATE message with the current value*/ - lv_msg_send(MSG_UPDATE_REQUEST, NULL); + /* As there are new UI elements that don't know the system's state + * send an UPDATE REQUEST message which will trigger an UPDATE message with the current value*/ + lv_msg_send(MSG_UPDATE_REQUEST, NULL); } static void value_handler(void * s, lv_msg_t * m) { - LV_UNUSED(s); + LV_UNUSED(s); - static int32_t value = 10; - int32_t old_value = value; - switch(lv_msg_get_id(m)) { - case MSG_INC: - if(value < 100) value++; - break; - case MSG_DEC: - if(value > 0) value--; - break; - case MSG_SET: { - const int32_t * new_value = lv_msg_get_payload(m); - value = *new_value; - } - break; - case MSG_UPDATE_REQUEST: - lv_msg_send(MSG_UPDATE, &value); - break; - default: - break; - } + static int32_t value = 10; + int32_t old_value = value; + switch(lv_msg_get_id(m)) { + case MSG_INC: + if(value < 100) value++; + break; + case MSG_DEC: + if(value > 0) value--; + break; + case MSG_SET: { + const int32_t * new_value = lv_msg_get_payload(m); + value = *new_value; + } + break; + case MSG_UPDATE_REQUEST: + lv_msg_send(MSG_UPDATE, &value); + break; + default: + break; + } - if(value != old_value) { - lv_msg_send(MSG_UPDATE, &value); - } + if(value != old_value) { + lv_msg_send(MSG_UPDATE, &value); + } } static void btn_event_cb(lv_event_t * e) { - lv_obj_t * btn = lv_event_get_target(e); - lv_event_code_t code = lv_event_get_code(e); - if(code == LV_EVENT_CLICKED || code == LV_EVENT_LONG_PRESSED_REPEAT) { - if(lv_obj_get_index(btn) == 0) { /*First object is the dec. button*/ - lv_msg_send(MSG_DEC, NULL); - } else { - lv_msg_send(MSG_INC, NULL); - } - } + lv_obj_t * btn = lv_event_get_target(e); + lv_event_code_t code = lv_event_get_code(e); + if(code == LV_EVENT_CLICKED || code == LV_EVENT_LONG_PRESSED_REPEAT) { + if(lv_obj_get_index(btn) == 0) { /*First object is the dec. button*/ + lv_msg_send(MSG_DEC, NULL); + } + else { + lv_msg_send(MSG_INC, NULL); + } + } } static void label_event_cb(lv_event_t * e) { - lv_obj_t * label = lv_event_get_target(e); - lv_event_code_t code = lv_event_get_code(e); - if (code == LV_EVENT_MSG_RECEIVED) { - lv_msg_t * m = lv_event_get_msg(e); - if(lv_msg_get_id(m) == MSG_UPDATE) { - const int32_t *v = lv_msg_get_payload(m); - lv_label_set_text_fmt(label, "%d %%", *v); - } - } + lv_obj_t * label = lv_event_get_target(e); + lv_event_code_t code = lv_event_get_code(e); + if(code == LV_EVENT_MSG_RECEIVED) { + lv_msg_t * m = lv_event_get_msg(e); + if(lv_msg_get_id(m) == MSG_UPDATE) { + const int32_t * v = lv_msg_get_payload(m); + lv_label_set_text_fmt(label, "%d %%", *v); + } + } } static void slider_event_cb(lv_event_t * e) { - lv_obj_t * slider = lv_event_get_target(e); - lv_event_code_t code = lv_event_get_code(e); - if(code == LV_EVENT_VALUE_CHANGED) { - int32_t v = lv_slider_get_value(slider); - lv_msg_send(MSG_SET, &v); - } else if (code == LV_EVENT_MSG_RECEIVED) { - lv_msg_t * m = lv_event_get_msg(e); - if(lv_msg_get_id(m) == MSG_UPDATE) { - const int32_t *v = lv_msg_get_payload(m); - lv_slider_set_value(slider, *v, LV_ANIM_OFF); - } - } + lv_obj_t * slider = lv_event_get_target(e); + lv_event_code_t code = lv_event_get_code(e); + if(code == LV_EVENT_VALUE_CHANGED) { + int32_t v = lv_slider_get_value(slider); + lv_msg_send(MSG_SET, &v); + } + else if(code == LV_EVENT_MSG_RECEIVED) { + lv_msg_t * m = lv_event_get_msg(e); + if(lv_msg_get_id(m) == MSG_UPDATE) { + const int32_t * v = lv_msg_get_payload(m); + lv_slider_set_value(slider, *v, LV_ANIM_OFF); + } + } } #endif diff --git a/src/extra/others/msg/lv_msg.c b/src/extra/others/msg/lv_msg.c index 10a1d5083..8fd434d06 100644 --- a/src/extra/others/msg/lv_msg.c +++ b/src/extra/others/msg/lv_msg.c @@ -39,7 +39,6 @@ static void obj_delete_event_cb(lv_event_t * e); * STATIC VARIABLES **********************/ static lv_ll_t subs_ll; -static lv_ll_t reqs_ll; /********************** * GLOBAL VARIABLES @@ -95,12 +94,6 @@ void lv_msg_unsubscribe(void * s) lv_mem_free(s); } -uint32_t lv_msg_id_range(uint32_t start, uint32_t end) -{ - if(start == end) return start; - else return start + (end << 16); -} - void lv_msg_send(uint32_t msg_id, const void * payload) { lv_msg_t m; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5967c5a86..42fedd00f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -97,7 +97,7 @@ set(LVGL_TEST_OPTIONS_16BIT set(LVGL_TEST_OPTIONS_16BIT_SWAP -DLV_COLOR_DEPTH=16 - -DLV_COLOR_16_SWAP=1 + -DLV_COLOR_16_SWAP=1 -DLV_MEM_SIZE=65536 -DLV_DPI_DEF=40 -DLV_DRAW_COMPLEX=1 @@ -123,7 +123,7 @@ set(LVGL_TEST_OPTIONS_16BIT_SWAP -DLV_USE_GIF=1 -DLV_USE_QRCODE=1 ) - + set(LVGL_TEST_OPTIONS_FULL_32BIT -DLV_COLOR_DEPTH=32 -DLV_MEM_SIZE=8388608 @@ -181,8 +181,8 @@ set(LVGL_TEST_OPTIONS_FULL_32BIT ${LVGL_TEST_COMMON_EXAMPLE_OPTIONS} -DLV_FONT_DEFAULT=&lv_font_montserrat_24 -DLV_USE_FS_STDIO=1 - -DLV_FS_STDIO_LETTER='A' - -DLV_USE_FS_POSIX=1 + -DLV_FS_STDIO_LETTER='A' + -DLV_USE_FS_POSIX=1 -DLV_FS_POSIX_LETTER='B' -DLV_USE_PNG=1 -DLV_USE_BMP=1 @@ -190,9 +190,10 @@ set(LVGL_TEST_OPTIONS_FULL_32BIT -DLV_USE_GIF=1 -DLV_USE_QRCODE=1 -DLV_USE_FRAGMENT=1 - -DLV_USE_IMGFONT=1 + -DLV_USE_IMGFONT=1 + -DLV_USE_MSG=1 ) - + set(LVGL_TEST_OPTIONS_TEST_COMMON --coverage -DLV_COLOR_DEPTH=32 @@ -276,7 +277,7 @@ set(COMPILE_OPTIONS -pedantic-errors -Wall -Wclobbered - -Wdeprecated + -Wdeprecated -Wdouble-promotion -Wempty-body -Werror @@ -361,7 +362,7 @@ foreach( test_case_fname ${TEST_CASE_FILES} ) target_compile_options(${test_name} PUBLIC ${LVGL_TESTFILE_COMPILE_OPTIONS}) add_test( - NAME ${test_name} + NAME ${test_name} WORKING_DIRECTORY ${LVGL_TEST_DIR} COMMAND ${test_name}) endforeach( test_case_fname ${TEST_CASE_FILES} )