2016-12-15 16:19:23 +01:00
|
|
|
/**
|
|
|
|
* @file lv_app_example.c
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
|
|
|
#include "lv_app_example.h"
|
2016-12-21 14:49:23 +01:00
|
|
|
#if LV_APP_ENABLE != 0 && USE_LV_APP_EXAMPLE != 0
|
|
|
|
|
2016-12-29 07:10:49 +01:00
|
|
|
#include "../lv_app/lv_app_util/lv_app_kb.h"
|
2016-12-17 21:22:16 +01:00
|
|
|
#include <stdio.h>
|
2016-12-15 16:19:23 +01:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/*Application specific data for an instance of this application*/
|
|
|
|
typedef struct
|
|
|
|
{
|
2016-12-22 21:41:47 +01:00
|
|
|
|
2016-12-21 14:49:23 +01:00
|
|
|
}my_app_data_t;
|
2016-12-15 16:19:23 +01:00
|
|
|
|
|
|
|
/*Application specific data a window of this application*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
|
2016-12-21 14:49:23 +01:00
|
|
|
}my_win_data_t;
|
2016-12-15 16:19:23 +01:00
|
|
|
|
|
|
|
/*Application specific data for a shortcut of this application*/
|
|
|
|
typedef struct
|
|
|
|
{
|
2016-12-21 14:49:23 +01:00
|
|
|
lv_obj_t * label;
|
|
|
|
}my_sc_data_t;
|
2016-12-15 16:19:23 +01:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
2016-12-29 23:48:01 +01:00
|
|
|
static void my_app_run(lv_app_inst_t * app, const char * cstr, void * conf);
|
2016-12-15 16:19:23 +01:00
|
|
|
static void my_app_close(lv_app_inst_t * app);
|
2016-12-22 15:00:22 +01:00
|
|
|
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 len);
|
2016-12-15 16:19:23 +01:00
|
|
|
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);
|
|
|
|
|
2016-12-22 21:41:47 +01:00
|
|
|
static lv_action_res_t ta_rel_action(lv_obj_t * ta, lv_dispi_t * dispi);
|
|
|
|
static void kb_ok_action(lv_obj_t * ta);
|
2016-12-21 14:49:23 +01:00
|
|
|
|
2016-12-15 16:19:23 +01:00
|
|
|
/**********************
|
|
|
|
* 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,
|
2016-12-21 14:49:23 +01:00
|
|
|
.com_rec = my_com_rec,
|
2016-12-15 16:19:23 +01:00
|
|
|
.win_open = my_win_open,
|
|
|
|
.win_close = my_win_close,
|
|
|
|
.sc_open = my_sc_open,
|
|
|
|
.sc_close = my_sc_close,
|
2016-12-21 14:49:23 +01:00
|
|
|
.app_data_size = sizeof(my_app_data_t),
|
|
|
|
.sc_data_size = sizeof(my_sc_data_t),
|
|
|
|
.win_data_size = sizeof(my_win_data_t),
|
2016-12-15 16:19:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* 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)
|
2016-12-29 23:48:01 +01:00
|
|
|
* @param conf pointer to a lv_app_example_conf_t structure with configuration data or NULL if unused
|
2016-12-15 16:19:23 +01:00
|
|
|
* @return pointer to the opened application or NULL if any error occurred
|
|
|
|
*/
|
2016-12-29 23:48:01 +01:00
|
|
|
static void my_app_run(lv_app_inst_t * app, const char * cstr, void * conf)
|
2016-12-15 16:19:23 +01:00
|
|
|
{
|
2016-12-22 21:41:47 +01:00
|
|
|
/*Initialize the application*/
|
|
|
|
if(cstr != NULL && cstr[0] != '\0') {
|
|
|
|
char buf[256];
|
|
|
|
sprintf(buf,"%s - %s", my_app_dsc.name, cstr);
|
|
|
|
lv_app_rename(app, buf);
|
2016-12-15 16:19:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2016-12-22 21:41:47 +01:00
|
|
|
/*No dynamically allocated data in 'my_app_data'*/
|
2016-12-15 16:19:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-21 14:49:23 +01:00
|
|
|
* Read the data have been sent to this application
|
|
|
|
* @param app_send pointer to an application which sent the message
|
2016-12-22 15:00:22 +01:00
|
|
|
* @param app_rec pointer to an application which is receiving the message
|
2016-12-21 14:49:23 +01:00
|
|
|
* @param type type of data from 'lv_app_com_type_t' enum
|
|
|
|
* @param data pointer to the sent data
|
|
|
|
* @param len length of 'data' in bytes
|
2016-12-15 16:19:23 +01:00
|
|
|
*/
|
2016-12-22 15:00:22 +01:00
|
|
|
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 len)
|
2016-12-15 16:19:23 +01:00
|
|
|
{
|
2016-12-21 14:49:23 +01:00
|
|
|
if(type == LV_APP_COM_TYPE_STR) { /*data: string*/
|
2016-12-22 15:00:22 +01:00
|
|
|
my_sc_data_t * sc_data = app_rec->sc_data;
|
|
|
|
if (sc_data->label != NULL) {
|
|
|
|
lv_label_set_text(sc_data->label, data);
|
|
|
|
lv_obj_align(sc_data->label , NULL,LV_ALIGN_CENTER, 0, 0);
|
|
|
|
}
|
2016-12-21 14:49:23 +01:00
|
|
|
}
|
|
|
|
else if(type == LV_APP_COM_TYPE_BIN) { /*data: array of 'int32_t' */
|
2016-12-15 16:19:23 +01:00
|
|
|
|
2016-12-21 14:49:23 +01:00
|
|
|
}
|
2016-12-22 21:41:47 +01:00
|
|
|
else if(type == LV_APP_COM_TYPE_TRIG) { /*data: ignored' */
|
|
|
|
|
|
|
|
}
|
2016-12-15 16:19:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2016-12-21 14:49:23 +01:00
|
|
|
my_sc_data_t * sc_data = app->sc_data;
|
|
|
|
|
|
|
|
sc_data->label = lv_label_create(sc, NULL);
|
2016-12-22 21:41:47 +01:00
|
|
|
lv_label_set_text(sc_data->label, "Empty");
|
2016-12-21 14:49:23 +01:00
|
|
|
lv_obj_set_style(sc_data->label, lv_labels_get(LV_LABELS_DEF, NULL));
|
|
|
|
lv_obj_align(sc_data->label, NULL, LV_ALIGN_CENTER, 0, 0);
|
2016-12-15 16:19:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close the shortcut of an application
|
|
|
|
* @param app pointer to an application
|
|
|
|
*/
|
|
|
|
static void my_sc_close(lv_app_inst_t * app)
|
|
|
|
{
|
2016-12-22 21:41:47 +01:00
|
|
|
/*No dynamically allocated data in 'my_sc_data'*/
|
2016-12-15 16:19:23 +01:00
|
|
|
}
|
|
|
|
|
2016-12-22 21:41:47 +01:00
|
|
|
|
2016-12-15 16:19:23 +01:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2016-12-18 22:07:03 +01:00
|
|
|
lv_obj_t * ta;
|
|
|
|
ta = lv_ta_create(win, NULL);
|
2016-12-19 11:58:11 +01:00
|
|
|
lv_obj_set_size_us(ta, 200, 100);
|
2016-12-22 21:41:47 +01:00
|
|
|
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");
|
2016-12-15 16:19:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close the window of an application
|
|
|
|
* @param app pointer to an application
|
|
|
|
*/
|
|
|
|
static void my_win_close(lv_app_inst_t * app)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-12-22 21:41:47 +01:00
|
|
|
/*--------------------
|
|
|
|
* OTHER FUNCTIONS
|
|
|
|
---------------------*/
|
2016-12-15 16:19:23 +01:00
|
|
|
|
2016-12-22 21:41:47 +01:00
|
|
|
/**
|
|
|
|
* 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 dispi 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_dispi_t * dispi)
|
2016-12-21 14:49:23 +01:00
|
|
|
{
|
2016-12-22 21:41:47 +01:00
|
|
|
lv_app_kb_open(ta, LV_APP_KB_MODE_TXT | LV_APP_KB_MODE_CLR, NULL, kb_ok_action);
|
|
|
|
return LV_ACTION_RES_OK;
|
|
|
|
}
|
2016-12-21 14:49:23 +01:00
|
|
|
|
2016-12-22 21:41:47 +01:00
|
|
|
/**
|
|
|
|
* 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);
|
2016-12-29 23:48:01 +01:00
|
|
|
lv_app_com_send(app, LV_APP_COM_TYPE_STR, txt, strlen(txt) + 1);
|
2016-12-21 14:49:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /*LV_APP_ENABLE != 0 && USE_LV_APP_EXAMPLE != 0*/
|