From 5f43c259249d90c2a9465240bfae597ef1237002 Mon Sep 17 00:00:00 2001 From: mason Date: Thu, 20 Jul 2023 03:03:27 +0000 Subject: [PATCH] RG351P battery led status --- .../devices/Anbernic RG351M/001-deviceconfig | 3 + packages/hardware/quirks/profile.d/999-export | 1 + .../sources/devices/RK3326/battery_led_status | 64 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 packages/sysutils/system-utils/sources/devices/RK3326/battery_led_status diff --git a/packages/hardware/quirks/devices/Anbernic RG351M/001-deviceconfig b/packages/hardware/quirks/devices/Anbernic RG351M/001-deviceconfig index adcb66bc3..5b4b42fe2 100644 --- a/packages/hardware/quirks/devices/Anbernic RG351M/001-deviceconfig +++ b/packages/hardware/quirks/devices/Anbernic RG351M/001-deviceconfig @@ -11,6 +11,9 @@ DEVICE_PLAYBACK_PATH_HP="HP" DEVICE_FUNC_KEYA_MODIFIER="BTN_SELECT" DEVICE_FUNC_KEYB_MODIFIER="BTN_START" DEVICE_BRIGHTNESS="128" +DEVICE_BATTERY_LED_STATUS=true +DEVICE_PWR_LED_GPIO="77" +DEVICE_TEMP_SENSOR="/sys/devices/virtual/thermal/thermal_zone0/temp" UI_SERVICE="weston.service" # FREQ governors diff --git a/packages/hardware/quirks/profile.d/999-export b/packages/hardware/quirks/profile.d/999-export index c29a10591..912a9e8d7 100755 --- a/packages/hardware/quirks/profile.d/999-export +++ b/packages/hardware/quirks/profile.d/999-export @@ -26,6 +26,7 @@ export SLOW_CORES \ DEVICE_KEY_VOLUMEUP \ DEVICE_LED_CONTROL \ DEVICE_PWR_LED_CONTROL \ + DEVICE_PWR_LED_GPIO \ DEVICE_PLAYBACK_PATH_HP \ DEVICE_PLAYBACK_PATH_SPK \ DEVICE_POWER_LED \ diff --git a/packages/sysutils/system-utils/sources/devices/RK3326/battery_led_status b/packages/sysutils/system-utils/sources/devices/RK3326/battery_led_status new file mode 100644 index 000000000..05c31622c --- /dev/null +++ b/packages/sysutils/system-utils/sources/devices/RK3326/battery_led_status @@ -0,0 +1,64 @@ +#!/bin/bash + +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2020-present Fewtarius + +# Simple script to watch the battery capacity and +# turn the power LED orange when it reaches 30%, red at 20%, and blinking red & orange at 10% + +. /etc/profile + +# Set export GPIO for Power LED +if [ ! -d "/sys/class/gpio/gpio${DEVICE_PWR_LED_GPIO}" ]; then + echo ${DEVICE_PWR_LED_GPIO} > /sys/class/gpio/export +fi + +function set_led() { + case $1 in + red) + echo out >/sys/class/gpio/gpio${DEVICE_PWR_LED_GPIO}/direction + echo 1 >/sys/class/gpio/gpio${DEVICE_PWR_LED_GPIO}/value + ;; + green) + echo out >/sys/class/gpio/gpio${DEVICE_PWR_LED_GPIO}/direction + echo 0 >/sys/class/gpio/gpio${DEVICE_PWR_LED_GPIO}/value + ;; + orange) + echo in >/sys/class/gpio/gpio${DEVICE_PWR_LED_GPIO}/direction + ;; + esac +} + + +while true +do + CAP=$(cat /sys/class/power_supply/battery/capacity) + STAT=$(cat /sys/class/power_supply/battery/status) + if [[ ${STAT} == "Discharging" ]] + then + #if (( ${CAP} <= 50 )) + #then + # for ctr in $(seq 1 1 5) + # do + # set_led orange + # sleep .5 + # set_led red + # sleep .5 + # done + # continue + #elif (( ${CAP} <= 20 )) + if (( ${CAP} <= 20 )) + then + set_led red + elif (( ${CAP} <= 30 )) + then + set_led orange + else + set_led green + fi + elif (( ${CAP} >= 95 )) + then + set_led green + fi + sleep 15 +done