rk3506b使用lvgl

关闭默认的UI

1
2
3
/etc/init.d/S49weston stop
/etc/init.d/S50systemui stop
killall systemui weston lv_demo 2>/dev/null

原始SDK的LVGL 的 evdev 触摸设备设备名匹配规则比较严格,会导致无法使用触摸。

在不想修改代码的请款下可以执行以下命令来找到正确的触摸设备。

1
export LV_EVENT_NAME=/dev/input/event0

之后就可以正常使用lv_demo程序了。并且lv_demo默认被编进固件,路径为/usr/bin/lv_demo

1
lv_demo

后续修改了evdev.c代码,可以匹配上触摸节点。

以上就已经结束了。

以下不用看

补充一个保留系统默认 UI,但按命令一键切换到 lv_demo/再切回”的脚本

功能:

1
2
3
demo:停 systemui/weston,启动 lv_demo
ui:停 lv_demo,恢复 weston + systemui
status:查看当前进程状态

建议部署步骤:

1
2
在 SDK 根目录执行:.build.sh extra-parts
刷写 OEM 分区:.rkflash.sh oem

板子上使用:

1
2
3
sh /oem/ui-switch.sh demo
sh /oem/ui-switch.sh ui
sh /oem/ui-switch.sh status
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
#!/bin/sh
# One-key switch between default system UI and LVGL demo.
# Usage:
# sh /oem/ui-switch.sh demo # switch to lv_demo
# sh /oem/ui-switch.sh ui # switch back to system UI
# sh /oem/ui-switch.sh status # show process/service status

set -u

WESTON_INIT="/etc/init.d/S49weston"
SYSTEMUI_INIT="/etc/init.d/S50systemui"
LV_DEMO_LOG="/tmp/lv_demo.log"

log() {
echo "[ui-switch] $*"
}

require_root() {
if [ "$(id -u)" != "0" ]; then
log "please run as root"
exit 1
fi
}

svc_stop() {
_svc="$1"
[ -x "$_svc" ] || return 0
"$_svc" stop >/dev/null 2>&1 || true
}

svc_start() {
_svc="$1"
[ -x "$_svc" ] || return 0
"$_svc" start >/dev/null 2>&1 || true
}

kill_if_running() {
_name="$1"
killall "$_name" >/dev/null 2>&1 || true
}

wait_wayland_ready() {
# Keep same environment behavior as init scripts.
[ -r /etc/profile ] && . /etc/profile

_runtime_dir="${XDG_RUNTIME_DIR:-/run/user/0}"
_sock="${_runtime_dir}/wayland-0"
_i=0
while [ ! -e "$_sock" ] && [ "$_i" -lt 80 ]; do
sleep 0.1
_i=$((_i + 1))
done

[ -e "$_sock" ]
}

to_demo() {
log "switching to lv_demo..."

svc_stop "$SYSTEMUI_INIT"
svc_stop "$WESTON_INIT"

kill_if_running systemui
kill_if_running weston
kill_if_running rk_demo
kill_if_running lv_demo

# Recommend cursor plane to reduce conflicts with primary plane.
export LV_DRIVERS_SET_PLANE="${LV_DRIVERS_SET_PLANE:-CURSOR}"

nohup lv_demo >"$LV_DEMO_LOG" 2>&1 &
sleep 1

if pidof lv_demo >/dev/null 2>&1; then
log "lv_demo is running (log: $LV_DEMO_LOG)"
return 0
fi

log "lv_demo failed to start, check: $LV_DEMO_LOG"
return 1
}

to_ui() {
log "switching back to default UI..."

kill_if_running lv_demo
kill_if_running rk_demo

svc_start "$WESTON_INIT"

if ! wait_wayland_ready; then
log "warning: wayland socket not ready, continue to start systemui"
fi

svc_start "$SYSTEMUI_INIT"

sleep 1
if pidof systemui >/dev/null 2>&1; then
log "systemui is running"
return 0
fi

log "systemui may not be running, check: /var/log/weston.log"
return 1
}

status() {
echo "=== process status ==="
ps -ef | grep -E "weston|systemui|lv_demo|rk_demo" | grep -v grep || true
echo ""
echo "=== service files ==="
[ -x "$WESTON_INIT" ] && echo "ok: $WESTON_INIT" || echo "missing: $WESTON_INIT"
[ -x "$SYSTEMUI_INIT" ] && echo "ok: $SYSTEMUI_INIT" || echo "missing: $SYSTEMUI_INIT"
}

usage() {
cat <<EOF
Usage: sh /oem/ui-switch.sh {demo|ui|status}
demo stop default UI stack and run lv_demo
ui stop lv_demo and recover default UI stack
status show running processes and service status
EOF
}

require_root

case "${1:-status}" in
demo)
to_demo
;;
ui)
to_ui
;;
status)
status
;;
*)
usage
exit 1
;;
esac