spruceUI / spruceOS

SD card overhaul for the Miyoo A30
https://spruceui.github.io/
127 stars 8 forks source link

Pull request: Add indicator for low battery warning #7

Closed oscarkcau closed 2 months ago

oscarkcau commented 2 months ago

When battery runs out during game play, files in Save folder and Roms fold may be broken as the device shutsdowns without notice. To ensure players power off the handheld before battery running out, I added a short script in .tmp_update\runtime.sh to blink the power LED as indicator of low battery warning.

# Add these lins in the beginning of .tmp_update\runtime.sh
#  Modify the values of PERCENTT and SLEEP to specify the warning threshold 
# and checking period.
PERCENT=20 
SLEEP=120

while true; do
    CAPACITY=$(cat /sys/class/power_supply/battery/capacity)
    if [ "$CAPACITY" -le $PERCENT ]; then 
        echo heartbeat > /sys/devices/platform/sunxi-led/leds/led1/trigger
    else
        echo 0 > /sys/devices/platform/sunxi-led/leds/led1/brightness
    fi
    sleep $SLEEP
done &
spruceUI commented 2 months ago

cool! what does the sleep=120 specify? i assume that percent=20 means itll blink the red led at 20% battery

oscarkcau commented 2 months ago

"sleep=120" means the while loop will sleep for 120 seconds before check the battery level again. i.e. the power LED would change its states every 2 min based on the current battery level.

"percent=20 means itll blink the red led at 20% battery" Yup! but only the blue LED (power LED) will blink, as I dont want to affect the charging indicator LED

spruceUI commented 2 months ago

If i'm at 20% battery the red led will blink every 2 minutes?

to be clear, this WILL NOT put the device to sleep correct?

This seems like a really cool addition and i am going to explore it fully and likely add it.

oscarkcau commented 2 months ago

The effect of this script is to add a process to check the battery level every 120 seconds, and make the BLUE LED blinks like heartbeats when battery level is lower than 20%. After the battery is charged above 20+%, the BLUE LED will turn off again.

to be clear, this WILL NOT put the device to sleep correct? YES, it only blinks the BLUE LED when the battery is low, player can choose to ignore it or charge the device or turn the device off.

P.S. I said to add the code to the beginning of .tmp_update\runtime.sh, however the new code should be inserted at the SECOND row, below the FIRST shebang line (#!/bin/sh).

Also the original line for turning off the POWER LED should be removed too:

# remove the following line
echo 0 > /sys/devices/platform/sunxi-led/leds/led1/brightness
oscarkcau commented 2 months ago

I add the whole updated file here, you can just replace the file and try it first~! runtime.zip

spruceUI commented 2 months ago

Thanks! i already added it to the dev beta. Its looking like we will add it!

Going to set it at 7% and 30 second interval. Any different suggestions?

oscarkcau commented 2 months ago

Cool! I hope this could help people from crashing the SD card due to battery run out! I just lost two hours progress on my rpg playing and realized that this indicator is definitely necessary.

spruceUI commented 2 months ago

Thanks so much for this! ill be sure to add you in the credits when 2.1 goes live. I left a note in the runtime.sh that names you as well.

oscarkcau commented 2 months ago

This is my honor! I really enjoy this device and love this CFW! Thank you for maintaining this nice piece of work!!