lvgl-demo: add support to initialize LVGL demo at boot

This commit adds a systemd service and a sysvinit script to initialize the LVGL
demo automatically on boot.

Signed-off-by: Arturo Buzarra <arturo.buzarra@digi.com>
This commit is contained in:
Arturo Buzarra 2024-01-23 18:05:19 +01:00
parent a1a176f091
commit a1f68f94d4
4 changed files with 190 additions and 1 deletions

View File

@ -0,0 +1,133 @@
#!/bin/sh
#===============================================================================
#
# Copyright (C) 2024 by Digi International Inc.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published by
# the Free Software Foundation.
#
#
# !Description: Initialize LVGL demo
#
#===============================================================================
readonly DEMO_NAME="lvgl_demo"
readonly DEMO_PATH="/usr/bin/${DEMO_NAME}"
readonly DEMO_TITLE="LVGL Demo Application"
readonly DEMO_DISPLAY="##DEMO_DISPLAY##"
readonly DEMO_ENV="##DEMO_ENV##"
readonly PID_FILE="/run/${DEMO_NAME}.pid"
log() {
if type "systemd-cat" >/dev/null 2>/dev/null; then
systemd-cat -p "${1}" -t "${DEMO_NAME}" printf "%s" "${2}"
fi
logger -p "${1}" -t "${DEMO_NAME}" "${2}"
}
get_demo_pid() {
local pid="$(pgrep -f ${DEMO_PATH})"
[ -n "${pid}" ] && { echo "${pid}"; return 0; }
return 1
}
check_is_running() {
local pid
if [ -s "${PID_FILE}" ]; then
pid="$(cat ${PID_FILE})"
else
pid="$(get_demo_pid)"
echo "${pid}" > ${PID_FILE}
fi
if [ "${pid}" ]; then
kill -0 "${pid}" >/dev/null 2>&1 && return 0
fi
rm -f "${PID_FILE}"
return 1
}
wait_for_wayland() {
local count=20
local wayland_socket="/run/user/0/${DEMO_DISPLAY}"
while [ ! -S "${wayland_socket}" ]; do
sleep 1
count=$((count-1))
if [ "${count}" = 0 ]; then
return 1
fi
done
sleep 1
return 0
}
stop() {
check_is_running || return
local pid="$(cat ${PID_FILE})"
kill -TERM "${pid}" >/dev/null 2>&1
local STOP_TIMEOUT="5"
for i in $(seq ${STOP_TIMEOUT}); do
check_is_running || { log info "stopped"; break; }
if [ "${i}" -eq ${STOP_TIMEOUT} ]; then
log warning "stop: ${DEMO_NAME} did not stop gracefully"
kill -KILL "${pid}" >/dev/null 2>&1
fi
sleep 1
done
}
start() {
check_is_running && { log warning "start: ${DEMO_NAME} ALREADY running"; exit 0; }
if [ -d "/usr/share/wayland" ]; then
wait_for_wayland
else
# Disable the cursor when displaying at full screen on fbdev
echo "0" > /sys/class/graphics/fbcon/cursor_blink
fi
# Launch demo
env ${DEMO_ENV} ${DEMO_PATH} >/dev/null 2>&1 &
if [ $? -eq 0 ]; then
echo $! > ${PID_FILE}
log info "$(cat ${PID_FILE})"
log info "started"
fi
}
case "$1" in
start)
echo -n "Starting ${DEMO_TITLE}: "
start
echo "done."
;;
stop)
stop
echo -n "Stopping ${DEMO_TITLE}: "
if [ -n "`/bin/pidof ${DEMO_PATH}`" ] ; then
echo "FAIL"
else
echo "OK"
fi
;;
restart)
stop
sleep 1
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac

View File

@ -0,0 +1,15 @@
[Unit]
Description=LVGL Demo Application
# Make sure we are started after graphic service is available
After=##WESTON_SERVICE##
Requires=##WESTON_SERVICE##
[Service]
Type=forking
PIDFile=/run/lvgl_demo.pid
ExecStart=/etc/lvgl-demo-init start
ExecStop=/etc/lvgl-demo-init stop
[Install]
WantedBy=multi-user.target

View File

@ -9,6 +9,8 @@ SRCBRANCH ?= "dey/master"
SRC_URI = " \
gitsm://github.com/digi-embedded/lv_port_linux_frame_buffer.git;branch=${SRCBRANCH};protocol=https \
file://lvgl-demo-init \
file://lvgl-demo-init.service \
"
SRCREV = "0a799d22a5aaf9de18aca428579945a0a9c2c270"
@ -23,7 +25,7 @@ PACKAGECONFIG = "${@bb.utils.contains('DISTRO_FEATURES', 'wayland', 'wayland', '
require lv-drivers.inc
inherit cmake
inherit cmake systemd update-rc.d
S = "${WORKDIR}/git"
@ -58,9 +60,47 @@ do_configure:prepend() {
-i "${S}/lv_drv_conf.h"
}
WESTON_SERVICE ?= "weston.service"
WESTON_SERVICE:ccmp15 ?= "weston-launch.service"
DEMO_DISPLAY ?= "wayland-0"
DEMO_DISPLAY:ccmp15 ?= "wayland-1"
DEMO_ENV ?= "DISPLAY=:0.0 XDG_RUNTIME_DIR=/run/user/0 WAYLAND_DISPLAY=\${DEMO_DISPLAY}"
DEMO_ENV:ccimx6ul ?= ""
do_install:append() {
install -d ${D}${bindir}
install -m 0755 ${B}/lvgl_fb ${D}${bindir}/lvgl_demo
# Install systemd service
if ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}; then
# Install systemd unit files
install -d ${D}${systemd_unitdir}/system
install -m 0644 ${WORKDIR}/lvgl-demo-init.service ${D}${systemd_unitdir}/system/
sed -i -e "s,##WESTON_SERVICE##,${WESTON_SERVICE},g" \
"${D}${systemd_unitdir}/system/lvgl-demo-init.service"
fi
# Install wrapper bootscript to launch LVGL demo on boot
install -d ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/lvgl-demo-init ${D}${sysconfdir}/lvgl-demo-init
sed -i -e "s@##DEMO_DISPLAY##@${DEMO_DISPLAY}@g" \
-e "s@##DEMO_ENV##@${DEMO_ENV}@g" \
"${D}${sysconfdir}/lvgl-demo-init"
ln -sf ${sysconfdir}/lvgl-demo-init ${D}${sysconfdir}/init.d/lvgl-demo-init
}
PACKAGES =+ "${PN}-init"
FILES:${PN}-init = " \
${sysconfdir}/lvgl-demo-init \
${sysconfdir}/init.d/lvgl-demo-init \
${systemd_unitdir}/system/lvgl-demo-init.service \
"
INITSCRIPT_PACKAGES += "${PN}-init"
INITSCRIPT_NAME:${PN}-init = "lvgl-demo-init"
INITSCRIPT_PARAMS:${PN}-init = "start 99 3 5 . stop 20 0 1 2 6 ."
SYSTEMD_PACKAGES = "${PN}-init"
SYSTEMD_SERVICE:${PN}-init = "lvgl-demo-init.service"
COMPATIBLE_MACHINE = "(ccimx6$|ccimx6ul|ccimx8m|ccimx8x|ccimx93|ccmp15)"

View File

@ -8,4 +8,5 @@ inherit packagegroup
RDEPENDS:${PN} += " \
lvgl-demo \
lvgl-demo-init \
"