app conf: app configuration added (terminal, files)
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#include "lv_app.h"
|
||||
|
||||
#if LV_APP_ENABLE != 0
|
||||
#include <stdio.h>
|
||||
|
||||
#include "lv_app_util/lv_app_kb.h"
|
||||
#include "lv_app_util/lv_app_notice.h"
|
||||
#include "lv_app_util/lv_app_fsel.h"
|
||||
@@ -19,6 +21,7 @@
|
||||
#include "../lv_appx/lv_app_sysmon.h"
|
||||
#include "../lv_appx/lv_app_terminal.h"
|
||||
#include "../lv_appx/lv_app_files.h"
|
||||
#include "../lv_appx/lv_app_visual.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@@ -45,7 +48,8 @@ static lv_action_res_t lv_app_sc_page_rel_action(lv_obj_t * sc, lv_dispi_t * dis
|
||||
static lv_action_res_t lv_app_sc_rel_action(lv_obj_t * sc, lv_dispi_t * dispi);
|
||||
static lv_action_res_t lv_app_sc_lpr_action(lv_obj_t * sc, lv_dispi_t * dispi);
|
||||
static lv_action_res_t lv_app_win_close_action(lv_obj_t * close_btn, lv_dispi_t * dispi);
|
||||
static lv_action_res_t lv_app_win_minim_action(lv_obj_t * close_minim, lv_dispi_t * dispi);
|
||||
static lv_action_res_t lv_app_win_minim_action(lv_obj_t * minim_btn, lv_dispi_t * dispi);
|
||||
static lv_action_res_t lv_app_win_conf_action(lv_obj_t * set_btn, lv_dispi_t * dispi);
|
||||
|
||||
static lv_action_res_t lv_app_win_open_anim_create(lv_app_inst_t * app);
|
||||
static lv_action_res_t lv_app_win_minim_anim_create(lv_app_inst_t * app);
|
||||
@@ -105,6 +109,10 @@ LV_IMG_DECLARE(img_ok);
|
||||
LV_IMG_DECLARE(img_right);
|
||||
#endif
|
||||
|
||||
#if USE_IMG_SETTINGS != 0
|
||||
LV_IMG_DECLARE(img_settings);
|
||||
#endif
|
||||
|
||||
#if USE_IMG_UP != 0
|
||||
LV_IMG_DECLARE(img_up);
|
||||
#endif
|
||||
@@ -162,6 +170,11 @@ void lv_app_init(void)
|
||||
dsc = ll_ins_head(&app_dsc_ll);
|
||||
*dsc = lv_app_files_init();
|
||||
#endif
|
||||
|
||||
#if USE_LV_APP_VISUAL != 0
|
||||
dsc = ll_ins_head(&app_dsc_ll);
|
||||
*dsc = lv_app_visual_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -301,10 +314,14 @@ lv_obj_t * lv_app_win_open(lv_app_inst_t * app)
|
||||
lv_rect_set_fit(win_content, false, true);
|
||||
lv_obj_set_width(win_content, LV_HOR_RES - 2 * app_style.win_style.pages.bg_rects.hpad);
|
||||
|
||||
lv_win_add_ctrl_btn(app->win, "U:/icon_down" ,lv_app_win_minim_action);
|
||||
lv_win_add_ctrl_btn(app->win, "U:/icon_close" ,lv_app_win_close_action);
|
||||
if(app->dsc->conf_open != NULL) {
|
||||
lv_win_add_ctrl_btn(app->win, "U:/icon_settings", lv_app_win_conf_action);
|
||||
}
|
||||
lv_win_add_ctrl_btn(app->win, "U:/icon_down", lv_app_win_minim_action);
|
||||
lv_win_add_ctrl_btn(app->win, "U:/icon_close",lv_app_win_close_action);
|
||||
|
||||
app->win_data = dm_alloc(app->dsc->win_data_size);
|
||||
|
||||
app->dsc->win_open(app, app->win);
|
||||
|
||||
return app->win;
|
||||
@@ -327,6 +344,7 @@ void lv_app_win_close(lv_app_inst_t * app)
|
||||
dm_free(app->win_data);
|
||||
app->win_data = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send data to other applications
|
||||
* @param app_send pointer to the application which is sending the message
|
||||
@@ -475,8 +493,7 @@ lv_app_inst_t * lv_app_get_next(lv_app_inst_t * prev, lv_app_dsc_t * dsc)
|
||||
if(next->dsc == dsc || dsc == NULL) return next;
|
||||
|
||||
prev = next;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -795,13 +812,13 @@ static lv_action_res_t lv_app_win_close_action(lv_obj_t * close_btn, lv_dispi_t
|
||||
|
||||
/**
|
||||
* Called when the minimization button of window is released
|
||||
* @param close_minimointer to the minim. button
|
||||
* @param minim_btn pointer to the minim. button
|
||||
* @param dispi pointer to the caller display input
|
||||
* @return LV_ACTION_RES_OK or LV_ACTION_RES_INC depending on LV_APP_EFFECT_... settings type
|
||||
*/
|
||||
static lv_action_res_t lv_app_win_minim_action(lv_obj_t * close_minim, lv_dispi_t * dispi)
|
||||
static lv_action_res_t lv_app_win_minim_action(lv_obj_t * minim_btn, lv_dispi_t * dispi)
|
||||
{
|
||||
lv_obj_t * win = lv_win_get_from_ctrl_btn(close_minim);
|
||||
lv_obj_t * win = lv_win_get_from_ctrl_btn(minim_btn);
|
||||
lv_app_inst_t * app = lv_obj_get_free_p(win);
|
||||
|
||||
lv_app_kb_close(false);
|
||||
@@ -813,6 +830,40 @@ static lv_action_res_t lv_app_win_minim_action(lv_obj_t * close_minim, lv_dispi_
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the settings of an application in a window (use the set_open function of the application)
|
||||
* @param set_btn pointer to the settings button
|
||||
* @param dispi pointer to the caller display input
|
||||
* @return always LV_ACTION_RES_OK because the button is not deleted here
|
||||
*/
|
||||
static lv_action_res_t lv_app_win_conf_action(lv_obj_t * set_btn, lv_dispi_t * dispi)
|
||||
{
|
||||
/*Close the app list if opened*/
|
||||
if(app_list != NULL) {
|
||||
lv_obj_del(app_list);
|
||||
app_list = NULL;
|
||||
}
|
||||
|
||||
lv_obj_t * win = lv_win_get_from_ctrl_btn(set_btn);
|
||||
lv_app_inst_t * app = lv_obj_get_free_p(win);
|
||||
|
||||
app->conf_win = lv_win_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_free_p(app->conf_win, app);
|
||||
lv_obj_set_style(app->conf_win, &app_style.win_style);
|
||||
char buf[256];
|
||||
sprintf(buf, "%s settings", app->dsc->name);
|
||||
lv_win_set_title(app->conf_win, buf);
|
||||
lv_obj_t * set_content = lv_page_get_scrl(app->conf_win);
|
||||
lv_rect_set_fit(set_content, false, true);
|
||||
lv_rect_set_layout(set_content, LV_RECT_LAYOUT_COL_L);
|
||||
lv_obj_set_width(set_content, LV_HOR_RES - 2 * app_style.win_style.pages.bg_rects.hpad);
|
||||
|
||||
lv_win_add_ctrl_btn(app->conf_win, "U:/icon_close" ,lv_win_close_action);
|
||||
|
||||
app->dsc->conf_open(app, app->conf_win);
|
||||
|
||||
return LV_ACTION_RES_OK;
|
||||
}
|
||||
/*-----------------------
|
||||
ANIMATIONS
|
||||
------------------------*/
|
||||
@@ -1133,6 +1184,10 @@ static void lv_app_init_icons(void)
|
||||
lv_img_create_file("icon_right", img_right);
|
||||
#endif
|
||||
|
||||
#if USE_IMG_SETTINGS != 0
|
||||
lv_img_create_file("icon_settings", img_settings);
|
||||
#endif
|
||||
|
||||
#if USE_IMG_UP != 0
|
||||
lv_img_create_file("icon_up", img_up);
|
||||
#endif
|
||||
|
||||
@@ -30,7 +30,7 @@ typedef enum
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LV_APP_COM_TYPE_CHAR, /*Stream of characters. Always '\0' terminated*/
|
||||
LV_APP_COM_TYPE_CHAR, /*Stream of characters. Not '\0' terminated*/
|
||||
LV_APP_COM_TYPE_INT, /*Stream of 'int32_t' numbers*/
|
||||
LV_APP_COM_TYPE_LOG, /*String about an event to log*/
|
||||
LV_APP_COM_TYPE_TRIG, /*A trigger to do some specific action (data is ignored)*/
|
||||
@@ -47,6 +47,7 @@ typedef struct
|
||||
lv_obj_t * sc;
|
||||
lv_obj_t * sc_title;
|
||||
lv_obj_t * win;
|
||||
lv_obj_t * conf_win;
|
||||
void * app_data;
|
||||
void * sc_data;
|
||||
void * win_data;
|
||||
@@ -63,6 +64,7 @@ typedef struct __LV_APP_DSC_T
|
||||
void (*sc_close) (lv_app_inst_t *);
|
||||
void (*win_open) (lv_app_inst_t *, lv_obj_t *);
|
||||
void (*win_close) (lv_app_inst_t *);
|
||||
void (*conf_open) (lv_app_inst_t *, lv_obj_t * );
|
||||
uint16_t app_data_size;
|
||||
uint16_t sc_data_size;
|
||||
uint16_t win_data_size;
|
||||
|
||||
@@ -45,7 +45,6 @@ typedef struct
|
||||
typedef struct
|
||||
{
|
||||
lv_obj_t * file_list;
|
||||
lv_obj_t * send_set_h;
|
||||
}my_win_data_t;
|
||||
|
||||
/*Application specific data for a shortcut of this application*/
|
||||
@@ -73,6 +72,7 @@ static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc);
|
||||
static void my_sc_close(lv_app_inst_t * app);
|
||||
static void my_win_open(lv_app_inst_t * app, lv_obj_t * win);
|
||||
static void my_win_close(lv_app_inst_t * app);
|
||||
static void my_conf_open(lv_app_inst_t * app, lv_obj_t * conf_win);
|
||||
|
||||
static void win_load_file_list(lv_app_inst_t * app);
|
||||
static void win_create_list(lv_app_inst_t * app);
|
||||
@@ -83,7 +83,6 @@ static lv_action_res_t win_drv_action(lv_obj_t * drv, lv_dispi_t * dispi);
|
||||
static lv_action_res_t win_folder_action(lv_obj_t * folder, lv_dispi_t * dispi);
|
||||
static lv_action_res_t win_file_action(lv_obj_t * file, lv_dispi_t * dispi);
|
||||
static lv_action_res_t win_send_rel_action(lv_obj_t * send, lv_dispi_t * dispi);
|
||||
static lv_action_res_t win_send_lpr_action(lv_obj_t * send, lv_dispi_t * dispi);
|
||||
static lv_action_res_t win_send_settings_element_rel_action(lv_obj_t * element, lv_dispi_t * dispi);
|
||||
static lv_action_res_t win_back_action(lv_obj_t * back, lv_dispi_t * dispi);
|
||||
static lv_action_res_t win_del_rel_action(lv_obj_t * del, lv_dispi_t * dispi);
|
||||
@@ -107,6 +106,7 @@ static lv_app_dsc_t my_app_dsc =
|
||||
.win_close = my_win_close,
|
||||
.sc_open = my_sc_open,
|
||||
.sc_close = my_sc_close,
|
||||
.conf_open = my_conf_open,
|
||||
.app_data_size = sizeof(my_app_data_t),
|
||||
.sc_data_size = sizeof(my_sc_data_t),
|
||||
.win_data_size = sizeof(my_win_data_t),
|
||||
@@ -247,7 +247,6 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
|
||||
|
||||
app_data->file_cnt = 0;
|
||||
win_data->file_list = NULL;
|
||||
win_data->send_set_h = NULL;
|
||||
|
||||
lv_win_set_title(win, app_data->path);
|
||||
|
||||
@@ -263,6 +262,77 @@ static void my_win_close(lv_app_inst_t * app)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create objects to configure the applications
|
||||
* @param app pointer to an application which settings should be created
|
||||
* @param conf_win pointer to a window where the objects can be created
|
||||
* (the window has the proper layout)
|
||||
*/
|
||||
static void my_conf_open(lv_app_inst_t * app, lv_obj_t * conf_win)
|
||||
{
|
||||
my_app_data_t * app_data = app->app_data;
|
||||
|
||||
/*Create check boxes*/
|
||||
lv_obj_t * cb;
|
||||
|
||||
/*Send file name check box*/
|
||||
cb = lv_cb_create(conf_win, NULL);
|
||||
lv_cb_set_text(cb, "Send file name");
|
||||
lv_obj_set_free_num(cb, SEND_SETTINGS_FN);
|
||||
lv_obj_set_free_p(cb, app);
|
||||
lv_btn_set_rel_action(cb, win_send_settings_element_rel_action);
|
||||
if(app_data->send_fn != 0) lv_btn_set_state(cb, LV_BTN_STATE_TGL_REL);
|
||||
else lv_btn_set_state(cb, LV_BTN_STATE_REL);
|
||||
|
||||
/*Send size check box*/
|
||||
cb = lv_cb_create(conf_win, cb);
|
||||
lv_cb_set_text(cb, "Send size");
|
||||
lv_obj_set_free_num(cb, SEND_SETTINGS_SIZE);
|
||||
if(app_data->send_size != 0) lv_btn_set_state(cb, LV_BTN_STATE_TGL_REL);
|
||||
else lv_btn_set_state(cb, LV_BTN_STATE_REL);
|
||||
|
||||
/*Send CRC check box*/
|
||||
cb = lv_cb_create(conf_win, cb);
|
||||
lv_cb_set_text(cb, "Send CRC");
|
||||
lv_obj_set_free_num(cb, SEND_SETTINGS_CRC);
|
||||
if(app_data->send_crc != 0) lv_btn_set_state(cb, LV_BTN_STATE_TGL_REL);
|
||||
else lv_btn_set_state(cb, LV_BTN_STATE_REL);
|
||||
|
||||
/*Create a text area the type chunk size*/
|
||||
lv_obj_t * val_set_h;
|
||||
val_set_h = lv_rect_create(conf_win, NULL);
|
||||
lv_obj_set_style(val_set_h, lv_rects_get(LV_RECTS_TRANSP, NULL));
|
||||
lv_obj_set_click(val_set_h, false);
|
||||
lv_rect_set_fit(val_set_h, true, true);
|
||||
lv_rect_set_layout(val_set_h, LV_RECT_LAYOUT_ROW_M);
|
||||
|
||||
lv_obj_t * label;
|
||||
label = lv_label_create(val_set_h, NULL);
|
||||
lv_label_set_text(label, "Chunk size");
|
||||
|
||||
lv_obj_t * ta;
|
||||
char buf[32];
|
||||
ta = lv_ta_create(val_set_h, NULL);
|
||||
lv_obj_set_style(ta, lv_tas_get(LV_TAS_SIMPLE, NULL));
|
||||
lv_rect_set_fit(ta, false, true);
|
||||
lv_obj_set_free_num(ta, SEND_SETTINGS_CHUNK_SIZE);
|
||||
lv_obj_set_free_p(ta, app);
|
||||
lv_page_set_rel_action(ta, win_send_settings_element_rel_action);
|
||||
sprintf(buf, "%d", app_data->chunk_size);
|
||||
lv_ta_set_text(ta, buf);
|
||||
|
||||
/*Create a text area to type the chunk delay*/
|
||||
val_set_h = lv_rect_create(conf_win, val_set_h);
|
||||
|
||||
label = lv_label_create(val_set_h, NULL);
|
||||
lv_label_set_text(label, "Inter-chunk delay");
|
||||
|
||||
ta = lv_ta_create(val_set_h, ta);
|
||||
lv_obj_set_free_num(ta, SEND_SETTINGS_CHUNK_DELAY);
|
||||
sprintf(buf, "%d", app_data->chunk_delay);
|
||||
lv_ta_set_text(ta, buf);
|
||||
}
|
||||
|
||||
/*--------------------
|
||||
* OTHER FUNCTIONS
|
||||
---------------------*/
|
||||
@@ -522,8 +592,6 @@ static lv_action_res_t win_file_action(lv_obj_t * file, lv_dispi_t * dispi)
|
||||
/*Send button*/
|
||||
liste = lv_list_add(win_data->file_list, NULL, "Send", win_send_rel_action);
|
||||
lv_obj_set_free_p(liste, app);
|
||||
lv_btn_set_lpr_action(liste, win_send_lpr_action);
|
||||
lv_obj_set_free_p(liste, app);
|
||||
|
||||
/*Delete button*/
|
||||
liste = lv_list_add(win_data->file_list, NULL, "Delete", win_del_rel_action);
|
||||
@@ -573,100 +641,6 @@ static lv_action_res_t win_send_rel_action(lv_obj_t * send, lv_dispi_t * dispi)
|
||||
return LV_ACTION_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the Send list element is long pressed to show/hide send settings
|
||||
* @param send pointer to the Up button
|
||||
* @param dispi pointer to the caller display input
|
||||
* @return LV_ACTION_RES_OK because the list is NOT deleted in the function
|
||||
*/
|
||||
static lv_action_res_t win_send_lpr_action(lv_obj_t * send, lv_dispi_t * dispi)
|
||||
{
|
||||
lv_app_inst_t * app = lv_obj_get_free_p(send);
|
||||
my_app_data_t * app_data = app->app_data;
|
||||
my_win_data_t * win_data = app->win_data;
|
||||
|
||||
/*Close the settings if it is opened*/
|
||||
if(win_data->send_set_h != NULL) {
|
||||
lv_obj_del(win_data->send_set_h);
|
||||
win_data->send_set_h = NULL;
|
||||
lv_dispi_wait_release(dispi);
|
||||
lv_btn_set_state(send, LV_BTN_STATE_REL);
|
||||
return LV_ACTION_RES_OK;
|
||||
}
|
||||
|
||||
/*Create the settings*/
|
||||
lv_btn_set_state(send, LV_BTN_STATE_REL);
|
||||
lv_rect_set_layout(send, LV_RECT_LAYOUT_COL_L);
|
||||
|
||||
/*Create holder for the settings*/
|
||||
win_data->send_set_h = lv_rect_create(send, NULL);
|
||||
lv_obj_set_style(win_data->send_set_h, lv_rects_get(LV_RECTS_TRANSP, NULL));
|
||||
lv_obj_set_click(win_data->send_set_h, false);
|
||||
lv_rect_set_fit(win_data->send_set_h, true, true);
|
||||
lv_rect_set_layout(win_data->send_set_h, LV_RECT_LAYOUT_COL_L);
|
||||
|
||||
/*Create check boxes*/
|
||||
lv_obj_t * cb;
|
||||
|
||||
/*Send file name check box*/
|
||||
cb = lv_cb_create(win_data->send_set_h, NULL);
|
||||
lv_cb_set_text(cb, "Send file name");
|
||||
lv_obj_set_free_num(cb, SEND_SETTINGS_FN);
|
||||
lv_obj_set_free_p(cb, app);
|
||||
lv_btn_set_rel_action(cb, win_send_settings_element_rel_action);
|
||||
if(app_data->send_fn != 0) lv_btn_set_state(cb, LV_BTN_STATE_TGL_REL);
|
||||
else lv_btn_set_state(cb, LV_BTN_STATE_REL);
|
||||
|
||||
/*Send size check box*/
|
||||
cb = lv_cb_create(win_data->send_set_h, cb);
|
||||
lv_cb_set_text(cb, "Send size");
|
||||
lv_obj_set_free_num(cb, SEND_SETTINGS_SIZE);
|
||||
if(app_data->send_size != 0) lv_btn_set_state(cb, LV_BTN_STATE_TGL_REL);
|
||||
else lv_btn_set_state(cb, LV_BTN_STATE_REL);
|
||||
|
||||
/*Send CRC check box*/
|
||||
cb = lv_cb_create(win_data->send_set_h, cb);
|
||||
lv_cb_set_text(cb, "Send CRC");
|
||||
lv_obj_set_free_num(cb, SEND_SETTINGS_CRC);
|
||||
if(app_data->send_crc != 0) lv_btn_set_state(cb, LV_BTN_STATE_TGL_REL);
|
||||
else lv_btn_set_state(cb, LV_BTN_STATE_REL);
|
||||
|
||||
/*Create a text area the type chunk size*/
|
||||
lv_obj_t * val_set_h;
|
||||
val_set_h = lv_rect_create(win_data->send_set_h, NULL);
|
||||
lv_obj_set_style(val_set_h, lv_rects_get(LV_RECTS_TRANSP, NULL));
|
||||
lv_obj_set_click(val_set_h, false);
|
||||
lv_rect_set_fit(val_set_h, true, true);
|
||||
lv_rect_set_layout(val_set_h, LV_RECT_LAYOUT_ROW_M);
|
||||
|
||||
lv_obj_t * label;
|
||||
label = lv_label_create(val_set_h, NULL);
|
||||
lv_label_set_text(label, "Chunk size");
|
||||
|
||||
lv_obj_t * ta;
|
||||
char buf[32];
|
||||
ta = lv_ta_create(val_set_h, NULL);
|
||||
lv_obj_set_style(ta, lv_tas_get(LV_TAS_SIMPLE, NULL));
|
||||
lv_rect_set_fit(ta, false, true);
|
||||
lv_obj_set_free_num(ta, SEND_SETTINGS_CHUNK_SIZE);
|
||||
lv_obj_set_free_p(ta, app);
|
||||
lv_page_set_rel_action(ta, win_send_settings_element_rel_action);
|
||||
sprintf(buf, "%d", app_data->chunk_size);
|
||||
lv_ta_set_text(ta, buf);
|
||||
|
||||
/*Create a text area to type the chunk delay*/
|
||||
val_set_h = lv_rect_create(win_data->send_set_h, val_set_h);
|
||||
|
||||
label = lv_label_create(val_set_h, NULL);
|
||||
lv_label_set_text(label, "Inter-chunk delay");
|
||||
|
||||
ta = lv_ta_create(val_set_h, ta);
|
||||
lv_obj_set_free_num(ta, SEND_SETTINGS_CHUNK_DELAY);
|
||||
sprintf(buf, "%d", app_data->chunk_delay);
|
||||
lv_ta_set_text(ta, buf);
|
||||
|
||||
return LV_ACTION_RES_OK;
|
||||
}
|
||||
/**
|
||||
* Called when a send settings element is released
|
||||
* @param element pointer to a chekbox or text area
|
||||
|
||||
@@ -6,7 +6,23 @@
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
#include <lv_conf.h>
|
||||
#include <lvgl/lv_misc/area.h>
|
||||
#include <lvgl/lv_obj/lv_dispi.h>
|
||||
#include <lvgl/lv_obj/lv_obj.h>
|
||||
#include <lvgl/lv_objx/lv_btn.h>
|
||||
#include <lvgl/lv_objx/lv_ddlist.h>
|
||||
#include <lvgl/lv_objx/lv_label.h>
|
||||
#include <lvgl/lv_objx/lv_page.h>
|
||||
#include <lvgl/lv_objx/lv_rect.h>
|
||||
#include <lvgl/lv_objx/lv_ta.h>
|
||||
#include <misc/others/color.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "lv_app_terminal.h"
|
||||
|
||||
#if LV_APP_ENABLE != 0 && USE_LV_APP_TERMINAL != 0
|
||||
|
||||
#include "lvgl/lv_app/lv_app_util/lv_app_kb.h"
|
||||
@@ -20,11 +36,13 @@
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
|
||||
/*Application specific data for an instance of this application*/
|
||||
typedef struct
|
||||
{
|
||||
char txt[LV_APP_TERMINAL_LENGTH + 1];
|
||||
lv_app_com_type_t com_type;
|
||||
lv_app_terminal_format_t format;
|
||||
lv_app_inst_t * last_sender;
|
||||
}my_app_data_t;
|
||||
|
||||
@@ -33,7 +51,6 @@ typedef struct
|
||||
{
|
||||
lv_obj_t * label;
|
||||
lv_obj_t * ta;
|
||||
lv_obj_t * com_type_btn;
|
||||
lv_obj_t * clear_btn;
|
||||
}my_win_data_t;
|
||||
|
||||
@@ -53,10 +70,12 @@ static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc);
|
||||
static void my_sc_close(lv_app_inst_t * app);
|
||||
static void my_win_open(lv_app_inst_t * app, lv_obj_t * win);
|
||||
static void my_win_close(lv_app_inst_t * app);
|
||||
static void my_conf_open(lv_app_inst_t * app, lv_obj_t * conf_win);
|
||||
|
||||
static void add_data(lv_app_inst_t * app, const void * data, uint16_t data_len);
|
||||
static lv_action_res_t win_ta_rel_action(lv_obj_t * ta, lv_dispi_t * dispi);
|
||||
static lv_action_res_t win_comch_rel_action(lv_obj_t * btn, lv_dispi_t * dispi);
|
||||
static lv_action_res_t win_comtype_action(lv_obj_t * btn, uint16_t opt);
|
||||
static lv_action_res_t win_format_action(lv_obj_t * btn, uint16_t opt);
|
||||
static lv_action_res_t win_clear_rel_action(lv_obj_t * btn, lv_dispi_t * dispi);
|
||||
static void win_ta_kb_ok_action(lv_obj_t * ta);
|
||||
|
||||
@@ -74,12 +93,15 @@ static lv_app_dsc_t my_app_dsc =
|
||||
.win_close = my_win_close,
|
||||
.sc_open = my_sc_open,
|
||||
.sc_close = my_sc_close,
|
||||
.conf_open = my_conf_open,
|
||||
.app_data_size = sizeof(my_app_data_t),
|
||||
.sc_data_size = sizeof(my_sc_data_t),
|
||||
.win_data_size = sizeof(my_win_data_t),
|
||||
};
|
||||
|
||||
const char * com_type_txt [LV_APP_COM_TYPE_NUM];
|
||||
const char * com_type_list_txt[] = {"Character", "Integer", "Log", "None", ""};
|
||||
lv_app_com_type_t com_type_list[] = {LV_APP_COM_TYPE_CHAR, LV_APP_COM_TYPE_INT, LV_APP_COM_TYPE_LOG, LV_APP_COM_TYPE_INV};
|
||||
const char * txt_format_list_txt[] = {"ASCII", "Hexadecimal", ""};
|
||||
lv_objs_t sc_txt_bgs;
|
||||
lv_labels_t sc_txts;
|
||||
|
||||
@@ -97,11 +119,6 @@ lv_labels_t sc_txts;
|
||||
*/
|
||||
const lv_app_dsc_t * lv_app_terminal_init(void)
|
||||
{
|
||||
com_type_txt[LV_APP_COM_TYPE_INT] = "Ch: Num";
|
||||
com_type_txt[LV_APP_COM_TYPE_CHAR] = "Ch: Chars";
|
||||
com_type_txt[LV_APP_COM_TYPE_LOG] = "Ch: Log";
|
||||
com_type_txt[LV_APP_COM_TYPE_INV] = "Ch: None";
|
||||
|
||||
lv_app_style_t * app_style = lv_app_style_get();
|
||||
|
||||
memcpy(&sc_txts, &app_style->sc_txt_style, sizeof(lv_labels_t));
|
||||
@@ -132,6 +149,7 @@ static void my_app_run(lv_app_inst_t * app, void * conf)
|
||||
/*Initialize the application*/
|
||||
my_app_data_t * app_data = app->app_data;
|
||||
app_data->com_type = LV_APP_COM_TYPE_CHAR;
|
||||
app_data->format = LV_APP_TERMINAL_FORMAT_ASCII;
|
||||
app_data->last_sender = NULL;
|
||||
memset(app_data->txt, 0, sizeof(app_data->txt));
|
||||
}
|
||||
@@ -160,17 +178,27 @@ static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec,
|
||||
{
|
||||
my_app_data_t * app_data = app_rec->app_data;
|
||||
|
||||
/*Add the recevied data if the type is matches*/
|
||||
/*Add the received data if the type is matches*/
|
||||
if(type == app_data->com_type) {
|
||||
|
||||
/*Insert the name of the sender application if it is not the last*/
|
||||
if(app_data->last_sender != app_send) {
|
||||
if(app_data->txt[0] != '\0') add_data(app_rec, "\n", 1);
|
||||
add_data(app_rec, "@", 1);
|
||||
add_data(app_rec, app_send->name, strlen(app_send->name));
|
||||
add_data(app_rec, "\n", 1);
|
||||
}
|
||||
add_data(app_rec, data, size);
|
||||
|
||||
if(app_data->format == LV_APP_TERMINAL_FORMAT_HEX) {
|
||||
char hex_buf[8];
|
||||
const char * data_buf = data;
|
||||
uint32_t i;
|
||||
for(i = 0; i < size; i++) {
|
||||
sprintf(hex_buf, "%02x", data_buf[i]);
|
||||
add_data(app_rec, hex_buf, 2);
|
||||
}
|
||||
} else {
|
||||
add_data(app_rec, data, size);
|
||||
}
|
||||
}
|
||||
|
||||
app_data->last_sender = app_send;
|
||||
@@ -245,25 +273,15 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
|
||||
lv_obj_set_style(win_data->ta, lv_tas_get(LV_TAS_DEF, NULL));
|
||||
lv_obj_align(win_data->ta, win_data->label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, opad);
|
||||
|
||||
|
||||
/*Create a button to set the communication type (char, integer etc.)*/
|
||||
win_data->com_type_btn = lv_btn_create(win, NULL);
|
||||
lv_rect_set_fit(win_data->com_type_btn, true, true);
|
||||
lv_obj_set_free_p(win_data->com_type_btn, app);
|
||||
lv_btn_set_rel_action(win_data->com_type_btn, win_comch_rel_action);
|
||||
lv_obj_t * btn_label = lv_label_create(win_data->com_type_btn, NULL);
|
||||
lv_obj_set_style(btn_label, lv_labels_get(LV_LABELS_BTN, NULL));
|
||||
lv_label_set_text(btn_label, com_type_txt[app_data->com_type]);
|
||||
lv_obj_align(win_data->com_type_btn, win_data->ta, LV_ALIGN_OUT_RIGHT_TOP, opad, 0);
|
||||
|
||||
|
||||
/*Create a clear button*/
|
||||
win_data->clear_btn = lv_btn_create(win, win_data->com_type_btn);
|
||||
win_data->clear_btn = lv_btn_create(win, NULL);
|
||||
lv_rect_set_fit(win_data->clear_btn, true, true);
|
||||
lv_obj_set_free_p(win_data->clear_btn, app);
|
||||
lv_btn_set_rel_action(win_data->clear_btn, win_clear_rel_action);
|
||||
btn_label = lv_label_create(win_data->clear_btn, NULL);
|
||||
lv_obj_t * btn_label = lv_label_create(win_data->clear_btn, NULL);
|
||||
lv_obj_set_style(btn_label, lv_labels_get(LV_LABELS_BTN, NULL));
|
||||
lv_label_set_text(btn_label, "Clear");
|
||||
lv_obj_align(win_data->clear_btn, win_data->com_type_btn, LV_ALIGN_OUT_RIGHT_TOP, opad, 0);
|
||||
lv_obj_align(win_data->clear_btn, win_data->ta, LV_ALIGN_OUT_RIGHT_TOP, opad, 0);
|
||||
|
||||
/*Align the window to see the text area on the bottom*/
|
||||
lv_obj_align(lv_page_get_scrl(app->win), NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0,
|
||||
@@ -280,6 +298,37 @@ static void my_win_close(lv_app_inst_t * app)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create objects to configure the applications
|
||||
* @param app pointer to an application which settings should be created
|
||||
* @param conf_win pointer to a window where the objects can be created
|
||||
* (the window has the proper layout)
|
||||
*/
|
||||
static void my_conf_open(lv_app_inst_t * app, lv_obj_t * conf_win)
|
||||
{
|
||||
my_app_data_t * app_data = app->app_data;
|
||||
lv_app_style_t * app_style = lv_app_style_get();
|
||||
|
||||
lv_obj_t * label;
|
||||
label = lv_label_create(conf_win, NULL);
|
||||
lv_label_set_text(label, "Communication type");
|
||||
lv_obj_set_style(label, &app_style->win_txt_style);
|
||||
|
||||
lv_obj_t * ddl;
|
||||
ddl = lv_ddlist_create(conf_win, NULL);
|
||||
lv_obj_set_free_p(ddl, app);
|
||||
lv_ddlist_set_options(ddl, com_type_list_txt);
|
||||
lv_ddlist_set_action(ddl, win_comtype_action);
|
||||
lv_ddlist_set_selected(ddl, app_data->com_type);
|
||||
|
||||
label = lv_label_create(conf_win, label);
|
||||
lv_label_set_text(label, "\nText format"); /*First '\n' keeps space from the list above*/
|
||||
ddl = lv_ddlist_create(conf_win, ddl);
|
||||
lv_ddlist_set_options(ddl, txt_format_list_txt);
|
||||
lv_ddlist_set_selected(ddl, app_data->format);
|
||||
lv_ddlist_set_action(ddl, win_format_action);
|
||||
}
|
||||
|
||||
/*--------------------
|
||||
* OTHER FUNCTIONS
|
||||
---------------------*/
|
||||
@@ -298,28 +347,44 @@ static lv_action_res_t win_ta_rel_action(lv_obj_t * ta, lv_dispi_t * dispi)
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the communication type button is released to change the type
|
||||
* @param btn pointer to the comm. type button
|
||||
* @param dispi pointer to the caller display input
|
||||
* @return LV_ACTION_RES_OK because the button is not deleted
|
||||
* Called when an option is chosen in the communication type drop down list on the configuration window
|
||||
* @param ddl pointer to the drop down list
|
||||
* @param opt id of the chosen option
|
||||
* @return LV_ACTION_RES_OK because the list is not deleted
|
||||
*/
|
||||
static lv_action_res_t win_comch_rel_action(lv_obj_t * btn, lv_dispi_t * dispi)
|
||||
static lv_action_res_t win_comtype_action(lv_obj_t * btn, uint16_t opt)
|
||||
{
|
||||
lv_app_inst_t * app = lv_obj_get_free_p(btn);
|
||||
my_app_data_t * app_data = app->app_data;
|
||||
my_win_data_t * win_data = app->win_data;
|
||||
|
||||
if(app_data->com_type == LV_APP_COM_TYPE_CHAR) app_data->com_type = LV_APP_COM_TYPE_LOG;
|
||||
else if(app_data->com_type == LV_APP_COM_TYPE_LOG) app_data->com_type = LV_APP_COM_TYPE_INT;
|
||||
else if(app_data->com_type == LV_APP_COM_TYPE_INT) app_data->com_type = LV_APP_COM_TYPE_INV;
|
||||
else app_data->com_type = LV_APP_COM_TYPE_CHAR;
|
||||
app_data->com_type = com_type_list[opt];
|
||||
|
||||
lv_label_set_text(lv_obj_get_child(win_data->com_type_btn, NULL), com_type_txt[app_data->com_type]);
|
||||
return LV_ACTION_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the Clear button is released to clear the ex od the terminal
|
||||
* Called when an option is chosen in the format drop down list on the configuration window
|
||||
* @param ddl pointer to the drop down list
|
||||
* @param opt id of the chosen option
|
||||
* @return LV_ACTION_RES_OK because the list is not deleted
|
||||
*/
|
||||
static lv_action_res_t win_format_action(lv_obj_t * btn, uint16_t opt)
|
||||
{
|
||||
lv_app_inst_t * app = lv_obj_get_free_p(btn);
|
||||
my_app_data_t * app_data = app->app_data;
|
||||
|
||||
if(strcmp(txt_format_list_txt[opt], "Hexadecimal") == 0) {
|
||||
app_data->format = LV_APP_TERMINAL_FORMAT_HEX;
|
||||
} else if (strcmp(txt_format_list_txt[opt], "ASCII") == 0) {
|
||||
app_data->format = LV_APP_TERMINAL_FORMAT_ASCII;
|
||||
}
|
||||
|
||||
return LV_ACTION_RES_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when the Clear button is released to clear the text of the terminal
|
||||
* @param btn pointer to the clear button
|
||||
* @param dispi pointer to the caller display input
|
||||
* @return LV_ACTION_RES_OK because the button is not deleted
|
||||
@@ -343,8 +408,7 @@ static lv_action_res_t win_clear_rel_action(lv_obj_t * btn, lv_dispi_t * dispi)
|
||||
cord_t opad = app_style->win_style.pages.scrl_rects.opad;
|
||||
lv_label_set_text_static(win_data->label, app_data->txt);
|
||||
lv_obj_align(win_data->ta, win_data->label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, opad);
|
||||
lv_obj_align(win_data->com_type_btn, win_data->ta, LV_ALIGN_OUT_RIGHT_TOP, opad, 0);
|
||||
lv_obj_align(win_data->clear_btn, win_data->com_type_btn, LV_ALIGN_OUT_RIGHT_TOP, opad, 0);
|
||||
lv_obj_align(win_data->clear_btn, win_data->ta, LV_ALIGN_OUT_RIGHT_TOP, opad, 0);
|
||||
lv_obj_align(lv_page_get_scrl(app->win), NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0,
|
||||
- app_style->win_style.pages.scrl_rects.vpad);
|
||||
}
|
||||
@@ -430,8 +494,7 @@ static void add_data(lv_app_inst_t * app, const void * data, uint16_t data_len)
|
||||
cord_t opad = app_style->win_style.pages.scrl_rects.opad;
|
||||
lv_label_set_text_static(win_data->label, app_data->txt);
|
||||
lv_obj_align(win_data->ta, win_data->label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, opad);
|
||||
lv_obj_align(win_data->com_type_btn, win_data->ta, LV_ALIGN_OUT_RIGHT_TOP, opad, 0);
|
||||
lv_obj_align(win_data->clear_btn, win_data->com_type_btn, LV_ALIGN_OUT_RIGHT_TOP, opad, 0);
|
||||
lv_obj_align(win_data->clear_btn, win_data->ta, LV_ALIGN_OUT_RIGHT_TOP, opad, 0);
|
||||
lv_obj_align(lv_page_get_scrl(app->win), NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0,
|
||||
- app_style->win_style.pages.scrl_rects.vpad);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,12 @@
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
typedef enum
|
||||
{
|
||||
LV_APP_TERMINAL_FORMAT_ASCII,
|
||||
LV_APP_TERMINAL_FORMAT_HEX,
|
||||
}lv_app_terminal_format_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user