From 7087726e34f00df1c6ae1a5dbd5c8edd11ac4687 Mon Sep 17 00:00:00 2001 From: fewtarius Date: Tue, 17 Sep 2024 22:25:28 +0000 Subject: [PATCH] Fix battery watchdog to prevent turning off LEDs when the battery is full. --- PKGBUILD/steamfork-device-support/PKGBUILD | 2 +- .../src/usr/bin/steamfork-battery-watchdog | 26 ++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/PKGBUILD/steamfork-device-support/PKGBUILD b/PKGBUILD/steamfork-device-support/PKGBUILD index 38924713..63888ca3 100644 --- a/PKGBUILD/steamfork-device-support/PKGBUILD +++ b/PKGBUILD/steamfork-device-support/PKGBUILD @@ -1,7 +1,7 @@ # Maintainer: Fewtarius pkgname=steamfork-device-support -pkgver=2024.09.06 +pkgver=2024.09.17 pkgrel=1 pkgdesc='Hardware support provider for PC handhelds.' arch=('any') diff --git a/PKGBUILD/steamfork-device-support/src/usr/bin/steamfork-battery-watchdog b/PKGBUILD/steamfork-device-support/src/usr/bin/steamfork-battery-watchdog index 9494bf17..f2a53629 100755 --- a/PKGBUILD/steamfork-device-support/src/usr/bin/steamfork-battery-watchdog +++ b/PKGBUILD/steamfork-device-support/src/usr/bin/steamfork-battery-watchdog @@ -14,7 +14,7 @@ then fi BATCNT=0 -FLASHDELAY=20 +FLASHDELAY=2 LED_PATH="/sys/class/leds/multicolor:chassis" unset CURRENT_MODE @@ -31,12 +31,29 @@ case $(get_setting system.loglevel) in esac function set_rgb() { - $DEBUG && log ${0} "multi_intensity: ${1} brightness: ${2}" + $DEBUG && log ${0} "set_rgb: multi_intensity: ${1} brightness: ${2}" echo "${1}" >${LED_PATH}/multi_intensity echo "${2}" >${LED_PATH}/brightness } +function get_intensity() { + LED_INTENSITY=$(cat ${LED_PATH}/multi_intensity) + $DEBUG && log ${0} "get_intensity: multi_intensity: ${LED_INTENSITY}" + echo ${LED_INTENSITY} +} + +function get_brightness() { + LED_BRIGHTNESS=$(cat ${LED_PATH}/brightness) + $DEBUG && log ${0} "get_brightness: brightness: ${LED_BRIGHTNESS}" + echo ${LED_BRIGHTNESS} +} + function led_flash() { + local INTENSITY=$(get_intensity) + local BRIGHTNESS=$(get_brightness) + + set_rgb "0 0 0" "0" + sleep .5 for i in $(seq 1 1 3) do set_rgb "255 0 0" "255" @@ -44,6 +61,7 @@ function led_flash() { set_rgb "0 0 0" "0" sleep .5 done + set_rgb "${INTENSITY}" "${BRIGHTNESS}" } while true @@ -54,7 +72,7 @@ do if (( "${BATCNT}" >= "${FLASHDELAY}" )) && [[ "${AC_STATUS}" =~ Disch ]] then - if (( ${BATLEFT} < "20" )) + if (( ${BATLEFT} <= "20" )) then led_flash FLASHDELAY=${BATLEFT} @@ -65,7 +83,7 @@ do if [[ "${AC_STATUS}" =~ ^Charg ]] then # Reset the LED as if the battery was full. - set_rgb "0 0 0" "0" + set_rgb "${LED_INTENSITY}" "${LED_BRIGHTNESS}" fi fi BATCNT=$(( ${BATCNT} + 1 ))