BigW Consortium Gitlab

Commit 7b3c0009 by Gabor Kiss-Vamosi

delete application (moved as examples to a new repo)

parent a5c85244
/**
* @file lv_app.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_app.h"
#if LV_APP_ENABLE != 0
#include <stdio.h>
#include "misc/gfx/anim.h"
#include "lvgl/lv_obj/lv_refr.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct {
lv_app_inst_t * sender;
lv_app_inst_t * receiver;
}lv_app_con_t;
/**********************
* STATIC PROTOTYPES
**********************/
#if LV_APP_DESKTOP != 0
static void lv_app_init_desktop(void);
#endif
/*Actions*/
#if LV_APP_DESKTOP != 0
static lv_action_res_t lv_app_menu_rel_action(lv_obj_t * app_btn, lv_indev_proc_t * indev_proc);
static lv_action_res_t lv_app_menu_elem_rel_action(lv_obj_t * app_elem_btn, lv_indev_proc_t * indev_proc);
static lv_action_res_t lv_app_sc_page_rel_action(lv_obj_t * sc, lv_indev_proc_t * indev_proc);
#endif
static lv_action_res_t lv_app_sc_rel_action(lv_obj_t * sc, lv_indev_proc_t * indev_proc);
static lv_action_res_t lv_app_sc_lpr_action(lv_obj_t * sc, lv_indev_proc_t * indev_proc);
static lv_action_res_t lv_app_win_close_action(lv_obj_t * close_btn, lv_indev_proc_t * indev_proc);
static lv_action_res_t lv_app_win_minim_action(lv_obj_t * minim_btn, lv_indev_proc_t * indev_proc);
static lv_action_res_t lv_app_win_conf_action(lv_obj_t * set_btn, lv_indev_proc_t * indev_proc);
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);
#if LV_APP_ANIM_WIN != 0
static void lv_app_win_open_anim_cb(lv_obj_t * app_win);
static void lv_app_win_close_anim_cb(lv_obj_t * app_win);
static void lv_app_win_minim_anim_cb(lv_obj_t * app_win);
#endif
static void lv_app_init_style(void);
/**********************
* STATIC VARIABLES
**********************/
static ll_dsc_t app_dsc_ll; /*Store a pointer to the app. descriptors*/
static ll_dsc_t app_inst_ll; /*Store the running apps*/
static ll_dsc_t app_con_ll; /*Store the communication connection between the apps*/
static lv_obj_t * app_scr; /*Screen of the applications*/
#if LV_APP_DESKTOP != 0
static lv_obj_t * menuh; /*Holder of timg_bubbleshe menu on the top*/
static lv_obj_t * app_btn; /*The "Apps" button on the menu*/
static lv_obj_t * sc_page; /*A page for the shortcuts */
#endif
static lv_obj_t * app_list; /*A list which is opened on 'app_btn' release*/
static lv_app_inst_t * con_send; /*The sender application in connection mode. Not NLL means connection mode is active*/
static lv_app_style_t app_style; /*Styles for application related things*/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the application system
*/
void lv_app_init(void)
{
/*Init linked lists*/
ll_init(&app_dsc_ll, sizeof(lv_app_dsc_t *));
ll_init(&app_inst_ll, sizeof(lv_app_inst_t));
ll_init(&app_con_ll, sizeof(lv_app_con_t));
app_scr = lv_scr_act();
lv_app_init_style();
#if LV_APP_DESKTOP != 0
/*Create the desktop elements*/
lv_app_init_desktop();
#endif
/*Init. the utilities*/
lv_app_kb_init();
lv_app_notice_init();
lv_app_fsel_init();
/*Initialize all application descriptors*/
/*ADD NEW APPLICATION INITS HERE!!!*/
const lv_app_dsc_t ** dsc;
#if USE_LV_APP_EXAMPLE != 0
dsc = ll_ins_head(&app_dsc_ll);
*dsc = lv_app_example_init();
#endif
#if USE_LV_APP_PHANTOM != 0
dsc = ll_ins_head(&app_dsc_ll);
*dsc = lv_app_phantom_init();
#endif
#if USE_LV_APP_SYSMON != 0
dsc = ll_ins_head(&app_dsc_ll);
*dsc = lv_app_sysmon_init();
#endif
#if USE_LV_APP_TERMINAL != 0
dsc = ll_ins_head(&app_dsc_ll);
*dsc = lv_app_terminal_init();
#endif
#if USE_LV_APP_FILES != 0
dsc = ll_ins_head(&app_dsc_ll);
*dsc = lv_app_files_init();
#endif
#if USE_LV_APP_BENCHMARK != 0
dsc = ll_ins_head(&app_dsc_ll);
*dsc = lv_app_benchmark_init();
#endif
#if USE_LV_APP_WIFI != 0
dsc = ll_ins_head(&app_dsc_ll);
*dsc = lv_app_wifi_init();
#endif
#if USE_LV_APP_GSM != 0
dsc = ll_ins_head(&app_dsc_ll);
*dsc = lv_app_gsm_init();
#endif
#if USE_LV_APP_ETHERNET != 0
dsc = ll_ins_head(&app_dsc_ll);
*dsc = lv_app_ethernet_init();
#endif
}
/**
* Get screen of the applications
*/
lv_obj_t * lv_scr_app(void)
{
return app_scr;
}
/**
* Allocate a new application descriptor
* @return pointer to an lv_app_dsc_t pointer. Save here a pointer to an app. dsc.
* E.g. *dsc = &my_app_dsc;
*/
lv_app_dsc_t ** lv_app_add_dsc(void)
{
return ll_ins_head(&app_dsc_ll);
}
/**
* Run an application according to 'app_dsc'
* @param app_dsc pointer to an application descriptor
* @param conf pointer to an application specific configuration structure or NULL if unused
* @return pointer to the opened application or NULL if any error occurred
*/
lv_app_inst_t * lv_app_run(const lv_app_dsc_t * app_dsc, void * conf)
{
/*Add a new application and initialize it*/
lv_app_inst_t * app;
app = ll_ins_head(&app_inst_ll);
app->dsc = app_dsc;
app->app_data = dm_alloc(app_dsc->app_data_size);
app->name = NULL;
app->sc = NULL;
app->sc_data = NULL;
app->sc_title = NULL;
app->win = NULL;
app->win_data = NULL;
lv_app_rename(app, app_dsc->name); /*Set a default name*/
/*Call the application specific run function*/
if(app_dsc->app_run != NULL) app_dsc->app_run(app, conf);
return app;
}
/**
* Close a running application. Close the Window and the Shortcut too if opened.
* @param app pointer to an application
*/
void lv_app_close(lv_app_inst_t * app)
{
lv_app_win_close(app);
lv_app_sc_close(app);
/*Clear the connection list*/
lv_app_con_del(app, NULL);
lv_app_con_del(NULL, app);
if(app->dsc->app_close != NULL) app->dsc->app_close(app);
memset(app->app_data, 0, app->dsc->app_data_size);
dm_free(app->app_data);
dm_free(app->name);
ll_rem(&app_inst_ll, app);
dm_free(app);
}
/**
* Open a shortcut for an application
* @param app pointer to an application
* @return pointer to the shortcut
*/
lv_obj_t * lv_app_sc_open(lv_app_inst_t * app)
{
if(app->dsc->sc_open == NULL) return NULL;
/*Create a basic shortcut*/
#if LV_APP_DESKTOP != 0
app->sc = lv_btn_create(sc_page, NULL);
lv_page_glue_obj(app->sc, true);
#else
app->sc = lv_btn_create(app_scr, NULL);
#endif
lv_obj_set_free_p(app->sc, app);
lv_btn_set_styles(app->sc, &app_style.sc_rel, &app_style.sc_pr, NULL, NULL, NULL);
lv_obj_set_size(app->sc, LV_APP_SC_WIDTH, LV_APP_SC_HEIGHT);
lv_cont_set_layout(app->sc, LV_CONT_LAYOUT_OFF);
lv_btn_set_rel_action(app->sc, lv_app_sc_rel_action);
lv_btn_set_lpr_action(app->sc, lv_app_sc_lpr_action);
if((app->dsc->mode & LV_APP_MODE_NO_SC_TITLE) == 0) {
/*Create a title on top of the shortcut*/
app->sc_title = lv_label_create(app->sc, NULL);
lv_obj_set_style(app->sc_title, &app_style.sc_title);
lv_obj_set_size(app->sc_title, LV_APP_SC_WIDTH, font_get_height(app_style.sc_title.font) >> FONT_ANTIALIAS);
lv_label_set_long_mode(app->sc_title, LV_LABEL_LONG_DOTS);
lv_label_set_text(app->sc_title, app->name);
lv_obj_align_us(app->sc_title, NULL, LV_ALIGN_IN_TOP_MID, 0, LV_DPI / 20);
lv_obj_set_protect(app->sc_title, LV_PROTECT_POS);
} else {
app->sc_title = NULL;
}
/*Allocate data and call the app specific sc_open function*/
app->sc_data = dm_alloc(app->dsc->sc_data_size);
app->dsc->sc_open(app, app->sc);
#if LV_APP_DESKTOP != 0
lv_page_focus(sc_page, app->sc, LV_APP_ANIM_DESKTOP);
#endif
return app->sc;
}
/**
* Close the shortcut of an application
* @param app pointer to an application
*/
void lv_app_sc_close(lv_app_inst_t * app)
{
if(app->sc == NULL) return;
if(app->dsc->sc_close != NULL) app->dsc->sc_close(app);
lv_obj_del(app->sc);
app->sc = NULL;
app->sc_title = NULL;
memset(app->sc_data, 0, app->dsc->sc_data_size);
dm_free(app->sc_data);
app->sc_data = NULL;
}
/**
* Open the application in a window
* @param app pointer to an application
* @return pointer to the shortcut
*/
lv_obj_t * lv_app_win_open(lv_app_inst_t * app)
{
/*Close the app list if opened*/
if(app_list != NULL) {
lv_obj_del(app_list);
app_list = NULL;
}
if(app->dsc->win_open == NULL) return NULL;
app->win = lv_win_create(lv_scr_act(), NULL);
lv_obj_set_free_p(app->win, app);
lv_obj_set_style(lv_win_get_header(app->win), &app_style.win_header);
lv_win_set_title(app->win, app->dsc->name);
lv_page_set_sb_mode(lv_win_get_page(app->win), LV_PAGE_SB_MODE_AUTO);
lv_win_set_styles_cbtn(app->win, &app_style.win_cbtn_rel, &app_style.win_cbtn_pr);
if(app->dsc->conf_open != NULL) {
lv_win_add_cbtn(app->win, SYMBOL_SETUP, lv_app_win_conf_action);
}
lv_win_add_cbtn(app->win, SYMBOL_DOWN, lv_app_win_minim_action);
lv_win_add_cbtn(app->win, SYMBOL_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;
}
/**
* Close the window of an application
* @param app pointer to an application
*/
void lv_app_win_close(lv_app_inst_t * app)
{
if(app->win == NULL) return;
lv_app_kb_close(false);
if(app->dsc->win_close != NULL) app->dsc->win_close(app);
lv_obj_del(app->win);
app->win = NULL;
memset(app->win_data, 0, app->dsc->win_data_size);
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
* @param type type of data from 'lv_app_com_type_t' enum
* @param data pointer to the sent data
* @param size length of 'data' in bytes
* @return number application which were received the message
*/
uint16_t lv_app_com_send(lv_app_inst_t * app_send, lv_app_com_type_t type , const void * data, uint32_t size)
{
if(type == LV_APP_COM_TYPE_INV) return 0;
lv_app_con_t * con;
uint16_t rec_cnt = 0;
LL_READ(app_con_ll, con) {
if(con->sender == app_send) {
if(con->receiver->dsc->com_rec != NULL)
con->receiver->dsc->com_rec(app_send, con->receiver, type, data, size);
rec_cnt ++;
}
}
return rec_cnt;
}
/**
* Test an application communication connection
* @param sender pointer to an application which sends data
* @param receiver pointer to an application which receives data
* @return false: no connection, true: there is connection
*/
bool lv_app_con_check(lv_app_inst_t * sender, lv_app_inst_t * receiver)
{
lv_app_con_t * con;
LL_READ(app_con_ll, con) {
if(con->sender == sender && con->receiver == receiver) {
return true;
}
}
return false;
}
/**
* Create a new connection between two applications
* @param sender pointer to a data sender application
* @param receiver pointer to a data receiver application
*/
void lv_app_con_set(lv_app_inst_t * sender, lv_app_inst_t * receiver)
{
if(lv_app_con_check(sender, receiver) == false) {
lv_app_con_t * con;
con = ll_ins_head(&app_con_ll);
con->sender = sender;
con->receiver = receiver;
}
}
/**
* Delete a communication connection
* @param sender pointer to a data sender application or NULL to be true for all sender
* @param receiver pointer to a data receiver application or NULL to be true for all receiver
*/
void lv_app_con_del(lv_app_inst_t * sender, lv_app_inst_t * receiver)
{
lv_app_con_t * con;
LL_READ(app_con_ll, con) {
if((con->sender == sender || sender == NULL) &&
(con->receiver == receiver || receiver == NULL)) {
ll_rem(&app_con_ll, con);
dm_free(con);
}
}
}
/**
* Get the application descriptor from its name
* @param name name of the app. dsc.
* @return pointer to the app. dsc.
*/
const lv_app_dsc_t * lv_app_dsc_get(const char * name)
{
const lv_app_dsc_t ** dsc;
LL_READ(app_dsc_ll, dsc) {
if(strcmp((*dsc)->name, name) == 0) {
return *dsc;
}
}
return NULL;
}
/**
* Rename an application
* @param app pointer to an application
* @param name a string with the new name
*/
void lv_app_rename(lv_app_inst_t * app, const char * name)
{
dm_free(app->name);
app->name = dm_alloc(strlen(name) + 1);
strcpy(app->name, name);
if(app->sc_title != NULL) {
lv_label_set_text(app->sc_title, app->name);
}
}
/**
* Get the window object from an object located on the window
* @param obj pointer to an object on the window
* @return pointer to the window of 'obj'
*/
lv_obj_t * lv_app_win_get_from_obj(lv_obj_t * obj)
{
lv_obj_t * par = obj;
lv_obj_t * win;
do {
win = par;
par = lv_obj_get_parent(win);
}
while(par != app_scr);
return win;
}
/**
* Read the list of the running applications. (Get he next element)
* @param prev the previous application (at the first call give NULL to get the first application)
* @param dsc pointer to an application descriptor to filer the applications (NULL to do not filter)
* @return pointer to the next running application or NULL if no more
*/
lv_app_inst_t * lv_app_get_next(lv_app_inst_t * prev, lv_app_dsc_t * dsc)
{
lv_app_inst_t * next;
while(1) {
if(prev == NULL) next = ll_get_head(&app_inst_ll);
else next = ll_get_next(&app_inst_ll, prev);
if(next == NULL) break;
if(next->dsc == dsc || dsc == NULL) return next;
prev = next;
}
return NULL;
}
/**
* Read the list of applications descriptors. (Get he next element)
* @param prev the previous application descriptors(at the first call give NULL to get the first)
* @return pointer to the next application descriptors or NULL if no more
*/
lv_app_dsc_t ** lv_app_dsc_get_next(lv_app_dsc_t ** prev)
{
lv_app_dsc_t ** next;
if(prev == NULL) next = ll_get_head(&app_dsc_ll);
else next = ll_get_next(&app_dsc_ll, prev);
if(next == NULL) return NULL;
return next;
}
/**
* Get a pointer to the application style structure. If modified then 'lv_app_refr_style' should be called
* @return pointer to the application style structure
*/
lv_app_style_t * lv_app_style_get(void)
{
return &app_style;
}
/**********************
* STATIC FUNCTIONS
**********************/
#if LV_APP_DESKTOP != 0
/**
* Create a desktop-like environment
*/
static void lv_app_init_desktop(void)
{
/*Menu on the top*/
menuh = lv_cont_create(lv_scr_act(), NULL);
lv_obj_set_width(menuh, LV_HOR_RES);
lv_cont_set_fit(menuh, false, true);
lv_obj_set_style(menuh, &app_style.menu);
app_btn = lv_btn_create(menuh, NULL);
lv_btn_set_styles(app_btn, &app_style.menu_btn_rel, &app_style.menu_btn_pr, NULL, NULL, NULL);
lv_cont_set_fit(app_btn, true, true);
lv_btn_set_rel_action(app_btn, lv_app_menu_rel_action);
lv_obj_t * app_label = lv_label_create(app_btn, NULL);
lv_label_set_text(app_label, "Apps");
lv_obj_set_pos(app_btn, 0, 0);
lv_obj_set_pos(menuh, 0, 0);
/*Shortcut area*/
sc_page = lv_page_create(lv_scr_act(), NULL);
lv_obj_set_style(sc_page, lv_style_get(LV_STYLE_TRANSP_TIGHT, NULL));
lv_obj_set_style(lv_page_get_scrl(sc_page), lv_style_get(LV_STYLE_TRANSP, NULL));
lv_obj_set_size(sc_page, LV_HOR_RES, LV_VER_RES - lv_obj_get_height(menuh));
lv_obj_set_pos(sc_page, 0, lv_obj_get_height(menuh));
lv_obj_set_width(lv_page_get_scrl(sc_page), LV_HOR_RES - 20);
lv_cont_set_fit(lv_page_get_scrl(sc_page), false, true);
lv_cont_set_layout(lv_page_get_scrl(sc_page), LV_CONT_LAYOUT_GRID);
lv_page_set_rel_action(sc_page, lv_app_sc_page_rel_action);
lv_page_set_sb_mode(sc_page, LV_PAGE_SB_MODE_AUTO);
}
#endif
/*-----------------------
APP. MENU ACTIONS
------------------------*/
#if LV_APP_DESKTOP != 0
/**
* Called when the "Apps" button is released to open or close the app. list
* @param app_btn pointer to the "Apps" button
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_OK because the "Apps" button is never deleted
*/
static lv_action_res_t lv_app_menu_rel_action(lv_obj_t * app_btn, lv_indev_proc_t * indev_proc)
{
/*Close the list if opened*/
if(app_list != NULL) {
lv_obj_del(app_list);
app_list = NULL;
}
/*Create the app. list*/
else {
app_list = lv_list_create(lv_scr_act(), NULL);
lv_obj_t * scrl = lv_page_get_scrl(app_list);
lv_obj_set_style(scrl, &app_style.menu);
lv_obj_set_size(app_list, LV_HOR_RES / 2, (LV_VER_RES * 3) / 4);
lv_obj_align(app_list, menuh, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
lv_list_set_styles_btn(app_list, &app_style.menu_btn_rel, &app_style.menu_btn_pr, NULL, NULL, NULL);
lv_app_dsc_t ** dsc;
lv_obj_t * elem;
LL_READ_BACK(app_dsc_ll, dsc) {
if(((*dsc)->mode & LV_APP_MODE_NOT_LIST) == 0) {
elem = lv_list_add(app_list, NULL, (*dsc)->name, lv_app_menu_elem_rel_action);
lv_obj_set_free_p(elem, *dsc);
}
}
}
return LV_ACTION_RES_OK;
}
/**
* Called when an element of the app list is released
* @param app_elem_btn pointer to an element of app list
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_INV because the list is dleted on release
*/
static lv_action_res_t lv_app_menu_elem_rel_action(lv_obj_t * app_elem_btn, lv_indev_proc_t * indev_proc)
{
lv_app_dsc_t * dsc = lv_obj_get_free_p(app_elem_btn);
/*Close the app list*/
lv_obj_del(app_list);
app_list = NULL;
lv_app_inst_t * app = lv_app_run(dsc, NULL);
lv_app_sc_open(app);
return LV_ACTION_RES_INV;
}
#endif
/*-----------------------
SHORTCUT ACTIONS
------------------------*/
#if LV_APP_DESKTOP != 0
/**
* Called when the shortcut page is released to hide the app list and/or
* go back from connection mode
* @param page pointer to the sc page
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_OK because the sc page is not deleted
*/
static lv_action_res_t lv_app_sc_page_rel_action(lv_obj_t * page, lv_indev_proc_t * indev_proc)
{
/*Close the list if opened*/
if(app_list != NULL) {
lv_obj_del(app_list);
app_list = NULL;
}
if(con_send != NULL) {
lv_app_inst_t * i;
LL_READ(app_inst_ll, i) {
if(i->sc != NULL) lv_btn_set_styles(i->sc, &app_style.sc_rel, &app_style.sc_pr, NULL, NULL, NULL);
}
con_send = NULL;
}
return LV_ACTION_RES_OK;
}
#endif
/**
* Called when a shortcut is released to open its window (or close app list if opened) (in normal mode) or
* add/remove it to/form a connection (in connection mode)
* @param sc pointer to the releases shortcut object
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_OK because the sc page is not deleted
*/
static lv_action_res_t lv_app_sc_rel_action(lv_obj_t * sc, lv_indev_proc_t * indev_proc)
{
/*Normal mode*/
if(con_send == NULL) {
#if LV_APP_DESKTOP != 0
#if LV_APP_ANIM_DESKTOP == 0
lv_page_focus(sc_page, sc, false);
#else
lv_page_focus(sc_page, sc, true);
#endif
#endif
/*Close the list if opened*/
if(app_list != NULL) {
lv_obj_del(app_list);
app_list = NULL;
}
/*Else open the window of the shortcut*/
else {
lv_app_inst_t * app = lv_obj_get_free_p(sc);
lv_app_win_open(app);
lv_app_win_open_anim_create(app);
}
}
/*Connection mode: toggle the connection of 'con_sender' and this app */
else {
lv_app_inst_t * app = lv_obj_get_free_p(sc);
if(app != con_send) { /*Do nothing with the sender*/
lv_style_t * style = lv_obj_get_style(sc);
/*Add connection to this application*/
if(style == &app_style.sc_rel) {
lv_btn_set_styles(sc, &app_style.sc_rec_rel, &app_style.sc_rec_pr, NULL, NULL, NULL);
lv_app_con_set(con_send, app);
} else { /*Remove the applications connection*/
lv_btn_set_styles(sc, &app_style.sc_rel, &app_style.sc_pr, NULL, NULL, NULL);
lv_app_con_del(con_send, app);
}
}
}
return LV_ACTION_RES_OK;
}
/**
* Called when a shortcut id long pressed to toggle normal and connection mode
* @param sc pointer to the long presse shortcut
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_OK because the shortcut is not deleted
*/
static lv_action_res_t lv_app_sc_lpr_action(lv_obj_t * sc, lv_indev_proc_t * indev_proc)
{
lv_app_inst_t * app_send = lv_obj_get_free_p(sc);
if(con_send == app_send) {
lv_app_inst_t * i;
LL_READ(app_inst_ll, i) {
if(i->sc != NULL) lv_btn_set_styles(i->sc, &app_style.sc_rel, &app_style.sc_pr, NULL, NULL, NULL);
}
con_send = NULL;
} else {
if(con_send != NULL) {
lv_app_inst_t * i;
LL_READ(app_inst_ll, i) {
if(i->sc != NULL) lv_btn_set_styles(i->sc, &app_style.sc_rel, &app_style.sc_pr, NULL, NULL, NULL);
}
}
con_send = app_send;
lv_btn_set_styles(sc, &app_style.sc_send_rel, &app_style.sc_send_pr, NULL, NULL, NULL);
lv_app_inst_t * i;
LL_READ(app_inst_ll, i) {
if(i->sc != NULL && lv_app_con_check(con_send, i) != false) {
lv_btn_set_styles(i->sc, &app_style.sc_rec_rel, &app_style.sc_rec_pr, NULL, NULL, NULL);
}
}
}
return LV_ACTION_RES_OK;
}
/*-----------------------
WINDOW ACTIONS
------------------------*/
/**
* Called when the close button of window is released
* @param close_btn pointer to the close button
* @param indev_proc 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_close_action(lv_obj_t * close_btn, lv_indev_proc_t * indev_proc)
{
lv_obj_t * win = lv_win_get_from_cbtn(close_btn);
lv_app_inst_t * app = lv_obj_get_free_p(win);
lv_app_kb_close(false);
#if LV_APP_ANIM_WIN != 0
/*Temporally set a simpler style for the window during the animation*/
lv_obj_t * win_page = lv_win_get_page(win);
lv_page_set_sb_mode(win_page, LV_PAGE_SB_MODE_OFF);
/*Hide some elements to speed up the animation*/
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->btnh, true);
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->title, true);
lv_obj_set_hidden(lv_page_get_scrl(win_page), true);
lv_obj_anim(app->win, LV_ANIM_FLOAT_BOTTOM | ANIM_OUT, LV_APP_ANIM_WIN, 0, NULL);
lv_obj_anim(app->win, LV_ANIM_FLOAT_LEFT | ANIM_OUT, LV_APP_ANIM_WIN, 0, lv_app_win_close_anim_cb);
lv_app_sc_close(app);
/*The animation will close the window*/
return LV_ACTION_RES_OK;
#else
lv_app_close(app);
return LV_ACTION_RES_INV;
#endif
}
/**
* Called when the minimization button of window is released
* @param minim_btn pointer to the minim. button
* @param indev_proc 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 * minim_btn, lv_indev_proc_t * indev_proc)
{
lv_obj_t * win = lv_win_get_from_cbtn(minim_btn);
lv_app_inst_t * app = lv_obj_get_free_p(win);
lv_app_kb_close(false);
/*Make an animation on window minimization*/
lv_action_res_t res;
res = lv_app_win_minim_anim_create(app);
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 indev_proc 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_indev_proc_t * indev_proc)
{
/*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_cbtn(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);
char buf[256];
sprintf(buf, "%s settings", app->dsc->name);
lv_win_add_cbtn(app->conf_win, SYMBOL_CLOSE ,lv_win_close_action);
lv_obj_set_style(lv_win_get_header(app->conf_win), &app_style.win_header);
lv_win_set_title(app->conf_win, buf);
lv_win_set_styles_cbtn(app->conf_win, &app_style.win_cbtn_rel, &app_style.win_cbtn_pr);
lv_obj_t * scrl = lv_page_get_scrl(lv_win_get_page(app->conf_win));
lv_cont_set_layout(scrl, LV_CONT_LAYOUT_COL_L);
app->dsc->conf_open(app, app->conf_win);
return LV_ACTION_RES_OK;
}
/*-----------------------
ANIMATIONS
------------------------*/
/**
* Create a window open animation
* @param app pointer to an application
* @return LV_ACTION_RES_OK: because the window is not deleted here
*/
static lv_action_res_t lv_app_win_open_anim_create(lv_app_inst_t * app)
{
/*Make an animation on window open*/
#if USE_ANIM != 0 && LV_APP_ANIM_WIN != 0
area_t cords; /*If no shortcut simulate one and load the its coordinates*/
if(app->sc == NULL) {
cords.x1 = (LV_HOR_RES / 2 - LV_APP_SC_WIDTH / 2);
cords.y1 = LV_VER_RES / 2 - LV_APP_SC_HEIGHT / 2;
cords.x2 = cords.x1 + LV_APP_SC_WIDTH;
cords.y2 = cords.y1 + LV_APP_SC_HEIGHT;
} else {
lv_obj_get_cords(app->sc, &cords);
}
/*Temporally set a simpler style for the window during the animation*/
lv_obj_t * win_page = lv_win_get_page(app->win);
lv_page_set_sb_mode(win_page, LV_PAGE_SB_MODE_OFF);
/*Hide some elements to speed up the animation*/
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->btnh, true);
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->title, true);
lv_obj_set_hidden(lv_page_get_scrl(win_page), true);
anim_t a;
a.act_time = 0;
a.time = LV_APP_ANIM_WIN;
a.end_cb = NULL;
a.playback = 0;
a.repeat = 0;
a.var = app->win;
a.path = anim_get_path(ANIM_PATH_LIN);
a.start = area_get_width(&cords) >> LV_ANTIALIAS;
a.end = LV_HOR_RES >> LV_ANTIALIAS;
a.fp = (anim_fp_t) lv_obj_set_width_us;
anim_create(&a);
a.start = area_get_height(&cords) >> LV_ANTIALIAS;
a.end = LV_VER_RES >> LV_ANTIALIAS;
a.fp = (anim_fp_t) lv_obj_set_height_us;
anim_create(&a);
a.start = cords.x1 >> LV_ANTIALIAS;
a.end = 0;
a.fp = (anim_fp_t) lv_obj_set_x_us;
anim_create(&a);
a.start = cords.y1 >> LV_ANTIALIAS;
a.end = 0;
a.fp = (anim_fp_t) lv_obj_set_y_us;
a.end_cb = (anim_cb_t)lv_app_win_open_anim_cb;
anim_create(&a);
/* Now a screen sized window is created but is is resized by the animations.
* Therefore the whole screen invalidated but only a small part is changed.
* So clear the invalidate buffer an refresh only the real area.
* Independently other parts on the screen might be changed
* but they will be soon covered by the window after the animations*/
lv_inv_area(NULL);
lv_inv_area(&cords);
#endif /* LV_APP_ANIM_WIN != 0*/
return LV_ACTION_RES_OK;
}
/**
* Create a window minimization animation
* @param app pointer to an application
* @return LV_ACTION_RES_OK or LV_ACTION_RES_INV depending on LV_APP_EFFECT_... settings
*/
static lv_action_res_t lv_app_win_minim_anim_create(lv_app_inst_t * app)
{
#if LV_APP_ANIM_WIN != 0
area_t cords;
if(app->sc == NULL) {
cords.x1 = LV_HOR_RES / 2 - LV_APP_SC_WIDTH / 2;
cords.y1 = LV_VER_RES / 2 - LV_APP_SC_HEIGHT / 2;
cords.x2 = cords.x1 + LV_APP_SC_WIDTH;
cords.y2 = cords.y1 + LV_APP_SC_HEIGHT;
} else {
lv_obj_get_cords(app->sc, &cords);
}
/*Temporally set a simpler style for the window during the animation*/
lv_obj_t * win_page = lv_win_get_page(app->win);
lv_page_set_sb_mode(win_page, LV_PAGE_SB_MODE_OFF);
/*Hide some elements to speed up the animation*/
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->btnh, true);
lv_obj_set_hidden(((lv_win_ext_t *)app->win->ext)->title, true);
lv_obj_set_hidden(lv_page_get_scrl(win_page), true);
anim_t a;
a.act_time = 0;
a.time = LV_APP_ANIM_WIN;
a.end_cb = NULL;
a.playback = 0;
a.repeat = 0;
a.var = app->win;
a.path = anim_get_path(ANIM_PATH_LIN);
a.start = LV_HOR_RES >> LV_ANTIALIAS;
a.end = area_get_width(&cords) >> LV_ANTIALIAS;
a.fp = (anim_fp_t) lv_obj_set_width_us;
anim_create(&a);
a.start = LV_VER_RES >> LV_ANTIALIAS;
a.end = area_get_height(&cords) >> LV_ANTIALIAS;
a.fp = (anim_fp_t) lv_obj_set_height_us;
anim_create(&a);
a.start = 0;
a.end = cords.x1 >> LV_ANTIALIAS;
a.fp = (anim_fp_t) lv_obj_set_x_us;
anim_create(&a);
a.start = 0;
a.end = cords.y1 >> LV_ANTIALIAS;
a.fp = (anim_fp_t) lv_obj_set_y_us;
a.end_cb = (void (*)(void *))lv_app_win_minim_anim_cb;
anim_create(&a);
return LV_ACTION_RES_OK;
#else /*LV_APP_ANIM_WIN == 0 || LV_APP_ANIM_LEVEL == 0*/
lv_app_win_close(app);
return LV_ACTION_RES_INV;
#endif
}
#if LV_APP_ANIM_WIN != 0
/**
* Called when the window open animation is ready to close the application
* @param app_win pointer to a window
*/
static void lv_app_win_open_anim_cb(lv_obj_t * app_win)
{
lv_obj_t * win_page = lv_win_get_page(app_win);
/*Unhide the the elements*/
lv_obj_set_hidden(((lv_win_ext_t *)app_win->ext)->btnh, false);
lv_obj_set_hidden(((lv_win_ext_t *)app_win->ext)->title, false);
lv_obj_set_hidden(lv_page_get_scrl(win_page), false);
lv_page_set_sb_mode(win_page, LV_PAGE_SB_MODE_AUTO);
}
/**
* Called when the window close animation is ready to close the application
* @param app_win pointer to a window
*/
static void lv_app_win_close_anim_cb(lv_obj_t * app_win)
{
lv_app_inst_t * app = lv_obj_get_free_p(app_win);
lv_app_close(app);
}
/**
* Called when the window minimization animation is ready to close the window
* @param app_win pointer to a window
*/
static void lv_app_win_minim_anim_cb(lv_obj_t * app_win)
{
lv_app_inst_t * app = lv_obj_get_free_p(app_win);
lv_app_win_close(app);
}
#endif
/**
* Init the application styles
*/
static void lv_app_init_style(void)
{
/*Menu style*/
lv_style_get(LV_STYLE_PLAIN,&app_style.menu);
app_style.menu.ccolor = COLOR_WHITE;
app_style.menu.mcolor = COLOR_MAKE(0x30, 0x30, 0x30);
app_style.menu.gcolor = COLOR_MAKE(0x30, 0x30, 0x30);
app_style.menu.bcolor = COLOR_MAKE(0x80, 0x80, 0x80);
app_style.menu.opa = OPA_COVER;
app_style.menu.radius = 0;
app_style.menu.bwidth = 0;
app_style.menu.swidth = 0;
app_style.menu.vpad = LV_DPI / 12;
app_style.menu.hpad = LV_DPI / 12;
app_style.menu.opad = LV_DPI / 12;
lv_style_get(LV_STYLE_BTN_REL,&app_style.menu_btn_rel);
app_style.menu_btn_rel.ccolor = COLOR_WHITE;
app_style.menu_btn_rel.mcolor = COLOR_MAKE(0x30, 0x30, 0x30);
app_style.menu_btn_rel.gcolor = COLOR_MAKE(0x30, 0x30, 0x30);
app_style.menu_btn_rel.bcolor = COLOR_MAKE(0xa0, 0xa0, 0xa0);
app_style.menu_btn_rel.bopa = OPA_20;
app_style.menu_btn_rel.bwidth = 0;
app_style.menu_btn_rel.radius = 0;
app_style.menu_btn_rel.swidth = 0;
app_style.menu_btn_rel.empty = 1;
app_style.menu_btn_rel.font = font_get(LV_APP_FONT_LARGE);
app_style.menu_btn_rel.img_recolor = OPA_90;
app_style.menu_btn_rel.vpad = LV_DPI / 10;
app_style.menu_btn_rel.hpad = LV_DPI / 10;
app_style.menu_btn_rel.opad = LV_DPI / 10;
memcpy(&app_style.menu_btn_pr, &app_style.menu_btn_rel, sizeof(lv_style_t));
app_style.menu_btn_pr.mcolor = COLOR_GRAY;
app_style.menu_btn_pr.gcolor = COLOR_GRAY;
app_style.menu_btn_pr.bcolor = COLOR_GRAY;
app_style.menu_btn_pr.bwidth = 0;
app_style.menu_btn_pr.radius = 0;
app_style.menu_btn_pr.empty = 0;
app_style.menu_btn_pr.swidth = 0;
/*Shortcut styles*/
lv_style_get(LV_STYLE_BTN_REL,&app_style.sc_rel);
app_style.sc_rel.ccolor = COLOR_MAKE(0x10, 0x18, 0x20);
app_style.sc_rel.opa = OPA_COVER;
app_style.sc_rel.mcolor = COLOR_WHITE;
app_style.sc_rel.gcolor = COLOR_MAKE(0x20, 0x30, 0x40);
app_style.sc_rel.bcolor = COLOR_MAKE(0x40, 0x60, 0x80);
app_style.sc_rel.bopa = OPA_70;
app_style.sc_rel.bwidth = 1 * LV_DOWNSCALE;
app_style.sc_rel.swidth = 0 * LV_DOWNSCALE;
app_style.sc_rel.font = font_get(LV_APP_FONT_MEDIUM);
app_style.sc_rel.txt_align = 1;
memcpy(&app_style.sc_pr, &app_style.sc_rel, sizeof(lv_style_t));
app_style.sc_pr.opa = OPA_COVER;
app_style.sc_pr.mcolor = COLOR_MAKE(0xB0, 0xD0, 0xF0);
app_style.sc_pr.gcolor = COLOR_MAKE(0x00, 0x00, 0x00);
app_style.sc_pr.bcolor = COLOR_MAKE(0xB0, 0xD0, 0xF0);
app_style.sc_pr.bopa = OPA_70;
app_style.sc_pr.bwidth = 1 * LV_DOWNSCALE;
app_style.sc_pr.swidth = 0 * LV_DOWNSCALE;
memcpy(&app_style.sc_send_rel, &app_style.sc_rel, sizeof(lv_style_t));
app_style.sc_send_rel.mcolor = COLOR_MAKE(0xFF, 0xE0, 0xE0);
app_style.sc_send_rel.gcolor = COLOR_MAKE(0x50, 0x20, 0x00);
app_style.sc_send_rel.bcolor = COLOR_BLACK;
app_style.sc_send_rel.bopa = OPA_30;
app_style.sc_send_rel.bwidth = 3 * LV_DOWNSCALE;
memcpy(&app_style.sc_send_pr, &app_style.sc_pr, sizeof(lv_style_t));
app_style.sc_send_pr.mcolor = COLOR_MAKE(0xFF, 0xB0, 0xB0);
app_style.sc_send_pr.gcolor = COLOR_MAKE(0x20, 0x10, 0x00);
app_style.sc_send_pr.gcolor = COLOR_BLACK;
app_style.sc_send_pr.bopa = OPA_30;
app_style.sc_send_pr.bwidth = 2 * LV_DOWNSCALE;
memcpy(&app_style.sc_rec_rel, &app_style.sc_send_rel, sizeof(lv_style_t));
app_style.sc_rec_rel.mcolor = COLOR_MAKE(0xE0, 0xFF, 0xE0);
app_style.sc_rec_rel.gcolor = COLOR_MAKE(0x20, 0x50, 0x20);
app_style.sc_rec_rel.bcolor = COLOR_BLACK;
app_style.sc_rec_rel.bopa = OPA_30;
app_style.sc_rec_rel.bwidth = 2 * LV_DOWNSCALE;
memcpy(&app_style.sc_rec_pr, &app_style.sc_send_pr, sizeof(lv_style_t));
app_style.sc_rec_pr.mcolor = COLOR_MAKE(0xB0, 0xFF, 0xB0);
app_style.sc_rec_pr.gcolor = COLOR_MAKE(0x20, 0x20, 0x10);
app_style.sc_rec_pr.bcolor = COLOR_BLACK;
app_style.sc_rec_pr.bopa = OPA_30;
app_style.sc_rec_pr.bwidth = 2 * LV_DOWNSCALE;
memcpy(&app_style.sc_title, &app_style.sc_rel, sizeof(lv_style_t));
app_style.sc_title.font = font_get(LV_APP_FONT_SMALL);
/*Window*/
lv_style_get(LV_STYLE_PLAIN_COLOR, &app_style.win_header);
memcpy(&app_style.win_header, &app_style.menu, sizeof(lv_style_t));
app_style.win_header.font = font_get(LV_APP_FONT_LARGE);
lv_style_get(LV_STYLE_TRANSP, &app_style.win_scrl);
lv_style_get(LV_STYLE_BTN_REL, &app_style.win_cbtn_rel);
memcpy(&app_style.win_cbtn_rel, &app_style.menu_btn_rel, sizeof(lv_style_t));
app_style.win_cbtn_rel.font = font_get(LV_IMG_DEF_SYMBOL_FONT);
lv_style_get(LV_STYLE_BTN_PR, &app_style.win_cbtn_pr);
memcpy(&app_style.win_cbtn_pr, &app_style.menu_btn_pr, sizeof(lv_style_t));
app_style.win_cbtn_pr.font = font_get(LV_IMG_DEF_SYMBOL_FONT);
}
#endif /*LV_APP_ENABLE != 0*/
/**
* @file lv_app.h
*
*/
#ifndef LV_APP_H
#define LV_APP_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lvgl/lvgl.h"
#if LV_APP_ENABLE != 0
/*********************
* DEFINES
*********************/
/*Check dependencies*/
#if LV_OBJ_FREE_P == 0
#error "lv_app: Free pointer is required for application. Enable it lv_conf.h: LV_OBJ_FREE_P 1"
#endif
#if LV_OBJ_FREE_NUM == 0
#error "lv_app: Free number is required for application. Enable it lv_conf.h: LV_OBJ_FREE_NUM 1"
#endif
#if DM_CUSTOM == 0 && DM_MEM_SIZE < (2 * 1024)
#error "lv_app: not enough dynamic memory. Increase it in misc_conf.h: DM_MEM_SIZE"
#endif
/**********************
* TYPEDEFS
**********************/
typedef enum
{
LV_APP_MODE_NONE = 0x0000,
LV_APP_MODE_NOT_LIST = 0x0001, /*Do not list the application*/
LV_APP_MODE_NO_SC_TITLE = 0x0002, /*No short cut title*/
}lv_app_mode_t;
typedef enum
{
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)*/
LV_APP_COM_TYPE_INV, /*Invalid type*/
LV_APP_COM_TYPE_NUM, /*Indicates the number of com. types*/
}lv_app_com_type_t;
struct __LV_APP_DSC_T;
typedef struct
{
const struct __LV_APP_DSC_T * dsc;
char * name;
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;
}lv_app_inst_t;
typedef struct __LV_APP_DSC_T
{
const char * name;
lv_app_mode_t mode;
void (*app_run)(lv_app_inst_t *, void *);
void (*app_close) (lv_app_inst_t *);
void (*com_rec) (lv_app_inst_t *, lv_app_inst_t *, lv_app_com_type_t, const void *, uint32_t);
void (*sc_open) (lv_app_inst_t *, lv_obj_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;
}lv_app_dsc_t;
typedef struct {
lv_style_t menu;
lv_style_t menu_btn_rel;
lv_style_t menu_btn_pr;
lv_style_t sc_rel;
lv_style_t sc_pr;
lv_style_t sc_send_rel;
lv_style_t sc_send_pr;
lv_style_t sc_rec_rel;
lv_style_t sc_rec_pr;
lv_style_t sc_title;
lv_style_t win_header;
lv_style_t win_scrl;
lv_style_t win_cbtn_rel;
lv_style_t win_cbtn_pr;
}lv_app_style_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the application system
*/
void lv_app_init(void);
/**
* Get screen of the applications
*/
lv_obj_t * lv_scr_app(void);
/**
* Allocate a new application descriptor
* @return pointer to an lv_app_dsc_t pointer. Save here a pointer to an app. dsc.
* E.g. *dsc = &my_app_dsc;
*/
lv_app_dsc_t ** lv_app_add_dsc(void);
/**
* Run an application according to 'app_dsc'
* @param app_dsc pointer to an application descriptor
* @param conf pointer to an application specific configuration structure or NULL if unused
* @return pointer to the opened application or NULL if any error occurred
*/
lv_app_inst_t * lv_app_run(const lv_app_dsc_t * app_dsc, void * conf);
/**
* Close a running application. Close the Window and the Shortcut too if opened.
* @param app pointer to an application
*/
void lv_app_close(lv_app_inst_t * app);
/**
* Open a shortcut for an application
* @param app pointer to an application
* @return pointer to the shortcut
*/
lv_obj_t * lv_app_sc_open(lv_app_inst_t * app);
/**
* Close the shortcut of an application
* @param app pointer to an application
*/
void lv_app_sc_close(lv_app_inst_t * app);
/**
* Open the application in a window
* @param app pointer to an application
* @return pointer to the shortcut
*/
lv_obj_t * lv_app_win_open(lv_app_inst_t * app);
/**
* Close the window of an application
* @param app pointer to an application
*/
void lv_app_win_close(lv_app_inst_t * app);
/**
* Send data to other applications
* @param app_send pointer to the application which is sending the message
* @param type type of data from 'lv_app_com_type_t' enum
* @param data pointer to the sent data
* @param size length of 'data' in bytes
* @return number application which were received the message
*/
uint16_t lv_app_com_send(lv_app_inst_t * app_send, lv_app_com_type_t type , const void * data, uint32_t size);
/**
* Test an application communication connection
* @param sender pointer to an application which sends data
* @param receiver pointer to an application which receives data
* @return false: no connection, true: there is connection
*/
bool lv_app_con_check(lv_app_inst_t * sender, lv_app_inst_t * receiver);
/**
* Create a new connection between two applications
* @param sender pointer to a data sender application
* @param receiver pointer to a data receiver application
*/
void lv_app_con_set(lv_app_inst_t * sender, lv_app_inst_t * receiver);
/**
* Delete a communication connection
* @param sender pointer to a data sender application or NULL to be true for all sender
* @param receiver pointer to a data receiver application or NULL to be true for all receiver
*/
void lv_app_con_del(lv_app_inst_t * sender, lv_app_inst_t * receiver);
/**
* Get the application descriptor from its name
* @param name name of the app. dsc.
* @return pointer to the app. dsc.
*/
const lv_app_dsc_t * lv_app_dsc_get(const char * name);
/**
* Rename an application
* @param app pointer to an application
* @param name a string with the new name
*/
void lv_app_rename(lv_app_inst_t * app, const char * name);
/**
* Get the window object from an object located on the window
* @param obj pointer to an object on the window
* @return pointer to the window of 'obj'
*/
lv_obj_t * lv_app_win_get_from_obj(lv_obj_t * obj);
/**
* Read the list of the running applications. (Get he next element)
* @param prev the previous application (at the first call give NULL to get the first application)
* @param dsc pointer to an application descriptor to filer the applications (NULL to do not filter)
* @return pointer to the next running application or NULL if no more
*/
lv_app_inst_t * lv_app_get_next(lv_app_inst_t * prev, lv_app_dsc_t * dsc);
/**
* Read the list of applications descriptors. (Get he next element)
* @param prev the previous application descriptors(at the first call give NULL to get the first)
* @return pointer to the next application descriptors or NULL if no more
*/
lv_app_dsc_t ** lv_app_dsc_get_next(lv_app_dsc_t ** prev);
/**
* Get a pointer to the application style structure. If modified then 'lv_app_refr_style' should be called
* @return pointer to the application style structure
*/
lv_app_style_t * lv_app_style_get(void);
/**********************
* MACROS
**********************/
/**********************
* POST-INCLUDES
*********************/
#include "lvgl/lv_app/lv_app_util/lv_app_kb.h"
#include "lvgl/lv_app/lv_app_util/lv_app_fsel.h"
#include "lvgl/lv_app/lv_app_util/lv_app_notice.h"
#include "lvgl/lv_appx/lv_app_example.h"
#include "lvgl/lv_appx/lv_app_phantom.h"
#include "lvgl/lv_appx/lv_app_sysmon.h"
#include "lvgl/lv_appx/lv_app_terminal.h"
#include "lvgl/lv_appx/lv_app_files.h"
#include "lvgl/lv_appx/lv_app_wifi.h"
#include "lvgl/lv_appx/lv_app_gsm.h"
#include "lvgl/lv_appx/lv_app_ethernet.h"
#include "lvgl/lv_appx/lv_app_benchmark.h"
#endif /*LV_APP_ENABLE*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_APP_H*/
/**
* @file lv_app_fsel.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_app_fsel.h"
#if USE_LV_APP_FSEL != 0
#include <stdio.h>
#include "lv_app_notice.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void fsel_refr(void);
static lv_action_res_t fsel_close_action(lv_obj_t * close, lv_indev_proc_t * indev_proc);
static lv_action_res_t fsel_up_action(lv_obj_t * up, lv_indev_proc_t * indev_proc);
static lv_action_res_t fsel_next_action(lv_obj_t * next, lv_indev_proc_t * indev_proc);
static lv_action_res_t fsel_prev_action(lv_obj_t * prev, lv_indev_proc_t * indev_proc);
static lv_action_res_t fsel_drv_action(lv_obj_t * drv, lv_indev_proc_t * indev_proc);
static lv_action_res_t fsel_drv_lpr_action(lv_obj_t * drv, lv_indev_proc_t * indev_proc);
static lv_action_res_t fsel_folder_action(lv_obj_t * folder, lv_indev_proc_t * indev_proc);
static lv_action_res_t fsel_folder_lpr_action(lv_obj_t * folder, lv_indev_proc_t * indev_proc);
static lv_action_res_t fsel_file_action(lv_obj_t * file, lv_indev_proc_t * indev_proc);
/**********************
* STATIC VARIABLES
**********************/
static const char * fsel_filter;
static char fsel_path[LV_APP_FSEL_PATH_MAX_LEN];
static uint16_t fsel_file_cnt;
static lv_obj_t * fsel_win;
static lv_obj_t * fsel_list;
static void * fsel_param;
static void (*fsel_ok_action)(void *, const char *);
static lv_style_t style_btn_symbol;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the File selector utility
*/
void lv_app_fsel_init(void)
{
lv_style_get(LV_STYLE_BTN_REL, &style_btn_symbol);
style_btn_symbol.font = font_get(LV_IMG_DEF_SYMBOL_FONT);
}
/**
* Open the File selector
* @param path start path
* @param filter show only files with a specific extension, e.g. "wav".
* "/" means filter to folders.
* @param param a free parameter which will be added to 'ok_action'
* @param ok_action an action to call when a file or folder is chosen
*/
void lv_app_fsel_open(const char * path, const char * filter, void * param, void (*ok_action)(void *, const char *))
{
/*Save the parameters*/
strcpy(fsel_path, path);
fsel_filter = filter;
fsel_file_cnt = 0;
fsel_param = param;
fsel_ok_action = ok_action;
/*Trim the extra '\' or '/' from the end of path*/
uint16_t i;
for(i = strlen(fsel_path) -1 ; fsel_path[i] == '/' || fsel_path[i] == '\\'; i--) {
fsel_path[i] = '\0';
}
/*Check filter: NULL and "" mean no filtering*/
if(fsel_filter == NULL) fsel_filter = "";
lv_app_style_t * app_style = lv_app_style_get();
/*Create a window for the File selector*/
fsel_win = lv_win_create(lv_scr_act(), NULL);
lv_obj_set_size(fsel_win, LV_HOR_RES, LV_VER_RES);
lv_win_set_styles_cbtn(fsel_win, &app_style->win_cbtn_rel, &app_style->win_cbtn_pr);
lv_obj_set_style(lv_win_get_header(fsel_win), &app_style->menu);
lv_win_add_cbtn(fsel_win, SYMBOL_CLOSE, fsel_close_action);
fsel_refr(); /*Refresh the list*/
/*Show instruction when first open with folder filter*/
static bool first_folder_call = false;
if(first_folder_call == false && fsel_filter[0] == '/') {
lv_app_notice_add("Press a folder long\nto choose it!");
first_folder_call = true;
}
}
/**
* Close the File selector
*/
void lv_app_fsel_close(void)
{
if(fsel_win != NULL) {
lv_obj_del(fsel_win);
}
fsel_win = NULL;
fsel_list = NULL;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Refresh the file list according to the current path and filter
*/
static void fsel_refr(void)
{
/*Delete the previous list*/
if(fsel_list != NULL) {
lv_obj_del(fsel_list);
}
lv_win_set_title(fsel_win, fsel_path);
/*Create a new list*/
fsel_list = lv_list_create(fsel_win, NULL);
lv_obj_set_width(fsel_list, lv_win_get_width(fsel_win));
lv_list_set_style_img(fsel_list, &style_btn_symbol);
lv_obj_set_style(lv_page_get_scrl(fsel_list), lv_style_get(LV_STYLE_TRANSP_TIGHT, NULL));
lv_obj_set_drag_parent(fsel_list, true);
lv_obj_set_drag_parent(lv_page_get_scrl(fsel_list), true);
lv_cont_set_fit(fsel_list, false, true);
fs_res_t res = FS_RES_OK;
lv_obj_t * liste;
/*At empty path show the drivers */
if(fsel_path[0] == '\0') {
char drv[16];
char buf[2];
fs_get_letters(drv);
uint8_t i;
for(i = 0; drv[i] != '\0'; i++) {
buf[0] = drv[i];
buf[1] = '\0';
liste = lv_list_add(fsel_list, SYMBOL_DRIVE, buf, fsel_drv_action);
/*Add long press action to choose the driver as a folder*/
if(fsel_filter[0] == '/') lv_btn_set_lpr_action(liste, fsel_drv_lpr_action);
}
}
/*List the files/folders with fs interface*/
else {
liste = lv_list_add(fsel_list, SYMBOL_UP, "Up", fsel_up_action);
fs_readdir_t rd;
res = fs_readdir_init(&rd, fsel_path);
if(res != FS_RES_OK) {
lv_app_notice_add("Can not read the path\nin File selector");
return;
}
/*At not first page add prev. page button */
if(fsel_file_cnt != 0) {
liste = lv_list_add(fsel_list, SYMBOL_LEFT, "Previous page", fsel_prev_action);
}
char fn[LV_APP_FSEL_FN_MAX_LEN];
/*Read the files from the previous pages*/
uint16_t file_cnt = 0;
while(file_cnt <= fsel_file_cnt) {
res = fs_readdir(&rd, fn);
if(res != FS_RES_OK){
lv_app_notice_add("Can not read the path\nin File selector");
return;
}
file_cnt ++;
}
/*Add list elements from the files and folders*/
while(res == FS_RES_OK && fn[0] != '\0') {
if(fn[0] == '/') { /*Add a folder*/
lv_obj_t * liste;
liste = lv_list_add(fsel_list, SYMBOL_FOLDER, &fn[1], fsel_folder_action);
/*Add long press action to choose a folder*/
if(fsel_filter[0] == '/') lv_btn_set_lpr_action(liste, fsel_folder_lpr_action);
fsel_file_cnt ++;
file_cnt ++;
}
/*Add a file if it is not filtered*/
else if(fsel_filter[0] == '\0' || /*No filtering or ...*/
(strcmp(fs_get_ext(fn), fsel_filter) == 0 && /*.. the filter matches*/
fsel_filter[0] != '/')) {
liste = lv_list_add(fsel_list, SYMBOL_FILE, fn, fsel_file_action);
fsel_file_cnt ++;
file_cnt ++;
}
/*Get the next element*/
res = fs_readdir(&rd, fn);
/*Show only LV_APP_FSEL_MAX_FILE elements and add a Next page button*/
if(fsel_file_cnt != 0 && fsel_file_cnt % LV_APP_FSEL_PAGE_SIZE == 0) {
liste = lv_list_add(fsel_list, SYMBOL_RIGHT, "Next page", fsel_next_action);
break;
}
}
/*Close the read directory*/
fs_readdir_close(&rd);
}
if(res != FS_RES_OK) {
lv_app_notice_add("Can not read the path\nin File selector");
}
/*Focus to the top of the list*/
lv_obj_set_y(lv_page_get_scrl(fsel_list), 0);
}
/**
* Called when the File selector window close button is released
* @param close pointer to the close button
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_INV because the window is deleted in the function
*/
static lv_action_res_t fsel_close_action(lv_obj_t * close, lv_indev_proc_t * indev_proc)
{
lv_app_fsel_close();
return LV_ACTION_RES_INV;
}
/**
* Called when the Up list element is released to step one level
* @param up pointer to the Up button
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_INV because the list is deleted in the function
*/
static lv_action_res_t fsel_up_action(lv_obj_t * up, lv_indev_proc_t * indev_proc)
{
fs_up(fsel_path);
fsel_file_cnt = 0;
fsel_refr();
return LV_ACTION_RES_INV;
}
/**
* Called when the Next list element is released to go to the next page
* @param next pointer to the Next button
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_INV because the list is deleted in the function
*/
static lv_action_res_t fsel_next_action(lv_obj_t * next, lv_indev_proc_t * indev_proc)
{
fsel_refr();
return LV_ACTION_RES_INV;
}
/**
* Called when the Prev list element is released to previous page
* @param prev pointer to the Prev button
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_INV because the list is deleted in the function
*/
static lv_action_res_t fsel_prev_action(lv_obj_t * prev, lv_indev_proc_t * indev_proc)
{
if(fsel_file_cnt <= 2 * LV_APP_FSEL_PAGE_SIZE) fsel_file_cnt = 0;
else if(fsel_file_cnt % LV_APP_FSEL_PAGE_SIZE == 0) {
fsel_file_cnt -= 2 * LV_APP_FSEL_PAGE_SIZE;
} else {
fsel_file_cnt = ((fsel_file_cnt / LV_APP_FSEL_PAGE_SIZE) - 1) * LV_APP_FSEL_PAGE_SIZE;
}
fsel_refr();
return LV_ACTION_RES_INV;
}
/**
* Called when the Driver list element is released to step into a driver
* @param drv pointer to the Driver button
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_INV because the list is deleted in the function
*/
static lv_action_res_t fsel_drv_action(lv_obj_t * drv, lv_indev_proc_t * indev_proc)
{
sprintf(fsel_path, "%s:", lv_list_get_element_text(drv));
fsel_file_cnt = 0;
fsel_refr();
return LV_ACTION_RES_INV;
}
/**
* Called when the Driver list element is long pressed to choose it
* @param drv pointer to the Driver button
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_INV because the list is deleted in the function
*/
static lv_action_res_t fsel_drv_lpr_action(lv_obj_t * drv, lv_indev_proc_t * indev_proc)
{
sprintf(fsel_path, "%s:", lv_list_get_element_text(drv));
if(fsel_ok_action != NULL) {
fsel_ok_action(fsel_param, fsel_path);
}
lv_app_fsel_close();
return LV_ACTION_RES_INV;
}
/**
* Called when a folder list element is released to enter into it
* @param folder pointer to a folder button
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_INV because the list is deleted in the function
*/
static lv_action_res_t fsel_folder_action(lv_obj_t * folder, lv_indev_proc_t * indev_proc)
{
sprintf(fsel_path, "%s/%s", fsel_path, lv_list_get_element_text(folder));
fsel_file_cnt = 0;
fsel_refr();
return LV_ACTION_RES_INV;
}
/**
* Called when a folder list element is long pressed to choose it
* @param folder pointer to a folder button
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_INV because the list is deleted in the function
*/
static lv_action_res_t fsel_folder_lpr_action(lv_obj_t * folder, lv_indev_proc_t * indev_proc)
{
sprintf(fsel_path, "%s/%s", fsel_path, lv_list_get_element_text(folder));
if(fsel_ok_action != NULL) {
fsel_ok_action(fsel_param, fsel_path);
}
lv_app_fsel_close();
return LV_ACTION_RES_INV;
}
/**
* Called when a file list element is released to choose it
* @param file pointer to a file button
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_INV because the list is deleted in the function
*/
static lv_action_res_t fsel_file_action(lv_obj_t * file, lv_indev_proc_t * indev_proc)
{
sprintf(fsel_path, "%s/%s", fsel_path, lv_list_get_element_text(file));
if(fsel_ok_action != NULL) {
fsel_ok_action(fsel_param, fsel_path);
}
lv_app_fsel_close();
return LV_ACTION_RES_INV;
}
#endif /*LV_APP_ENABLE != 0*/
/**
* @file lv_app_fsel.h
*
*/
#ifndef LV_APP_FSEL_H
#define LV_APP_FSEL_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_app.h"
#if USE_LV_APP_FSEL != 0
/*********************
* DEFINES
*********************/
/*Add the required configurations*/
#ifndef LV_APP_FSEL_FN_MAX_LEN
#define LV_APP_FSEL_FN_MAX_LEN 128
#endif
#ifndef LV_APP_FSEL_PATH_MAX_LEN
#define LV_APP_FSEL_PATH_MAX_LEN 256
#endif
#ifndef LV_APP_FSEL_PAGE_SIZE
#define LV_APP_FSEL_PAGE_SIZE 8
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the File selector utility
*/
void lv_app_fsel_init(void);
/**
* Open the File selector
* @param path start path
* @param filter show only files with a specific extension, e.g. "wav".
* "/" means filter to folders.
* @param param a free parameter which will be added to 'ok_action'
* @param ok_action an action to call when a file or folder is chosen (give 'param' and the path as parameters)
*/
void lv_app_fsel_open(const char * path, const char * filter, void * param,
void (*ok_action)(void *, const char *));
/**
* Close the File selector
*/
void lv_app_fsel_close(void);
/**********************
* MACROS
**********************/
#endif /*LV_APP_ENABLE*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_APP_FSEL_H*/
/**
* @file lv_app_kb.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_app_kb.h"
#if USE_LV_APP_KB != 0
#include "lvgl/lv_objx/lv_btnm.h"
#include "lvgl/lv_objx/lv_ta.h"
/*********************
* DEFINES
*********************/
#ifndef LV_APP_KB_ANIM_TIME
#define LV_APP_KB_ANIM_TIME 300 /*ms*/
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static lv_action_res_t lv_app_kb_action(lv_obj_t * btnm, uint16_t i);
/**********************
* STATIC VARIABLES
**********************/
static lv_obj_t * kb_btnm;
static lv_obj_t * kb_win;
static lv_obj_t * kb_ta;
static const char * kb_map_lc[] = {
"\0051#", "\004q", "\004w", "\004e", "\004r", "\004t", "\004y", "\004u", "\004i", "\004o", "\004p", "\007Del", "\n",
"\006ABC", "\003a", "\003s", "\003d", "\003f", "\003g", "\003h", "\003j", "\003k", "\003l", "\010Enter", "\n",
"_", "-", "z", "x", "c", "v", "b", "n", "m", ".", ",", ":", "\n",
"\003Hide", "\003Left", "\006 ", "\003Right", "\003Ok", ""
};
static const char * kb_map_uc[] = {
"\0051#", "\004Q", "\004W", "\004E", "\004R", "\004T", "\004Y", "\004U", "\004I", "\004O", "\004P", "\007Del", "\n",
"\006abc", "\003A", "\003S", "\003D", "\003F", "\003G", "\003H", "\003J", "\003K", "\003L", "\010Enter", "\n",
"_", "-", "Z", "X", "C", "V", "B", "N", "M", ".", ",", ":", "\n",
"\003Hide", "\003Left", "\006 ", "\003Right", "\003Ok", ""
};
static const char * kb_map_spec[] = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "\002Del", "\n",
"\002abc", "+", "-", "/", "*", "=", "%", "!", "?", "#", "<", ">", "\n",
"\\", "@", "$", "(", ")", "{", "}", "[", "]", ";", "\"", "'", "\n",
"\003Hide", "\003Left", "\006 ", "\003Right", "\003Ok", ""
};
static const char * kb_map_num[] = {
"1", "2", "3", "\002Hide","\n",
"4", "5", "6", "\002Ok", "\n",
"7", "8", "9", "\002Del", "\n",
"+/-", "0", ".", "Left", "Right", ""
};
static cord_t kb_ta_ori_size;
static uint8_t kb_mode;
static void (*kb_close_action)(lv_obj_t *);
static void (*kb_ok_action)(lv_obj_t *);
static lv_style_t style_bg;
static lv_style_t style_btn_rel;
static lv_style_t style_btn_pr;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the application keyboard
*/
void lv_app_kb_init(void)
{
lv_app_style_t * app_style = lv_app_style_get();
memcpy(&style_bg, &app_style->menu, sizeof(lv_style_t));
style_bg.opa = OPA_COVER;
style_bg.hpad = 0;
style_bg.vpad = 0;
style_bg.opad = 0;
memcpy(&style_btn_rel, &app_style->menu_btn_rel, sizeof(lv_style_t));
style_btn_rel.radius = 0;
style_btn_rel.bwidth = 1;
memcpy(&style_btn_pr, &app_style->menu_btn_pr, sizeof(lv_style_t));
style_btn_pr.radius = 0;
style_btn_pr.bwidth = 1;
}
/**
* Open a keyboard for a text area object
* @param ta pointer to a text area object
* @param mode 'OR'd values of 'lv_app_kb_mode_t' enum
* @param close a function to call when the keyboard is closed
* @param ok a function to called when the "Ok" button is pressed
* @return the created button matrix objects
*/
lv_obj_t * lv_app_kb_open(lv_obj_t * ta, lv_app_kb_mode_t mode, void (*close)(lv_obj_t *), void (*ok)(lv_obj_t *))
{
/*Close the previous keyboard*/
if(kb_btnm != NULL) {
lv_app_kb_close(false);
}
/*Save some parameters*/
kb_ta = ta;
kb_mode = mode;
kb_close_action = close;
kb_ok_action = ok;
/*Create a button matrix for the keyboard */
kb_btnm = lv_btnm_create(lv_scr_act(), NULL);
lv_obj_set_style(kb_btnm, &style_bg);
lv_obj_set_size(kb_btnm, LV_HOR_RES, LV_VER_RES / 2);
lv_obj_align(kb_btnm, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
lv_btnm_set_action(kb_btnm, lv_app_kb_action);
if(mode & LV_APP_KB_MODE_TXT) {
style_btn_rel.font = font_get(LV_APP_FONT_MEDIUM);
style_btn_pr.font = font_get(LV_APP_FONT_MEDIUM);
lv_btnm_set_map(kb_btnm, kb_map_lc);
}
else if(mode & LV_APP_KB_MODE_NUM) {
style_btn_rel.font = font_get(LV_APP_FONT_LARGE);
style_btn_pr.font = font_get(LV_APP_FONT_LARGE);
lv_btnm_set_map(kb_btnm, kb_map_num);
}
lv_btnm_set_styles_btn(kb_btnm, &style_btn_rel, &style_btn_pr);
kb_win = NULL;
kb_ta_ori_size = 0;
if(mode & LV_APP_KB_MODE_WIN_RESIZE) {
/*Reduce the size of the window and align it to the top*/
kb_win = lv_app_win_get_from_obj(kb_ta);
lv_obj_set_height(kb_win, LV_VER_RES / 2);
lv_obj_set_y(kb_win, 0);
/*If the text area is higher then the new size of the window reduce its size too*/
cord_t cont_h = lv_obj_get_height(kb_win) - lv_obj_get_height(lv_win_get_header(kb_win));
kb_ta_ori_size = lv_obj_get_height(kb_ta);
if(lv_obj_get_height(kb_ta) > cont_h - LV_DPI / 10) {
lv_obj_set_height(kb_ta, cont_h - LV_DPI / 10);
}
lv_page_focus(lv_win_get_page(kb_win), kb_ta, 0);
}
lv_ta_set_cursor_pos(kb_ta, LV_TA_CUR_LAST);
if(kb_mode & LV_APP_KB_MODE_CUR_MANAGE) {
lv_ta_set_cursor_show(kb_ta, true);
}
if(kb_mode & LV_APP_KB_MODE_ANIM_IN) {
lv_obj_anim(kb_btnm, LV_ANIM_FLOAT_BOTTOM | ANIM_IN, LV_APP_KB_ANIM_TIME, 0, NULL);
}
return kb_btnm;
}
/**
* Close the keyboard
* @param ok true: call the ok function, false: call the close function
*/
void lv_app_kb_close(bool ok)
{
if(kb_btnm == NULL) return;
if(ok == false) {
if(kb_close_action != NULL) kb_close_action(kb_ta);
} else {
if(kb_ok_action != NULL) kb_ok_action(kb_ta);
}
/*Reset the modified sizes*/
if((kb_mode & LV_APP_KB_MODE_WIN_RESIZE) && kb_win != NULL) {
lv_obj_set_height(kb_ta, kb_ta_ori_size);
lv_obj_set_size(kb_win, LV_HOR_RES, LV_VER_RES);
kb_win = NULL;
}
if(kb_mode & LV_APP_KB_MODE_CUR_MANAGE) {
lv_ta_set_cursor_show(kb_ta, false);
}
if(kb_mode & LV_APP_KB_MODE_ANIM_OUT) {
lv_obj_anim(kb_btnm, LV_ANIM_FLOAT_BOTTOM | ANIM_OUT, LV_APP_KB_ANIM_TIME, 0, lv_obj_del);
} else {
lv_obj_del(kb_btnm);
}
kb_btnm = NULL;
kb_ta = NULL;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Called when a button of 'kb_btnm' is released
* @param btnm pointer to 'kb_btnm'
* @param i the index of the released button from the current btnm map
* @return LV_ACTION_RES_INV if the btnm is deleted else LV_ACTION_RES_OK
*/
static lv_action_res_t lv_app_kb_action(lv_obj_t * btnm, uint16_t i)
{
const char ** map = lv_btnm_get_map(btnm);
const char * txt = map[i];
/*Ignore the unit size number of the text*/
if(txt[0] <= '\011') txt++;
/*Do the corresponding action according to the text of the button*/
if(strcmp(txt, "abc") == 0) {
lv_btnm_set_map(btnm, kb_map_lc);
} else if(strcmp(txt, "ABC") == 0) {
lv_btnm_set_map(btnm, kb_map_uc);
} else if(strcmp(txt, "1#") == 0) {
lv_btnm_set_map(btnm, kb_map_spec);
} else if(strcmp(txt, "Enter") == 0) {
lv_ta_add_char(kb_ta, '\n');
} else if(strcmp(txt, "Left") == 0) {
lv_ta_cursor_left(kb_ta);
} else if(strcmp(txt, "Right") == 0) {
lv_ta_cursor_right(kb_ta);
} else if(strcmp(txt, "Del") == 0) {
lv_ta_del(kb_ta);
} else if(strcmp(txt, "+/-") == 0) {
uint16_t cur = lv_ta_get_cursor_pos(kb_ta);
const char * ta_txt = lv_ta_get_txt(kb_ta);
if(ta_txt[0] == '-') {
lv_ta_set_cursor_pos(kb_ta, 1);
lv_ta_del(kb_ta);
lv_ta_add_char(kb_ta, '+');
lv_ta_set_cursor_pos(kb_ta, cur);
} else if(ta_txt[0] == '+') {
lv_ta_set_cursor_pos(kb_ta, 1);
lv_ta_del(kb_ta);
lv_ta_add_char(kb_ta, '-');
lv_ta_set_cursor_pos(kb_ta, cur);
} else {
lv_ta_set_cursor_pos(kb_ta, 0);
lv_ta_add_char(kb_ta, '-');
lv_ta_set_cursor_pos(kb_ta, cur + 1);
}
} else if(strcmp(txt, "Hide") == 0) {
lv_app_kb_close(false);
return LV_ACTION_RES_INV;
} else if(strcmp(txt, "Ok") == 0) {
lv_app_kb_close(true);
return LV_ACTION_RES_INV;
} else {
lv_ta_add_text(kb_ta, txt);
}
if(kb_mode & LV_APP_KB_MODE_WIN_RESIZE) {
#if LV_APP_ANIM_LEVEL != 0
lv_page_focus(lv_win_get_content(kb_win), kb_ta, true);
#else
lv_page_focus(lv_win_get_page(kb_win), kb_ta, 0);
#endif
}
return LV_ACTION_RES_OK;
}
#endif /*LV_APP_ENABLE != 0*/
/**
* @file lv_app_kb.h
*
*/
#ifndef LV_APP_KB_H
#define LV_APP_KB_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_app.h"
#if USE_LV_APP_KB != 0
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef enum
{
LV_APP_KB_MODE_TXT = 0x0001,
LV_APP_KB_MODE_NUM = 0x0002,
LV_APP_KB_MODE_WIN_RESIZE = 0x0004,
LV_APP_KB_MODE_CUR_MANAGE = 0x0008,
LV_APP_KB_MODE_ANIM_IN = 0x0010,
LV_APP_KB_MODE_ANIM_OUT = 0x0020,
}lv_app_kb_mode_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the application keyboard
*/
void lv_app_kb_init(void);
/**
* Open a keyboard for a text area object
* @param ta pointer to a text area object
* @param mode 'OR'd values of 'lv_app_kb_mode_t' enum
* @param close a function to call when the keyboard is closed
* @param ok a function to called when the "Ok" button is pressed
* @return the created button matrix objects
*/
lv_obj_t * lv_app_kb_open(lv_obj_t * ta, lv_app_kb_mode_t mode, void (*close)(lv_obj_t *), void (*ok)(lv_obj_t *));
/**
* Close the keyboard
* @param ok true: call the ok function, false: call the close function
*/
void lv_app_kb_close(bool ok);
/**********************
* MACROS
**********************/
#endif /*LV_APP_ENABLE*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_APP_KB_H*/
/**
* @file lv_app_notice.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_app_notice.h"
#if USE_LV_APP_NOTICE != 0
#include "../../lv_objx/lv_cont.h"
#include "../../lv_objx/lv_label.h"
#include "misc/gfx/anim.h"
#include <stdio.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
/**********************
* STATIC VARIABLES
**********************/
static lv_obj_t * notice_h;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the Notifications
*/
void lv_app_notice_init(void)
{
notice_h = lv_cont_create(lv_scr_act(), NULL);
lv_obj_set_size(notice_h, LV_HOR_RES, LV_VER_RES - LV_DPI / 8);
lv_obj_set_y(notice_h, LV_DPI / 8);
lv_obj_set_click(notice_h, false);
lv_obj_set_style(notice_h, lv_style_get(LV_STYLE_TRANSP, NULL));
lv_cont_set_layout(notice_h, LV_CONT_LAYOUT_COL_R);
}
/**
* Add a notification with a given text
* @param format pritntf-like format string
* @return pointer the notice which is a message box (lv_mbox) object
*/
lv_obj_t * lv_app_notice_add(const char * format, ...)
{
char txt[LV_APP_NOTICE_MAX_LEN];
va_list va;
va_start(va, format);
vsprintf(txt,format, va);
va_end(va);
lv_obj_t * mbox;
mbox = lv_mbox_create(notice_h, NULL);
lv_mbox_set_text(mbox, txt);
lv_mbox_set_anim_close_time(mbox, LV_APP_NOTICE_CLOSE_ANIM_TIME);
#if LV_APP_NOTICE_SHOW_TIME != 0
lv_mbox_start_auto_close(mbox, LV_APP_NOTICE_SHOW_TIME);
#endif
/*Delete the last children if there are too many*/
uint32_t child_num = lv_obj_get_child_num(notice_h);
if(child_num > LV_APP_NOTICE_MAX_NUM) {
lv_obj_t * last_child = ll_get_tail(&notice_h->child_ll);
lv_obj_del(last_child);
}
/*make sure the notices are on the top*/
lv_obj_set_parent(notice_h, lv_scr_act());
return mbox;
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif
/**
* @file lv_app_notice.h
*
*/
#ifndef LV_APP_NOTICE_H
#define LV_APP_NOTICE_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_app.h"
#include <stdarg.h>
#if USE_LV_APP_NOTICE != 0
/*********************
* DEFINES
*********************/
/*Add the required configurations*/
#ifndef LV_APP_NOTICE_SHOW_TIME
#define LV_APP_NOTICE_SHOW_TIME 4000
#endif
#ifndef LV_APP_NOTICE_CLOSE_ANIM_TIME
#define LV_APP_NOTICE_CLOSE_ANIM_TIME 300
#endif
#ifndef LV_APP_NOTICE_MAX_NUM
#define LV_APP_NOTICE_MAX_NUM 6
#endif
#ifndef LV_APP_NOTICE_MAX_LEN
#define LV_APP_NOTICE_MAX_LEN 256
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize the Notifications
*/
void lv_app_notice_init(void);
/**
* Add a notification with a given text
* @param format pritntf-like format string
* @return pointer the notice which is a message box (lv_mbox) object
*/
lv_obj_t * lv_app_notice_add(const char * format, ...);
/**********************
* MACROS
**********************/
#endif /*LV_APP_ENABLE*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_APP_NOTICE_H*/
/**
* @file lv_app_benchmark.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_app_benchmark.h"
#if LV_APP_ENABLE != 0 && USE_LV_APP_BENCHMARK != 0
#include "../lv_app/lv_app_util/lv_app_kb.h"
#include "lvgl/lv_obj/lv_refr.h"
#include <stdio.h>
/*********************
* DEFINES
*********************/
#define SHADOW_WIDTH (LV_DPI / 8)
#define IMG_RECOLOR OPA_30
#define OPACITY OPA_60
/**********************
* TYPEDEFS
**********************/
/*Application specific data for an instance of this application*/
typedef struct
{
uint8_t wp :1;
uint8_t recolor :1;
uint8_t upscalse :1;
uint8_t shdw :1;
uint8_t opa :1;
}my_app_data_t;
/*Application specific data a window of this application*/
typedef struct
{
lv_obj_t * wp;
lv_obj_t * value_l;
lv_style_t style_wp;
lv_style_t style_value_l;
lv_style_t style_btn_rel;
lv_style_t style_btn_pr;
lv_style_t style_btn_trel;
lv_style_t style_btn_tpr;
lv_style_t style_btn_ina;
}my_win_data_t;
/*Application specific data for a shortcut of this application*/
typedef struct
{
lv_obj_t * label;
}my_sc_data_t;
/**********************
* STATIC PROTOTYPES
**********************/
static void my_app_run(lv_app_inst_t * app, void * conf);
static void my_app_close(lv_app_inst_t * app);
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec, lv_app_com_type_t type , const void * data, uint32_t size);
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 refr_monitor(uint32_t time_ms, uint32_t px_num);
static lv_action_res_t run_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc);
static lv_action_res_t wp_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc);
static lv_action_res_t recolor_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc);
static lv_action_res_t upscale_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc);
static lv_action_res_t shadow_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc);
static lv_action_res_t opa_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc);
/**********************
* STATIC VARIABLES
**********************/
static lv_app_dsc_t my_app_dsc =
{
.name = "Benchmark",
.mode = LV_APP_MODE_NONE,
.app_run = my_app_run,
.app_close = my_app_close,
.com_rec = my_com_rec,
.win_open = my_win_open,
.win_close = my_win_close,
.sc_open = my_sc_open,
.sc_close = my_sc_close,
.app_data_size = sizeof(my_app_data_t),
.sc_data_size = sizeof(my_sc_data_t),
.win_data_size = sizeof(my_win_data_t),
};
static lv_style_t style_win_scrl;
static lv_style_t style_sc_btn_rel;
static lv_style_t style_sc_btn_pr;
static bool caputre_next;
static const color_int_t img_benchmark_bg[];
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the application
* @return pointer to the application descriptor of this application
*/
const lv_app_dsc_t * lv_app_benchmark_init(void)
{
lv_refr_set_monitor_cb(refr_monitor);
lv_img_create_file("app_bm_wp", img_benchmark_bg);
lv_style_get(LV_STYLE_TRANSP, &style_win_scrl);
style_win_scrl.opad = 2 * SHADOW_WIDTH + SHADOW_WIDTH / 8 ;
style_win_scrl.hpad = SHADOW_WIDTH;
style_win_scrl.vpad = SHADOW_WIDTH;
lv_style_get(LV_STYLE_BTN_REL, &style_sc_btn_rel);
style_sc_btn_rel.font = font_get(LV_IMG_DEF_SYMBOL_FONT);
lv_style_get(LV_STYLE_BTN_PR, &style_sc_btn_pr);
style_sc_btn_pr.font = font_get(LV_IMG_DEF_SYMBOL_FONT);
return &my_app_dsc;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Run an application according to 'app_dsc'
* @param app_dsc pointer to an application descriptor
* @param conf pointer to a lv_app_benchmark_conf_t structure with configuration data or NULL if unused
* @return pointer to the opened application or NULL if any error occurred
*/
static void my_app_run(lv_app_inst_t * app, void * conf)
{
/*Initialize the application*/
my_app_data_t * ad = app->app_data;
ad->opa = 0;
ad->recolor = 0;
ad->shdw = 0;
ad->upscalse = 0;
ad->wp = 0;
}
/**
* Close a running application.
* Close the Window and the Shortcut too if opened.
* Free all the allocated memory by this application.
* @param app pointer to an application
*/
static void my_app_close(lv_app_inst_t * app)
{
/*No dynamically allocated data in 'my_app_data'*/
}
/**
* Read the data have been sent to this application
* @param app_send pointer to an application which sent the message
* @param app_rec pointer to an application which is receiving the message
* @param type type of data from 'lv_app_com_type_t' enum
* @param data pointer to the sent data
* @param size length of 'data' in bytes
*/
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec,
lv_app_com_type_t type , const void * data, uint32_t size)
{
if(type == LV_APP_COM_TYPE_CHAR) { /*data: string*/
my_sc_data_t * sc_data = app_rec->sc_data;
if (sc_data->label != NULL) {
lv_label_set_text_array(sc_data->label, data, size);
lv_obj_align(sc_data->label , NULL,LV_ALIGN_CENTER, 0, 0);
}
}
}
/**
* Open a shortcut for an application
* @param app pointer to an application
* @param sc pointer to an object where the application
* can create content of the shortcut
*/
static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc)
{
my_sc_data_t * sc_data = app->sc_data;
lv_cont_set_layout(sc, LV_CONT_LAYOUT_CENTER);
sc_data->label = lv_label_create(sc, NULL);
lv_label_set_text(sc_data->label, "N/A ms");
lv_obj_t * btn = lv_btn_create(sc, NULL);
lv_btn_set_rel_action(btn, run_rel_action);
lv_cont_set_fit(btn, true, true);
lv_btn_set_styles(btn, &style_sc_btn_rel, &style_sc_btn_pr, NULL, NULL, NULL);
lv_obj_t * btn_l = lv_label_create(btn, NULL);
lv_label_set_text(btn_l, SYMBOL_PLAY);
}
/**
* Close the shortcut of an application
* @param app pointer to an application
*/
static void my_sc_close(lv_app_inst_t * app)
{
/*No dynamically allocated data in 'my_sc_data'*/
}
/**
* Open the application in a window
* @param app pointer to an application
* @param win pointer to a window object where
* the application can create content
*/
static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
{
my_win_data_t * wdata = app->win_data;
my_app_data_t * adata = app->app_data;
lv_style_get(LV_STYLE_BTN_INA, &wdata->style_value_l);
wdata->style_value_l.ccolor = COLOR_BLACK;
lv_style_get(LV_STYLE_BTN_REL, &wdata->style_btn_rel);
lv_style_get(LV_STYLE_BTN_PR, &wdata->style_btn_pr);
lv_style_get(LV_STYLE_BTN_TREL, &wdata->style_btn_trel);
lv_style_get(LV_STYLE_BTN_TPR, &wdata->style_btn_tpr);
lv_style_get(LV_STYLE_BTN_INA, &wdata->style_btn_ina);
lv_style_get(LV_STYLE_PLAIN, &wdata->style_wp);
wdata->style_wp.ccolor = COLOR_RED;//MAKE(0x10, 0x20, 0x30);
if(adata->opa == 0) {
wdata->style_btn_rel.opa = OPA_COVER;
wdata->style_btn_pr.opa = OPA_COVER;
wdata->style_btn_trel.opa =OPA_COVER;
wdata->style_btn_tpr.opa = OPA_COVER;
wdata->style_btn_ina.opa = OPA_COVER;
} else {
wdata->style_btn_rel.opa = OPACITY;
wdata->style_btn_pr.opa = OPACITY;
wdata->style_btn_trel.opa =OPACITY;
wdata->style_btn_tpr.opa = OPACITY;
wdata->style_btn_ina.opa = OPACITY;
}
if(adata->shdw == 0) {
wdata->style_btn_rel.swidth = 0;
wdata->style_btn_pr.swidth = 0;
wdata->style_btn_trel.swidth = 0;
wdata->style_btn_tpr.swidth = 0;
wdata->style_btn_ina.swidth = 0;
} else {
wdata->style_btn_rel.swidth = SHADOW_WIDTH;
wdata->style_btn_pr.swidth = SHADOW_WIDTH;
wdata->style_btn_trel.swidth = SHADOW_WIDTH;
wdata->style_btn_tpr.swidth = SHADOW_WIDTH;
wdata->style_btn_ina.swidth = SHADOW_WIDTH;
}
if(adata->recolor == 0) {
wdata->style_wp.img_recolor = OPA_TRANSP;
} else {
wdata->style_wp.img_recolor = IMG_RECOLOR;
}
lv_obj_set_style(lv_page_get_scrl(lv_win_get_page(win)), &style_win_scrl);
wdata->wp = lv_img_create(win, NULL);
lv_obj_set_protect(wdata->wp, LV_PROTECT_PARENT);
lv_obj_set_parent(wdata->wp, lv_win_get_page(win));
lv_img_set_file(wdata->wp, "U:/app_bm_wp");
lv_obj_set_size(wdata->wp, LV_HOR_RES, LV_VER_RES - lv_obj_get_height(lv_win_get_header(win)));
lv_obj_set_pos(wdata->wp, 0, 0);
lv_obj_set_style(wdata->wp, &wdata->style_wp);
lv_img_set_auto_size(wdata->wp, false);
if(adata->wp == 0) lv_obj_set_hidden(wdata->wp, true);
if(adata->upscalse != 0) lv_img_set_upscale(wdata->wp, true);
/* The order is changed because the wallpaper's parent change
* Therefore add the scrollable again */
lv_obj_set_parent(lv_page_get_scrl(lv_win_get_page(win)), lv_win_get_page(win));
lv_cont_set_layout(lv_page_get_scrl(lv_win_get_page(win)), LV_CONT_LAYOUT_PRETTY);
lv_obj_t * holder;
holder = lv_cont_create(win, NULL);
lv_cont_set_fit(holder, true, true);
lv_obj_set_style(holder, &wdata->style_btn_ina);
lv_page_glue_obj(holder, true);
wdata->value_l = lv_label_create(holder, NULL);
lv_obj_set_style(wdata->value_l, &wdata->style_value_l);
lv_label_set_text(wdata->value_l, "Screen load: N/A ms\nN/A px/ms");
lv_obj_t * btn;
btn = lv_btn_create(win, NULL);
lv_obj_set_free_p(btn, app);
lv_page_glue_obj(btn, true);
lv_cont_set_fit(btn, true, true);
lv_btn_set_styles(btn, &wdata->style_btn_rel, &wdata->style_btn_pr, &wdata->style_btn_trel, &wdata->style_btn_tpr, NULL);
lv_btn_set_rel_action(btn, run_rel_action);
lv_obj_t * btn_l;
btn_l = lv_label_create(btn, NULL);
lv_label_set_text(btn_l, "Run\ntest!");
lv_obj_set_protect(btn, LV_PROTECT_FOLLOW);
btn = lv_btn_create(win, btn);
lv_btn_set_tgl(btn, true);
lv_obj_clr_protect(btn, LV_PROTECT_FOLLOW);
if(adata->wp != 0) lv_btn_set_state(btn, LV_BTN_STATE_TREL);
else lv_btn_set_state(btn, LV_BTN_STATE_REL);
lv_btn_set_rel_action(btn, wp_rel_action);
btn_l = lv_label_create(btn, btn_l);
lv_label_set_text(btn_l, "Wallpaper");
btn = lv_btn_create(win, btn);
if(adata->recolor != 0) lv_btn_set_state(btn, LV_BTN_STATE_TREL);
else lv_btn_set_state(btn, LV_BTN_STATE_REL);
lv_btn_set_rel_action(btn, recolor_rel_action);
btn_l = lv_label_create(btn, btn_l);
lv_label_set_text(btn_l, "Wp. recolor!");
btn = lv_btn_create(win, btn);
if(adata->upscalse != 0) lv_btn_set_state(btn, LV_BTN_STATE_TREL);
else lv_btn_set_state(btn, LV_BTN_STATE_REL);
lv_btn_set_rel_action(btn, upscale_rel_action);
btn_l = lv_label_create(btn, btn_l);
lv_label_set_text(btn_l, "Wp. upscalse!");
btn = lv_btn_create(win, btn);
if(adata->shdw != 0) lv_btn_set_state(btn, LV_BTN_STATE_TREL);
else lv_btn_set_state(btn, LV_BTN_STATE_REL);
lv_btn_set_rel_action(btn, shadow_rel_action);
btn_l = lv_label_create(btn, btn_l);
lv_label_set_text(btn_l, "Shadow");
btn = lv_btn_create(win, btn);
if(adata->opa != 0) lv_btn_set_state(btn, LV_BTN_STATE_TREL);
else lv_btn_set_state(btn, LV_BTN_STATE_REL);
lv_btn_set_rel_action(btn, opa_rel_action);
btn_l = lv_label_create(btn, btn_l);
lv_label_set_text(btn_l, "Opacity");
}
/**
* Close the window of an application
* @param app pointer to an application
*/
static void my_win_close(lv_app_inst_t * app)
{
}
/*--------------------
* OTHER FUNCTIONS
---------------------*/
static void refr_monitor(uint32_t time_ms, uint32_t px_num)
{
if(caputre_next != false) {
lv_app_inst_t * app = NULL;
app = lv_app_get_next(app, &my_app_dsc);
char w_buf[256];
if(time_ms != 0) sprintf(w_buf, "Screen load: %d ms\n%d px/ms", time_ms, px_num/time_ms);
else sprintf(w_buf, "Screen load: %d ms\nN/A px/ms", time_ms);
char s_buf[16];
sprintf(s_buf, "%d ms", time_ms);
while(app != NULL) {
if(app->win_data != NULL) {
my_win_data_t * wdata = app->win_data;
lv_label_set_text(wdata->value_l, w_buf);
}
if(app->sc_data != NULL) {
my_sc_data_t * sdata = app->sc_data;
lv_label_set_text(sdata->label, s_buf);
}
app = lv_app_get_next(app, &my_app_dsc);
}
caputre_next = false;
}
}
static lv_action_res_t run_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc)
{
lv_obj_inv(lv_scr_act());
caputre_next = true;
return LV_ACTION_RES_OK;
}
static lv_action_res_t wp_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(btn);
my_win_data_t * wdata = app->win_data;
my_app_data_t * adata = app->app_data;
if(lv_btn_get_state(btn) == LV_BTN_STATE_TREL) {
adata->wp = 1;
lv_obj_set_hidden(wdata->wp, false);
} else {
adata->wp = 0;
lv_obj_set_hidden(wdata->wp, true);
}
return LV_ACTION_RES_OK;
}
static lv_action_res_t recolor_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(btn);
my_win_data_t * wdata = app->win_data;
my_app_data_t * adata = app->app_data;
if(lv_btn_get_state(btn) == LV_BTN_STATE_TREL) {
adata->recolor = 1;
wdata->style_wp.img_recolor = IMG_RECOLOR;
} else {
adata->recolor = 0;
wdata->style_wp.img_recolor = OPA_TRANSP;
}
lv_obj_refr_style(wdata->wp);
return LV_ACTION_RES_OK;
}
static lv_action_res_t upscale_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(btn);
my_win_data_t * wdata = app->win_data;
my_app_data_t * adata = app->app_data;
if(lv_btn_get_state(btn) == LV_BTN_STATE_TREL) {
adata->upscalse = 1;
lv_img_set_upscale(wdata->wp, true);
} else {
adata->upscalse = 0;
lv_img_set_upscale(wdata->wp, false);
}
lv_obj_set_size(wdata->wp, LV_HOR_RES, LV_VER_RES - lv_obj_get_height(lv_win_get_header(app->win)));
return LV_ACTION_RES_OK;
}
static lv_action_res_t shadow_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(btn);
my_win_data_t * wdata = app->win_data;
my_app_data_t * adata = app->app_data;
if(lv_btn_get_state(btn) == LV_BTN_STATE_TREL) {
adata->shdw = 1;
wdata->style_btn_rel.swidth = SHADOW_WIDTH;
wdata->style_btn_pr.swidth = SHADOW_WIDTH;
wdata->style_btn_trel.swidth = SHADOW_WIDTH;
wdata->style_btn_tpr.swidth = SHADOW_WIDTH;
wdata->style_btn_ina.swidth = SHADOW_WIDTH;
} else {
adata->shdw = 0;
wdata->style_btn_rel.swidth = 0;
wdata->style_btn_pr.swidth = 0;
wdata->style_btn_trel.swidth =0;
wdata->style_btn_tpr.swidth = 0;
wdata->style_btn_ina.swidth = 0;
}
lv_style_refr_objs(&wdata->style_btn_rel);
lv_style_refr_objs(&wdata->style_btn_pr);
lv_style_refr_objs(&wdata->style_btn_trel);
lv_style_refr_objs(&wdata->style_btn_tpr);
lv_style_refr_objs(&wdata->style_btn_ina);
return LV_ACTION_RES_OK;
}
static lv_action_res_t opa_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(btn);
my_win_data_t * wdata = app->win_data;
my_app_data_t * adata = app->app_data;
if(lv_btn_get_state(btn) == LV_BTN_STATE_TREL) {
adata->opa = 1;
wdata->style_btn_rel.opa = OPACITY;
wdata->style_btn_pr.opa = OPACITY;
wdata->style_btn_trel.opa =OPACITY;
wdata->style_btn_tpr.opa = OPACITY;
wdata->style_btn_ina.opa = OPACITY;
} else {
adata->opa = 0;
wdata->style_btn_rel.opa = OPA_COVER;
wdata->style_btn_pr.opa = OPA_COVER;
wdata->style_btn_trel.opa =OPA_COVER;
wdata->style_btn_tpr.opa = OPA_COVER;
wdata->style_btn_ina.opa = OPA_COVER;
}
lv_style_refr_objs(&wdata->style_btn_rel);
lv_style_refr_objs(&wdata->style_btn_pr);
lv_style_refr_objs(&wdata->style_btn_trel);
lv_style_refr_objs(&wdata->style_btn_tpr);
lv_style_refr_objs(&wdata->style_btn_ina);
return LV_ACTION_RES_OK;
}
/*Exceptionally store the data because the big array would be bothering*/
#if COLOR_DEPTH == 8
static const color_int_t img_benchmark_bg[] = {
/*HEADER
Width = 40
Height = 40
Transp: 0
Color depth: 8*/
40, 128, 2, 2,
/*IMAGE DATA*/
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 5, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 5, 0, 5, 5, 5, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 5, 5, 0, 5, 5, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 5, 5, 5, 5, 5, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 5, 5, 0, 0, 5, 0, 0, 0, 5, 5, 5, 5, 5, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 5, 5, 5, 5, 5, 5, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 0, 0, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 0, 0, 0, 5, 5, 5, 0, 5, 5, 5, 5, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 0, 5, 5, 5, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 0, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 0, 5, 5, 5, 0, 5, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 0, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 0, 0, 0, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 5, 5, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 5, 5, 5, 5, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
#endif /*COLOR_DEPTH*/
#if COLOR_DEPTH == 16
static const color_int_t img_benchmark_bg[] = {
/*HEADER
Width = 40
Height = 40
Transp: 0
Color depth: 16*/
32808, 1026,
/*IMAGE DATA*/
32, 32, 32, 2113, 2113, 4258, 6339, 4258, 4258, 4226, 4226, 2145, 4226, 2113, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 2145, 2145, 4226, 4226, 4226, 4226, 4226, 2145, 32, 32, 32, 32,
0, 32, 2113, 32, 6339, 10565, 8452, 4258, 4226, 4226, 2145, 4226, 6339, 4226, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 2145, 4226, 2145, 2145, 4226, 4226, 4226, 6371, 6339, 4226, 32, 32, 32,
32, 32, 2113, 4226, 8484, 8484, 8452, 6371, 4226, 2145, 4226, 4258, 4258, 4258, 2145, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 2145, 4226, 4226, 4226, 4226, 2145, 2145, 4226, 6339, 4258, 4258, 4226, 32, 32,
32, 32, 4258, 6371, 8452, 6371, 6371, 6339, 4226, 2145, 4226, 4226, 2145, 4226, 4226, 2113, 32, 0, 0, 0, 0, 32, 0, 0, 32, 2113, 2145, 2145, 2145, 4226, 4226, 4226, 2145, 4226, 6339, 4226, 6371, 6339, 2145, 32,
2113, 2145, 6371, 6339, 4226, 4226, 4226, 4226, 4258, 4258, 4226, 2145, 4226, 2145, 2145, 4226, 4258, 32, 0, 0, 0, 0, 0, 2113, 6339, 4226, 2113, 2145, 2145, 2145, 4226, 4226, 4258, 4226, 4258, 4258, 4258, 6339, 6339, 2145,
4226, 4258, 6339, 4226, 4226, 2145, 2145, 2145, 4226, 4226, 4226, 2145, 2145, 2145, 4226, 6339, 8452, 6339, 32, 0, 0, 0, 2113, 6339, 6371, 6339, 2145, 2113, 2145, 2145, 4226, 4226, 4226, 4226, 4226, 4226, 4226, 4258, 4258, 4226,
4226, 4226, 2145, 4226, 2145, 2145, 4226, 4226, 2145, 4226, 4226, 4226, 2145, 4226, 6371, 6371, 6371, 8452, 4258, 32, 0, 2113, 6371, 6371, 6371, 6339, 6339, 2145, 2145, 4226, 2145, 2145, 2145, 4226, 4258, 4226, 4226, 4226, 2145, 4226,
4226, 2145, 4226, 2145, 2145, 4226, 4226, 4226, 4226, 4226, 2145, 2145, 4258, 6371, 8452, 6371, 6371, 6371, 8452, 6339, 2145, 6339, 8452, 6371, 6339, 6371, 6371, 6339, 4226, 2145, 2145, 2145, 2145, 2145, 4258, 4258, 2145, 2145, 2145, 2145,
4226, 2145, 4226, 2113, 2145, 4226, 4258, 4226, 2145, 2145, 2145, 4258, 6371, 8452, 6371, 6339, 6371, 6371, 8452, 8452, 6339, 8452, 8452, 8452, 6371, 6371, 8452, 8452, 6339, 4226, 2145, 2145, 2145, 2145, 4226, 4258, 2145, 2113, 2145, 2145,
2145, 2145, 2113, 2145, 4226, 4226, 4226, 2145, 2145, 2113, 4226, 6339, 6371, 6371, 6371, 6371, 6371, 8452, 6371, 8452, 8452, 6371, 8452, 8452, 6339, 6371, 8452, 8452, 8452, 6371, 4226, 2145, 4226, 4226, 4226, 4226, 4226, 4226, 2145, 4226,
4226, 4226, 2145, 4226, 4226, 2145, 4226, 2145, 2113, 2145, 6339, 6371, 6371, 8452, 8452, 8452, 8484, 8452, 6371, 6371, 6371, 6371, 6371, 6371, 6371, 6371, 6371, 6371, 8452, 8452, 6339, 2145, 2145, 4226, 4226, 2145, 4226, 4226, 2145, 4226,
2145, 4226, 4258, 2145, 2145, 2145, 2113, 2145, 4226, 6339, 6371, 6371, 6371, 8452, 8484, 8484, 8452, 6371, 6371, 6371, 6371, 6371, 6371, 8452, 6371, 6339, 6371, 6371, 6371, 8452, 8452, 6339, 4226, 2145, 2145, 4226, 4226, 2145, 4226, 2145,
32, 2113, 4226, 4226, 2145, 2145, 2113, 2145, 8452, 8452, 6371, 6371, 6339, 8484, 8484, 8484, 8484, 8452, 6371, 6339, 6371, 6371, 6371, 6371, 6371, 6371, 6339, 6339, 6339, 6339, 8452, 8484, 6371, 2145, 2145, 4226, 2145, 4226, 4226, 2113,
0, 0, 2145, 4226, 4226, 4226, 4258, 6371, 6371, 8452, 6371, 6339, 6339, 8452, 8484, 8452, 8452, 8452, 6371, 6371, 8452, 8452, 8452, 6371, 6371, 6339, 6371, 6339, 6371, 6371, 8452, 8452, 8484, 8452, 4226, 4226, 4258, 4258, 2113, 32,
0, 0, 32, 2113, 2145, 6339, 8452, 8452, 6339, 6339, 8452, 6371, 6339, 6371, 10565, 8484, 8452, 8484, 8452, 6371, 6339, 8452, 8452, 6371, 6371, 6339, 6371, 6371, 6371, 8452, 8452, 8452, 8484, 10565, 6371, 4258, 4226, 2145, 32, 0,
0, 0, 0, 0, 2113, 6339, 8452, 6371, 6371, 6339, 6371, 8452, 6371, 6371, 8452, 8484, 8452, 8452, 8484, 8452, 4258, 8452, 8452, 6339, 6339, 6339, 6339, 6371, 6371, 6371, 6371, 8452, 8452, 8452, 8484, 8452, 2113, 0, 0, 32,
0, 0, 0, 0, 0, 4258, 6371, 6371, 6371, 6371, 6371, 6371, 6371, 6371, 8452, 8452, 8452, 8484, 8452, 2145, 32, 4226, 6371, 6371, 6371, 6339, 6371, 6371, 6371, 6371, 6371, 6371, 8452, 8452, 8452, 4226, 32, 0, 0, 32,
0, 0, 0, 0, 0, 0, 4226, 8452, 6371, 6371, 6371, 6339, 6371, 8452, 8452, 8452, 8484, 8452, 2145, 0, 0, 0, 4226, 8452, 6371, 6371, 6371, 6339, 6339, 6371, 6371, 6371, 8452, 8484, 4258, 0, 32, 32, 32, 0,
0, 0, 0, 0, 0, 0, 32, 4258, 6371, 6371, 6371, 6371, 6371, 8452, 8452, 8452, 8452, 2145, 0, 0, 32, 0, 0, 4226, 6371, 6371, 6339, 6339, 6371, 6371, 6371, 6371, 6371, 2145, 0, 0, 32, 32, 32, 0,
0, 0, 0, 0, 0, 0, 0, 32, 6339, 6371, 6371, 6371, 6371, 8452, 8484, 8452, 4226, 32, 0, 0, 0, 0, 0, 0, 4226, 6339, 6339, 6339, 6371, 6371, 6371, 6371, 4226, 0, 32, 32, 32, 32, 0, 0,
0, 0, 0, 0, 0, 0, 0, 2113, 6339, 6371, 6371, 6371, 6371, 8452, 8484, 8484, 4258, 32, 0, 0, 0, 0, 0, 32, 4258, 6339, 6339, 6371, 6371, 6371, 8452, 8452, 4258, 32, 32, 32, 32, 32, 0, 32,
0, 0, 0, 32, 0, 0, 2113, 6339, 8484, 8452, 6371, 6371, 8452, 8484, 8484, 8484, 8452, 4226, 0, 0, 0, 0, 32, 6339, 8452, 6371, 6371, 6371, 6371, 6371, 8452, 8452, 8484, 6371, 2113, 32, 32, 32, 32, 32,
0, 0, 0, 0, 0, 2113, 6339, 8452, 8484, 8484, 8452, 6371, 8452, 10597, 8452, 8452, 8452, 6371, 4226, 0, 0, 32, 4258, 8452, 8452, 8452, 8452, 6371, 6339, 6371, 6371, 6371, 8484, 8484, 6339, 2113, 0, 32, 32, 32,
0, 0, 0, 0, 2113, 6371, 8452, 8452, 8452, 8452, 8452, 8452, 8484, 10597, 8452, 8452, 6371, 8452, 8452, 4258, 2113, 6339, 8452, 8452, 8452, 6371, 8452, 8452, 8452, 8452, 6371, 6371, 8452, 8484, 8484, 6371, 2113, 32, 32, 32,
0, 0, 0, 32, 2145, 6339, 8484, 8452, 8452, 8452, 8452, 8452, 8484, 8484, 8452, 8452, 6371, 8452, 8452, 10565, 8484, 8452, 8484, 8452, 8452, 6371, 8452, 8484, 8452, 8484, 8452, 6371, 8484, 8484, 10597, 6371, 6339, 2145, 0, 32,
0, 0, 0, 2145, 4226, 2145, 6339, 8452, 8452, 8452, 8452, 8452, 8452, 8452, 8452, 8452, 8452, 8452, 8452, 8484, 8452, 8452, 8452, 8452, 8452, 6371, 8452, 8452, 8452, 8484, 8484, 8484, 8484, 12678, 6371, 4226, 6371, 4258, 32, 0,
0, 32, 2145, 4226, 4226, 2145, 2145, 6339, 8484, 10565, 8452, 8452, 8452, 8452, 8484, 8484, 8452, 8452, 6371, 6371, 6371, 6339, 8452, 8452, 8452, 8452, 6371, 8452, 8484, 8484, 8452, 8484, 10565, 8484, 4258, 4226, 6339, 6339, 2145, 32,
2113, 4226, 4258, 4226, 4226, 4226, 2145, 2145, 8452, 8484, 8452, 6371, 8452, 8452, 8484, 8452, 8452, 6371, 6339, 6339, 6339, 6371, 6371, 8452, 8452, 8452, 6371, 6371, 6339, 8452, 8484, 8484, 6371, 4226, 4258, 6339, 4226, 4258, 6339, 4226,
2145, 2145, 4226, 4226, 4226, 4226, 2145, 2145, 2145, 10565, 8452, 8452, 8452, 6371, 8452, 8452, 8452, 6371, 8452, 6371, 6339, 6371, 6371, 6371, 8452, 6371, 6371, 6339, 6339, 6371, 6371, 6339, 4226, 4258, 4226, 6339, 6339, 4258, 6339, 4226,
2145, 2145, 2113, 4226, 4226, 4226, 4226, 4226, 2145, 4226, 6339, 6371, 6371, 8452, 8452, 8452, 8452, 8452, 6371, 6371, 6371, 6339, 8452, 8452, 8452, 8452, 8452, 8452, 6371, 6371, 4258, 2145, 4226, 4258, 6339, 4258, 4258, 4226, 4226, 4258,
2145, 2145, 2145, 2145, 2145, 4226, 4226, 4226, 4226, 2145, 2145, 6371, 8484, 8452, 8452, 8452, 8452, 8452, 8452, 6371, 6371, 6371, 8452, 8484, 8452, 8452, 8452, 8484, 8484, 6339, 2145, 2145, 4226, 4226, 4258, 6339, 4226, 2145, 4226, 4226,
2145, 2145, 4226, 4226, 4226, 4258, 4226, 4258, 4258, 4226, 2145, 4226, 6371, 8452, 8452, 6371, 8452, 8452, 8452, 8452, 6339, 8452, 8452, 8452, 8484, 10565, 8452, 8484, 6371, 4226, 4226, 4258, 6339, 6339, 6339, 6339, 4226, 2145, 2145, 4226,
2145, 2145, 2145, 4226, 4226, 6339, 6339, 6339, 4226, 4226, 4226, 2145, 4258, 6339, 8452, 8452, 8452, 8452, 8484, 4258, 2113, 6339, 8452, 8452, 8452, 8484, 8452, 6339, 4258, 4226, 6339, 6339, 6339, 6339, 6339, 6339, 4226, 2145, 2145, 4258,
2145, 4226, 4226, 4226, 4258, 4226, 6371, 6339, 4226, 4226, 4226, 4226, 2145, 4226, 6339, 8452, 8452, 8452, 4258, 32, 0, 2113, 6339, 8484, 10565, 8484, 6339, 4226, 4258, 6339, 6339, 6339, 6339, 4258, 4226, 2145, 4258, 4226, 4226, 4258,
2145, 4226, 4258, 4258, 4226, 4226, 4226, 4258, 6339, 4258, 4226, 2145, 2145, 2145, 4226, 6371, 8452, 4226, 32, 0, 0, 0, 32, 6371, 10565, 8452, 4226, 4226, 4258, 4258, 6339, 6339, 6371, 4226, 2145, 4226, 4226, 4226, 4258, 4226,
32, 2113, 6339, 4258, 4258, 4226, 4226, 4226, 4258, 4258, 4226, 4226, 4226, 4226, 4226, 4226, 4226, 32, 0, 0, 0, 0, 0, 2113, 8452, 6339, 4258, 4226, 4226, 4226, 4258, 6339, 4258, 4258, 4226, 4258, 6339, 4258, 4226, 2113,
0, 0, 2113, 4258, 4258, 4258, 4258, 4226, 2145, 2145, 4226, 4226, 4226, 4258, 4258, 2113, 32, 32, 32, 32, 32, 0, 32, 2113, 2145, 4258, 6371, 6339, 4258, 6339, 4258, 4226, 4258, 8484, 6371, 8452, 8484, 6339, 2113, 0,
0, 0, 0, 2113, 6339, 6339, 4258, 4226, 2145, 2145, 2145, 4226, 6339, 4258, 2145, 32, 32, 32, 32, 32, 0, 0, 32, 32, 2113, 2145, 6339, 8452, 8452, 4258, 4226, 4258, 6339, 8484, 10565, 10597, 8452, 2145, 32, 0,
0, 0, 0, 0, 4258, 6371, 6339, 4226, 4226, 2145, 2145, 4226, 4258, 4226, 32, 0, 32, 32, 32, 32, 0, 32, 0, 32, 32, 32, 2145, 8452, 8452, 4258, 4226, 4226, 4258, 8484, 8452, 8484, 4226, 0, 0, 0,
0, 0, 0, 0, 32, 4226, 4258, 6339, 4226, 4226, 4226, 4226, 2145, 32, 32, 0, 0, 32, 32, 32, 0, 0, 0, 0, 32, 2113, 2113, 2145, 4226, 4226, 4226, 4226, 6339, 6371, 4226, 2145, 32, 0, 0, 0,
};
#endif /*COLOR_DEPTH == 16*/
#if COLOR_DEPTH == 24
static const color_int_t img_benchmark_bg[] = {
/*HEADER
Width = 40
Height = 40
Transp: 0
Color depth: 24*/
100827176,
/*IMAGE DATA*/
263172, 460551, 460551, 526344, 723723, 1447446, 1644825, 1447446, 1447446, 1052688, 1052688, 921102, 1052688, 723723, 263172, 197379, 131586, 65793, 65793, 0, 65793, 0, 65793, 65793, 65793, 65793, 65793, 328965, 789516, 855309, 1250067, 1052688, 1052688, 1184274, 1184274, 986895, 394758, 394758, 394758, 328965,
131586, 460551, 526344, 394758, 1776411, 2631720, 2105376, 1447446, 1250067, 1052688, 855309, 1052688, 1579032, 1250067, 460551, 65793, 65793, 65793, 65793, 65793, 0, 65793, 65793, 0, 0, 0, 328965, 986895, 1184274, 789516, 921102, 1250067, 1052688, 1052688, 1842204, 1644825, 1052688, 328965, 263172, 328965,
394758, 460551, 526344, 1052688, 2434341, 2434341, 2236962, 1907997, 1052688, 855309, 1052688, 1315860, 1381653, 1447446, 855309, 263172, 0, 0, 131586, 131586, 131586, 131586, 131586, 65793, 0, 263172, 855309, 1052688, 1052688, 1052688, 1118481, 921102, 986895, 1052688, 1579032, 1513239, 1513239, 1118481, 394758, 328965,
263172, 460551, 1447446, 1842204, 2171169, 1973790, 1973790, 1776411, 1052688, 986895, 1184274, 1250067, 921102, 1118481, 1118481, 723723, 263172, 0, 65793, 131586, 197379, 263172, 131586, 131586, 328965, 657930, 921102, 855309, 921102, 1052688, 1052688, 1052688, 855309, 1250067, 1579032, 1250067, 1842204, 1710618, 986895, 263172,
657930, 921102, 1842204, 1776411, 1250067, 1118481, 1052688, 1118481, 1315860, 1381653, 1052688, 855309, 1052688, 855309, 921102, 1184274, 1381653, 394758, 65793, 131586, 131586, 131586, 65793, 526344, 1579032, 1052688, 723723, 789516, 855309, 921102, 1052688, 1184274, 1315860, 1052688, 1315860, 1447446, 1513239, 1710618, 1644825, 855309,
1052688, 1315860, 1710618, 1250067, 1052688, 986895, 921102, 921102, 1052688, 1052688, 1184274, 855309, 855309, 921102, 1052688, 1776411, 2302755, 1644825, 394758, 0, 131586, 131586, 657930, 1776411, 1907997, 1710618, 855309, 723723, 855309, 986895, 1052688, 1052688, 1184274, 1184274, 1052688, 1184274, 1250067, 1513239, 1447446, 1184274,
1184274, 1052688, 986895, 1052688, 921102, 986895, 1184274, 1052688, 921102, 1052688, 1052688, 1052688, 986895, 1118481, 1907997, 1907997, 1973790, 2171169, 1513239, 394758, 65793, 657930, 1973790, 1973790, 1842204, 1776411, 1579032, 855309, 789516, 1052688, 986895, 986895, 986895, 1250067, 1315860, 1118481, 1250067, 1118481, 986895, 1118481,
1250067, 986895, 1052688, 855309, 986895, 1250067, 1184274, 1052688, 1052688, 1052688, 986895, 921102, 1315860, 1973790, 2105376, 1842204, 1842204, 1973790, 2171169, 1579032, 789516, 1710618, 2105376, 1973790, 1776411, 1907997, 1973790, 1710618, 1118481, 855309, 855309, 855309, 921102, 986895, 1315860, 1381653, 986895, 855309, 789516, 986895,
1250067, 855309, 1052688, 657930, 986895, 1118481, 1315860, 1118481, 986895, 986895, 855309, 1381653, 1907997, 2105376, 1842204, 1776411, 1842204, 1907997, 2105376, 2171169, 1776411, 2105376, 2236962, 2105376, 1842204, 1973790, 2171169, 2236962, 1776411, 1052688, 855309, 986895, 921102, 921102, 1118481, 1513239, 921102, 657930, 921102, 855309,
986895, 855309, 657930, 855309, 1052688, 1118481, 1118481, 986895, 855309, 657930, 1052688, 1776411, 1907997, 1907997, 1973790, 1907997, 1907997, 2171169, 1973790, 2236962, 2171169, 1973790, 2105376, 2105376, 1776411, 1973790, 2236962, 2236962, 2302755, 1842204, 1118481, 855309, 1052688, 1052688, 1052688, 1184274, 1118481, 1052688, 921102, 1052688,
1250067, 1250067, 855309, 1052688, 1052688, 986895, 1052688, 855309, 657930, 855309, 1710618, 1907997, 1907997, 2105376, 2171169, 2302755, 2368548, 2105376, 1973790, 1907997, 1842204, 1842204, 1907997, 1907997, 1842204, 1907997, 1973790, 1973790, 2171169, 2302755, 1776411, 855309, 855309, 1052688, 1052688, 986895, 1184274, 1184274, 855309, 1052688,
986895, 1052688, 1315860, 855309, 855309, 855309, 723723, 789516, 1052688, 1710618, 1973790, 1842204, 1973790, 2302755, 2434341, 2434341, 2302755, 1973790, 1842204, 1842204, 1842204, 1973790, 1907997, 2236962, 1907997, 1776411, 1907997, 1907997, 1973790, 2105376, 2236962, 1776411, 1052688, 855309, 855309, 1184274, 1052688, 986895, 1184274, 986895,
328965, 657930, 1052688, 1052688, 855309, 855309, 723723, 921102, 2105376, 2236962, 1907997, 1973790, 1710618, 2368548, 2434341, 2434341, 2368548, 2236962, 1842204, 1710618, 1842204, 1842204, 1907997, 1973790, 1907997, 1842204, 1776411, 1710618, 1776411, 1776411, 2171169, 2368548, 1907997, 855309, 986895, 1052688, 986895, 1118481, 1052688, 723723,
131586, 131586, 855309, 1118481, 1052688, 1118481, 1447446, 1907997, 1842204, 2105376, 1907997, 1776411, 1776411, 2171169, 2500134, 2171169, 2171169, 2236962, 1907997, 1907997, 2105376, 2105376, 2171169, 1973790, 1842204, 1776411, 1842204, 1776411, 1842204, 1842204, 2171169, 2105376, 2434341, 2105376, 1118481, 1052688, 1381653, 1315860, 657930, 328965,
65793, 131586, 263172, 657930, 855309, 1579032, 2236962, 2171169, 1776411, 1776411, 2105376, 1842204, 1776411, 1973790, 2631720, 2434341, 2302755, 2368548, 2105376, 1842204, 1776411, 2236962, 2171169, 1842204, 1842204, 1776411, 1842204, 1842204, 1842204, 2105376, 2105376, 2105376, 2500134, 2631720, 1907997, 1381653, 1052688, 789516, 263172, 197379,
65793, 131586, 131586, 131586, 526344, 1644825, 2105376, 1842204, 1907997, 1776411, 1907997, 2105376, 1842204, 1973790, 2105376, 2368548, 2236962, 2302755, 2368548, 2171169, 1513239, 2105376, 2171169, 1776411, 1644825, 1710618, 1644825, 1842204, 1973790, 1973790, 1842204, 2105376, 2236962, 2236962, 2565927, 2105376, 657930, 131586, 131586, 328965,
65793, 131586, 197379, 131586, 197379, 1315860, 1973790, 1973790, 1907997, 1907997, 1907997, 1842204, 1842204, 1973790, 2171169, 2236962, 2302755, 2434341, 2302755, 855309, 263172, 1184274, 1842204, 1973790, 1842204, 1710618, 1907997, 1842204, 1842204, 1973790, 1973790, 1842204, 2105376, 2302755, 2105376, 1184274, 328965, 197379, 131586, 263172,
65793, 131586, 131586, 65793, 0, 197379, 1250067, 2105376, 1973790, 1907997, 1973790, 1776411, 1842204, 2236962, 2171169, 2105376, 2500134, 2171169, 789516, 131586, 197379, 197379, 1184274, 2171169, 1907997, 1907997, 1842204, 1710618, 1710618, 1842204, 1907997, 1842204, 2171169, 2368548, 1315860, 65793, 263172, 394758, 263172, 197379,
65793, 131586, 131586, 131586, 65793, 0, 263172, 1315860, 1907997, 1907997, 1842204, 1907997, 1973790, 2302755, 2302755, 2236962, 2171169, 855309, 131586, 131586, 263172, 131586, 197379, 1052688, 1973790, 1907997, 1710618, 1710618, 1907997, 1842204, 1907997, 1973790, 1973790, 986895, 131586, 197379, 394758, 394758, 263172, 131586,
65793, 197379, 65793, 131586, 131586, 131586, 65793, 394758, 1579032, 1907997, 1907997, 1907997, 1973790, 2171169, 2565927, 2171169, 1118481, 263172, 131586, 197379, 197379, 131586, 131586, 197379, 1118481, 1776411, 1776411, 1776411, 1842204, 1907997, 1973790, 1973790, 1052688, 131586, 263172, 328965, 394758, 328965, 197379, 197379,
131586, 131586, 131586, 197379, 131586, 131586, 131586, 592137, 1644825, 1973790, 1842204, 1973790, 1973790, 2236962, 2500134, 2368548, 1447446, 263172, 65793, 197379, 197379, 131586, 131586, 394758, 1447446, 1776411, 1776411, 1842204, 1907997, 1973790, 2105376, 2171169, 1513239, 394758, 328965, 460551, 460551, 328965, 197379, 263172,
197379, 197379, 197379, 328965, 197379, 131586, 592137, 1710618, 2368548, 2302755, 1907997, 1907997, 2236962, 2434341, 2368548, 2434341, 2236962, 1052688, 131586, 65793, 197379, 131586, 328965, 1579032, 2302755, 1973790, 1842204, 1842204, 1842204, 1907997, 2105376, 2302755, 2500134, 1907997, 657930, 394758, 394758, 394758, 394758, 328965,
131586, 131586, 131586, 197379, 131586, 526344, 1776411, 2302755, 2434341, 2368548, 2171169, 1842204, 2302755, 2894892, 2302755, 2236962, 2171169, 1907997, 1118481, 197379, 131586, 394758, 1513239, 2236962, 2171169, 2105376, 2105376, 1842204, 1710618, 1842204, 1907997, 1907997, 2368548, 2565927, 1644825, 592137, 197379, 394758, 328965, 328965,
65793, 131586, 131586, 65793, 526344, 1842204, 2302755, 2236962, 2302755, 2302755, 2105376, 2105376, 2434341, 2894892, 2302755, 2105376, 1973790, 2105376, 2105376, 1381653, 592137, 1644825, 2236962, 2302755, 2105376, 1973790, 2171169, 2171169, 2105376, 2105376, 1973790, 1973790, 2171169, 2565927, 2565927, 1973790, 657930, 460551, 460551, 263172,
0, 65793, 65793, 263172, 855309, 1776411, 2434341, 2105376, 2236962, 2105376, 2302755, 2302755, 2368548, 2368548, 2105376, 2105376, 1973790, 2171169, 2302755, 2829099, 2565927, 2302755, 2500134, 2105376, 2105376, 1842204, 2171169, 2368548, 2302755, 2368548, 2171169, 1907997, 2368548, 2500134, 2894892, 1842204, 1579032, 789516, 197379, 263172,
0, 0, 197379, 789516, 1052688, 921102, 1710618, 2302755, 2105376, 2171169, 2302755, 2236962, 2105376, 2105376, 2302755, 2171169, 2171169, 2302755, 2105376, 2434341, 2302755, 2171169, 2302755, 2105376, 2105376, 1973790, 2105376, 2302755, 2302755, 2368548, 2434341, 2368548, 2500134, 3158064, 1973790, 1118481, 1907997, 1315860, 328965, 131586,
65793, 263172, 986895, 1184274, 1052688, 855309, 921102, 1644825, 2368548, 2631720, 2302755, 2236962, 2171169, 2302755, 2565927, 2368548, 2105376, 2105376, 1907997, 1907997, 1973790, 1776411, 2105376, 2171169, 2171169, 2105376, 1907997, 2302755, 2500134, 2434341, 2236962, 2434341, 2829099, 2434341, 1513239, 1184274, 1644825, 1776411, 921102, 394758,
657930, 1052688, 1381653, 1184274, 1052688, 1052688, 855309, 855309, 2105376, 2368548, 2105376, 1973790, 2171169, 2302755, 2565927, 2302755, 2171169, 1907997, 1776411, 1710618, 1776411, 1973790, 1842204, 2105376, 2236962, 2105376, 1907997, 1842204, 1776411, 2236962, 2368548, 2500134, 1973790, 1184274, 1513239, 1710618, 1250067, 1381653, 1776411, 1118481,
855309, 921102, 1118481, 1118481, 1184274, 1052688, 986895, 855309, 855309, 2631720, 2105376, 2105376, 2105376, 1973790, 2236962, 2302755, 2105376, 1907997, 2171169, 1907997, 1710618, 1842204, 1842204, 1842204, 2236962, 1842204, 1842204, 1710618, 1776411, 1842204, 1842204, 1579032, 1118481, 1513239, 1250067, 1579032, 1579032, 1513239, 1644825, 1052688,
986895, 855309, 723723, 1052688, 1052688, 1052688, 1250067, 1052688, 986895, 1052688, 1644825, 1907997, 1973790, 2302755, 2236962, 2236962, 2236962, 2236962, 1973790, 1907997, 1907997, 1710618, 2105376, 2302755, 2105376, 2105376, 2105376, 2105376, 1973790, 1973790, 1315860, 789516, 1118481, 1513239, 1579032, 1381653, 1513239, 1118481, 1052688, 1315860,
855309, 855309, 855309, 855309, 986895, 1184274, 1052688, 1118481, 1052688, 921102, 855309, 1842204, 2368548, 2302755, 2236962, 2105376, 2105376, 2236962, 2171169, 1973790, 1907997, 1842204, 2105376, 2434341, 2236962, 2171169, 2302755, 2434341, 2500134, 1776411, 986895, 855309, 1118481, 1250067, 1513239, 1776411, 1184274, 855309, 1052688, 1118481,
855309, 789516, 1052688, 1052688, 1052688, 1381653, 1250067, 1315860, 1447446, 1052688, 855309, 1052688, 1973790, 2302755, 2105376, 1973790, 2105376, 2171169, 2302755, 2171169, 1710618, 2105376, 2171169, 2171169, 2500134, 2631720, 2105376, 2434341, 1907997, 1052688, 1118481, 1513239, 1579032, 1579032, 1776411, 1776411, 1184274, 789516, 986895, 1184274,
986895, 855309, 789516, 1052688, 1250067, 1644825, 1776411, 1579032, 1184274, 1052688, 1052688, 986895, 1315860, 1776411, 2171169, 2171169, 2105376, 2302755, 2368548, 1315860, 592137, 1710618, 2236962, 2236962, 2171169, 2500134, 2171169, 1710618, 1315860, 1184274, 1644825, 1776411, 1776411, 1776411, 1644825, 1579032, 1184274, 921102, 855309, 1315860,
921102, 1052688, 1052688, 1184274, 1315860, 1250067, 1842204, 1776411, 1250067, 1184274, 1118481, 1052688, 986895, 1052688, 1710618, 2302755, 2302755, 2302755, 1315860, 263172, 65793, 526344, 1644825, 2368548, 2631720, 2434341, 1644825, 1052688, 1315860, 1644825, 1579032, 1710618, 1579032, 1447446, 1052688, 921102, 1315860, 1118481, 1118481, 1315860,
855309, 1184274, 1513239, 1315860, 1052688, 1118481, 1184274, 1513239, 1579032, 1381653, 1118481, 986895, 986895, 986895, 1052688, 1907997, 2302755, 1184274, 263172, 131586, 131586, 131586, 460551, 1973790, 2829099, 2171169, 1052688, 1184274, 1315860, 1381653, 1644825, 1644825, 1842204, 1250067, 986895, 1184274, 1052688, 1250067, 1513239, 1250067,
394758, 657930, 1644825, 1381653, 1315860, 1184274, 1184274, 1184274, 1315860, 1381653, 1052688, 1052688, 1052688, 1184274, 1118481, 1118481, 1052688, 328965, 131586, 197379, 131586, 131586, 197379, 592137, 2105376, 1710618, 1447446, 1184274, 1052688, 1250067, 1447446, 1579032, 1513239, 1513239, 1250067, 1513239, 1579032, 1513239, 1118481, 592137,
197379, 197379, 657930, 1381653, 1513239, 1315860, 1315860, 1250067, 789516, 855309, 1250067, 1250067, 1052688, 1513239, 1315860, 657930, 328965, 328965, 328965, 263172, 263172, 197379, 328965, 526344, 855309, 1513239, 1973790, 1710618, 1315860, 1579032, 1381653, 1184274, 1447446, 2368548, 1907997, 2105376, 2500134, 1644825, 657930, 131586,
197379, 131586, 131586, 657930, 1710618, 1776411, 1447446, 1052688, 855309, 855309, 921102, 1118481, 1579032, 1447446, 855309, 328965, 328965, 394758, 328965, 263172, 131586, 197379, 263172, 460551, 657930, 789516, 1710618, 2236962, 2105376, 1447446, 1250067, 1381653, 1776411, 2368548, 2631720, 3026478, 2236962, 789516, 263172, 131586,
197379, 197379, 131586, 197379, 1381653, 1973790, 1579032, 1184274, 1052688, 921102, 855309, 1052688, 1447446, 1052688, 328965, 131586, 328965, 460551, 460551, 328965, 131586, 263172, 197379, 328965, 460551, 460551, 921102, 2236962, 2105376, 1447446, 1118481, 1250067, 1513239, 2434341, 2302755, 2565927, 1052688, 131586, 131586, 131586,
197379, 131586, 131586, 131586, 328965, 1052688, 1447446, 1644825, 1250067, 1052688, 1184274, 1052688, 855309, 394758, 263172, 197379, 131586, 263172, 328965, 263172, 197379, 131586, 197379, 197379, 263172, 592137, 657930, 921102, 1118481, 1250067, 1118481, 1118481, 1710618, 1973790, 1250067, 855309, 263172, 131586, 197379, 131586,
};
#endif /*COLOR_DEPTH == 24*/
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_BENCHMARK != 0*/
/**
* @file lv_app_benchmark.h
*
*/
#ifndef LV_APP_BENCHMARK_H
#define LV_APP_BENCHMARK_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lvgl/lv_app/lv_app.h"
#if LV_APP_ENABLE != 0 && USE_LV_APP_BENCHMARK != 0
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct
{
}lv_app_benchmark_conf_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
const lv_app_dsc_t * lv_app_benchmark_init(void);
/**********************
* MACROS
**********************/
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_BENCHMARK != 0*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* LV_APP_BENCHMARK_H */
/**
* @file lv_app_ethernet.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_app_ethernet.h"
#if LV_APP_ENABLE != 0 && USE_LV_APP_ETHERNET != 0
#include "../lv_app/lv_app_util/lv_app_kb.h"
#include "hal/eth/eth.h"
#include "misc/os/ptask.h"
#include "hal/systick/systick.h"
#include <stdio.h>
/*********************
* DEFINES
*********************/
#define ETH_MONITOR_PERIOD 1000 /*ms*/
/**********************
* TYPEDEFS
**********************/
/*Application specific data for an instance of this application*/
typedef struct
{
uint8_t * last_msg_dp;
uint16_t last_msg_size;
}my_app_data_t;
/*Application specific data a window of this application*/
typedef struct
{
}my_win_data_t;
/*Application specific data for a shortcut of this application*/
typedef struct
{
lv_obj_t * label;
}my_sc_data_t;
/**********************
* STATIC PROTOTYPES
**********************/
static void my_app_run(lv_app_inst_t * app, void * conf);
static void my_app_close(lv_app_inst_t * app);
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec, lv_app_com_type_t type , const void * data, uint32_t size);
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 eth_state_monitor_task(void * param);
static void tcp_transf_cb(eth_state_t state, const char * txt);
/**********************
* STATIC VARIABLES
**********************/
static lv_app_dsc_t my_app_dsc =
{
.name = "Ethernet",
.mode = LV_APP_MODE_NONE,
.app_run = my_app_run,
.app_close = my_app_close,
.com_rec = my_com_rec,
.win_open = my_win_open,
.win_close = my_win_close,
.sc_open = my_sc_open,
.sc_close = my_sc_close,
.app_data_size = sizeof(my_app_data_t),
.sc_data_size = sizeof(my_sc_data_t),
.win_data_size = sizeof(my_win_data_t),
};
static lv_app_inst_t * app_act_com = NULL;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the application
* @return pointer to the application descriptor of this application
*/
const lv_app_dsc_t * lv_app_ethernet_init(void)
{
ptask_create(eth_state_monitor_task, ETH_MONITOR_PERIOD, PTASK_PRIO_LOW, NULL);
return &my_app_dsc;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Run an application according to 'app_dsc'
* @param app_dsc pointer to an application descriptor
* @param conf pointer to a lv_app_ethernet_conf_t structure with configuration data or NULL if unused
* @return pointer to the opened application or NULL if any error occurred
*/
static void my_app_run(lv_app_inst_t * app, void * conf)
{
/*Initialize the application*/
}
/**
* Close a running application.
* Close the Window and the Shortcut too if opened.
* Free all the allocated memory by this application.
* @param app pointer to an application
*/
static void my_app_close(lv_app_inst_t * app)
{
/*No dynamically allocated data in 'my_app_data'*/
}
/**
* Read the data have been sent to this application
* @param app_send pointer to an application which sent the message
* @param app_rec pointer to an application which is receiving the message
* @param type type of data from 'lv_app_com_type_t' enum
* @param data pointer to the sent data
* @param size length of 'data' in bytes
*/
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec,
lv_app_com_type_t type , const void * data, uint32_t size)
{
if(type == LV_APP_COM_TYPE_CHAR) { /*data: string*/
eth_tcp_transf(data, size, tcp_transf_cb);
app_act_com = app_rec;
my_app_data_t * adata = app_act_com->app_data;
if(adata->last_msg_dp != NULL) dm_free(adata->last_msg_dp);
adata->last_msg_dp = dm_alloc(size);
memcpy(adata->last_msg_dp, data, size);
adata->last_msg_size = size;
}
}
/**
* Open a shortcut for an application
* @param app pointer to an application
* @param sc pointer to an object where the application
* can create content of the shortcut
*/
static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc)
{
my_sc_data_t * sc_data = app->sc_data;
sc_data->label = lv_label_create(sc, NULL);
lv_label_set_text(sc_data->label, "Empty");
lv_obj_align(sc_data->label, NULL, LV_ALIGN_CENTER, 0, 0);
}
/**
* Close the shortcut of an application
* @param app pointer to an application
*/
static void my_sc_close(lv_app_inst_t * app)
{
/*No dynamically allocated data in 'my_sc_data'*/
}
/**
* Open the application in a window
* @param app pointer to an application
* @param win pointer to a window object where
* the application can create content
*/
static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
{
}
/**
* Close the window of an application
* @param app pointer to an application
*/
static void my_win_close(lv_app_inst_t * app)
{
}
/*--------------------
* OTHER FUNCTIONS
---------------------*/
static void eth_state_monitor_task(void * param)
{
/* The eth. should be busy if there is sg. to send.
* It means fail during last send. Try again*/
if(app_act_com != NULL && eth_busy() == false) {
/*Try to send the message again*/
lv_app_notice_add("Resend Ethernet message");
my_app_data_t * adata = app_act_com->app_data;
eth_tcp_transf(adata->last_msg_dp, adata->last_msg_size, tcp_transf_cb);
}
}
static void tcp_transf_cb(eth_state_t state, const char * txt)
{
if(state == ETH_STATE_OK) {
uint16_t size = txt[0] + ((txt[1] << 8) & 0xFF00);
char buf[256];
memcpy(buf, &txt[2], size);
buf[size] = '\0';
lv_app_com_send(app_act_com, LV_APP_COM_TYPE_CHAR, &txt[2], size);
my_app_data_t * adata = app_act_com->app_data;
dm_free(adata->last_msg_dp);
adata->last_msg_dp = NULL;
adata->last_msg_size = 0;
app_act_com = NULL;
}else if(state == ETH_STATE_ERROR) {
lv_app_notice_add("Ethernet TCP transfer error\n%s", txt);
}
}
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_ETHERNET != 0*/
/**
* @file lv_app_ethernet.h
*
*/
#ifndef LV_APP_ETHERNET_H
#define LV_APP_ETHERNET_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lvgl/lv_app/lv_app.h"
#if LV_APP_ENABLE != 0 && USE_LV_APP_ETHERNET != 0
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct
{
}lv_app_ethernet_conf_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
const lv_app_dsc_t * lv_app_ethernet_init(void);
/**********************
* MACROS
**********************/
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_ETHERNET != 0*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* LV_APP_ETHERNET_H */
/**
* @file lv_app_example.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_app_example.h"
#if LV_APP_ENABLE != 0 && USE_LV_APP_EXAMPLE != 0
#include "../lv_app/lv_app_util/lv_app_kb.h"
#include <stdio.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Application specific data for an instance of this application*/
typedef struct
{
}my_app_data_t;
/*Application specific data a window of this application*/
typedef struct
{
}my_win_data_t;
/*Application specific data for a shortcut of this application*/
typedef struct
{
lv_obj_t * label;
}my_sc_data_t;
/**********************
* STATIC PROTOTYPES
**********************/
static void my_app_run(lv_app_inst_t * app, void * conf);
static void my_app_close(lv_app_inst_t * app);
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec, lv_app_com_type_t type , const void * data, uint32_t size);
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 lv_action_res_t ta_rel_action(lv_obj_t * ta, lv_indev_proc_t * indev_proc);
static void kb_ok_action(lv_obj_t * ta);
/**********************
* STATIC VARIABLES
**********************/
static lv_app_dsc_t my_app_dsc =
{
.name = "Example",
.mode = LV_APP_MODE_NONE,
.app_run = my_app_run,
.app_close = my_app_close,
.com_rec = my_com_rec,
.win_open = my_win_open,
.win_close = my_win_close,
.sc_open = my_sc_open,
.sc_close = my_sc_close,
.app_data_size = sizeof(my_app_data_t),
.sc_data_size = sizeof(my_sc_data_t),
.win_data_size = sizeof(my_win_data_t),
};
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the application
* @return pointer to the application descriptor of this application
*/
const lv_app_dsc_t * lv_app_example_init(void)
{
return &my_app_dsc;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Run an application according to 'app_dsc'
* @param app_dsc pointer to an application descriptor
* @param conf pointer to a lv_app_example_conf_t structure with configuration data or NULL if unused
* @return pointer to the opened application or NULL if any error occurred
*/
static void my_app_run(lv_app_inst_t * app, void * conf)
{
/*Initialize the application*/
}
/**
* Close a running application.
* Close the Window and the Shortcut too if opened.
* Free all the allocated memory by this application.
* @param app pointer to an application
*/
static void my_app_close(lv_app_inst_t * app)
{
/*No dynamically allocated data in 'my_app_data'*/
}
/**
* Read the data have been sent to this application
* @param app_send pointer to an application which sent the message
* @param app_rec pointer to an application which is receiving the message
* @param type type of data from 'lv_app_com_type_t' enum
* @param data pointer to the sent data
* @param size length of 'data' in bytes
*/
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec,
lv_app_com_type_t type , const void * data, uint32_t size)
{
if(type == LV_APP_COM_TYPE_CHAR) { /*data: string*/
my_sc_data_t * sc_data = app_rec->sc_data;
if (sc_data->label != NULL) {
lv_label_set_text_array(sc_data->label, data, size);
lv_obj_align(sc_data->label , NULL,LV_ALIGN_CENTER, 0, 0);
}
}
}
/**
* Open a shortcut for an application
* @param app pointer to an application
* @param sc pointer to an object where the application
* can create content of the shortcut
*/
static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc)
{
my_sc_data_t * sc_data = app->sc_data;
sc_data->label = lv_label_create(sc, NULL);
lv_label_set_text(sc_data->label, "Empty");
lv_obj_align(sc_data->label, NULL, LV_ALIGN_CENTER, 0, 0);
}
/**
* Close the shortcut of an application
* @param app pointer to an application
*/
static void my_sc_close(lv_app_inst_t * app)
{
/*No dynamically allocated data in 'my_sc_data'*/
}
/**
* Open the application in a window
* @param app pointer to an application
* @param win pointer to a window object where
* the application can create content
*/
static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
{
lv_obj_t * ta;
ta = lv_ta_create(win, NULL);
lv_obj_set_size_us(ta, 200, 100);
lv_obj_set_pos_us(ta, 0, 0);
lv_obj_set_free_p(ta, app);
lv_page_set_rel_action(ta, ta_rel_action);
lv_ta_set_text(ta, "Write a text to send to the other applications");
}
/**
* Close the window of an application
* @param app pointer to an application
*/
static void my_win_close(lv_app_inst_t * app)
{
}
/*--------------------
* OTHER FUNCTIONS
---------------------*/
/**
* Called when the text area on the window is released to open the app. keyboard
* @param ta pointer to the text area on the window
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_OK because the text area is not deleted
*/
static lv_action_res_t ta_rel_action(lv_obj_t * ta, lv_indev_proc_t * indev_proc)
{
lv_ta_set_text(ta, ""); /*Clear the ta*/
lv_app_kb_open(ta, LV_APP_KB_MODE_TXT | LV_APP_KB_MODE_WIN_RESIZE, NULL, kb_ok_action);
return LV_ACTION_RES_OK;
}
/**
* Called when the "Ok" button is pressed on the app. keyboard
* @param ta pointer to the text area assigned to the app. kexboard
*/
static void kb_ok_action(lv_obj_t * ta)
{
lv_app_inst_t * app = lv_obj_get_free_p(ta);
const char * txt = lv_ta_get_txt(ta);
lv_app_com_send(app, LV_APP_COM_TYPE_CHAR, txt, strlen(txt));
}
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_EXAMPLE != 0*/
/**
* @file lv_app_example.h
*
*/
#ifndef LV_APP_EXAMPLE_H
#define LV_APP_EXAMPLE_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lvgl/lv_app/lv_app.h"
#if LV_APP_ENABLE != 0 && USE_LV_APP_EXAMPLE != 0
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct
{
}lv_app_example_conf_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
const lv_app_dsc_t * lv_app_example_init(void);
/**********************
* MACROS
**********************/
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_EXAMPLE != 0*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* LV_APP_EXAMPLE_H */
/**
* @file lv_app_example.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_app_files.h"
#if LV_APP_ENABLE != 0 && USE_LV_APP_FILES != 0
#include <stdio.h>
#include "misc/os/ptask.h"
#include "../lv_app/lv_app_util/lv_app_kb.h"
#include "../lv_app/lv_app_util/lv_app_notice.h"
/*********************
* DEFINES
*********************/
#define LV_APP_FILES_CHUNK_MIN_SIZE 32
#define LV_APP_FILES_CHUNK_MIN_TIME 10
#define LV_APP_FILES_CHUNK_MAX_TIME 10000
/**********************
* TYPEDEFS
**********************/
/*Application specific data for an instance of this application*/
typedef struct
{
char path[LV_APP_FILES_PATH_MAX_LEN];
char fn[LV_APP_FILES_FN_MAX_LEN];
fs_file_t file;
uint8_t file_cnt;
uint16_t chunk_delay;
uint16_t chunk_size;
uint8_t send_fn :1;
uint8_t send_size :1;
uint8_t send_crc :1;
uint8_t send_in_prog :1;
ptask_t * send_task;
}my_app_data_t;
/*Application specific data a window of this application*/
typedef struct
{
lv_obj_t * file_list;
}my_win_data_t;
/*Application specific data for a shortcut of this application*/
typedef struct
{
lv_obj_t * label;
}my_sc_data_t;
typedef enum
{
SEND_SETTINGS_FN,
SEND_SETTINGS_SIZE,
SEND_SETTINGS_CRC,
SEND_SETTINGS_CHUNK_SIZE,
SEND_SETTINGS_CHUNK_DELAY,
}send_settings_id_t;
/**********************
* STATIC PROTOTYPES
**********************/
static void my_app_run(lv_app_inst_t * app, void * conf);
static void my_app_close(lv_app_inst_t * app);
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec, lv_app_com_type_t type , const void * data, uint32_t size);
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);
static lv_action_res_t win_up_action(lv_obj_t * up, lv_indev_proc_t * indev_proc);
static lv_action_res_t win_next_action(lv_obj_t * next, lv_indev_proc_t * indev_proc);
static lv_action_res_t win_prev_action(lv_obj_t * prev, lv_indev_proc_t * indev_proc);
static lv_action_res_t win_drv_action(lv_obj_t * drv, lv_indev_proc_t * indev_proc);
static lv_action_res_t win_folder_action(lv_obj_t * folder, lv_indev_proc_t * indev_proc);
static lv_action_res_t win_file_action(lv_obj_t * file, lv_indev_proc_t * indev_proc);
static lv_action_res_t win_send_rel_action(lv_obj_t * send, lv_indev_proc_t * indev_proc);
static lv_action_res_t win_send_settings_element_rel_action(lv_obj_t * element, lv_indev_proc_t * indev_proc);
static lv_action_res_t win_back_action(lv_obj_t * back, lv_indev_proc_t * indev_proc);
static lv_action_res_t win_del_rel_action(lv_obj_t * del, lv_indev_proc_t * indev_proc);
static lv_action_res_t win_del_lpr_action(lv_obj_t * del, lv_indev_proc_t * indev_proc);
static void send_settings_kb_close_action(lv_obj_t * ta);
static void send_settings_kb_ok_action(lv_obj_t * ta);
static void start_send(lv_app_inst_t * app, const char * path);
static void send_task(void * param);
/**********************
* STATIC VARIABLES
**********************/
static lv_app_dsc_t my_app_dsc =
{
.name = "Files",
.mode = LV_APP_MODE_NONE,
.app_run = my_app_run,
.app_close = my_app_close,
.com_rec = my_com_rec,
.win_open = my_win_open,
.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),
};
static lv_style_t style_sc_label;
static lv_style_t style_btn_symbol;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the application
* @return pointer to the application descriptor of this application
*/
const lv_app_dsc_t * lv_app_files_init(void)
{
lv_app_style_t * app_style = lv_app_style_get();
memcpy(&style_sc_label, &app_style->sc_rec_rel, sizeof(lv_style_t));
style_sc_label.font = font_get(LV_APP_FONT_LARGE);
lv_style_get(LV_STYLE_BTN_REL, &style_btn_symbol);
style_btn_symbol.font = font_get(LV_IMG_DEF_SYMBOL_FONT);
return &my_app_dsc;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Run an application according to 'app_dsc'
* @param app_dsc pointer to an application descriptor
* @param conf pointer to a lv_app_example_conf_t structure with configuration data or NULL if unused
* @return pointer to the opened application or NULL if any error occurred
*/
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->file_cnt = 0;
app_data->path[0] = '\0';
app_data->fn[0] = '\0';
app_data->send_fn = 0;
app_data->send_size = 0;
app_data->send_crc = 0;
app_data->chunk_size = LV_APP_FILES_CHUNK_DEF_SIZE;
app_data->chunk_delay = LV_APP_FILES_CHUNK_DEF_TIME;
app_data->send_in_prog = 0;
app_data->send_task = ptask_create(send_task, LV_APP_FILES_CHUNK_DEF_TIME, PTASK_PRIO_OFF, app);
}
/**
* Close a running application.
* Close the Window and the Shortcut too if opened.
* Free all the allocated memory by this application.
* @param app pointer to an application
*/
static void my_app_close(lv_app_inst_t * app)
{
/*No dynamically allocated data in 'my_app_data'*/
my_app_data_t * app_data = app->app_data;
ptask_del(app_data->send_task);
if(app_data->send_in_prog != 0) fs_close(&app_data->file);
}
/**
* Read the data have been sent to this application
* @param app_send pointer to an application which sent the message
* @param app_rec pointer to an application which is receiving the message
* @param type type of data from 'lv_app_com_type_t' enum
* @param data pointer to the sent data
* @param size length of 'data' in bytes
*/
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec,
lv_app_com_type_t type , const void * data, uint32_t size)
{
if(type == LV_APP_COM_TYPE_CHAR) {
/*Check for file query. E.g. "U:/file.txt?"*/
const char * path = data;
if(path[size - 1] == '?') {
if(size > LV_APP_FILES_PATH_MAX_LEN + LV_APP_FILES_FN_MAX_LEN) {
lv_app_notice_add("Can not send file:\ntoo long path");
}
char path_fn[LV_APP_FILES_PATH_MAX_LEN + LV_APP_FILES_FN_MAX_LEN];
memcpy(path_fn, data, size - 1); /*-1 to ignore the '?' at the end*/
path_fn[size - 1] = '\0';
start_send(app_rec, path_fn);
}
}
}
/**
* Open a shortcut for an application
* @param app pointer to an application
* @param sc pointer to an object where the application
* can create content of the shortcut
*/
static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc)
{
my_sc_data_t * sc_data = app->sc_data;
my_app_data_t * app_data = app->app_data;
sc_data->label = lv_label_create(sc, NULL);
lv_obj_set_style(sc_data->label, &style_sc_label);
lv_label_set_text(sc_data->label, fs_get_last(app_data->path));
lv_obj_align(sc_data->label, NULL, LV_ALIGN_CENTER, 0, 0);
}
/**
* Close the shortcut of an application
* @param app pointer to an application
*/
static void my_sc_close(lv_app_inst_t * app)
{
/*No dynamically allocated data in 'my_sc_data'*/
}
/**
* Open the application in a window
* @param app pointer to an application
* @param win pointer to a window object where
* the application can create content
*/
static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
{
my_win_data_t * win_data = app->win_data;
my_app_data_t * app_data = app->app_data;
app_data->file_cnt = 0;
win_data->file_list = NULL;
lv_win_set_title(win, app_data->path);
win_load_file_list(app);
}
/**
* Close the window of an application
* @param app pointer to an application
*/
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_TREL);
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_TREL);
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_TREL);
else lv_btn_set_state(cb, LV_BTN_STATE_REL);
/*Create a text area to type chunk size*/
lv_obj_t * val_set_h;
val_set_h = lv_cont_create(conf_win, NULL);
lv_obj_set_style(val_set_h, lv_style_get(LV_STYLE_PLAIN_COLOR, NULL));
lv_obj_set_click(val_set_h, false);
lv_cont_set_fit(val_set_h, true, true);
lv_cont_set_layout(val_set_h, LV_CONT_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_cont_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_cont_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
---------------------*/
/**
* Create an mpty list on the window. 'win_load_file_list' will fill it.
* @param app pointer to a Files application
*/
static void win_create_list(lv_app_inst_t * app)
{
my_win_data_t * win_data = app->win_data;
/*Delete the previous list*/
if(win_data->file_list != NULL) {
lv_obj_del(win_data->file_list);
}
/*Create a new list*/
win_data->file_list = lv_list_create(app->win, NULL);
lv_obj_set_width(win_data->file_list, lv_win_get_width(app->win));
lv_list_set_style_img(win_data->file_list, &style_btn_symbol);
lv_obj_set_style(lv_page_get_scrl(win_data->file_list), lv_style_get(LV_STYLE_TRANSP_TIGHT, NULL));
lv_obj_set_drag_parent(win_data->file_list, true);
lv_obj_set_drag_parent(lv_page_get_scrl(win_data->file_list), true);
lv_cont_set_fit(win_data->file_list, false, true);
lv_cont_set_layout(lv_page_get_scrl(win_data->file_list), LV_CONT_LAYOUT_COL_L);
}
/**
* Load the file list from the current path on the window
* @param app pointer to a Files application
*/
static void win_load_file_list(lv_app_inst_t * app)
{
my_app_data_t * app_data = app->app_data;
my_win_data_t * win_data = app->win_data;
/*Create a new list*/
win_create_list(app);
fs_res_t res = FS_RES_OK;
/*At empty path show the drivers */
lv_obj_t * liste;
if(app_data->path[0] == '\0') {
char drv[16];
char buf[2];
fs_get_letters(drv);
uint8_t i;
for(i = 0; drv[i] != '\0'; i++) {
buf[0] = drv[i];
buf[1] = '\0';
liste = lv_list_add(win_data->file_list, SYMBOL_DRIVE, buf, win_drv_action);
lv_obj_set_free_p(liste, app);
}
}
/*List the files/folders with fs interface*/
else {
liste = lv_list_add(win_data->file_list, SYMBOL_UP, "Up", win_up_action);
lv_obj_set_free_p(liste, app);
fs_readdir_t rd;
res = fs_readdir_init(&rd, app_data->path);
if(res != FS_RES_OK) {
lv_app_notice_add("Can not read the\npath in Files");
return;
}
/*At not first page add prev. page button */
if(app_data->file_cnt != 0) {
liste = lv_list_add(win_data->file_list, SYMBOL_LEFT, "Previous page", win_prev_action);
lv_obj_set_free_p(liste, app);
}
char fn[LV_APP_FILES_FN_MAX_LEN];
/*Read the files from the previous pages*/
uint16_t file_cnt = 0;
while(file_cnt <= app_data->file_cnt) {
res = fs_readdir(&rd, fn);
if(res != FS_RES_OK ){
lv_app_notice_add("Can not read\nthe path in Files");
return;
}
file_cnt ++;
}
/*Add list elements from the files and folders*/
while(res == FS_RES_OK && fn[0] != '\0') {
if(fn[0] == '/') { /*Add a folder*/
lv_obj_t * liste;
liste = lv_list_add(win_data->file_list, SYMBOL_FOLDER, &fn[1], win_folder_action);
lv_obj_set_free_p(liste, app);
app_data->file_cnt ++;
}
/*Add a file*/
else {
liste = lv_list_add(win_data->file_list, SYMBOL_FILE, fn, win_file_action);
lv_obj_set_free_p(liste, app);
app_data->file_cnt ++;
}
/*Get the next element*/
res = fs_readdir(&rd, fn);
/*Show only LV_APP_FSEL_MAX_FILE elements and add a Next page button*/
if(app_data->file_cnt != 0 && app_data->file_cnt % LV_APP_FILES_PAGE_SIZE == 0) {
liste = lv_list_add(win_data->file_list, SYMBOL_RIGHT, "Next page", win_next_action);
lv_obj_set_free_p(liste, app);
break;
}
}
/*Close the read directory*/
fs_readdir_close(&rd);
}
if(res != FS_RES_OK) {
lv_app_notice_add("Can not read\nthe path in Files");
}
/*Focus to the top of the list*/
lv_obj_set_y(lv_page_get_scrl(win_data->file_list), 0);
return;
}
/**
* Called when the Up list element is released to step one level
* @param up pointer to the Up button
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_INV because the list is deleted in the function
*/
static lv_action_res_t win_up_action(lv_obj_t * up, lv_indev_proc_t * indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(up);
my_app_data_t * app_data = app->app_data;
fs_up(app_data->path);
app_data->file_cnt = 0;
lv_win_set_title(app->win, app_data->path);
my_sc_data_t * sc_data = app->sc_data;
if(sc_data != NULL) {
lv_label_set_text(sc_data->label, fs_get_last(app_data->path));
lv_obj_align(sc_data->label, NULL, LV_ALIGN_CENTER, 0, 0);
}
win_load_file_list(app);
return LV_ACTION_RES_INV;
}
/**
* Called when the Next list element is released to go to the next page
* @param next pointer to the Next button
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_INV because the list is deleted in the function
*/
static lv_action_res_t win_next_action(lv_obj_t * next, lv_indev_proc_t * indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(next);
win_load_file_list(app);
return LV_ACTION_RES_INV;
}
/**
* Called when the Prev list element is released to previous page
* @param prev pointer to the Prev button
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_INV because the list is deleted in the function
*/
static lv_action_res_t win_prev_action(lv_obj_t * prev, lv_indev_proc_t * indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(prev);
my_app_data_t * app_data = app->app_data;
if(app_data->file_cnt <= 2 * LV_APP_FILES_PAGE_SIZE) app_data->file_cnt = 0;
else if(app_data->file_cnt % LV_APP_FILES_PAGE_SIZE == 0) {
app_data->file_cnt -= 2 * LV_APP_FILES_PAGE_SIZE;
} else {
app_data->file_cnt = ((app_data->file_cnt / LV_APP_FILES_PAGE_SIZE) - 1) * LV_APP_FILES_PAGE_SIZE;
}
win_load_file_list(app);
return LV_ACTION_RES_INV;
}
/**
* Called when the Driver list element is released to step into a driver
* @param drv pointer to the Driver button
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_INV because the list is deleted in the function
*/
static lv_action_res_t win_drv_action(lv_obj_t * drv, lv_indev_proc_t * indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(drv);
my_app_data_t * app_data = app->app_data;
sprintf(app_data->path, "%s:", lv_list_get_element_text(drv));
app_data->file_cnt = 0;
lv_win_set_title(app->win, app_data->path);
my_sc_data_t * sc_data = app->sc_data;
if(sc_data != NULL) {
lv_label_set_text(sc_data->label, fs_get_last(app_data->path));
lv_obj_align(sc_data->label, NULL, LV_ALIGN_CENTER, 0, 0);
}
win_load_file_list(app);
return LV_ACTION_RES_INV;
}
/**
* Called when a folder list element is released to enter into it
* @param folder pointer to a folder button
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_INV because the list is deleted in the function
*/
static lv_action_res_t win_folder_action(lv_obj_t * folder, lv_indev_proc_t * indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(folder);
my_app_data_t * app_data = app->app_data;
sprintf(app_data->path, "%s/%s", app_data->path, lv_list_get_element_text(folder));
app_data->file_cnt = 0;
lv_win_set_title(app->win, app_data->path);
my_sc_data_t * sc_data = app->sc_data;
if(sc_data != NULL) {
lv_label_set_text(sc_data->label, fs_get_last(app_data->path));
lv_obj_align(sc_data->label, NULL, LV_ALIGN_CENTER, 0, 0);
}
win_load_file_list(app);
return LV_ACTION_RES_INV;
}
/**
* Called when a file list element is released to show the list of operation on it
* @param file pointer to a file button
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_INV because the list is deleted in the function
*/
static lv_action_res_t win_file_action(lv_obj_t * file, lv_indev_proc_t * indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(file);
my_app_data_t * app_data = app->app_data;
my_win_data_t * win_data = app->win_data;
sprintf(app_data->fn, "%s", lv_list_get_element_text(file));
win_create_list(app);
/*Create the list of operations*/
lv_obj_t * liste;
liste = lv_list_add(win_data->file_list, SYMBOL_LEFT, "Back", win_back_action);
lv_obj_set_free_p(liste, app);
/*Send button*/
liste = lv_list_add(win_data->file_list, NULL, "Send", win_send_rel_action);
lv_obj_set_free_p(liste, app);
/*Delete button*/
liste = lv_list_add(win_data->file_list, NULL, "Delete", win_del_rel_action);
lv_btn_set_lpr_action(liste, win_del_lpr_action);
lv_obj_set_free_p(liste, app);
return LV_ACTION_RES_INV;
}
/**
* Called when the Back list element is released to when a file chosen to
* go back to the file list from file operation
* @param back pointer to the back button
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_INV because the list is deleted in the function
*/
static lv_action_res_t win_back_action(lv_obj_t * up, lv_indev_proc_t * indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(up);
my_app_data_t * app_data = app->app_data;
app_data->file_cnt = 0;
win_load_file_list(app);
return LV_ACTION_RES_INV;
}
/**
* Called when the Send list element is released to send the file
* @param sed pointer to the Up button
* @param indev_proc 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_rel_action(lv_obj_t * send, lv_indev_proc_t * indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(send);
my_app_data_t * app_data = app->app_data;
if(app_data->send_in_prog != 0) {
lv_app_notice_add("File sending\nin progress");
return LV_ACTION_RES_OK;
}
char path_fn[LV_APP_FILES_PATH_MAX_LEN + LV_APP_FILES_FN_MAX_LEN];
sprintf(path_fn, "%s/%s", app_data->path, app_data->fn);
start_send(app, path_fn);
return LV_ACTION_RES_OK;
}
/**
* Called when a send settings element is released
* @param element pointer to a chekbox or text area
* @param indev_proc 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_settings_element_rel_action(lv_obj_t * element, lv_indev_proc_t * indev_proc)
{
send_settings_id_t id = lv_obj_get_free_num(element);
lv_app_inst_t * app = lv_obj_get_free_p(element);
my_app_data_t * app_data = app->app_data;
if(id == SEND_SETTINGS_FN) {
app_data->send_fn = lv_btn_get_state(element) == LV_BTN_STATE_REL ? 0 : 1;
} else if(id == SEND_SETTINGS_SIZE) {
app_data->send_size = lv_btn_get_state(element) == LV_BTN_STATE_REL ? 0 : 1;
} else if(id == SEND_SETTINGS_CRC) {
app_data->send_crc = lv_btn_get_state(element) == LV_BTN_STATE_REL ? 0 : 1;
/*TODO CRC sending is not supported yet*/
if(app_data->send_crc != 0) {
lv_app_notice_add("CRC sending is\nnot supported yet");
}
} else if(id == SEND_SETTINGS_CHUNK_SIZE) {
lv_app_kb_open(element, LV_APP_KB_MODE_NUM | LV_APP_KB_MODE_WIN_RESIZE, send_settings_kb_close_action, send_settings_kb_ok_action);
} else if(id == SEND_SETTINGS_CHUNK_DELAY) {
lv_app_kb_open(element, LV_APP_KB_MODE_NUM | LV_APP_KB_MODE_WIN_RESIZE, send_settings_kb_close_action, send_settings_kb_ok_action);
}
return LV_ACTION_RES_OK;
}
/**
* Called when the Delete list element is released.
* It will show a notification to long press the Delete button to remove the file
* @param del pointer to the back button
* @param indev_proc 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_del_rel_action(lv_obj_t * del, lv_indev_proc_t * indev_proc)
{
lv_app_notice_add("Press long the Delete button\n"
"to remove the file");
return LV_ACTION_RES_OK;
}
/**
* Called when the Delete list element is long pressed to remove a file
* @param del pointer to the Delete button
* @param indev_proc 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_del_lpr_action(lv_obj_t * del, lv_indev_proc_t * indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(del);
my_app_data_t * app_data = app->app_data;
char path_fn[LV_APP_FILES_PATH_MAX_LEN + LV_APP_FILES_FN_MAX_LEN];
sprintf(path_fn, "%s/%s", app_data->path, app_data->fn);
fs_res_t res = fs_remove(path_fn);
if(res == FS_RES_OK) lv_app_notice_add("%s deleted", app_data->fn);
else lv_app_notice_add("Can not delete\n%s", app_data->fn);
return LV_ACTION_RES_OK;
}
/**
* Called when a send setting is typed and 'Close' pressed on the App. keyboard.
* The function reverts the original value in the text area.
* @param ta pointer to a text area
*/
static void send_settings_kb_close_action(lv_obj_t * ta)
{
send_settings_id_t id = lv_obj_get_free_num(ta);
lv_app_inst_t * app = lv_obj_get_free_p(ta);
my_app_data_t * app_data = app->app_data;
char buf[32];
buf[0] = '\0';
if(id == SEND_SETTINGS_CHUNK_DELAY) {
sprintf(buf, "%d", app_data->chunk_size);
} else if(id == SEND_SETTINGS_CHUNK_SIZE) {
sprintf(buf, "%d", app_data->chunk_size);
}
lv_ta_set_text(ta, buf);
}
/**
* Called when a send setting is typed and 'Ok' pressed on the App. keyboard.
* The function saves teh new value.
* @param ta pointer to a text area
*/
static void send_settings_kb_ok_action(lv_obj_t * ta)
{
send_settings_id_t id = lv_obj_get_free_num(ta);
lv_app_inst_t * app = lv_obj_get_free_p(ta);
my_app_data_t * app_data = app->app_data;
int num;
sscanf(lv_ta_get_txt(ta), "%d", &num);
if(id == SEND_SETTINGS_CHUNK_DELAY) {
if(num > LV_APP_FILES_CHUNK_MAX_TIME) num = LV_APP_FILES_CHUNK_MAX_TIME;
if(num < LV_APP_FILES_CHUNK_MIN_TIME) num = LV_APP_FILES_CHUNK_MIN_TIME;
app_data->chunk_delay = (uint16_t) num;
} else if(id == SEND_SETTINGS_CHUNK_SIZE) {
if(num > LV_APP_FILES_CHUNK_MAX_SIZE) num = LV_APP_FILES_CHUNK_MAX_SIZE;
if(num < LV_APP_FILES_CHUNK_MIN_SIZE) num = LV_APP_FILES_CHUNK_MIN_SIZE;
app_data->chunk_size= (uint16_t) num;
}
}
/**
* Start the sending of a file
* @param app pointer to a Files application
* @param path path of the file to send
*/
static void start_send(lv_app_inst_t * app, const char * path)
{
my_app_data_t * app_data = app->app_data;
/*Open the file*/
fs_res_t res = fs_open(&app_data->file, path, FS_MODE_RD);
if(res == FS_RES_OK) {
app_data->send_in_prog = 1;
/*Send the header*/
if(app_data->send_fn != 0) {
lv_app_com_send(app, LV_APP_COM_TYPE_CHAR, app_data->path, strlen(app_data->path));
lv_app_com_send(app, LV_APP_COM_TYPE_CHAR, "/", 1);
lv_app_com_send(app, LV_APP_COM_TYPE_CHAR, app_data->fn, strlen(app_data->fn));
lv_app_com_send(app, LV_APP_COM_TYPE_CHAR, "\n", 1);
}
if(app_data->send_size != 0) {
char buf[64];
uint32_t size;
fs_size(&app_data->file, &size);
sprintf(buf,"%d", (int) size);
lv_app_com_send(app, LV_APP_COM_TYPE_CHAR, buf, strlen(buf));
lv_app_com_send(app, LV_APP_COM_TYPE_CHAR, "\n", 1);
}
if(app_data->send_crc != 0) {
lv_app_com_send(app, LV_APP_COM_TYPE_CHAR, "0x0000", 6);
lv_app_com_send(app, LV_APP_COM_TYPE_CHAR, "\n", 1);
}
/*Add an extra \n to separate the header from the file data*/
if(app_data->send_fn != 0 || app_data->send_size != 0 || app_data->send_crc != 0) {
lv_app_com_send(app, LV_APP_COM_TYPE_CHAR, "\n", 1);
}
}
/*If an error occurred close the file*/
if(res != FS_RES_OK) {
fs_close(&app_data->file);
ptask_set_prio(app_data->send_task, PTASK_PRIO_OFF);
app_data->send_in_prog = 0;
lv_app_notice_add("Can not send\nthe file in Files");
}
/*If no error show notification, start the sender task and refresh the shortcut*/
else {
/*Start the sender task*/
ptask_set_period(app_data->send_task, app_data->chunk_delay);
ptask_reset(app_data->send_task);
ptask_set_prio(app_data->send_task, PTASK_PRIO_HIGH);
lv_app_notice_add("Sending\n%s", fs_get_last(path));
/*Refresh the shortcut with the percentage of the sending*/
if(app->sc_data != NULL) {
my_sc_data_t * sc_data = app->sc_data;
uint32_t size;
fs_size(&app_data->file, &size);
uint32_t pos;
fs_tell(&app_data->file, &pos);
int pct = (uint32_t) (pos * 100) / size;
char buf[256];
sprintf(buf, "Sending\n%d%%", pct);
lv_label_set_text(sc_data->label, buf);
lv_obj_align(sc_data->label, NULL, LV_ALIGN_CENTER, 0, 0);
}
}
}
/**
* Periodically send the next chunk of the file
* @param app pointer to a Files application
*/
static void send_task(void * param)
{
lv_app_inst_t * app = param;
my_app_data_t * app_data = app->app_data;
if(app_data->send_in_prog == 0) return;
/*Read a chunk*/
uint32_t rn;
char rd_buf[LV_APP_FILES_CHUNK_MAX_SIZE];
fs_res_t res = fs_read(&app_data->file, rd_buf, app_data->chunk_size, &rn);
if(res == FS_RES_OK) {
app_data->send_in_prog = 1;
lv_app_com_send(app, LV_APP_COM_TYPE_CHAR, rd_buf, rn);
}
/*If the read failed close the file and show an error*/
if(res != FS_RES_OK) {
fs_close(&app_data->file);
app_data->send_in_prog = 0;
lv_app_notice_add("Can not send\nthe file in Files");
}
/*If the read was successful*/
else {
my_sc_data_t * sc_data = app->sc_data;
/*If the file is read close it a show a notification*/
if(rn < app_data->chunk_size) {
lv_app_notice_add("File sent");
fs_close(&app_data->file);
app_data->send_in_prog = 0;
/*Refresh the shortut*/
if(sc_data != NULL) {
lv_label_set_text(sc_data->label, fs_get_last(app_data->path));
lv_obj_align(sc_data->label, NULL, LV_ALIGN_CENTER, 0, 0);
}
}
/*If the file is not sent yet refresh the shortcut with percentage of sending*/
else {
if(sc_data != NULL) {
uint32_t size;
fs_size(&app_data->file, &size);
uint32_t pos;
fs_tell(&app_data->file, &pos);
uint8_t pct = (uint32_t) (pos * 100) / size;
char buf[256];
sprintf(buf, "Sending\n%d%%", pct);
lv_label_set_text(sc_data->label, buf);
lv_obj_align(sc_data->label, NULL, LV_ALIGN_CENTER, 0, 0);
}
}
}
}
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_FILES != 0*/
/**
* @file lv_app_files.h
*
*/
#ifndef LV_APP_FILES_H
#define LV_APP_FILES_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lvgl/lv_app/lv_app.h"
#if LV_APP_ENABLE != 0 && USE_LV_APP_FILES != 0
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct
{
}lv_app_files_conf_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
const lv_app_dsc_t * lv_app_files_init(void);
/**********************
* MACROS
**********************/
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_FILES != 0*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* LV_APP_EXAMPLE_H */
/**
* @file lv_app_gsm.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_app_gsm.h"
#if LV_APP_ENABLE != 0 && USE_LV_APP_GSM != 0
#include "../lv_app/lv_app_util/lv_app_kb.h"
#include "hal/gsm/gsm.h"
#include "misc/os/ptask.h"
#include "hal/systick/systick.h"
#include "misc/comm/gsmmng.h"
#include <stdio.h>
/*********************
* DEFINES
*********************/
#define GSM_MONITOR_PERIOD 1000 /*ms*/
/**********************
* TYPEDEFS
**********************/
/*Application specific data for an instance of this application*/
typedef struct
{
char set_apn[128];
char set_ip[32];
char set_port[16];
uint8_t * last_msg_dp;
uint16_t last_msg_size;
}my_app_data_t;
/*Application specific data a window of this application*/
typedef struct
{
lv_obj_t * title;
lv_obj_t * netw_apn_ta;
lv_obj_t * tcp_ip_ta;
lv_obj_t * tcp_port_ta;
}my_win_data_t;
/*Application specific data for a shortcut of this application*/
typedef struct
{
lv_obj_t * label;
}my_sc_data_t;
/**********************
* STATIC PROTOTYPES
**********************/
static void my_app_run(lv_app_inst_t * app, void * conf);
static void my_app_close(lv_app_inst_t * app);
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec, lv_app_com_type_t type , const void * data, uint32_t size);
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 gsm_state_monitor_task(void * param);
static lv_action_res_t netw_con_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc);
static lv_action_res_t netw_apn_rel_action( lv_obj_t * ta, lv_indev_proc_t * indev_proc);
static lv_action_res_t tcp_ip_rel_action( lv_obj_t * ta, lv_indev_proc_t * indev_proc);
static lv_action_res_t tcp_port_rel_action( lv_obj_t * ta, lv_indev_proc_t * indev_proc);
static void netw_apn_kb_ok(lv_obj_t * ta);
static void netw_apn_kb_close(lv_obj_t * ta);
static void tcp_ip_kb_ok(lv_obj_t * ta);
static void tcp_ip_kb_close(lv_obj_t * ta);
static void tcp_port_kb_ok(lv_obj_t * ta);
static void tcp_port_kb_close(lv_obj_t * ta);
static void tcp_transf_cb(gsm_state_t state, const char * txt);
static void win_title_refr(void);
static void save_conf(lv_app_inst_t * app);
/**********************
* STATIC VARIABLES
**********************/
static lv_app_dsc_t my_app_dsc =
{
.name = "GSM",
.mode = LV_APP_MODE_NONE,
.app_run = my_app_run,
.app_close = my_app_close,
.com_rec = my_com_rec,
.win_open = my_win_open,
.win_close = my_win_close,
.sc_open = my_sc_open,
.sc_close = my_sc_close,
.app_data_size = sizeof(my_app_data_t),
.sc_data_size = sizeof(my_sc_data_t),
.win_data_size = sizeof(my_win_data_t),
};
static lv_app_inst_t * app_act_com;
static char def_apn[128];
static char def_ip[32];
static char def_port[16];
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the application
* @return pointer to the application descriptor of this application
*/
const lv_app_dsc_t * lv_app_gsm_init(void)
{
#ifdef LV_APP_GSM_CONF_PATH
fs_file_t f;
fs_res_t res;
res = fs_open(&f, LV_APP_GSM_CONF_PATH, FS_MODE_RD);
if(res == FS_RES_NOT_EX) {
res = fs_open(&f, LV_APP_GSM_CONF_PATH, FS_MODE_WR | FS_MODE_RD);
if(res == FS_RES_OK) {
const char * def_conf = "apn\n100.101.102.103\n1234";
fs_write(&f, def_conf, strlen(def_conf) + 1, NULL);
fs_seek(&f, 0);
}
}
if(res == FS_RES_OK) {
volatile char buf[256];
volatile uint32_t rn;
fs_read(&f, (char *)buf, sizeof(buf) - 1, (uint32_t *)&rn);
volatile uint16_t i;
volatile uint16_t j = 0;
volatile uint8_t line_cnt = 0;
for(i = 0; i < rn; i++) {
if(buf[i] != '\n') {
if(line_cnt == 0) def_apn[j] = buf[i];
if(line_cnt == 1) def_ip[j] = buf[i];
if(line_cnt == 2) def_port[j] = buf[i];
j++;
} else {
if(line_cnt == 0) def_apn[j] = '\0';
if(line_cnt == 1) def_ip[j] = '\0';
if(line_cnt == 2) def_port[j] = '\0';
j = 0;
line_cnt ++;
}
}
fs_close(&f);
} else {
lv_app_notice_add("SD card error");
}
#else
strcpy(def_apn, LV_APP_GSM_APN_DEF);
strcpy(def_ip, LV_APP_GSM_IP_DEF);
strcpy(def_port, LV_APP_GSM_PORT_DEF);
#endif
#if LV_APP_GSM_AUTO_CONNECT != 0
gsmmng_set_last_apn(def_apn);
gsmmng_set_last_tcp(def_ip, def_port);
#endif
ptask_create(gsm_state_monitor_task, GSM_MONITOR_PERIOD, PTASK_PRIO_LOW, NULL);
return &my_app_dsc;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Run an application according to 'app_dsc'
* @param app_dsc pointer to an application descriptor
* @param conf pointer to a lv_app_example_conf_t structure with configuration data or NULL if unused
* @return pointer to the opened application or NULL if any error occurred
*/
static void my_app_run(lv_app_inst_t * app, void * conf)
{
/*Initialize the application*/
my_app_data_t * adata = app->app_data;
strcpy(adata->set_apn, def_apn);
strcpy(adata->set_ip, def_ip);
strcpy(adata->set_port, def_port);
}
/**
* Close a running application.
* Close the Window and the Shortcut too if opened.
* Free all the allocated memory by this application.
* @param app pointer to an application
*/
static void my_app_close(lv_app_inst_t * app)
{
/*No dynamically allocated data in 'my_app_data'*/
}
/**
* Read the data have been sent to this application
* @param app_send pointer to an application which sent the message
* @param app_rec pointer to an application which is receiving the message
* @param type type of data from 'lv_app_com_type_t' enum
* @param data pointer to the sent data
* @param size length of 'data' in bytes
*/
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec,
lv_app_com_type_t type , const void * data, uint32_t size)
{
if(type == LV_APP_COM_TYPE_CHAR) { /*data: string*/
app_act_com = app_rec;
gsm_tcp_transf(data, size, tcp_transf_cb);
my_app_data_t * adata = app_act_com->app_data;
if(adata->last_msg_dp != NULL) dm_free(adata->last_msg_dp);
adata->last_msg_dp = dm_alloc(size);
memcpy(adata->last_msg_dp, data, size);
adata->last_msg_size = size;
}
}
/**
* Open a shortcut for an application
* @param app pointer to an application
* @param sc pointer to an object where the application
* can create content of the shortcut
*/
static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc)
{
my_sc_data_t * sc_data = app->sc_data;
sc_data->label = lv_label_create(sc, NULL);
lv_label_set_text(sc_data->label, "Empty");
lv_obj_align(sc_data->label, NULL, LV_ALIGN_CENTER, 0, 0);
}
/**
* Close the shortcut of an application
* @param app pointer to an application
*/
static void my_sc_close(lv_app_inst_t * app)
{
/*No dynamically allocated data in 'my_sc_data'*/
}
/**
* Open the application in a window
* @param app pointer to an application
* @param win pointer to a window object where
* the application can create content
*/
static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
{
my_app_data_t * adata = app->app_data;
my_win_data_t * wdata = app->win_data;
wdata->title = lv_label_create(win, NULL);
lv_obj_t * ta_cont = lv_cont_create(win, NULL);
lv_cont_set_fit(ta_cont, true, true);
lv_cont_set_layout(ta_cont, LV_CONT_LAYOUT_COL_L);
lv_obj_set_style(ta_cont, lv_style_get(LV_STYLE_TRANSP_TIGHT, NULL));
wdata->netw_apn_ta = lv_ta_create(ta_cont, NULL);
lv_cont_set_fit(wdata->netw_apn_ta, false, true);
lv_obj_set_free_p(wdata->netw_apn_ta, app);
lv_obj_set_width(wdata->netw_apn_ta, LV_DPI * 3);
lv_page_set_rel_action(wdata->netw_apn_ta, netw_apn_rel_action);
lv_ta_set_text(wdata->netw_apn_ta, adata->set_apn);
lv_ta_set_cursor_show(wdata->netw_apn_ta, false);
wdata->tcp_ip_ta = lv_ta_create(ta_cont, wdata->netw_apn_ta);
lv_page_set_rel_action(wdata->tcp_ip_ta, tcp_ip_rel_action);
lv_ta_set_text(wdata->tcp_ip_ta, adata->set_ip);
wdata->tcp_port_ta = lv_ta_create(ta_cont, wdata->netw_apn_ta);
lv_page_set_rel_action(wdata->tcp_port_ta, tcp_port_rel_action);
lv_ta_set_text(wdata->tcp_port_ta, adata->set_port);
lv_obj_t * con_btn = lv_btn_create(win, NULL);
lv_obj_set_free_p(con_btn, app);
lv_btn_set_rel_action(con_btn, netw_con_rel_action);
lv_obj_t * label = lv_label_create(con_btn, NULL);
lv_label_set_text(label, "Connect");
lv_cont_set_layout(lv_page_get_scrl(lv_win_get_page(win)), LV_CONT_LAYOUT_PRETTY);
win_title_refr();
}
/**
* Close the window of an application
* @param app pointer to an application
*/
static void my_win_close(lv_app_inst_t * app)
{
}
/*--------------------
* OTHER FUNCTIONS
---------------------*/
static void gsm_state_monitor_task(void * param)
{
static gsmmng_state_t state_prev = GSMMNG_STATE_WAIT;
gsmmng_state_t state_act = gsmmng_get_state();
if(state_prev != state_act && state_act == GSMMNG_STATE_READY) {
lv_app_notice_add("GSM connected to:\n%s\n%s:%s",
gsmmng_get_last_apn(), gsmmng_get_last_ip(), gsmmng_get_last_port());
win_title_refr();
}
/* The GSM should be busy if there is sg. to send.
* It means fail during last send. Try again*/
if(app_act_com != NULL) {
if(gsm_busy() == false && state_act == GSMMNG_STATE_READY) {
/*Try to send the message again*/
lv_app_notice_add("Resend GSM message");
my_app_data_t * adata = app_act_com->app_data;
gsm_tcp_transf(adata->last_msg_dp, adata->last_msg_size, tcp_transf_cb);
}
}
state_prev = state_act;
}
static lv_action_res_t netw_con_rel_action(lv_obj_t * btn, lv_indev_proc_t* indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(btn);
my_app_data_t * adata = app->app_data;
gsmmng_set_last_apn(adata->set_apn);
gsmmng_set_last_tcp(adata->set_ip, adata->set_port);
gsmmng_reconnect();
save_conf(app);
lv_app_notice_add("Connecting to GSM network\n%s\n %s:%s",
adata->set_apn, adata->set_ip, adata->set_port);
return LV_ACTION_RES_OK;
}
static lv_action_res_t netw_apn_rel_action( lv_obj_t * ta, lv_indev_proc_t* indev_proc)
{
lv_app_kb_open(ta, LV_APP_KB_MODE_TXT | LV_APP_KB_MODE_WIN_RESIZE | LV_APP_KB_MODE_CUR_MANAGE, netw_apn_kb_close ,netw_apn_kb_ok);
return LV_ACTION_RES_OK;
}
static lv_action_res_t tcp_ip_rel_action( lv_obj_t * ta, lv_indev_proc_t* indev_proc)
{
lv_app_kb_open(ta, LV_APP_KB_MODE_TXT | LV_APP_KB_MODE_WIN_RESIZE | LV_APP_KB_MODE_CUR_MANAGE, tcp_ip_kb_close ,tcp_ip_kb_ok);
return LV_ACTION_RES_OK;
}
static lv_action_res_t tcp_port_rel_action( lv_obj_t * ta, lv_indev_proc_t* indev_proc)
{
lv_app_kb_open(ta, LV_APP_KB_MODE_NUM | LV_APP_KB_MODE_WIN_RESIZE | LV_APP_KB_MODE_CUR_MANAGE, tcp_port_kb_close ,tcp_port_kb_ok);
return LV_ACTION_RES_OK;
}
static void netw_apn_kb_ok(lv_obj_t * ta)
{
lv_app_inst_t * app = lv_obj_get_free_p(ta);
my_app_data_t * adata = app->app_data;
strcpy(adata->set_apn, lv_ta_get_txt(ta));
}
static void netw_apn_kb_close(lv_obj_t * ta)
{
lv_app_inst_t * app = lv_obj_get_free_p(ta);
my_app_data_t * adata = app->app_data;
lv_ta_set_text(ta, adata->set_apn);
}
static void tcp_ip_kb_ok(lv_obj_t * ta)
{
lv_app_inst_t * app = lv_obj_get_free_p(ta);
my_app_data_t * adata = app->app_data;
strcpy(adata->set_ip, lv_ta_get_txt(ta));
}
static void tcp_ip_kb_close(lv_obj_t * ta)
{
lv_app_inst_t * app = lv_obj_get_free_p(ta);
my_app_data_t * adata = app->app_data;
lv_ta_set_text(ta, adata->set_ip);
}
static void tcp_port_kb_ok(lv_obj_t * ta)
{
lv_app_inst_t * app = lv_obj_get_free_p(ta);
my_app_data_t * adata = app->app_data;
strcpy(adata->set_port, lv_ta_get_txt(ta));
}
static void tcp_port_kb_close(lv_obj_t * ta)
{
lv_app_inst_t * app = lv_obj_get_free_p(ta);
my_app_data_t * adata = app->app_data;
lv_ta_set_text(ta, adata->set_port);
}
static void tcp_transf_cb(gsm_state_t state, const char * txt)
{
if(state == GSM_STATE_OK) {
uint16_t size = txt[0] + ((txt[1] << 8) & 0xFF00);
char buf[256];
memcpy(buf, &txt[2], size);
buf[size] = '\0';
lv_app_com_send(app_act_com, LV_APP_COM_TYPE_CHAR, &txt[2], size);
my_app_data_t * adata = app_act_com->app_data;
dm_free(adata->last_msg_dp);
adata->last_msg_dp = NULL;
adata->last_msg_size = 0;
app_act_com = NULL;
}else if(state == GSM_STATE_ERROR) {
lv_app_notice_add("GSM TCP transfer error\n%s", txt);
lv_app_notice_add("Reconnecting to GSM...");
gsmmng_reconnect();
}
}
static void win_title_refr(void)
{
lv_app_inst_t * app;
app = lv_app_get_next(NULL, &my_app_dsc);
while(app != NULL) {
if(app->win != NULL) {
my_win_data_t * wdata = app->win_data;
if(gsmmng_get_state() == GSMMNG_STATE_IDLE) {
lv_label_set_text(wdata->title, "Not connected");
} else if(gsmmng_get_state() == GSMMNG_STATE_READY) {
lv_label_set_text(wdata->title, "Connecting ...");
} else {
char buf[256];
sprintf(buf, "%s - %s:%s", gsmmng_get_last_apn(), gsmmng_get_last_ip(), gsmmng_get_last_port());
lv_label_set_text(wdata->title, buf);
}
lv_obj_set_width(wdata->title, lv_win_get_width(app->win));
}
app = lv_app_get_next(app, &my_app_dsc);
}
}
static void save_conf(lv_app_inst_t * app)
{
#ifdef LV_APP_GSM_CONF_PATH
my_app_data_t * adata = app->app_data;
fs_file_t f;
fs_res_t res;
res = fs_open(&f, LV_APP_GSM_CONF_PATH, FS_MODE_WR);
if(res == FS_RES_OK) {
char buf[256];
sprintf(buf,"%s\n%s\n%s", adata->set_apn, adata->set_ip, adata->set_port);
fs_write(&f, buf, strlen(buf) + 1, NULL);
fs_close(&f);
}
#endif
}
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_EXAMPLE != 0*/
/**
* @file lv_app_gsm.h
*
*/
#ifndef LV_APP_GSM_H
#define LV_APP_GSM_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lvgl/lv_app/lv_app.h"
#if LV_APP_ENABLE != 0 && USE_LV_APP_GSM != 0
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct
{
}lv_app_gsm_conf_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
const lv_app_dsc_t * lv_app_gsm_init(void);
/**********************
* MACROS
**********************/
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_EXAMPLE != 0*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* LV_APP_EXAMPLE_H */
/**
* @file lv_app_example.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_app_phantom.h"
#if LV_APP_ENABLE != 0 && USE_LV_APP_PHANTOM != 0
#include "../lv_app/lv_app_util/lv_app_kb.h"
#include <stdio.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Application specific data for an instance of this application*/
typedef struct
{
void (*com_listen)(lv_app_inst_t * app_send, lv_app_inst_t * app_rec,
lv_app_com_type_t type , const void * data, uint32_t size);
}my_app_data_t;
/*Application specific data a window of this application*/
typedef struct
{
}my_win_data_t;
/*Application specific data for a shortcut of this application*/
typedef struct
{
lv_obj_t * label;
}my_sc_data_t;
/**********************
* STATIC PROTOTYPES
**********************/
static void my_app_run(lv_app_inst_t * app, void * conf);
static void my_app_close(lv_app_inst_t * app);
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec,
lv_app_com_type_t type , const void * data, uint32_t size);
/**********************
* STATIC VARIABLES
**********************/
static lv_app_dsc_t my_app_dsc =
{
.name = "Phantom",
.mode = LV_APP_MODE_NONE,
.app_run = my_app_run,
.app_close = my_app_close,
.com_rec = my_com_rec,
.win_open = NULL,
.win_close = NULL,
.sc_open = NULL,
.sc_close = NULL,
.app_data_size = sizeof(my_app_data_t),
.sc_data_size = sizeof(my_sc_data_t),
.win_data_size = sizeof(my_win_data_t),
};
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the application
* @return pointer to the application descriptor of this application
*/
const lv_app_dsc_t * lv_app_phantom_init(void)
{
return &my_app_dsc;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Run an application according to 'app_dsc'
* @param app_dsc pointer to an application descriptor
* @param conf pointer to a lv_app_phantom_conf_t structure with configuration data or NULL if unused
* @return pointer to the opened application or NULL if any error occurred
*/
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_listen = NULL;
if(conf != NULL) {
lv_app_phantom_conf_t * my_conf = conf;
app_data->com_listen = my_conf->com_listen;
}
}
/**
* Close a running application.
* Close the Window and the Shortcut too if opened.
* Free all the allocated memory by this application.
* @param app pointer to an application
*/
static void my_app_close(lv_app_inst_t * app)
{
/*No dynamically allocated data in 'my_app_data'*/
}
/**
* Read the data have been sent to this application
* @param app_send pointer to an application which sent the message
* @param app_rec pointer to an application which is receiving the message
* @param type type of data from 'lv_app_com_type_t' enum
* @param data pointer to the sent data
* @param size length of 'data' in bytes
*/
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec,
lv_app_com_type_t type , const void * data, uint32_t size)
{
my_app_data_t * app_data = app_rec->app_data;
if(app_data->com_listen != NULL) {
app_data->com_listen(app_send, app_rec, type, data, size);
}
}
/*--------------------
* OTHER FUNCTIONS
---------------------*/
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_EXAMPLE != 0*/
/**
* @file lv_app_phantom.h
*
*/
#ifndef LV_APP_PHANTOM_H
#define LV_APP_PHANTOM_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lvgl/lv_app/lv_app.h"
#if LV_APP_ENABLE != 0 && USE_LV_APP_PHANTOM != 0
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct
{
void (*com_listen)(lv_app_inst_t * app_send,
lv_app_inst_t * app_rec,
lv_app_com_type_t type ,
const void * data, uint32_t size);
}lv_app_phantom_conf_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
const lv_app_dsc_t * lv_app_phantom_init(void);
/**********************
* MACROS
**********************/
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_PHANTOM != 0*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* LV_APP_PHANTOM_H */
/**
* @file lv_app_sysmon.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_app_sysmon.h"
#if LV_APP_ENABLE != 0 && USE_LV_APP_SYSMON != 0
#include <stdio.h>
#include "misc/os/ptask.h"
#include "misc/os/idle.h"
#include "lvgl/lv_objx/lv_chart.h"
#include "lvgl/lv_app/lv_app_util/lv_app_notice.h"
#include "../hal/systick/systick.h"
/*********************
* DEFINES
*********************/
#define CPU_LABEL_COLOR "FF0000"
#define MEM_LABEL_COLOR "0000FF"
/**********************
* TYPEDEFS
**********************/
/*Application specific data for an instance of this application*/
typedef struct
{
}my_app_data_t;
/*Application specific data a window of this application*/
typedef struct
{
lv_obj_t * chart;
lv_chart_dl_t * cpu_dl;
lv_chart_dl_t * mem_dl;
lv_obj_t * label;
}my_win_data_t;
/*Application specific data for a shortcut of this application*/
typedef struct
{
lv_obj_t * bar_cpu;
lv_obj_t * bar_mem;
}my_sc_data_t;
/**********************
* STATIC PROTOTYPES
**********************/
static void my_app_run(lv_app_inst_t * app, void * conf);
static void my_app_close(lv_app_inst_t * app);
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec, lv_app_com_type_t type , const void * data, uint32_t size);
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 sysmon_task(void * param);
static void lv_app_sysmon_refr(void);
/**********************
* STATIC VARIABLES
**********************/
static lv_app_dsc_t my_app_dsc =
{
.name = "Sys. monitor",
.mode = LV_APP_MODE_NONE,
.app_run = my_app_run,
.app_close = my_app_close,
.com_rec = my_com_rec,
.win_open = my_win_open,
.win_close = my_win_close,
.sc_open = my_sc_open,
.sc_close = my_sc_close,
.app_data_size = sizeof(my_app_data_t),
.sc_data_size = sizeof(my_sc_data_t),
.win_data_size = sizeof(my_win_data_t),
};
static uint8_t mem_pct[LV_APP_SYSMON_PNUM];
static uint8_t cpu_pct[LV_APP_SYSMON_PNUM];
static lv_style_t cpu_bar_bg;
static lv_style_t mem_bar_bg;
static lv_style_t cpu_bar_indic;
static lv_style_t mem_bar_indic;
#if USE_DYN_MEM != 0 && DM_CUSTOM == 0
static dm_mon_t mem_mon;
#endif
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the application
* @return pointer to the application descriptor of this application
*/
const lv_app_dsc_t * lv_app_sysmon_init(void)
{
ptask_create(sysmon_task, LV_APP_SYSMON_REFR_TIME, PTASK_PRIO_LOW, NULL);
memset(mem_pct, 0, sizeof(mem_pct));
memset(cpu_pct, 0, sizeof(cpu_pct));
/*Create bar styles for the shortcut*/
lv_style_get(LV_STYLE_PRETTY, &cpu_bar_bg);
cpu_bar_bg.ccolor = COLOR_MAKE(0x40, 0x00, 0x00);
cpu_bar_bg.font = font_get(LV_APP_FONT_MEDIUM);
cpu_bar_bg.line_space = 0;
cpu_bar_bg.txt_align = 1;
cpu_bar_bg.hpad = 0;
cpu_bar_bg.vpad = 0;
memcpy(&mem_bar_bg, &cpu_bar_bg, sizeof(lv_style_t));
mem_bar_bg.ccolor = COLOR_MAKE(0x00, 0x40, 0x00);
lv_style_get(LV_STYLE_PRETTY_COLOR, &cpu_bar_indic);
cpu_bar_indic.gcolor = COLOR_MARRON;
cpu_bar_indic.mcolor = COLOR_RED;
cpu_bar_indic.bcolor = COLOR_BLACK;
//cpu_bar_indic.bwidth = 1 * LV_DOWNSCALE;
cpu_bar_indic.bopa = OPA_50;
cpu_bar_indic.hpad = 0 * LV_DOWNSCALE;
cpu_bar_indic.vpad = 0 * LV_DOWNSCALE;
memcpy(&mem_bar_indic, &cpu_bar_indic, sizeof(lv_style_t));
mem_bar_indic.gcolor = COLOR_GREEN;
mem_bar_indic.mcolor = COLOR_LIME;
return &my_app_dsc;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Run an application according to 'app_dsc'
* @param app_dsc pointer to an application descriptor
* @param conf pointer to a lv_app_sysmon_conf_t structure with configuration data or NULL if unused
* @return pointer to the opened application or NULL if any error occurred
*/
static void my_app_run(lv_app_inst_t * app, void * conf)
{
}
/**
* Close a running application.
* Close the Window and the Shortcut too if opened.
* Free all the allocated memory by this application.
* @param app pointer to an application
*/
static void my_app_close(lv_app_inst_t * app)
{
/*No dynamically allocated data in 'my_app_data'*/
}
/**
* Read the data have been sent to this application
* @param app_send pointer to an application which sent the message
* @param app_rec pointer to an application which is receiving the message
* @param type type of data from 'lv_app_com_type_t' enum
* @param data pointer to the sent data
* @param size length of 'data' in bytes
*/
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec,
lv_app_com_type_t type , const void * data, uint32_t size)
{
}
/**
* Open a shortcut for an application
* @param app pointer to an application
* @param sc pointer to an object where the application
* can create content of the shortcut
*/
static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc)
{
my_sc_data_t * sc_data = app->sc_data;
cord_t w = lv_obj_get_width(sc) / 5;
/*Create 2 bars for the CPU and the Memory*/
sc_data->bar_cpu = lv_bar_create(sc, NULL);
lv_obj_set_size(sc_data->bar_cpu, w, 5 * lv_obj_get_height(sc) / 8);
lv_obj_align(sc_data->bar_cpu, NULL, LV_ALIGN_IN_BOTTOM_LEFT, w, - lv_obj_get_height(sc) / 8);
lv_obj_set_style(sc_data->bar_cpu, &cpu_bar_bg);
lv_bar_set_style_indic(sc_data->bar_cpu, &cpu_bar_indic);
lv_obj_set_click(sc_data->bar_cpu, false);
lv_bar_set_range(sc_data->bar_cpu, 0, 100);
lv_obj_t * label = lv_label_create(sc_data->bar_cpu, NULL);
lv_label_set_text(label, "C\nP\nU");
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
sc_data->bar_mem = lv_bar_create(sc, sc_data->bar_cpu);
lv_obj_align(sc_data->bar_mem, sc_data->bar_cpu, LV_ALIGN_OUT_RIGHT_MID, w, 0);
lv_obj_set_style(sc_data->bar_mem, &mem_bar_bg);
lv_bar_set_style_indic(sc_data->bar_mem, &mem_bar_indic);
label = lv_label_create(sc_data->bar_mem, NULL);
lv_label_set_text(label, "M\nE\nM");
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
lv_app_sysmon_refr();
}
/**
* Close the shortcut of an application
* @param app pointer to an application
*/
static void my_sc_close(lv_app_inst_t * app)
{
/*No dynamically allocated data in 'my_sc_data'*/
}
/**
* Open the application in a window
* @param app pointer to an application
* @param win pointer to a window object where
* the application can create content
*/
static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
{
my_win_data_t * win_data = app->win_data;
/*Make the window content responsive*/
lv_cont_set_layout(lv_page_get_scrl(lv_win_get_page(win)), LV_CONT_LAYOUT_PRETTY);
/*Create a chart with two data lines*/
win_data->chart = lv_chart_create(win, NULL);
lv_obj_set_size(win_data->chart, LV_HOR_RES / 2, LV_VER_RES / 2);
lv_obj_set_pos(win_data->chart, LV_DPI / 10, LV_DPI / 10);
lv_chart_set_pnum(win_data->chart, LV_APP_SYSMON_PNUM);
lv_chart_set_range(win_data->chart, 0, 100);
lv_chart_set_type(win_data->chart, LV_CHART_LINE);
lv_chart_set_dl_width(win_data->chart, 2 * LV_DOWNSCALE);
win_data->cpu_dl = lv_chart_add_data_line(win_data->chart, COLOR_RED);
win_data->mem_dl = lv_chart_add_data_line(win_data->chart, COLOR_BLUE);
uint16_t i;
for(i = 0; i < LV_APP_SYSMON_PNUM; i ++) {
win_data->cpu_dl->points[i] = cpu_pct[i];
win_data->mem_dl->points[i] = mem_pct[i];
}
/*Create a label for the details of Memory and CPU usage*/
win_data->label = lv_label_create(win, NULL);
lv_label_set_recolor(win_data->label, true);
lv_obj_align(win_data->label, win_data->chart, LV_ALIGN_OUT_RIGHT_TOP, LV_DPI / 4, 0);
lv_app_sysmon_refr();
}
/**
* Close the window of an application
* @param app pointer to an application
*/
static void my_win_close(lv_app_inst_t * app)
{
}
/*--------------------
* OTHER FUNCTIONS
---------------------*/
/**
* Called periodically to monitor the CPU and memory usage.
* It refreshes the shortcuts and windows and also add notifications if there is any problem.
* @param param unused
*/
static void sysmon_task(void * param)
{
/*Shift out the oldest data*/
uint16_t i;
for(i = 1; i < LV_APP_SYSMON_PNUM; i++) {
mem_pct[i - 1] = mem_pct[i];
cpu_pct[i - 1] = cpu_pct[i];
}
/*Get CPU and memory information */
uint8_t cpu_busy = 0;
#if USE_IDLE != 0 /*Use the more precise idle module if enabled*/
cpu_busy = 100 - idle_get();
#else
cpu_busy = 100 - ptask_get_idle();
#endif
uint8_t mem_used_pct = 0;
#if USE_DYN_MEM != 0 && DM_CUSTOM == 0
dm_monitor(&mem_mon);
mem_used_pct = mem_mon.pct_used;
#endif
/*Add the CPU and memory data*/
cpu_pct[LV_APP_SYSMON_PNUM - 1] = cpu_busy;
mem_pct[LV_APP_SYSMON_PNUM - 1] = mem_used_pct;
/*Refresh the shortcuts and windows*/
lv_app_sysmon_refr();
#if USE_DYN_MEM != 0 && DM_CUSTOM == 0
/*Handle periodic defrag. if enabled*/
#if LV_APP_SYSMON_DEFRAG_PERIOD != 0
static uint32_t last_defrag = 0;
if(systick_elaps(last_defrag) > LV_APP_SYSMON_DEFRAG_PERIOD) {
dm_defrag();
last_defrag = systick_get();
}
#endif
/*Add notifications if something is critical*/
static bool mem_warn_report = false;
if(mem_mon.size_free < LV_APP_SYSMON_MEM_WARN && mem_warn_report == false) {
mem_warn_report = true;
lv_app_notice_add("Critically low memory");
}
if(mem_mon.size_free > LV_APP_SYSMON_MEM_WARN) mem_warn_report = false;
static bool frag_warn_report = false;
if(mem_mon.pct_frag > LV_APP_SYSMON_FRAG_WARN) {
if(frag_warn_report == false) {
frag_warn_report = true;
lv_app_notice_add("Critical memory\nfragmentation");
dm_defrag(); /*Defrag. if the fragmentation is critical*/
}
}
if(mem_mon.pct_frag < LV_APP_SYSMON_FRAG_WARN) frag_warn_report = false;
#endif
}
/**
* Refresh the shortcuts and windows.
*/
static void lv_app_sysmon_refr(void)
{
char buf_long[256];
char buf_short[128];
sprintf(buf_long, "%c%s CPU: %d %%%c\n\n",TXT_RECOLOR_CMD, CPU_LABEL_COLOR, cpu_pct[LV_APP_SYSMON_PNUM - 1], TXT_RECOLOR_CMD);
sprintf(buf_short, "CPU: %d %%\n", cpu_pct[LV_APP_SYSMON_PNUM - 1]);
#if USE_DYN_MEM != 0 && DM_CUSTOM == 0
sprintf(buf_long, "%s%c%s MEMORY: %d %%%c\nTotal: %d bytes\nUsed: %d bytes\nFree: %d bytes\nFrag: %d %%",
buf_long,
TXT_RECOLOR_CMD,
MEM_LABEL_COLOR,
mem_pct[LV_APP_SYSMON_PNUM - 1],
TXT_RECOLOR_CMD,
(int)mem_mon.size_total,
(int)mem_mon.size_total - mem_mon.size_free, mem_mon.size_free, mem_mon.pct_frag);
sprintf(buf_short, "%sMem: %d %%\nFrag: %d %%\n",
buf_short, mem_pct[LV_APP_SYSMON_PNUM - 1], mem_mon.pct_frag);
#else
sprintf(buf_long, "%s%c%s MEMORY: N/A%c", buf_long, TXT_RECOLOR_CMD, MEM_LABEL_COLOR, TXT_RECOLOR_CMD);
sprintf(buf_short, "%sMem: N/A\nFrag: N/A", buf_short);
#endif
lv_app_inst_t * app;
app = lv_app_get_next(NULL, &my_app_dsc);
while(app != NULL) {
/*Refresh the windows*/
my_win_data_t * win_data = app->win_data;
if(win_data != NULL) {
lv_label_set_text(win_data->label, buf_long);
lv_chart_set_next(win_data->chart, win_data->mem_dl, mem_pct[LV_APP_SYSMON_PNUM - 1]);
lv_chart_set_next(win_data->chart, win_data->cpu_dl, cpu_pct[LV_APP_SYSMON_PNUM - 1]);
}
/*Refresh the shortcut*/
my_sc_data_t * sc_data = app->sc_data;
if(sc_data != NULL) {
lv_bar_set_value(sc_data->bar_cpu, cpu_pct[LV_APP_SYSMON_PNUM - 1]);
lv_bar_set_value(sc_data->bar_mem, mem_pct[LV_APP_SYSMON_PNUM - 1]);
}
lv_app_com_send(app, LV_APP_COM_TYPE_CHAR, buf_short, strlen(buf_short));
app = lv_app_get_next(app, &my_app_dsc);
}
}
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_SYSMON != 0*/
/**
* @file lv_app_example.h
*
*/
#ifndef LV_APP_SYSMON_H
#define LV_APP_SYSMON_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lvgl/lv_app/lv_app.h"
#if LV_APP_ENABLE != 0 && USE_LV_APP_SYSMON != 0
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct
{
}lv_app_sysmon_conf_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
const lv_app_dsc_t * lv_app_sysmon_init(void);
/**********************
* MACROS
**********************/
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_SYSMON != 0*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* LV_APP_SYSMON_H */
/**
* @file lv_app_terminal.c
*
*/
/*********************
* INCLUDES
*********************/
#include <lvgl/lv_obj/lv_indev.h>
#include "lv_conf.h"
#include "../lv_obj/lv_obj.h"
#include "../lv_objx/lv_btn.h"
#include "../lv_objx/lv_cont.h"
#include "../lv_objx/lv_ddlist.h"
#include "../lv_objx/lv_label.h"
#include "../lv_objx/lv_page.h"
#include "../lv_objx/lv_ta.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"
#include <stdio.h>
/*********************
* DEFINES
*********************/
#define OBJ_PAD (LV_DPI / 12)
#define AUTO_CONNECT_TCP_DELAY 5000 /*Wait before TCS server connect when the WiFi connect is ready*/
/**********************
* 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;
/*Application specific data a window of this application*/
typedef struct
{
lv_obj_t * label;
lv_obj_t * ta;
lv_obj_t * clear_btn;
}my_win_data_t;
/*Application specific data for a shortcut of this application*/
typedef struct
{
lv_obj_t * label;
}my_sc_data_t;
/**********************
* STATIC PROTOTYPES
**********************/
static void my_app_run(lv_app_inst_t * app, void * conf);
static void my_app_close(lv_app_inst_t * app);
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec, lv_app_com_type_t type , const void * data, uint32_t size);
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_indev_proc_t * indev_proc);
static lv_action_res_t win_comtype_action(lv_obj_t * ddlist, lv_indev_proc_t * indev_proc);
static lv_action_res_t win_format_action(lv_obj_t * ddlist, lv_indev_proc_t * indev_proc);
static lv_action_res_t win_clear_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc);
static void win_ta_kb_ok_action(lv_obj_t * ta);
/**********************
* STATIC VARIABLES
**********************/
static lv_app_dsc_t my_app_dsc =
{
.name = "Terminal",
.mode = LV_APP_MODE_NONE,
.app_run = my_app_run,
.app_close = my_app_close,
.com_rec = my_com_rec,
.win_open = my_win_open,
.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),
};
static const char * com_type_list_txt[] = {"Character", "Integer", "Log", "None", ""};
static 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};
static const char * txt_format_list_txt[] = {"ASCII", "Hexadecimal", ""};
static lv_style_t style_sc_term;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the application
* @return pointer to the application descriptor of this application
*/
const lv_app_dsc_t * lv_app_terminal_init(void)
{
lv_style_get(LV_STYLE_PLAIN, &style_sc_term);
style_sc_term.line_space = 0;
style_sc_term.letter_space = 0;
style_sc_term.txt_align = 0;
style_sc_term.ccolor = COLOR_WHITE;
style_sc_term.mcolor = COLOR_MAKE(0x20, 0x20, 0x20);
style_sc_term.gcolor = COLOR_MAKE(0x20, 0x20, 0x20);
return &my_app_dsc;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Run an application according to 'app_dsc'
* @param app_dsc pointer to an application descriptor
* @param conf pointer to a lv_app_example_conf_t structure with configuration data or NULL if unused
* @return pointer to the opened application or NULL if any error occurred
*/
static void my_app_run(lv_app_inst_t * app, void * conf)
{
/*Initialize the application*/
my_app_data_t * app_data = app->app_data;
if(conf != NULL) {
app_data->com_type = ((lv_app_terminal_conf_t * ) conf)->com_type;
app_data->format = ((lv_app_terminal_conf_t * ) conf)->format;
} else {
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));
}
/**
* Close a running application.
* Close the Window and the Shortcut too if opened.
* Free all the allocated memory by this application.
* @param app pointer to an application
*/
static void my_app_close(lv_app_inst_t * app)
{
/*No dynamically allocated data in 'my_app_data'*/
}
/**
* Read the data have been sent to this applicationstring
* @param app_send pointer to an application which sent the message
* @param app_rec pointer to an application which is receiving the message
* @param type type of data from 'lv_app_com_type_t' enum
* @param data pointer to the sent data
* @param size length of 'data' in bytes
*/
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec,
lv_app_com_type_t type , const void * data, uint32_t size)
{
my_app_data_t * app_data = app_rec->app_data;
/*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) {
add_data(app_rec, "\n@", 2);
add_data(app_rec, app_send->name, strlen(app_send->name));
add_data(app_rec, "\n", 1);
}
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;
}
/**
* Open a shortcut for an application
* @param app pointer to an application
* @param sc pointer to an object where the application
* can create content of the shortcut
*/
static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc)
{
my_sc_data_t * sc_data = app->sc_data;
my_app_data_t * app_data = app->app_data;
/*Create a dark background*/
lv_obj_t * txt_bg = lv_obj_create(sc, NULL);
lv_obj_set_size(txt_bg, 7 * LV_APP_SC_WIDTH / 8 , app->sc->cords.y2 - app->sc_title->cords.y2 - 10 * LV_DOWNSCALE);
lv_obj_set_style(txt_bg, &style_sc_term);
lv_obj_align(txt_bg, app->sc_title, LV_ALIGN_OUT_BOTTOM_MID, 0, 3 * LV_DOWNSCALE);
lv_obj_set_click(txt_bg, false);
/*Add a text with the text of the terminal*/
sc_data->label = lv_label_create(txt_bg, NULL);
lv_label_set_long_mode(sc_data->label, LV_LABEL_LONG_BREAK);
lv_obj_set_width(sc_data->label, lv_obj_get_width(txt_bg) - LV_APP_SC_WIDTH / 8);
lv_label_set_text_static(sc_data->label, app_data->txt);
lv_obj_align(sc_data->label, txt_bg, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
}
/**
* Close the shortcut of an application
* @param app pointer to an application
*/
static void my_sc_close(lv_app_inst_t * app)
{
/*No dynamically allocated data in 'my_sc_data'*/
}
/**
* Open the application in a window
* @param app pointer to an application
* @param win pointer to a window object where
* the application can create content
*/
static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
{
my_win_data_t * win_data = app->win_data;
my_app_data_t * app_data = app->app_data;
/*Make the window content responsive*/
lv_cont_set_layout(lv_page_get_scrl(lv_win_get_page(win)), LV_CONT_LAYOUT_PRETTY);
/*Create a label for the text of the terminal*/
win_data->label = lv_label_create(win, NULL);
lv_label_set_long_mode(win_data->label, LV_LABEL_LONG_BREAK);
lv_obj_set_width(win_data->label, lv_win_get_width(win));
lv_label_set_text_static(win_data->label, app_data->txt); /*Use the app. data text directly*/
/*Create a text area. Text can be added to the terminal from here by app. keyboard.*/
win_data->ta = lv_ta_create(win, NULL);
lv_obj_set_size(win_data->ta, 3 * LV_HOR_RES / 5, LV_VER_RES / 4);
lv_obj_set_free_p(win_data->ta, app);
lv_page_set_rel_action(win_data->ta, win_ta_rel_action);
lv_page_glue_obj(win_data->ta, true);
lv_ta_set_text(win_data->ta, "");
/*Create a clear button*/
win_data->clear_btn = lv_btn_create(win, NULL);
lv_cont_set_fit(win_data->clear_btn, true, true);
lv_obj_set_free_p(win_data->clear_btn, app);
lv_page_glue_obj(win_data->ta, true);
lv_btn_set_rel_action(win_data->clear_btn, win_clear_rel_action);
lv_obj_t * btn_label = lv_label_create(win_data->clear_btn, NULL);
lv_label_set_text(btn_label, "Clear");
/*Align the window to see the text area on the bottom*/
lv_obj_t * page = lv_win_get_page(app->win);
lv_obj_align(lv_page_get_scrl(page), NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, - LV_VER_RES);
}
/**
* Close the window of an application
* @param app pointer to an application
*/
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_obj_t * label;
label = lv_label_create(conf_win, NULL);
lv_label_set_text(label, "Communication type");
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
---------------------*/
/**
* Called when the Text area is released to open the app. keybard
* @param ta pointer to the text area
* @param indev_proc pointer to the caller display input
* @return LV_ACTION_RES_OK because the text area is not deleted
*/
static lv_action_res_t win_ta_rel_action(lv_obj_t * ta, lv_indev_proc_t * indev_proc)
{
lv_app_kb_open(ta, LV_APP_KB_MODE_TXT | LV_APP_KB_MODE_WIN_RESIZE, NULL, win_ta_kb_ok_action);
return LV_ACTION_RES_OK;
}
/**
* 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 indev_proc pointer to the caller display input
* @return LV_ACTION_RES_OK because the list is not deleted
*/
static lv_action_res_t win_comtype_action(lv_obj_t * ddlist, lv_indev_proc_t * indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(ddlist);
my_app_data_t * app_data = app->app_data;
app_data->com_type = com_type_list[lv_ddlist_get_selected(ddlist)];
return LV_ACTION_RES_OK;
}
/**
* 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 indev_proc pointer to the caller display input
* @return LV_ACTION_RES_OK because the list is not deleted
*/
static lv_action_res_t win_format_action(lv_obj_t * ddlist, lv_indev_proc_t * indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(ddlist);
my_app_data_t * app_data = app->app_data;
uint16_t opt = lv_ddlist_get_selected(ddlist);
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 indev_proc pointer to the caller display input
* @return LV_ACTION_RES_OK because the button is not deleted
*/
static lv_action_res_t win_clear_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc)
{
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;
my_sc_data_t * sc_data = app->sc_data;
app_data->txt[0] = '\0';
if(sc_data != NULL) {
lv_label_set_text_static(sc_data->label, app_data->txt);
lv_obj_align(sc_data->label, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
}
if(win_data != NULL) {
lv_label_set_text_static(win_data->label, app_data->txt);
lv_obj_t * page = lv_win_get_page(app->win);
lv_obj_align(lv_page_get_scrl(page), NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, - LV_VER_RES);
}
return LV_ACTION_RES_OK;
}
/**
* Called when the 'Ok' button of the keyboard in the window
* is pressed to write to the Terminal
* @param ta pointer to the Text area in the window
*/
static void win_ta_kb_ok_action(lv_obj_t * ta)
{
lv_app_inst_t * app = lv_obj_get_free_p(ta);
my_app_data_t * app_data = app->app_data;
const char * ta_txt = lv_ta_get_txt(ta);
uint32_t ta_txt_len = strlen(ta_txt);
if(app_data->txt[0] != '\0') add_data(app, "\n", 1);
add_data(app, ">", 1);
add_data(app, ta_txt, ta_txt_len);
lv_app_com_send(app, app_data->com_type, ta_txt, ta_txt_len);
lv_ta_set_text(ta, "");
app_data->last_sender = NULL; /*Now the least data in the terminal is from this app*/
}
/**
* Add data to the terminal
* @param app pointer to a Terminal application
* @param data pointer to the data
* @param data_len length of 'data' in bytes
*/
static void add_data(lv_app_inst_t * app, const void * data, uint16_t data_len)
{
my_app_data_t * app_data = app->app_data;
uint16_t old_len = strlen(app_data->txt);
const char * txt = data;
/*IF the data is longer then the terminal ax size show the last part of data*/
if(data_len > LV_APP_TERMINAL_LENGTH) {
txt += (data_len - LV_APP_TERMINAL_LENGTH);
data_len = LV_APP_TERMINAL_LENGTH;
old_len = 0;
}
/*If the text become too long 'forget' the oldest lines*/
else if(old_len + data_len > LV_APP_TERMINAL_LENGTH) {
uint16_t new_start;
for(new_start = 0; new_start < old_len; new_start++) {
if(app_data->txt[new_start] == '\n') {
/*If there is enough space break*/
if(new_start >= data_len) {
/*Ignore line breaks*/
while(app_data->txt[new_start] == '\n' || app_data->txt[new_start] == '\r') new_start++;
break;
}
}
}
/* If it wasn't able to make enough space on line breaks
* simply forget the oldest characters*/
if(new_start == old_len) {
new_start = old_len - (LV_APP_TERMINAL_LENGTH - data_len);
}
/*Move the remaining text to the beginning*/
uint16_t j;
for(j = new_start; j < old_len; j++) {
app_data->txt[j - new_start] = app_data->txt[j];
}
old_len = old_len - new_start;
app_data->txt[old_len] = '\0';
}
memcpy(&app_data->txt[old_len], txt, data_len);
app_data->txt[old_len + data_len] = '\0';
my_win_data_t * win_data = app->win_data;
my_sc_data_t * sc_data = app->sc_data;
if(win_data != NULL) {
lv_label_set_text_static(win_data->label, app_data->txt);
lv_obj_t * page = lv_win_get_page(app->win);
lv_obj_align(lv_page_get_scrl(page), NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, - LV_VER_RES);
}
/*Set the last line on the shortcut*/
if(sc_data != NULL) {
lv_label_set_text_static(sc_data->label, app_data->txt);
lv_obj_align(sc_data->label, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
}
}
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_TERMINAL != 0*/
/**
* @file lv_app_terminal.h
*
*/
#ifndef LV_APP_TERMINAL_H
#define LV_APP_TERMINAL_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lvgl/lv_app/lv_app.h"
#if LV_APP_ENABLE != 0 && USE_LV_APP_TERMINAL != 0
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef enum
{
LV_APP_TERMINAL_FORMAT_ASCII,
LV_APP_TERMINAL_FORMAT_HEX,
}lv_app_terminal_format_t;
typedef struct
{
lv_app_terminal_format_t format; /*Data display format*/
lv_app_com_type_t com_type; /*The listened communication type (channel) */
}lv_app_terminal_conf_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
const lv_app_dsc_t * lv_app_terminal_init(void);
/**********************
* MACROS
**********************/
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_TERMINAL != 0*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* LV_APP_TERMINAL_H */
/**
* @file lv_app_wifi.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_app_wifi.h"
#if LV_APP_ENABLE != 0 && USE_LV_APP_WIFI != 0
#include "../lv_app/lv_app_util/lv_app_kb.h"
#include "hal/wifi/wifi.h"
#include "misc/os/ptask.h"
#include "hal/systick/systick.h"
#include "misc/comm/wifimng.h"
#include "misc/fs/fat32/integer.h"
#include <stdio.h>
/*********************
* DEFINES
*********************/
#define SSID_LIST_MAX_LENGTH 512
#define WIFI_MONITOR_PERIOD 1000 /*ms*/
/**********************
* TYPEDEFS
**********************/
/*Application specific data for an instance of this application*/
typedef struct
{
char set_ssid[64];
char set_pwd[64];
char set_ip[32];
char set_port[16];
uint8_t * last_msg_dp;
uint16_t last_msg_size;
}my_app_data_t;
/*Application specific data a window of this application*/
typedef struct
{
lv_obj_t * list;
lv_obj_t * title;
lv_obj_t * netw_ssid_ta;
lv_obj_t * netw_pwd_ta;
lv_obj_t * tcp_ip_ta;
lv_obj_t * tcp_port_ta;
}my_win_data_t;
/*Application specific data for a shortcut of this application*/
typedef struct
{
lv_obj_t * label;
}my_sc_data_t;
/**********************
* STATIC PROTOTYPES
**********************/
static void my_app_run(lv_app_inst_t * app, void * conf);
static void my_app_close(lv_app_inst_t * app);
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec, lv_app_com_type_t type , const void * data, uint32_t size);
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 wifi_state_monitor_task(void * param);
static lv_action_res_t netw_list_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc);
static lv_action_res_t netw_con_rel_action(lv_obj_t * btn, lv_indev_proc_t* indev_proc);
static lv_action_res_t netw_ssid_rel_action( lv_obj_t * ta, lv_indev_proc_t* indev_proc);
static lv_action_res_t netw_pwd_rel_action( lv_obj_t * ta, lv_indev_proc_t* indev_proc);
static lv_action_res_t tcp_ip_rel_action( lv_obj_t * ta, lv_indev_proc_t* indev_proc);
static lv_action_res_t tcp_port_rel_action( lv_obj_t * ta, lv_indev_proc_t* indev_proc);
static lv_action_res_t wifi_ap_select_action( lv_obj_t * ddlist, lv_indev_proc_t* indev_proc);
static void netw_ssid_kb_ok(lv_obj_t * ta);
static void netw_ssid_kb_close(lv_obj_t * ta);
static void netw_pwd_kb_ok(lv_obj_t * ta);
static void netw_pwd_kb_close(lv_obj_t * ta);
static void tcp_ip_kb_ok(lv_obj_t * ta);
static void tcp_ip_kb_close(lv_obj_t * ta);
static void tcp_port_kb_ok(lv_obj_t * ta);
static void tcp_port_kb_close(lv_obj_t * ta);
static void list_cb(wifi_state_t state, const char * txt);
static void tcp_transf_cb(wifi_state_t state, const char * txt);
static void win_title_refr(void);
static void save_conf(lv_app_inst_t * app);
/**********************
* STATIC VARIABLES
**********************/
static lv_app_dsc_t my_app_dsc =
{
.name = "WiFi",
.mode = LV_APP_MODE_NONE,
.app_run = my_app_run,
.app_close = my_app_close,
.com_rec = my_com_rec,
.win_open = my_win_open,
.win_close = my_win_close,
.sc_open = my_sc_open,
.sc_close = my_sc_close,
.app_data_size = sizeof(my_app_data_t),
.sc_data_size = sizeof(my_sc_data_t),
.win_data_size = sizeof(my_win_data_t),
};
static char def_ssid[64];
static char def_pwd[64];
static char def_ip[32];
static char def_port[16];
static char ssid_list[SSID_LIST_MAX_LENGTH];
static lv_app_inst_t * app_act_com;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/**
* Initialize the application
* @return pointer to the application descriptor of this application
*/
const lv_app_dsc_t * lv_app_wifi_init(void)
{
strcpy(ssid_list, "");
#ifdef LV_APP_WIFI_CONF_PATH
fs_file_t f;
fs_res_t res;
res = fs_open(&f, LV_APP_WIFI_CONF_PATH, FS_MODE_RD);
if(res == FS_RES_NOT_EX) {
res = fs_open(&f, LV_APP_WIFI_CONF_PATH, FS_MODE_WR | FS_MODE_RD);
if(res == FS_RES_OK) {
const char * def_conf = "ssid\npwd\n100.101.102.103\n1234";
fs_write(&f, def_conf, strlen(def_conf) + 1, NULL);
fs_seek(&f, 0);
}
}
if(res == FS_RES_OK) {
volatile char buf[256];
volatile uint32_t rn;
fs_read(&f, (char *)buf, sizeof(buf) - 1, (uint32_t *)&rn);
volatile uint16_t i;
volatile uint16_t j = 0;
volatile uint8_t line_cnt = 0;
for(i = 0; i < rn; i++) {
if(buf[i] != '\n') {
if(line_cnt == 0) def_ssid[j] = buf[i];
if(line_cnt == 1) def_pwd[j] = buf[i];
if(line_cnt == 2) def_ip[j] = buf[i];
if(line_cnt == 3) def_port[j] = buf[i];
j++;
} else {
if(line_cnt == 0) def_ssid[j] = '\0';
if(line_cnt == 1) def_pwd[j] = '\0';
if(line_cnt == 2) def_ip[j] = '\0';
if(line_cnt == 3) def_port[j] = '\0';
j = 0;
line_cnt ++;
}
}
fs_close(&f);
} else {
lv_app_notice_add("SD card error");
}
#else
strcpy(def_ssid, LV_APP_WIFI_SSID_DEF);
strcpy(def_pwd, LV_APP_WIFI_PWD_DEF);
strcpy(def_ip, LV_APP_WIFI_IP_DEF);
strcpy(def_port, LV_APP_WIFI_PORT_DEF);
#endif
#if LV_APP_WIFI_AUTO_CONNECT != 0
wifimng_set_last_netw(def_ssid, def_pwd);
wifimng_set_last_tcp(def_ip, def_port);
#endif
ptask_create(wifi_state_monitor_task, WIFI_MONITOR_PERIOD, PTASK_PRIO_LOW, NULL);
return &my_app_dsc;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Run an application according to 'app_dsc'
* @param app_dsc pointer to an application descriptor
* @param conf pointer to a lv_app_example_conf_t structure with configuration data or NULL if unused
* @return pointer to the opened application or NULL if any error occurred
*/
static void my_app_run(lv_app_inst_t * app, void * conf)
{
/*Initialize the application*/
my_app_data_t * adata = app->app_data;
strcpy(adata->set_ssid, def_ssid);
strcpy(adata->set_pwd, def_pwd);
strcpy(adata->set_ip, def_ip);
strcpy(adata->set_port, def_port);
adata->last_msg_dp = NULL;
adata->last_msg_size = 0;
}
/**
* Close a running application.
* Close the Window and the Shortcut too if opened.
* Free all the allocated memory by this application.
* @param app pointer to an application
*/
static void my_app_close(lv_app_inst_t * app)
{
/*No dynamically allocated data in 'my_app_data'*/
}
/**
* Read the data have been sent to this application
* @param app_send pointer to an application which sent the message
* @param app_rec pointer to an application which is receiving the message
* @param type type of data from 'lv_app_com_type_t' enum
* @param data pointer to the sent data
* @param size length of 'data' in bytes
*/
static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec,
lv_app_com_type_t type , const void * data, uint32_t size)
{
if(type == LV_APP_COM_TYPE_CHAR) { /*data: string*/
app_act_com = app_rec;
my_app_data_t * adata = app_act_com->app_data;
if(adata->last_msg_dp != NULL) dm_free(adata->last_msg_dp);
adata->last_msg_dp = dm_alloc(size);
memcpy(adata->last_msg_dp, data, size);
adata->last_msg_size = size;
wifi_tcp_transf(data, size, tcp_transf_cb);
}
}
/**
* Open a shortcut for an application
* @param app pointer to an application
* @param sc pointer to an object where the application
* can create content of the shortcut
*/
static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc)
{
my_sc_data_t * sc_data = app->sc_data;
sc_data->label = lv_label_create(sc, NULL);
lv_label_set_text(sc_data->label, "Empty");
lv_obj_align(sc_data->label, NULL, LV_ALIGN_CENTER, 0, 0);
}
/**
* Close the shortcut of an application
* @param app pointer to an application
*/
static void my_sc_close(lv_app_inst_t * app)
{
/*No dynamically allocated data in 'my_sc_data'*/
}
/**
* Open the application in a window
* @param app pointer to an application
* @param win pointer to a window object where
* the application can create content
*/
static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
{
my_app_data_t * adata = app->app_data;
my_win_data_t * wdata = app->win_data;
wdata->title = lv_label_create(win, NULL);
wdata->list = lv_ddlist_create(win, NULL);
lv_obj_set_free_p(wdata->list, app);
lv_ddlist_set_options_str(wdata->list, ssid_list);
lv_ddlist_set_action(wdata->list, wifi_ap_select_action);
lv_obj_t * list_btn = lv_btn_create(win, NULL);
lv_obj_set_free_p(list_btn, app);
lv_btn_set_rel_action(list_btn, netw_list_rel_action);
lv_obj_t * label = lv_label_create(list_btn, NULL);
lv_label_set_text(label, "List\nrefresh");
lv_obj_t * ta_cont = lv_cont_create(win, NULL);
lv_cont_set_fit(ta_cont, true, true);
lv_cont_set_layout(ta_cont, LV_CONT_LAYOUT_COL_L);
lv_obj_set_style(ta_cont, lv_style_get(LV_STYLE_TRANSP_TIGHT, NULL));
wdata->netw_ssid_ta = lv_ta_create(ta_cont, NULL);
lv_cont_set_fit(wdata->netw_ssid_ta, false, true);
lv_obj_set_free_p(wdata->netw_ssid_ta, app);
lv_page_set_rel_action(wdata->netw_ssid_ta, netw_ssid_rel_action);
lv_ta_set_text(wdata->netw_ssid_ta, adata->set_ssid);
lv_ta_set_cursor_show(wdata->netw_ssid_ta, false);
wdata->netw_pwd_ta = lv_ta_create(ta_cont, wdata->netw_ssid_ta);
lv_page_set_rel_action(wdata->netw_pwd_ta, netw_pwd_rel_action);
lv_ta_set_text(wdata->netw_pwd_ta, adata->set_pwd);
wdata->tcp_ip_ta = lv_ta_create(ta_cont, wdata->netw_ssid_ta);
lv_page_set_rel_action(wdata->tcp_ip_ta, tcp_ip_rel_action);
lv_ta_set_text(wdata->tcp_ip_ta, adata->set_ip);
wdata->tcp_port_ta = lv_ta_create(ta_cont, wdata->netw_ssid_ta);
lv_page_set_rel_action(wdata->tcp_port_ta, tcp_port_rel_action);
lv_ta_set_text(wdata->tcp_port_ta, adata->set_port);
lv_obj_t * con_btn = lv_btn_create(win, NULL);
lv_obj_set_free_p(con_btn, app);
lv_btn_set_rel_action(con_btn, netw_con_rel_action);
label = lv_label_create(con_btn, NULL);
lv_label_set_text(label, "Connect");
lv_cont_set_layout(lv_page_get_scrl(lv_win_get_page(win)), LV_CONT_LAYOUT_PRETTY);
win_title_refr();
}
/**
* Close the window of an application
* @param app pointer to an application
*/
static void my_win_close(lv_app_inst_t * app)
{
}
/*--------------------
* OTHER FUNCTIONS
---------------------*/
static void wifi_state_monitor_task(void * param)
{
static wifimng_state_t state_prev = WIFIMNG_STATE_WAIT;
wifimng_state_t state_act = wifimng_get_state();
if(state_prev != state_act && state_act == WIFIMNG_STATE_READY) {
lv_app_notice_add("WiFi connected to:\n%s\n%s:%s",
wifimng_get_last_ssid(), wifimng_get_last_ip(), wifimng_get_last_port());
win_title_refr();
}
/* The wifi should be busy if there is sg. to send.
* It means fail during last send. Try again*/
if(app_act_com != NULL) {
if(wifi_busy() == false && state_act == WIFIMNG_STATE_READY) {
/*Try to send the message again*/
lv_app_notice_add("Resend WiFi message");
my_app_data_t * adata = app_act_com->app_data;
wifi_tcp_transf(adata->last_msg_dp, adata->last_msg_size, tcp_transf_cb);
}
}
state_prev = state_act;
}
static lv_action_res_t netw_list_rel_action(lv_obj_t * btn, lv_indev_proc_t* indev_proc)
{
wifi_state_t ret;
ret = wifi_netw_list(list_cb);
if(ret == WIFI_STATE_OK) {
lv_app_notice_add("Listing WiFi networks");
} else {
lv_app_notice_add("Cannot list networks\nWiFi was busy. Try again");
}
return LV_ACTION_RES_OK;
}
static lv_action_res_t netw_con_rel_action(lv_obj_t * btn, lv_indev_proc_t* indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(btn);
my_app_data_t * adata = app->app_data;
wifimng_set_last_netw(adata->set_ssid, adata->set_pwd);
wifimng_set_last_tcp(adata->set_ip, adata->set_port);
wifimng_reconnect();
save_conf(app);
lv_app_notice_add("Connecting to WiFi network\n%s, %s:%s",
adata->set_ssid, adata->set_ip, adata->set_port);
return LV_ACTION_RES_OK;
}
static lv_action_res_t netw_ssid_rel_action( lv_obj_t * ta, lv_indev_proc_t* indev_proc)
{
lv_app_kb_open(ta, LV_APP_KB_MODE_TXT | LV_APP_KB_MODE_WIN_RESIZE | LV_APP_KB_MODE_CUR_MANAGE, netw_ssid_kb_close ,netw_ssid_kb_ok);
return LV_ACTION_RES_OK;
}
static lv_action_res_t netw_pwd_rel_action( lv_obj_t * ta, lv_indev_proc_t* indev_proc)
{
lv_app_kb_open(ta, LV_APP_KB_MODE_TXT | LV_APP_KB_MODE_WIN_RESIZE | LV_APP_KB_MODE_CUR_MANAGE, netw_pwd_kb_close ,netw_pwd_kb_ok);
return LV_ACTION_RES_OK;
}
static lv_action_res_t tcp_ip_rel_action( lv_obj_t * ta, lv_indev_proc_t* indev_proc)
{
lv_app_kb_open(ta, LV_APP_KB_MODE_TXT | LV_APP_KB_MODE_WIN_RESIZE | LV_APP_KB_MODE_CUR_MANAGE, tcp_ip_kb_close ,tcp_ip_kb_ok);
return LV_ACTION_RES_OK;
}
static lv_action_res_t tcp_port_rel_action( lv_obj_t * ta, lv_indev_proc_t* indev_proc)
{
lv_app_kb_open(ta, LV_APP_KB_MODE_NUM | LV_APP_KB_MODE_WIN_RESIZE | LV_APP_KB_MODE_CUR_MANAGE, tcp_port_kb_close ,tcp_port_kb_ok);
return LV_ACTION_RES_OK;
}
static lv_action_res_t wifi_ap_select_action( lv_obj_t * ddlist, lv_indev_proc_t* indev_proc)
{
lv_app_inst_t * app = lv_obj_get_free_p(ddlist);
my_app_data_t * adata = app->app_data;
char ssid[256];
lv_ddlist_get_selected_str(ddlist, ssid);
my_win_data_t * wdata = app->win_data;
lv_ta_set_text(wdata->netw_ssid_ta, ssid);
strcpy(adata->set_ssid, ssid);
return LV_ACTION_RES_OK;
}
static void netw_ssid_kb_ok(lv_obj_t * ta)
{
lv_app_inst_t * app = lv_obj_get_free_p(ta);
my_app_data_t * adata = app->app_data;
strcpy(adata->set_ssid, lv_ta_get_txt(ta));
}
static void netw_ssid_kb_close(lv_obj_t * ta)
{
lv_app_inst_t * app = lv_obj_get_free_p(ta);
my_app_data_t * adata = app->app_data;
lv_ta_set_text(ta, adata->set_ssid);
}
static void netw_pwd_kb_ok(lv_obj_t * ta)
{
lv_app_inst_t * app = lv_obj_get_free_p(ta);
my_app_data_t * adata = app->app_data;
strcpy(adata->set_pwd, lv_ta_get_txt(ta));
}
static void netw_pwd_kb_close(lv_obj_t * ta)
{
lv_app_inst_t * app = lv_obj_get_free_p(ta);
my_app_data_t * adata = app->app_data;
lv_ta_set_text(ta, adata->set_pwd);
}
static void tcp_ip_kb_ok(lv_obj_t * ta)
{
lv_app_inst_t * app = lv_obj_get_free_p(ta);
my_app_data_t * adata = app->app_data;
strcpy(adata->set_ip, lv_ta_get_txt(ta));
}
static void tcp_ip_kb_close(lv_obj_t * ta)
{
lv_app_inst_t * app = lv_obj_get_free_p(ta);
my_app_data_t * adata = app->app_data;
lv_ta_set_text(ta, adata->set_ip);
}
static void tcp_port_kb_ok(lv_obj_t * ta)
{
lv_app_inst_t * app = lv_obj_get_free_p(ta);
my_app_data_t * adata = app->app_data;
strcpy(adata->set_port, lv_ta_get_txt(ta));
}
static void tcp_port_kb_close(lv_obj_t * ta)
{
lv_app_inst_t * app = lv_obj_get_free_p(ta);
my_app_data_t * adata = app->app_data;
lv_ta_set_text(ta, adata->set_port);
}
static void list_cb(wifi_state_t state, const char * txt)
{
if(state == WIFI_STATE_OK) {
if(txt[0] == '\0') {
lv_app_notice_add("WiFi network list ready");
return;
}
if(strlen(ssid_list) + strlen(txt) + 4 < sizeof(ssid_list)) {
sprintf(ssid_list, "%s\n%s", ssid_list, txt);
}
lv_app_inst_t * app = lv_app_get_next(NULL, &my_app_dsc);
while(app != NULL) {
if(app->win_data != NULL) {
my_win_data_t * wdata = app->win_data;
lv_ddlist_set_options_str(wdata->list, ssid_list);
}
app = lv_app_get_next(app, &my_app_dsc);
}
} else if(state == WIFI_STATE_ERROR) {
lv_app_notice_add("WiFi network list error\n%s", txt);
}
}
static void tcp_transf_cb(wifi_state_t state, const char * txt)
{
if(state == WIFI_STATE_OK) {
uint16_t size = txt[0] + ((txt[1] << 8) & 0xFF00);
char buf[256];
memcpy(buf, &txt[2], size);
buf[size] = '\0';
lv_app_com_send(app_act_com, LV_APP_COM_TYPE_CHAR, &txt[2], size);
my_app_data_t * adata = app_act_com->app_data;
dm_free(adata->last_msg_dp);
adata->last_msg_dp = NULL;
adata->last_msg_size = 0;
app_act_com = NULL;
}else if(state == WIFI_STATE_ERROR) {
lv_app_notice_add("WiFi TCP transfer error\n%s", txt);
lv_app_notice_add("Reconnecting to WiFi...");
wifimng_reconnect();
}
}
static void win_title_refr(void)
{
lv_app_inst_t * app;
app = lv_app_get_next(NULL, &my_app_dsc);
while(app != NULL) {
if(app->win != NULL) {
my_win_data_t * wdata = app->win_data;
if(wifimng_get_state() == WIFIMNG_STATE_IDLE) {
lv_label_set_text(wdata->title, "Not connected");
}
else if(wifimng_get_state() == WIFIMNG_STATE_READY) {
char buf[256];
sprintf(buf, "%s - %s:%s", wifimng_get_last_ssid(), wifimng_get_last_ip(), wifimng_get_last_port());
lv_label_set_text(wdata->title, buf);
}
else {
lv_label_set_text(wdata->title, "Connecting ...");
}
lv_obj_set_width(wdata->title, lv_win_get_width(app->win));
}
app = lv_app_get_next(app, &my_app_dsc);
}
}
static void save_conf(lv_app_inst_t * app)
{
#ifdef LV_APP_WIFI_CONF_PATH
my_app_data_t * adata = app->app_data;
fs_file_t f;
fs_res_t res;
res = fs_open(&f, LV_APP_WIFI_CONF_PATH, FS_MODE_WR);
if(res == FS_RES_OK) {
char buf[256];
sprintf(buf,"%s\n%s\n%s\n%s", adata->set_ssid, adata->set_pwd, adata->set_ip, adata->set_port);
fs_write(&f, buf, strlen(buf) + 1, NULL);
fs_close(&f);
}
#endif
}
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_EXAMPLE != 0*/
/**
* @file lv_app_example.h
*
*/
#ifndef LV_APP_WIFI_H
#define LV_APP_WIFI_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lvgl/lv_app/lv_app.h"
#if LV_APP_ENABLE != 0 && USE_LV_APP_WIFI != 0
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct
{
}lv_app_wifi_conf_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
const lv_app_dsc_t * lv_app_wifi_init(void);
/**********************
* MACROS
**********************/
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_EXAMPLE != 0*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* LV_APP_EXAMPLE_H */
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