From 352cd819bd1ef367dc3a33d62b05b9e1d8bd4a61 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Tue, 29 Oct 2024 11:46:47 -0400 Subject: [PATCH] Add hvutils --- recipes-support/hvutils/files/hvutils.sh | 99 ++++++++++++++++++++++++ recipes-support/hvutils/hvutils.bb | 18 +++++ 2 files changed, 117 insertions(+) create mode 100644 recipes-support/hvutils/files/hvutils.sh create mode 100644 recipes-support/hvutils/hvutils.bb diff --git a/recipes-support/hvutils/files/hvutils.sh b/recipes-support/hvutils/files/hvutils.sh new file mode 100644 index 0000000..019dcb5 --- /dev/null +++ b/recipes-support/hvutils/files/hvutils.sh @@ -0,0 +1,99 @@ +#!/bin/sh + +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2023 Hugo Villeneuve + +COLOR_ERR="\033[0;31m" +COLOR_WARN="\033[0;33m" +COLOR_NONE="\033[0m" + +# When using /bin/sh, echo needs to be prefixed with its path to avoid +# printing "-e". +ECHO="/bin/echo -e" + +if [ "${debug}" = "" ]; then + # Set default value, debug disabled. + # Define to 1 to display debug messages. + debug=0 +fi + +log_info() { + ${ECHO} "${COLOR_NONE}${*}" +} + +log_dbg() { + if [ ${debug} -eq 1 ]; then + ${ECHO} "${*}" + fi +} + +log_warn() { + ${ECHO} >&2 "${COLOR_WARN}${*}${COLOR_NONE}" +} + +log_err() { + ${ECHO} >&2 "${COLOR_ERR}${*}${COLOR_NONE}" +} + +lcd() { + printf "$@" > /dev/lcd +} + +lcd_clear() { + lcd '\f' +} + +lcd_init() { + # Cursor off + lcd "\x1b[Lc" + lcd_clear +} + +# Input variables: +# l1 to l4 +# l1p to l4p +lcd_update() { + + # TODO: scroll long lines... + + if [ "${l1}" != "${l1p}" -o \ + "${l2}" != "${l2p}" -o \ + "${l3}" != "${l3p}" -o \ + "${l4}" != "${l4p}" ]; then + lcd_clear + + log_dbg "lcd_update()" + log_dbg " l1=$l1" + log_dbg " l2=$l2" + log_dbg " l3=$l3" + log_dbg " l4=$l4" + + # Make sure strings are at least 20 characters long: + l1f="${l1}${fill}" + l2f="${l2}${fill}" + l3f="${l3}${fill}" + l4f="${l4}${fill}" + + l1t="$(printf "%.20s\n" "${l1f}")" + l2t="$(printf "%.20s\n" "${l2f}")" + # Bug, écran défectueux ligne 3... + l3t="" + l4t="$(printf "%.20s\n" "${l4f}")" + + # TODO: remove trailing whitespace + + l13="${l1t}${l3t}" + l24="${l2t}${l4t}" + + log_dbg " l13=$l13" + log_dbg " l24=$l24" + + lcd "${l13}\n" + lcd "${l24}\n" + + l1p="${l1}" + l2p="${l2}" + l3p="${l3}" + l4p="${l4}" + fi +} diff --git a/recipes-support/hvutils/hvutils.bb b/recipes-support/hvutils/hvutils.bb new file mode 100644 index 0000000..754c7a0 --- /dev/null +++ b/recipes-support/hvutils/hvutils.bb @@ -0,0 +1,18 @@ +DESCRIPTION = "HV utils scripts" + +LICENSE = "GPL-2.0-only" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0-only;md5=801f80980d171dd6425610833a22dbe6" + +PV = "0.0.1" + +SRC_URI += "file://hvutils.sh" + +RDEPENDS:${PN} +="bash" + +do_install () { + # Common header shell script: + install -d ${D}${bindir} + install -m 0644 ${WORKDIR}/hvutils.sh ${D}${bindir}/ +} + +FILES:${PN} += "${bindir}/hvutils.sh" -- 2.20.1