forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lvgl_shell.c
204 lines (172 loc) · 5.07 KB
/
lvgl_shell.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* Copyright (c) 2023 Fabian Blatz <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/shell/shell.h>
#include <lvgl.h>
#include <autoconf.h>
#ifdef CONFIG_LV_Z_MEM_POOL_SYS_HEAP
#include "lvgl_mem.h"
#endif
#ifdef CONFIG_LV_USE_MONKEY
static lv_monkey_t *lvgl_monkeys[CONFIG_LV_Z_MAX_MONKEY_COUNT];
static const char *lvgl_monkey_indev_as_string(lv_monkey_t *monkey)
{
lv_indev_t *input_device;
input_device = lv_monkey_get_indev(monkey);
if (!input_device || !input_device->driver) {
return "unknown";
}
switch (input_device->driver->type) {
case LV_INDEV_TYPE_POINTER:
return "pointer";
case LV_INDEV_TYPE_KEYPAD:
return "keypad";
case LV_INDEV_TYPE_BUTTON:
return "button";
case LV_INDEV_TYPE_ENCODER:
return "encoder";
default:
return "unknown";
}
}
static int lvgl_monkey_indev_from_string(const char *str, lv_indev_type_t *input_device)
{
if (strcmp(str, "pointer") == 0) {
*input_device = LV_INDEV_TYPE_POINTER;
} else if (strcmp(str, "keypad") == 0) {
*input_device = LV_INDEV_TYPE_KEYPAD;
} else if (strcmp(str, "button") == 0) {
*input_device = LV_INDEV_TYPE_BUTTON;
} else if (strcmp(str, "encoder") == 0) {
*input_device = LV_INDEV_TYPE_ENCODER;
} else {
return -EINVAL;
}
return 0;
}
static void dump_monkey_info(const struct shell *sh)
{
shell_print(sh, "id device active");
for (size_t i = 0; i < CONFIG_LV_Z_MAX_MONKEY_COUNT; i++) {
if (lvgl_monkeys[i] != NULL) {
shell_print(sh, "%-4u %-9s %-3s", i,
lvgl_monkey_indev_as_string(lvgl_monkeys[i]),
lv_monkey_get_enable(lvgl_monkeys[i]) ? "yes" : "no");
}
}
}
static int cmd_lvgl_monkey(const struct shell *sh, size_t argc, char *argv[])
{
ARG_UNUSED(argc);
ARG_UNUSED(argv);
dump_monkey_info(sh);
shell_print(sh, "");
shell_help(sh);
return SHELL_CMD_HELP_PRINTED;
}
static int cmd_lvgl_monkey_create(const struct shell *sh, size_t argc, char *argv[])
{
bool created_monkey = false;
lv_monkey_config_t default_config;
lv_monkey_config_init(&default_config);
if (argc == 2) {
if (lvgl_monkey_indev_from_string(argv[1], &default_config.type) < 0) {
shell_error(sh, "Invalid monkey input device %s", argv[1]);
shell_help(sh);
return SHELL_CMD_HELP_PRINTED;
}
}
for (size_t i = 0; i < CONFIG_LV_Z_MAX_MONKEY_COUNT; i++) {
if (lvgl_monkeys[i] == NULL) {
lvgl_monkeys[i] = lv_monkey_create(&default_config);
lv_monkey_set_enable(lvgl_monkeys[i], true);
created_monkey = true;
break;
}
}
if (!created_monkey) {
shell_error(sh, "Error creating monkey instance");
return -ENOSPC;
}
dump_monkey_info(sh);
return 0;
}
static int cmd_lvgl_monkey_set(const struct shell *sh, size_t argc, char *argv[])
{
int index;
index = atoi(argv[1]);
if (index < 0 || index >= CONFIG_LV_Z_MAX_MONKEY_COUNT || lvgl_monkeys[index] == NULL) {
shell_error(sh, "Invalid monkey index");
return -ENOEXEC;
}
if (strcmp(argv[2], "active") == 0) {
lv_monkey_set_enable(lvgl_monkeys[index], true);
} else if (strcmp(argv[2], "inactive") == 0) {
lv_monkey_set_enable(lvgl_monkeys[index], false);
} else {
shell_error(sh, "Invalid monkey state %s", argv[2]);
shell_help(sh);
return SHELL_CMD_HELP_PRINTED;
}
dump_monkey_info(sh);
return 0;
}
#endif /* CONFIG_LV_USE_MONKEY */
static int cmd_lvgl_stats(const struct shell *sh, size_t argc, char *argv[])
{
ARG_UNUSED(argc);
ARG_UNUSED(argv);
shell_help(sh);
return SHELL_CMD_HELP_PRINTED;
}
static int cmd_lvgl_stats_memory(const struct shell *sh, size_t argc, char *argv[])
{
#ifdef CONFIG_LV_Z_MEM_POOL_SYS_HEAP
bool dump_chunks = false;
if (argc == 2) {
if (strcmp(argv[1], "-c") == 0) {
dump_chunks = true;
} else {
shell_error(sh, "unsupported option %s", argv[1]);
shell_help(sh);
return SHELL_CMD_HELP_PRINTED;
}
}
lvgl_print_heap_info(dump_chunks);
return 0;
#else
ARG_UNUSED(argc);
ARG_UNUSED(argv);
shell_error(sh, "Set CONFIG_LV_Z_MEM_POOL_SYS_HEAP to enable memory statistics support.");
return -ENOTSUP;
#endif
}
SHELL_STATIC_SUBCMD_SET_CREATE(lvgl_cmd_stats,
SHELL_CMD_ARG(memory, NULL,
"Show LVGL memory statistics\n"
"Usage: lvgl stats memory [-c]\n"
"-c dump chunk information",
cmd_lvgl_stats_memory, 1, 1),
SHELL_SUBCMD_SET_END);
#ifdef CONFIG_LV_USE_MONKEY
SHELL_STATIC_SUBCMD_SET_CREATE(
lvgl_cmd_monkey,
SHELL_CMD_ARG(create, NULL,
"Create a new monkey instance (default: pointer)\n"
"Usage: lvgl monkey create [pointer|keypad|button|encoder]",
cmd_lvgl_monkey_create, 1, 1),
SHELL_CMD_ARG(set, NULL,
"Activate/deactive a monkey instance\n"
"Usage: lvgl monkey set <index> <active|inactive>\n",
cmd_lvgl_monkey_set, 3, 0),
SHELL_SUBCMD_SET_END);
#endif /* CONFIG_LV_USE_MONKEY */
SHELL_STATIC_SUBCMD_SET_CREATE(
lvgl_cmds, SHELL_CMD(stats, &lvgl_cmd_stats, "Show LVGL statistics", cmd_lvgl_stats),
#ifdef CONFIG_LV_USE_MONKEY
SHELL_CMD(monkey, &lvgl_cmd_monkey, "LVGL monkey testing", cmd_lvgl_monkey),
#endif /* CONFIG_LV_USE_MONKEY */
SHELL_SUBCMD_SET_END);
SHELL_CMD_REGISTER(lvgl, &lvgl_cmds, "LVGL shell commands", NULL);