From 2bdfdc0ed2ac487f25704f10f0ee00104e9afb1c Mon Sep 17 00:00:00 2001 From: Gabor Date: Wed, 26 Jul 2017 11:37:02 +0200 Subject: [PATCH] hello_world example added and encoder_ctrl begun --- lv_conf_templ.h | 3 +- .../1_1_lv_hello_world/lv_hello_world.c | 67 ++++++ .../1_1_lv_hello_world/lv_hello_world.h | 42 ++++ .../animations.c | 0 .../animations.h | 0 .../anti_aliasing.c | 0 .../anti_aliasing.h | 0 .../new_obj_type.c | 0 .../new_obj_type.h | 0 lv_examples/2_2_encoder_ctrl/encoder_ctrl.c | 197 ++++++++++++++++++ lv_examples/2_2_encoder_ctrl/encoder_ctrl.h | 42 ++++ lv_obj/lv_group.h | 1 - lv_objx/lv_cb.c | 3 +- 13 files changed, 352 insertions(+), 3 deletions(-) rename lv_examples/{1_4_animations => 1_5_animations}/animations.c (100%) rename lv_examples/{1_4_animations => 1_5_animations}/animations.h (100%) rename lv_examples/{1_5_anti_aliasing => 1_6_anti_aliasing}/anti_aliasing.c (100%) rename lv_examples/{1_5_anti_aliasing => 1_6_anti_aliasing}/anti_aliasing.h (100%) rename lv_examples/{1_6_new_obj_type => 1_8_new_obj_type}/new_obj_type.c (100%) rename lv_examples/{1_6_new_obj_type => 1_8_new_obj_type}/new_obj_type.h (100%) diff --git a/lv_conf_templ.h b/lv_conf_templ.h index 808c679bf..fc87d5a21 100644 --- a/lv_conf_templ.h +++ b/lv_conf_templ.h @@ -50,7 +50,8 @@ #define LV_OBJ_GROUP 1 /*Enable object groups*/ /*Others*/ -#define LV_COLOR_TRANSP COLOR_LIME +#define LV_COLOR_TRANSP COLOR_LIME /*This could mean transparent pixel*/ +#define USE_LV_EXAMPLE 1 /*Enable examples (lvgl/lv_examples/). Disable to save memory*/ /*================== * LV OBJ X USAGE diff --git a/lv_examples/1_1_lv_hello_world/lv_hello_world.c b/lv_examples/1_1_lv_hello_world/lv_hello_world.c index e69de29bb..c9a65c6e9 100644 --- a/lv_examples/1_1_lv_hello_world/lv_hello_world.c +++ b/lv_examples/1_1_lv_hello_world/lv_hello_world.c @@ -0,0 +1,67 @@ +/** + * @file lv_hello_world.c + * + */ + +/* + * Greetings, + * this is the first example in the tutorial hence this is the most simple one. + * It only creates a Label, set its text, and align to the middle. + * + * Be sure in lv_conf.h LV_APP_ENEBLE is 0 (just for simplicity) + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_hello_world.h" +#if USE_LV_EXAMPLE != 0 + +#include "lvgl/lvgl.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a simple 'Hello world!' label + */ +void lv_hello_world_init(void) +{ + /*Create a Label on the current screen*/ + lv_obj_t * label1 = lv_label_create(lv_scr_act(), NULL); + + /*Modify the Label's text*/ + lv_label_set_text(label1, "Hello world!"); + + /* Align the Label to the center + * NULL means align on parent (which is the screen now) + * 0, 0 at the and means an x, y offset after alignment*/ + lv_obj_align_us(label1, NULL, LV_ALIGN_CENTER, 0, 0); +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +#endif /*USE_LV_EXAMPLE != 0*/ diff --git a/lv_examples/1_1_lv_hello_world/lv_hello_world.h b/lv_examples/1_1_lv_hello_world/lv_hello_world.h index e69de29bb..a14b3f043 100644 --- a/lv_examples/1_1_lv_hello_world/lv_hello_world.h +++ b/lv_examples/1_1_lv_hello_world/lv_hello_world.h @@ -0,0 +1,42 @@ +/** + * @file lv_hello_world.h + * + */ + +#ifndef LV_HELLO_WORLD_H +#define LV_HELLO_WORLD_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_conf.h" +#if USE_LV_EXAMPLE != 0 + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +void lv_hello_world_init(void); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_EXAMPLE != 0*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_HELLO_WORLD_H*/ diff --git a/lv_examples/1_4_animations/animations.c b/lv_examples/1_5_animations/animations.c similarity index 100% rename from lv_examples/1_4_animations/animations.c rename to lv_examples/1_5_animations/animations.c diff --git a/lv_examples/1_4_animations/animations.h b/lv_examples/1_5_animations/animations.h similarity index 100% rename from lv_examples/1_4_animations/animations.h rename to lv_examples/1_5_animations/animations.h diff --git a/lv_examples/1_5_anti_aliasing/anti_aliasing.c b/lv_examples/1_6_anti_aliasing/anti_aliasing.c similarity index 100% rename from lv_examples/1_5_anti_aliasing/anti_aliasing.c rename to lv_examples/1_6_anti_aliasing/anti_aliasing.c diff --git a/lv_examples/1_5_anti_aliasing/anti_aliasing.h b/lv_examples/1_6_anti_aliasing/anti_aliasing.h similarity index 100% rename from lv_examples/1_5_anti_aliasing/anti_aliasing.h rename to lv_examples/1_6_anti_aliasing/anti_aliasing.h diff --git a/lv_examples/1_6_new_obj_type/new_obj_type.c b/lv_examples/1_8_new_obj_type/new_obj_type.c similarity index 100% rename from lv_examples/1_6_new_obj_type/new_obj_type.c rename to lv_examples/1_8_new_obj_type/new_obj_type.c diff --git a/lv_examples/1_6_new_obj_type/new_obj_type.h b/lv_examples/1_8_new_obj_type/new_obj_type.h similarity index 100% rename from lv_examples/1_6_new_obj_type/new_obj_type.h rename to lv_examples/1_8_new_obj_type/new_obj_type.h diff --git a/lv_examples/2_2_encoder_ctrl/encoder_ctrl.c b/lv_examples/2_2_encoder_ctrl/encoder_ctrl.c index e69de29bb..eee72fdf7 100644 --- a/lv_examples/2_2_encoder_ctrl/encoder_ctrl.c +++ b/lv_examples/2_2_encoder_ctrl/encoder_ctrl.c @@ -0,0 +1,197 @@ +/** + * @file encoder_ctrl.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "encoder_ctrl.h" +#if USE_LV_EXAMPLE != 0 + +#include "lvgl/lvgl.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static lv_action_res_t btn_next(lv_obj_t * btn, lv_dispi_t * dispi); +static lv_action_res_t btn_inc(lv_obj_t * btn, lv_dispi_t * dispi); +static lv_action_res_t btn_dec(lv_obj_t * btn, lv_dispi_t * dispi); +static lv_action_res_t btn_sel(lv_obj_t * btn, lv_dispi_t * dispi); + +/********************** + * STATIC VARIABLES + **********************/ +lv_group_t * g1; /*Declare an Object Group*/ +lv_group_t * g2; /*Declare an Object Group*/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + */ +void encoder_ctrl_init(void) +{ + /* Create a Container screen and use Pretty layout + * to make the content responsive. + * See the 'responsive' example for more information */ + lv_obj_t * scr = lv_page_create(NULL, NULL); + lv_cont_set_layout(lv_page_get_scrl(scr), LV_CONT_LAYOUT_PRETTY); + lv_scr_load(scr); + + g1 = lv_group_create(); + g2 = lv_group_create(); + + lv_obj_t * title = lv_label_create(scr, NULL); + lv_label_set_text(title, "Channel 1"); + lv_obj_set_protect(title, LV_PROTECT_FOLLOW); /*Make a line break in the layout*/ + + + /*Create a holder, a subtitle and a drop down list*/ + lv_obj_t * holder = lv_cont_create(scr, NULL); /*Create a transparent holder to group some objects*/ + lv_cont_set_fit(holder, true, true); + lv_cont_set_layout(holder, LV_CONT_LAYOUT_COL_L); + lv_obj_set_style(holder, lv_style_get(LV_STYLE_TRANSP_TIGHT, NULL)); + + lv_obj_t * subtitle = lv_label_create(holder, NULL); + lv_label_set_text(subtitle, "Temperature"); + + lv_obj_t * ddlist = lv_ddlist_create(holder, NULL); + lv_ddlist_set_options_str(ddlist, "Low\nMedium\nHigh"); + lv_group_add_obj(g1, ddlist); /*Add the object to the first group*/ + + lv_ddlist_create(holder, ddlist); + + /*Copy the previous holder and subtitle and add check boxes*/ + holder = lv_cont_create(scr, holder); + subtitle = lv_label_create(holder, subtitle); + lv_label_set_text(subtitle, "Colors"); + lv_obj_t * cb = lv_cb_create(holder, NULL); + lv_cb_set_text(cb, "Red"); + lv_group_add_obj(g1, cb); + + cb = lv_cb_create(holder, cb); + lv_cb_set_text(cb, "Green"); + + cb = lv_cb_create(holder, cb); + lv_cb_set_text(cb, "Blue"); + + /*Copy the previous holder and subtitle and add sliders*/ + holder = lv_cont_create(scr, holder); + subtitle = lv_label_create(holder, subtitle); + lv_label_set_text(subtitle, "Voltage"); + lv_obj_t * slider = lv_slider_create(holder, NULL); + lv_obj_set_size_us(slider, 180, 30); + + subtitle = lv_label_create(holder, subtitle); + lv_label_set_text(subtitle, "Current"); + slider = lv_slider_create(holder, slider); + + lv_obj_t * list = lv_list_create(lv_scr_act(), NULL); + lv_list_add(list, "", "List1", NULL); + lv_list_add(list, "", "List2", NULL); + lv_list_add(list, "", "List3", NULL); + lv_list_add(list, "", "List4", NULL); + lv_list_add(list, "", "List5", NULL); + lv_list_add(list, "", "List6", NULL); + lv_list_add(list, "", "List7", NULL); + lv_list_add(list, "", "List8", NULL); + lv_group_add_obj(g1, list); + + lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL); + lv_obj_t * l = lv_label_create(btn, NULL); + lv_label_set_text(l, "Button1"); + lv_group_add_obj(g1, btn); + + + btn = lv_btn_create(lv_scr_act(), NULL); + lv_btn_set_tgl(btn, true); + l = lv_label_create(btn, NULL); + lv_label_set_text(l, "Button\nToggle"); + lv_group_add_obj(g1, btn); + + btn = lv_btn_create(lv_scr_act(), btn); + lv_btn_set_tgl(btn, true); + l = lv_label_create(btn, NULL); + lv_label_set_text(l, "Button\nToggle\nCopy"); + + + l = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(l, "Single\nlabel"); + lv_obj_set_protect(l, LV_PROTECT_FOLLOW); + lv_group_add_obj(g1, l); + + btn = lv_btn_create(lv_scr_act(), NULL); + lv_btn_set_rel_action(btn, btn_next); + l = lv_label_create(btn, NULL); + lv_label_set_text(l, "Next"); + + btn = lv_btn_create(lv_scr_act(), NULL); + lv_btn_set_rel_action(btn, btn_dec); + l = lv_label_create(btn, NULL); + lv_label_set_text(l, "Dec"); + + btn = lv_btn_create(lv_scr_act(), NULL); + lv_btn_set_rel_action(btn, btn_inc); + l = lv_label_create(btn, NULL); + lv_label_set_text(l, "Inc"); + + btn = lv_btn_create(lv_scr_act(), NULL); + lv_btn_set_rel_action(btn, btn_sel); + l = lv_label_create(btn, NULL); + lv_label_set_text(l, "Sel"); +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +static lv_action_res_t btn_next(lv_obj_t * btn, lv_dispi_t * dispi) +{ + lv_group_focus_next(g1); + + return LV_ACTION_RES_OK; +} + +static lv_action_res_t btn_prev(lv_obj_t * btn, lv_dispi_t * dispi) +{ + lv_group_focus_prev(g1); + + return LV_ACTION_RES_OK; +} + + +static lv_action_res_t btn_inc(lv_obj_t * btn, lv_dispi_t * dispi) +{ + lv_group_send(g1, LV_GROUP_KEY_RIGHT); + return LV_ACTION_RES_OK; +} + +static lv_action_res_t btn_dec(lv_obj_t * btn, lv_dispi_t * dispi) +{ + lv_group_send(g1, LV_GROUP_KEY_LEFT); + + return LV_ACTION_RES_OK; +} + +static lv_action_res_t btn_sel(lv_obj_t * btn, lv_dispi_t * dispi) +{ + lv_group_send(g1, LV_GROUP_KEY_ENTER); + + return LV_ACTION_RES_OK; +} + +#endif /*USE_LV_EXAMPLE != 0*/ diff --git a/lv_examples/2_2_encoder_ctrl/encoder_ctrl.h b/lv_examples/2_2_encoder_ctrl/encoder_ctrl.h index e69de29bb..8cd3651b0 100644 --- a/lv_examples/2_2_encoder_ctrl/encoder_ctrl.h +++ b/lv_examples/2_2_encoder_ctrl/encoder_ctrl.h @@ -0,0 +1,42 @@ +/** + * @file encoder_ctrl.h + * + */ + +#ifndef ENCODER_CTRL_H +#define ENCODER_CTRL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_conf.h" +#if USE_LV_EXAMPLE != 0 + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +void encoder_ctrl_init(void); + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_EXAMPLE != 0*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*ENCODER_CTRL_H*/ diff --git a/lv_obj/lv_group.h b/lv_obj/lv_group.h index b538545c3..bb4a4ea45 100644 --- a/lv_obj/lv_group.h +++ b/lv_obj/lv_group.h @@ -14,7 +14,6 @@ extern "C" { * INCLUDES *********************/ #include "lv_conf.h" - #include "lv_obj.h" /********************* diff --git a/lv_objx/lv_cb.c b/lv_objx/lv_cb.c index af6cbee15..52bae6188 100644 --- a/lv_objx/lv_cb.c +++ b/lv_objx/lv_cb.c @@ -77,7 +77,6 @@ lv_obj_t * lv_cb_create(lv_obj_t * par, lv_obj_t * copy) lv_cont_set_fit(new_cb, true, true); lv_btn_set_tgl(new_cb, true); - lv_obj_set_design_f(ext->bullet, lv_bullet_design); lv_obj_set_click(ext->bullet, false); lv_btn_set_styles(ext->bullet, lv_style_get(LV_STYLE_PRETTY, NULL), lv_style_get(LV_STYLE_PRETTY_COLOR, NULL), lv_style_get(LV_STYLE_BTN_TREL, NULL), lv_style_get(LV_STYLE_BTN_TPR, NULL), @@ -94,6 +93,8 @@ lv_obj_t * lv_cb_create(lv_obj_t * par, lv_obj_t * copy) /*Refresh the style with new signal function*/ lv_obj_refr_style(new_cb); } + + lv_obj_set_design_f(ext->bullet, lv_bullet_design); return new_cb; }