The very basics of apps working. Sc and Win open close ok. Example app written
This commit is contained in:
186
lv_app/lv_app.c
Normal file
186
lv_app/lv_app.c
Normal file
@@ -0,0 +1,186 @@
|
||||
/**
|
||||
* @file lv_app.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_app.h"
|
||||
#include "lvgl/lv_objx/lv_btn.h"
|
||||
#include "lvgl/lv_objx/lv_win.h"
|
||||
#include "img_conf.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_app_sc_rel_action(lv_obj_t * sc, lv_dispi_t * dispi);
|
||||
static bool lv_app_win_close_action(lv_obj_t * close_btn, lv_dispi_t * dispi);
|
||||
|
||||
|
||||
/**********************
|
||||
* 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*/
|
||||
LV_IMG_DECLARE(img_close);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the application system
|
||||
*/
|
||||
void lv_app_init(void)
|
||||
{
|
||||
ll_init(&app_dsc_ll, sizeof(lv_app_dsc_t *));
|
||||
ll_init(&app_inst_ll, sizeof(lv_app_inst_t));
|
||||
|
||||
/*Create images for the window control buttons*/
|
||||
lv_img_create_file("close",img_close);
|
||||
|
||||
/*Initialize all application descriptors*/
|
||||
const lv_app_dsc_t ** dsc;
|
||||
#if USE_LV_APP_EXAMPLE
|
||||
dsc = ll_ins_head(&app_dsc_ll);
|
||||
*dsc = lv_app_example_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Run an application according to 'app_dsc'
|
||||
* @param app_dsc pointer to an application descriptor
|
||||
* @param cstr a Create STRing which can give initial parameters to the application (NULL or "" 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, const char * cstr)
|
||||
{
|
||||
/*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);
|
||||
|
||||
/*Call the application specific run function*/
|
||||
app_dsc->app_run(app, cstr);
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish an event.
|
||||
* @param app pointer to an application which publishes the event
|
||||
* @param event an event from 'lv_app_event_t' enum
|
||||
*/
|
||||
void lv_app_event_send(lv_app_inst_t * app, lv_app_event_t event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
app->sc = lv_btn_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_free_p(app->sc, app);
|
||||
lv_btn_set_rel_action(app->sc, lv_app_sc_rel_action);
|
||||
|
||||
app->sc_data = dm_alloc(app->dsc->sc_data_size);
|
||||
app->dsc->sc_open(app, app->sc);
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
app->win = lv_win_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_free_p(app->win, app);
|
||||
lv_win_add_ctrl_btn(app->win, "U:/close", lv_app_win_close_action);
|
||||
|
||||
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)
|
||||
{
|
||||
lv_obj_del(app->win);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
static bool lv_app_sc_rel_action(lv_obj_t * sc, lv_dispi_t * dispi)
|
||||
{
|
||||
lv_app_inst_t * app = lv_obj_get_free_p(sc);
|
||||
lv_app_win_open(app);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool lv_app_win_close_action(lv_obj_t * close_btn, lv_dispi_t * dispi)
|
||||
{
|
||||
lv_obj_t * win = lv_win_get_from_ctrl_btn(close_btn);
|
||||
lv_app_inst_t * app = lv_obj_get_free_p(win);
|
||||
lv_app_win_close(app);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
91
lv_app/lv_app.h
Normal file
91
lv_app/lv_app.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* @file lv_app.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_APP_H
|
||||
#define LV_APP_H
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lvgl/lvgl.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
typedef enum
|
||||
{
|
||||
LV_APP_MODE_NONE = 0x0000,
|
||||
LV_APP_MODE_RUN_ONCE = 0x0001,
|
||||
LV_APP_MODE_NO_SC = 0x0002, /*No short cut*/
|
||||
LV_APP_MODE_NO_WIN = 0x0004, /*No window mode*/
|
||||
LV_APP_MODE_NO_CON = 0x0008, /*No connection to other apps*/
|
||||
LV_APP_MODE_NO_CLOSE = 0x0010, /*No close control button*/
|
||||
LV_APP_MODE_NO_FIX = 0x0020, /*No fix control button*/
|
||||
}lv_app_mode_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LV_APP_EVENT_OPEN,
|
||||
LV_APP_EVENT_CLOSE,
|
||||
LV_APP_EVENT_SC_OPENED,
|
||||
LV_APP_EVENT_SC_CLOSED,
|
||||
LV_APP_EVENT_WIN_OPENED,
|
||||
LV_APP_EVENT_WIN_CLOSED,
|
||||
}lv_app_event_t;
|
||||
|
||||
struct __LV_APP_DSC_T;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const struct __LV_APP_DSC_T * dsc;
|
||||
const char * name_mod;
|
||||
lv_obj_t * sc;
|
||||
lv_obj_t * 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 *, const char *);
|
||||
void (*app_close) (lv_app_inst_t *);
|
||||
void (*event_read) (lv_app_inst_t *, lv_app_event_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 *);
|
||||
uint16_t app_data_size;
|
||||
uint16_t sc_data_size;
|
||||
uint16_t win_data_size;
|
||||
}lv_app_dsc_t;
|
||||
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_app_init(void);
|
||||
lv_app_inst_t * lv_app_run(const lv_app_dsc_t * app_dsc, const char * cstr);
|
||||
void lv_app_close(lv_app_inst_t * app);
|
||||
void lv_app_event_send(lv_app_inst_t * app, lv_app_event_t event);
|
||||
lv_obj_t * lv_app_sc_open(lv_app_inst_t * app);
|
||||
void lv_app_sc_close(lv_app_inst_t * app);
|
||||
lv_obj_t * lv_app_win_open(lv_app_inst_t * app);
|
||||
void lv_app_win_close(lv_app_inst_t * app);
|
||||
const lv_app_dsc_t * lv_app_dsc_get(const char * name);
|
||||
|
||||
const lv_app_dsc_t * lv_app_example_init(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif
|
||||
167
lv_appx/lv_app_example.c
Normal file
167
lv_appx/lv_app_example.c
Normal file
@@ -0,0 +1,167 @@
|
||||
/**
|
||||
* @file lv_app_example.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_app_example.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/*Application specific data for an instance of this application*/
|
||||
typedef struct
|
||||
{
|
||||
const char * txt;
|
||||
}app_data_t;
|
||||
|
||||
/*Application specific data a window of this application*/
|
||||
typedef struct
|
||||
{
|
||||
|
||||
}win_data_t;
|
||||
|
||||
/*Application specific data for a shortcut of this application*/
|
||||
typedef struct
|
||||
{
|
||||
|
||||
}sc_data_t;
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void my_app_run(lv_app_inst_t * app, const char * cstr);
|
||||
static void my_app_close(lv_app_inst_t * app);
|
||||
static void my_event_read(lv_app_inst_t * app, lv_app_event_t event);
|
||||
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 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,
|
||||
.event_read = my_event_read,
|
||||
.win_open = my_win_open,
|
||||
.win_close = my_win_close,
|
||||
.sc_open = my_sc_open,
|
||||
.sc_close = my_sc_close,
|
||||
.app_data_size = sizeof(app_data_t),
|
||||
.sc_data_size = sizeof(sc_data_t),
|
||||
.win_data_size = sizeof(win_data_t),
|
||||
};
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
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 cstr a Create STRing which can give initial parameters to the application (NULL or "" if unused)
|
||||
* @return pointer to the opened application or NULL if any error occurred
|
||||
*/
|
||||
static void my_app_run(lv_app_inst_t * app, const char * cstr)
|
||||
{
|
||||
/*Check the create string*/
|
||||
if(cstr == NULL || cstr[0] == '\0') {
|
||||
cstr = "No create string";
|
||||
}
|
||||
|
||||
/*Initialize the application*/
|
||||
((app_data_t *)app->app_data)->txt = cstr; /*Save the create string*/
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish an event.
|
||||
* @param app pointer to an application which publishes the event
|
||||
* @param event an event from 'lv_app_event_t' enum
|
||||
*/
|
||||
static void my_event_read(lv_app_inst_t * app, lv_app_event_t event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
lv_obj_t * label;
|
||||
label = lv_label_create(sc, NULL);
|
||||
lv_label_set_text(label, ((app_data_t *)app->app_data)->txt);
|
||||
lv_obj_set_style(label, lv_labels_get(LV_LABELS_BTN, NULL));
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the shortcut of an application
|
||||
* @param app pointer to an application
|
||||
*/
|
||||
static void my_sc_close(lv_app_inst_t * app)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 * label;
|
||||
label = lv_label_create(win, NULL);
|
||||
lv_label_set_text(label, ((app_data_t *)app->app_data)->txt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the window of an application
|
||||
* @param app pointer to an application
|
||||
*/
|
||||
static void my_win_close(lv_app_inst_t * app)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
30
lv_appx/lv_app_example.h
Normal file
30
lv_appx/lv_app_example.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @file lv_app_example.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_APP_EXAMPLE_H
|
||||
#define LV_APP_EXAMPLE_H
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lvgl/lv_app/lv_app.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /* LV_APP_EXAMPLE */
|
||||
@@ -3,8 +3,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _2D_H
|
||||
#define _2D_H
|
||||
#ifndef AREA_H
|
||||
#define AREA_H
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @file lv_base_obj.h
|
||||
* @file lv_obj.h
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -250,6 +250,7 @@ lv_signal_f_t lv_obj_get_signal_f(lv_obj_t * obj);
|
||||
void * lv_obj_get_ext(lv_obj_t * obj);
|
||||
void * lv_obj_get_style(lv_obj_t * obj);
|
||||
uint8_t lv_obj_get_free_num(lv_obj_t * obj);
|
||||
void * lv_obj_get_free_p(lv_obj_t * obj);
|
||||
|
||||
lv_objs_t * lv_objs_get(lv_objs_builtin_t style, lv_objs_t * copy_p);
|
||||
|
||||
|
||||
6
lvgl.h
6
lvgl.h
@@ -25,12 +25,14 @@
|
||||
#include "lv_objx/lv_ta.h"
|
||||
#include "lv_objx/lv_win.h"
|
||||
|
||||
#include "lv_app/lv_app.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LVGL_VERSION_MAJOR 1
|
||||
#define LVGL_VERSION_MINOR 3
|
||||
#define LVGL_VERSION_BUGFIX 1
|
||||
#define LVGL_VERSION_MINOR 4
|
||||
#define LVGL_VERSION_BUGFIX 0
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
|
||||
Reference in New Issue
Block a user