BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lvgl
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
lvgl
Commits
d3f468b0
Commit
d3f468b0
authored
Jan 06, 2017
by
Gabor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lv_app: create string deleted minor updates
parent
b73efc27
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
172 additions
and
69 deletions
+172
-69
lv_app.c
lv_app/lv_app.c
+39
-7
lv_app.h
lv_app/lv_app.h
+7
-2
lv_app_fsel.c
lv_app/lv_app_util/lv_app_fsel.c
+13
-18
lv_app_notice.c
lv_app/lv_app_util/lv_app_notice.c
+10
-2
lv_app_notice.h
lv_app/lv_app_util/lv_app_notice.h
+2
-1
lv_app_example.c
lv_appx/lv_app_example.c
+2
-8
lv_app_sysmon.c
lv_appx/lv_app_sysmon.c
+7
-7
lv_app_terminal.c
lv_appx/lv_app_terminal.c
+92
-24
No files found.
lv_app/lv_app.c
View file @
d3f468b0
...
...
@@ -18,6 +18,7 @@
#include "../lv_appx/lv_app_example.h"
#include "../lv_appx/lv_app_sysmon.h"
#include "../lv_appx/lv_app_terminal.h"
#include "../lv_appx/lv_app_files.h"
/*********************
* DEFINES
...
...
@@ -140,16 +141,20 @@ void lv_app_init(void)
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
}
/**
* 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)
* @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
,
const
char
*
cstr
,
void
*
conf
)
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
;
...
...
@@ -165,7 +170,7 @@ lv_app_inst_t * lv_app_run(const lv_app_dsc_t * app_dsc, const char * cstr, void
lv_app_rename
(
app
,
app_dsc
->
name
);
/*Set a default name*/
/*Call the application specific run function*/
app_dsc
->
app_run
(
app
,
c
str
,
c
onf
);
app_dsc
->
app_run
(
app
,
conf
);
return
app
;
}
...
...
@@ -185,6 +190,7 @@ void lv_app_close(lv_app_inst_t * app)
app
->
dsc
->
app_close
(
app
);
memset
(
app
->
app_data
,
0
,
app
->
dsc
->
app_data_size
);
dm_free
(
app
->
app_data
);
dm_free
(
app
->
name
);
...
...
@@ -253,6 +259,7 @@ void lv_app_sc_close(lv_app_inst_t * 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
;
}
...
...
@@ -299,6 +306,8 @@ void lv_app_win_close(lv_app_inst_t * 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
;
}
...
...
@@ -455,6 +464,22 @@ lv_app_inst_t * lv_app_get_next(lv_app_inst_t * prev, lv_app_dsc_t * dsc)
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
;
}
/**
* Refresh the style of the applications
...
...
@@ -468,6 +493,12 @@ void lv_app_style_refr(void)
lv_obj_set_width
(
lv_page_get_scrl
(
sc_page
),
LV_HOR_RES
-
2
*
(
app_style
.
sc_page_style
.
bg_rects
.
hpad
));
app_style
.
win_useful_w
=
LV_HOR_RES
-
2
*
(
app_style
.
win_style
.
pages
.
bg_rects
.
hpad
+
app_style
.
win_style
.
pages
.
scrl_rects
.
hpad
);
app_style
.
win_useful_h
=
LV_VER_RES
-
2
*
(
app_style
.
win_style
.
pages
.
bg_rects
.
vpad
+
app_style
.
win_style
.
pages
.
scrl_rects
.
vpad
);
}
...
...
@@ -580,7 +611,7 @@ static lv_action_res_t lv_app_menu_elem_rel_action(lv_obj_t * app_elem_btn, lv_d
lv_obj_del
(
app_list
);
app_list
=
NULL
;
lv_app_inst_t
*
app
=
lv_app_run
(
dsc
,
""
,
NULL
);
lv_app_inst_t
*
app
=
lv_app_run
(
dsc
,
NULL
);
lv_app_sc_open
(
app
);
#if LV_APP_EFFECT_ANIM != 0 && LV_APP_EFFECT_OPA_ANIM != 0 && LV_APP_ANIM_SC != 0
...
...
@@ -1016,13 +1047,13 @@ static void lv_app_init_style(void)
lv_labels_get
(
LV_LABELS_DEF
,
&
app_style
.
sc_title_style
);
app_style
.
sc_title_style
.
font
=
LV_APP_FONT_SMALL
;
app_style
.
sc_title_style
.
objs
.
color
=
COLOR_MAKE
(
0x10
,
0x
20
,
0x3
0
);
app_style
.
sc_title_style
.
objs
.
color
=
COLOR_MAKE
(
0x10
,
0x
18
,
0x2
0
);
app_style
.
sc_title_style
.
mid
=
1
;
lv_labels_get
(
LV_LABELS_DEF
,
&
app_style
.
sc_txt_style
);
app_style
.
sc_txt_style
.
font
=
LV_APP_FONT_MEDIUM
;
app_style
.
sc_txt_style
.
objs
.
color
=
COLOR_MAKE
(
0x
20
,
0x30
,
0x4
0
);
app_style
.
sc_txt_style
.
mid
=
0
;
app_style
.
sc_txt_style
.
objs
.
color
=
COLOR_MAKE
(
0x
10
,
0x18
,
0x2
0
);
app_style
.
sc_txt_style
.
mid
=
1
;
/*Window styles*/
lv_wins_get
(
LV_WINS_DEF
,
&
app_style
.
win_style
);
...
...
@@ -1039,6 +1070,7 @@ static void lv_app_init_style(void)
2
*
app_style
.
win_style
.
header
.
vpad
;
app_style
.
win_style
.
pages
.
bg_rects
.
hpad
=
5
*
LV_DOWNSCALE
;
app_style
.
win_style
.
pages
.
scrl_rects
.
objs
.
transp
=
1
;
app_style
.
win_style
.
pages
.
sb_mode
=
LV_PAGE_SB_MODE_AUTO
;
lv_labels_get
(
LV_LABELS_DEF
,
&
app_style
.
win_txt_style
);
app_style
.
win_txt_style
.
font
=
LV_APP_FONT_MEDIUM
;
...
...
lv_app/lv_app.h
View file @
d3f468b0
...
...
@@ -55,7 +55,7 @@ typedef struct __LV_APP_DSC_T
{
const
char
*
name
;
lv_app_mode_t
mode
;
void
(
*
app_run
)(
lv_app_inst_t
*
,
const
char
*
,
void
*
);
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
*
);
...
...
@@ -91,6 +91,10 @@ typedef struct {
cord_t
app_list_w
;
cord_t
app_list_h
;
cord_t
sc_title_margin
;
/*Calculated values, do not set them!*/
cord_t
win_useful_w
;
cord_t
win_useful_h
;
}
lv_app_style_t
;
...
...
@@ -98,7 +102,7 @@ typedef struct {
* 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
*
conf
);
lv_app_inst_t
*
lv_app_run
(
const
lv_app_dsc_t
*
app_dsc
,
void
*
conf
);
void
lv_app_close
(
lv_app_inst_t
*
app
);
uint16_t
lv_app_com_send
(
lv_app_inst_t
*
app_send
,
lv_app_com_type_t
type
,
const
void
*
data
,
uint32_t
size
);
lv_obj_t
*
lv_app_sc_open
(
lv_app_inst_t
*
app
);
...
...
@@ -116,6 +120,7 @@ void lv_app_rename(lv_app_inst_t * app, const char * name);
void
lv_app_style_refr
(
void
);
lv_app_inst_t
*
lv_app_get_next
(
lv_app_inst_t
*
prev
,
lv_app_dsc_t
*
dsc
);
lv_app_dsc_t
**
lv_app_dsc_get_next
(
lv_app_dsc_t
**
prev
);
const
lv_app_dsc_t
*
lv_app_example_init
(
void
);
...
...
lv_app/lv_app_util/lv_app_fsel.c
View file @
d3f468b0
...
...
@@ -17,7 +17,7 @@
*********************/
#define LV_APP_FSEL_FN_MAX_LEN 128
#define LV_APP_FSEL_PATH_MAX_LEN 256
#define LV_APP_FSEL_
MAX_FILE
8
#define LV_APP_FSEL_
PAGE_SIZE
8
/**********************
* TYPEDEFS
...
...
@@ -62,12 +62,7 @@ static void (*fsel_ok_action)(void *, const char *);
*/
void
lv_app_fsel_init
(
void
)
{
lv_app_style_t
*
app_style
=
lv_app_style_get
();
lv_lists_get
(
LV_LISTS_TRANSP
,
&
fsel_lists
);
memcpy
(
&
fsel_lists
.
liste_labels
,
&
app_style
->
menu_btn_label_style
,
sizeof
(
lv_labels_t
));
memcpy
(
&
fsel_lists
.
liste_imgs
,
&
app_style
->
menu_btn_img_style
,
sizeof
(
lv_imgs_t
));
}
/**
...
...
@@ -144,13 +139,14 @@ static void fsel_refr(void)
lv_win_set_title
(
fsel_win
,
fsel_path
);
/*Create a new list*/
lv_
wins_t
*
wins
=
lv_obj_get_style
(
fsel_win
);
lv_
app_style_t
*
app_style
=
lv_app_style_get
(
);
fsel_list
=
lv_list_create
(
fsel_win
,
NULL
);
lv_obj_set_size
(
fsel_list
,
LV_HOR_RES
-
2
*
(
wins
->
pages
.
bg_rects
.
hpad
+
wins
->
pages
.
scrl_rects
.
hpad
),
LV_VER_RES
-
wins
->
pages
.
bg_rects
.
vpad
-
2
*
wins
->
pages
.
scrl_rects
.
vpad
);
lv_obj_align
(
fsel_list
,
NULL
,
LV_ALIGN_CENTER
,
0
,
0
);
lv_obj_set_style
(
fsel_list
,
&
fsel_lists
);
lv_obj_set_width
(
fsel_list
,
app_style
->
win_useful_w
);
lv_obj_set_style
(
fsel_list
,
lv_lists_get
(
LV_LISTS_TRANSP
,
NULL
));
lv_list_set_fit
(
fsel_list
,
LV_LIST_FIT_WIDTH_SB
);
lv_obj_set_drag_parent
(
fsel_list
,
true
);
lv_obj_set_drag_parent
(
lv_page_get_scrl
(
fsel_list
),
true
);
lv_rect_set_fit
(
fsel_list
,
false
,
true
);
fs_res_t
res
=
FS_RES_OK
;
...
...
@@ -222,7 +218,7 @@ static void fsel_refr(void)
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_
MAX_FIL
E
==
0
)
{
if
(
fsel_file_cnt
!=
0
&&
fsel_file_cnt
%
LV_APP_FSEL_
PAGE_SIZ
E
==
0
)
{
lv_list_add
(
fsel_list
,
"U:/icon_right"
,
"Next page"
,
fsel_next_action
);
break
;
}
...
...
@@ -238,7 +234,6 @@ static void fsel_refr(void)
/*Focus to the top of the list*/
lv_obj_set_y
(
lv_page_get_scrl
(
fsel_list
),
0
);
return
;
}
/**
...
...
@@ -287,11 +282,11 @@ static lv_action_res_t fsel_next_action(lv_obj_t * next, lv_dispi_t * dispi)
*/
static
lv_action_res_t
fsel_prev_action
(
lv_obj_t
*
prev
,
lv_dispi_t
*
dispi
)
{
if
(
fsel_file_cnt
<=
2
*
LV_APP_FSEL_
MAX_FIL
E
)
fsel_file_cnt
=
0
;
else
if
(
fsel_file_cnt
%
LV_APP_FSEL_
MAX_FIL
E
==
0
)
{
fsel_file_cnt
-=
2
*
LV_APP_FSEL_
MAX_FIL
E
;
if
(
fsel_file_cnt
<=
2
*
LV_APP_FSEL_
PAGE_SIZ
E
)
fsel_file_cnt
=
0
;
else
if
(
fsel_file_cnt
%
LV_APP_FSEL_
PAGE_SIZ
E
==
0
)
{
fsel_file_cnt
-=
2
*
LV_APP_FSEL_
PAGE_SIZ
E
;
}
else
{
fsel_file_cnt
=
((
fsel_file_cnt
/
LV_APP_FSEL_
MAX_FILE
)
-
1
)
*
LV_APP_FSEL_MAX_FIL
E
;
fsel_file_cnt
=
((
fsel_file_cnt
/
LV_APP_FSEL_
PAGE_SIZE
)
-
1
)
*
LV_APP_FSEL_PAGE_SIZ
E
;
}
fsel_refr
();
...
...
@@ -366,7 +361,7 @@ static lv_action_res_t fsel_folder_lpr_action(lv_obj_t * folder, lv_dispi_t * di
}
/**
* Called when a file list element is
long pres
sed to choose it
* Called when a file list element is
relea
sed to choose it
* @param file pointer to a file button
* @param dispi pointer to the caller display input
* @return LV_ACTION_RES_INV because the list is deleted in the function
...
...
lv_app/lv_app_util/lv_app_notice.c
View file @
d3f468b0
...
...
@@ -13,6 +13,7 @@
#include "lvgl/lv_objx/lv_label.h"
#include "lvgl/lv_misc/anim.h"
#include <stdio.h>
/*********************
* DEFINES
...
...
@@ -75,10 +76,17 @@ void lv_app_notice_init(void)
/**
* Add a notification with a given text
* @param
txt the text of the notification
* @param
format pritntf-like format string
*/
void
lv_app_notice_add
(
const
char
*
txt
)
void
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_app_style_t
*
app_style
=
lv_app_style_get
();
lv_obj_t
*
n
;
...
...
lv_app/lv_app_util/lv_app_notice.h
View file @
d3f468b0
...
...
@@ -10,6 +10,7 @@
* INCLUDES
*********************/
#include "../lv_app.h"
#include <stdarg.h>
#if LV_APP_ENABLE != 0
/*********************
...
...
@@ -24,7 +25,7 @@
* GLOBAL PROTOTYPES
**********************/
void
lv_app_notice_init
(
void
);
void
lv_app_notice_add
(
const
char
*
txt
);
void
lv_app_notice_add
(
const
char
*
format
,
...
);
/**********************
* MACROS
...
...
lv_appx/lv_app_example.c
View file @
d3f468b0
...
...
@@ -41,7 +41,7 @@ typedef struct
/**********************
* STATIC PROTOTYPES
**********************/
static
void
my_app_run
(
lv_app_inst_t
*
app
,
const
char
*
cstr
,
void
*
conf
);
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
);
...
...
@@ -95,18 +95,12 @@ const lv_app_dsc_t * lv_app_example_init(void)
/**
* 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)
* @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
,
const
char
*
cstr
,
void
*
conf
)
static
void
my_app_run
(
lv_app_inst_t
*
app
,
void
*
conf
)
{
/*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
);
}
}
/**
...
...
lv_appx/lv_app_sysmon.c
View file @
d3f468b0
...
...
@@ -49,7 +49,7 @@ typedef struct
/**********************
* STATIC PROTOTYPES
**********************/
static
void
my_app_run
(
lv_app_inst_t
*
app
,
const
char
*
cstr
,
void
*
conf
);
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
);
...
...
@@ -57,7 +57,7 @@ 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
);
static
void
sysmon_task
(
void
*
param
);
static
void
lv_app_sysmon_refr
(
void
);
/**********************
...
...
@@ -101,7 +101,7 @@ static dm_mon_t mem_mon;
*/
const
lv_app_dsc_t
*
lv_app_sysmon_init
(
void
)
{
ptask_create
(
sysmon_task
,
LV_APP_SYSMON_REFR_TIME
,
PTASK_PRIO_LOW
);
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
));
...
...
@@ -142,11 +142,10 @@ const lv_app_dsc_t * lv_app_sysmon_init(void)
/**
* 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)
* @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
,
const
char
*
cstr
,
void
*
conf
)
static
void
my_app_run
(
lv_app_inst_t
*
app
,
void
*
conf
)
{
}
...
...
@@ -267,8 +266,9 @@ static void my_win_close(lv_app_inst_t * app)
/**
* 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
)
static
void
sysmon_task
(
void
*
param
)
{
/*Shift out the oldest data*/
uint16_t
i
;
...
...
@@ -353,7 +353,7 @@ static void lv_app_sysmon_refr(void)
DM_MEM_SIZE
,
DM_MEM_SIZE
-
mem_mon
.
size_free
,
mem_mon
.
size_free
,
mem_mon
.
pct_frag
);
sprintf
(
buf_short
,
"%sMem: %d %%
\n
Frag: %d %%"
,
sprintf
(
buf_short
,
"%sMem: %d %%
\n
Frag: %d %%
\n
"
,
buf_short
,
mem_pct
[
LV_APP_SYSMON_PNUM
-
1
],
mem_mon
.
pct_frag
);
#else
sprintf
(
buf_long
,
"%sMEMORY: N/A"
,
buf_long
);
...
...
lv_appx/lv_app_terminal.c
View file @
d3f468b0
...
...
@@ -25,6 +25,7 @@ typedef struct
{
char
txt
[
LV_APP_TERMINAL_LENGTH
+
1
];
lv_app_com_type_t
com_type
;
lv_app_inst_t
*
last_sender
;
}
my_app_data_t
;
/*Application specific data a window of this application*/
...
...
@@ -33,6 +34,7 @@ typedef struct
lv_obj_t
*
label
;
lv_obj_t
*
ta
;
lv_obj_t
*
com_type_btn
;
lv_obj_t
*
clear_btn
;
}
my_win_data_t
;
/*Application specific data for a shortcut of this application*/
...
...
@@ -44,7 +46,7 @@ typedef struct
/**********************
* STATIC PROTOTYPES
**********************/
static
void
my_app_run
(
lv_app_inst_t
*
app
,
const
char
*
cstr
,
void
*
conf
);
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
);
...
...
@@ -55,6 +57,7 @@ static void my_win_close(lv_app_inst_t * app);
static
void
add_data
(
lv_app_inst_t
*
app
,
const
void
*
data
,
uint16_t
data_len
);
static
lv_action_res_t
win_ta_rel_action
(
lv_obj_t
*
ta
,
lv_dispi_t
*
dispi
);
static
lv_action_res_t
win_comch_rel_action
(
lv_obj_t
*
btn
,
lv_dispi_t
*
dispi
);
static
lv_action_res_t
win_clear_rel_action
(
lv_obj_t
*
btn
,
lv_dispi_t
*
dispi
);
static
void
win_ta_kb_ok_action
(
lv_obj_t
*
ta
);
/**********************
...
...
@@ -94,16 +97,17 @@ lv_labels_t sc_txts;
*/
const
lv_app_dsc_t
*
lv_app_terminal_init
(
void
)
{
com_type_txt
[
LV_APP_COM_TYPE_INT
]
=
"C
omm. ch.
\n
numbers
"
;
com_type_txt
[
LV_APP_COM_TYPE_CHAR
]
=
"C
omm. ch.
\n
c
hars"
;
com_type_txt
[
LV_APP_COM_TYPE_LOG
]
=
"C
omm. ch.
\n
l
og"
;
com_type_txt
[
LV_APP_COM_TYPE_INV
]
=
"C
omm. ch.
\n
n
one"
;
com_type_txt
[
LV_APP_COM_TYPE_INT
]
=
"C
h: Num
"
;
com_type_txt
[
LV_APP_COM_TYPE_CHAR
]
=
"C
h: C
hars"
;
com_type_txt
[
LV_APP_COM_TYPE_LOG
]
=
"C
h: L
og"
;
com_type_txt
[
LV_APP_COM_TYPE_INV
]
=
"C
h: N
one"
;
lv_app_style_t
*
app_style
=
lv_app_style_get
();
memcpy
(
&
sc_txts
,
&
app_style
->
sc_txt_style
,
sizeof
(
lv_labels_t
));
sc_txts
.
line_space
=
0
;
sc_txts
.
letter_space
=
0
;
sc_txts
.
mid
=
0
;
sc_txts
.
objs
.
color
=
COLOR_WHITE
;
lv_objs_get
(
LV_OBJS_DEF
,
&
sc_txt_bgs
);
...
...
@@ -120,16 +124,16 @@ const lv_app_dsc_t * lv_app_terminal_init(void)
/**
* 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)
* @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
,
const
char
*
cstr
,
void
*
conf
)
static
void
my_app_run
(
lv_app_inst_t
*
app
,
void
*
conf
)
{
/*Initialize the application*/
my_app_data_t
*
app_data
=
app
->
app_data
;
app_data
->
com_type
=
LV_APP_COM_TYPE_CHAR
;
memset
(
app_data
->
txt
,
0
,
sizeof
(
app_data
->
txt
));;
app_data
->
last_sender
=
NULL
;
memset
(
app_data
->
txt
,
0
,
sizeof
(
app_data
->
txt
));
}
/**
...
...
@@ -158,12 +162,18 @@ static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec,
/*Add the recevied data if the type is matches*/
if
(
type
==
app_data
->
com_type
)
{
if
(
app_data
->
txt
[
0
]
!=
'\0'
)
add_data
(
app_rec
,
"
\n
"
,
1
);
add_data
(
app_rec
,
"@"
,
1
);
add_data
(
app_rec
,
app_send
->
name
,
strlen
(
app_send
->
name
));
add_data
(
app_rec
,
"
\n
"
,
1
);
add_data
(
app_rec
,
data
,
size
);
/*Insert the name of the sender application if it is not the last*/
if
(
app_data
->
last_sender
!=
app_send
)
{
if
(
app_data
->
txt
[
0
]
!=
'\0'
)
add_data
(
app_rec
,
"
\n
"
,
1
);
add_data
(
app_rec
,
"@"
,
1
);
add_data
(
app_rec
,
app_send
->
name
,
strlen
(
app_send
->
name
));
add_data
(
app_rec
,
"
\n
"
,
1
);
}
add_data
(
app_rec
,
data
,
size
);
}
app_data
->
last_sender
=
app_send
;
}
/**
...
...
@@ -236,7 +246,7 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
lv_obj_align
(
win_data
->
ta
,
win_data
->
label
,
LV_ALIGN_OUT_BOTTOM_LEFT
,
0
,
opad
);
/*Creat a button to set the communication type (char, integer etc.)*/
/*Creat
e
a button to set the communication type (char, integer etc.)*/
win_data
->
com_type_btn
=
lv_btn_create
(
win
,
NULL
);
lv_rect_set_fit
(
win_data
->
com_type_btn
,
true
,
true
);
lv_obj_set_free_p
(
win_data
->
com_type_btn
,
app
);
...
...
@@ -246,6 +256,15 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
lv_label_set_text
(
btn_label
,
com_type_txt
[
app_data
->
com_type
]);
lv_obj_align
(
win_data
->
com_type_btn
,
win_data
->
ta
,
LV_ALIGN_OUT_RIGHT_TOP
,
opad
,
0
);
/*Create a clear button*/
win_data
->
clear_btn
=
lv_btn_create
(
win
,
win_data
->
com_type_btn
);
lv_btn_set_rel_action
(
win_data
->
clear_btn
,
win_clear_rel_action
);
btn_label
=
lv_label_create
(
win_data
->
clear_btn
,
NULL
);
lv_obj_set_style
(
btn_label
,
lv_labels_get
(
LV_LABELS_BTN
,
NULL
));
lv_label_set_text
(
btn_label
,
"Clear"
);
lv_obj_align
(
win_data
->
clear_btn
,
win_data
->
com_type_btn
,
LV_ALIGN_OUT_RIGHT_TOP
,
opad
,
0
);
/*Align the window to see the text area on the bottom*/
lv_obj_align
(
lv_page_get_scrl
(
app
->
win
),
NULL
,
LV_ALIGN_IN_BOTTOM_LEFT
,
0
,
-
app_style
->
win_style
.
pages
.
scrl_rects
.
vpad
);
...
...
@@ -300,6 +319,40 @@ static lv_action_res_t win_comch_rel_action(lv_obj_t * btn, lv_dispi_t * dispi)
}
/**
* Called when the Clear button is released to clear the ex od the terminal
* @param btn pointer to the clear button
* @param dispi pointer to the caller display input
* @return LV_ACTION_RES_OK because the button is not deleted
*/
static
lv_action_res_t
win_clear_rel_action
(
lv_obj_t
*
btn
,
lv_dispi_t
*
dispi
)
{
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_app_style_t
*
app_style
=
lv_app_style_get
();
cord_t
opad
=
app_style
->
win_style
.
pages
.
scrl_rects
.
opad
;
lv_label_set_text_static
(
win_data
->
label
,
app_data
->
txt
);
lv_obj_align
(
win_data
->
ta
,
win_data
->
label
,
LV_ALIGN_OUT_BOTTOM_LEFT
,
0
,
opad
);
lv_obj_align
(
win_data
->
com_type_btn
,
win_data
->
ta
,
LV_ALIGN_OUT_RIGHT_TOP
,
opad
,
0
);
lv_obj_align
(
win_data
->
clear_btn
,
win_data
->
com_type_btn
,
LV_ALIGN_OUT_RIGHT_TOP
,
opad
,
0
);
lv_obj_align
(
lv_page_get_scrl
(
app
->
win
),
NULL
,
LV_ALIGN_IN_BOTTOM_LEFT
,
0
,
-
app_style
->
win_style
.
pages
.
scrl_rects
.
vpad
);
}
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
...
...
@@ -331,25 +384,39 @@ static void add_data(lv_app_inst_t * app, const void * data, uint16_t data_len)
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*/
if
(
old_len
+
data_len
>
LV_APP_TERMINAL_LENGTH
)
{
uint16_t
i
;
for
(
i
=
0
;
i
<
old_len
;
i
++
)
{
if
(
app_data
->
txt
[
i
]
==
'\n'
)
{
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
(
i
>=
data_len
)
{
/*Ignore line braks*/
while
(
app_data
->
txt
[
i
]
==
'\n'
||
app_data
->
txt
[
i
]
==
'\r'
)
i
++
;
if
(
new_start
>=
data_len
)
{
/*Ignore line br
e
aks*/
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
=
i
;
j
<
old_len
;
j
++
)
{
app_data
->
txt
[
j
-
i
]
=
app_data
->
txt
[
j
];
for
(
j
=
new_start
;
j
<
old_len
;
j
++
)
{
app_data
->
txt
[
j
-
new_start
]
=
app_data
->
txt
[
j
];
}
old_len
=
old_len
-
i
;
old_len
=
old_len
-
new_start
;
app_data
->
txt
[
old_len
]
=
'\0'
;
}
memcpy
(
&
app_data
->
txt
[
old_len
],
txt
,
data_len
);
...
...
@@ -364,6 +431,7 @@ static void add_data(lv_app_inst_t * app, const void * data, uint16_t data_len)
lv_label_set_text_static
(
win_data
->
label
,
app_data
->
txt
);
lv_obj_align
(
win_data
->
ta
,
win_data
->
label
,
LV_ALIGN_OUT_BOTTOM_LEFT
,
0
,
opad
);
lv_obj_align
(
win_data
->
com_type_btn
,
win_data
->
ta
,
LV_ALIGN_OUT_RIGHT_TOP
,
opad
,
0
);
lv_obj_align
(
win_data
->
clear_btn
,
win_data
->
com_type_btn
,
LV_ALIGN_OUT_RIGHT_TOP
,
opad
,
0
);
lv_obj_align
(
lv_page_get_scrl
(
app
->
win
),
NULL
,
LV_ALIGN_IN_BOTTOM_LEFT
,
0
,
-
app_style
->
win_style
.
pages
.
scrl_rects
.
vpad
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment