BigW Consortium Gitlab

Commit a7a24bcf by Gabor

example_encoder: GUI added

parent 73d4fd00
......@@ -22,6 +22,11 @@
/**********************
* STATIC PROTOTYPES
**********************/
static void channel_create(uint8_t ch_id, lv_group_t * g);
static lv_action_res_t mbox_yes_action(lv_obj_t * btn, lv_dispi_t * dispi);
static lv_action_res_t mbox_no_action(lv_obj_t * btn, lv_dispi_t * dispi);
static lv_action_res_t enable_action(lv_obj_t * btn, lv_dispi_t * dispi);
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);
......@@ -30,8 +35,10 @@ 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*/
static lv_obj_t * scr;
static lv_style_t style_mbox_bg;
static lv_group_t * g; /*Declare an Object Group*/
/**********************
* MACROS
......@@ -45,18 +52,23 @@ lv_group_t * g2; /*Declare an Object Group*/
*/
void encoder_ctrl_init(void)
{
/* Create a Container screen and use Pretty layout
* to make the content responsive.
/* Create a Page screen (to make it scrollable)
* 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);
scr = lv_page_create(NULL, NULL);
lv_cont_set_layout(lv_page_get_scrl(scr), LV_CONT_LAYOUT_PRETTY);
lv_page_set_sb_mode(scr, LV_PAGE_SB_MODE_AUTO);
lv_scr_load(scr);
g1 = lv_group_create();
g2 = lv_group_create();
g = lv_group_create();
lv_style_get(LV_STYLE_PLAIN, &style_mbox_bg);
style_mbox_bg.mcolor = COLOR_BLACK;
style_mbox_bg.gcolor = COLOR_BLACK;
style_mbox_bg.opa = OPA_50;
lv_obj_t * title = lv_label_create(scr, NULL);
lv_label_set_text(title, "Channel 1");
lv_label_set_text(title, "adasds");
lv_obj_set_protect(title, LV_PROTECT_FOLLOW); /*Make a line break in the layout*/
......@@ -64,24 +76,17 @@ void encoder_ctrl_init(void)
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_set_style(holder, lv_style_get(LV_STYLE_TRANSP, NULL));
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);
lv_group_add_obj(g, ddlist); /*Add the object to the first group*/
/*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);
lv_group_add_obj(g, cb);
cb = lv_cb_create(holder, cb);
lv_cb_set_text(cb, "Green");
......@@ -91,105 +96,111 @@ void encoder_ctrl_init(void)
/*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);
lv_group_add_obj(g, slider);
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 * btn = lv_btn_create(scr, NULL);
lv_btn_set_rel_action(btn, enable_action);
lv_cont_set_fit(btn, true, true);
lv_group_add_obj(g, btn);
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");
lv_label_set_text(l, "Enable");
lv_obj_set_protect(btn, LV_PROTECT_FOLLOW);
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);
lv_cont_set_fit(btn, true, true);
l = lv_label_create(btn, NULL);
lv_label_set_text(l, "Next");
lv_label_set_text(l, ">");
btn = lv_btn_create(lv_scr_act(), NULL);
lv_btn_set_rel_action(btn, btn_dec);
lv_cont_set_fit(btn, true, true);
l = lv_label_create(btn, NULL);
lv_label_set_text(l, "Dec");
lv_label_set_text(l, "-");
btn = lv_btn_create(lv_scr_act(), NULL);
lv_btn_set_rel_action(btn, btn_inc);
lv_cont_set_fit(btn, true, true);
l = lv_label_create(btn, NULL);
lv_label_set_text(l, "Inc");
lv_label_set_text(l, "+");
btn = lv_btn_create(lv_scr_act(), NULL);
lv_btn_set_rel_action(btn, btn_sel);
lv_cont_set_fit(btn, true, true);
l = lv_label_create(btn, NULL);
lv_label_set_text(l, "Sel");
lv_label_set_text(l, "!");
}
/**********************
* STATIC FUNCTIONS
**********************/
static lv_action_res_t btn_next(lv_obj_t * btn, lv_dispi_t * dispi)
static lv_action_res_t enable_action(lv_obj_t * btn, lv_dispi_t * dispi)
{
lv_group_focus_next(g1);
if(lv_btn_get_state(btn) == LV_BTN_STATE_REL) {
lv_obj_t * bg = lv_obj_create(scr, NULL);
lv_obj_set_protect(bg, LV_PROTECT_PARENT);
lv_obj_set_parent(bg, scr);
lv_obj_set_style(bg, &style_mbox_bg);
lv_obj_set_size(bg, LV_HOR_RES, LV_VER_RES);
lv_obj_set_pos(bg, 0, 0);
lv_obj_set_click(bg, false);
lv_obj_t * mbox = lv_mbox_create(bg, NULL);
lv_mbox_set_text(mbox, "Really Enable the outputs?");
lv_group_add_obj(g, mbox);
lv_mbox_add_btn(mbox, "Yes", mbox_yes_action);
lv_mbox_add_btn(mbox, "No", mbox_no_action);
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, - LV_DPI / 2);
lv_group_focus_obj(mbox);
}
return LV_ACTION_RES_OK;
}
static lv_action_res_t btn_prev(lv_obj_t * btn, lv_dispi_t * dispi)
static lv_action_res_t mbox_yes_action(lv_obj_t * btn, lv_dispi_t * dispi)
{
lv_obj_t * mbox = lv_mbox_get_from_btn(btn);
lv_obj_del(lv_obj_get_parent(mbox));
}
static lv_action_res_t mbox_no_action(lv_obj_t * btn, lv_dispi_t * dispi)
{
lv_group_focus_prev(g1);
lv_obj_t * mbox = lv_mbox_get_from_btn(btn);
lv_obj_del(lv_obj_get_parent(mbox));
}
static lv_action_res_t btn_next(lv_obj_t * btn, lv_dispi_t * dispi)
{
lv_group_focus_next(g);
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);
lv_group_send(g, 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);
lv_group_send(g, 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);
lv_group_send(g, LV_GROUP_KEY_ENTER);
return LV_ACTION_RES_OK;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment