use single powerdown script
Signed-off-by: Michel-FK <michel.stempin@funkey-project.com>
This commit is contained in:
parent
cefbb581ee
commit
7d80bc7eed
|
@ -42,7 +42,7 @@ QR_CODE_IMG="/root/logs/assembly_tests/qrcode.png"
|
||||||
## Function called when SIGURS1 is caught while waiting for it
|
## Function called when SIGURS1 is caught while waiting for it
|
||||||
function function_magnet_detected_ok {
|
function function_magnet_detected_ok {
|
||||||
## Kill scheduled shutdown
|
## Kill scheduled shutdown
|
||||||
pkill sched_shutdown
|
pkill -f "powerdown schedule"
|
||||||
|
|
||||||
## Write magnet_detected file
|
## Write magnet_detected file
|
||||||
if $test_failed; then
|
if $test_failed; then
|
||||||
|
@ -55,7 +55,7 @@ function function_magnet_detected_ok {
|
||||||
## Clean shutdown
|
## Clean shutdown
|
||||||
echo " Caught SIGUSR1 signal: magnet detected"
|
echo " Caught SIGUSR1 signal: magnet detected"
|
||||||
echo " Rebooting now..."
|
echo " Rebooting now..."
|
||||||
shutdown_funkey
|
powerdown now
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,6 +370,6 @@ if ! $test_failed; then
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
## Shutdown
|
## Shutdown
|
||||||
shutdown_funkey &
|
powerdown now &
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# Uncomment the following line to get debug info
|
|
||||||
#set -x
|
|
||||||
|
|
||||||
if [ ${#} != 0 ]; then
|
|
||||||
echo "Usage: $(basename ${0})"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
pkill sched_powerdown
|
|
||||||
exit 0
|
|
|
@ -63,7 +63,7 @@ pid erase
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Now terminate gracefully
|
# Now terminate gracefully
|
||||||
exec shutdown_funkey
|
exec powerdown now
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
|
|
|
@ -3,30 +3,28 @@
|
||||||
# General constants declaration
|
# General constants declaration
|
||||||
THRESHOLD_PERCENT_LOW_BAT=5
|
THRESHOLD_PERCENT_LOW_BAT=5
|
||||||
THRESHOLD_PERCENT_EXTREMELY_LOW_BAT=2
|
THRESHOLD_PERCENT_EXTREMELY_LOW_BAT=2
|
||||||
MAX_EXTREMELY_LOW_BAT_BEFORE_SHUTDOWN=5
|
MAX_LOW_BAT_COUNT=5
|
||||||
SLEEP_SECS=2
|
SLEEP_SECS=2
|
||||||
RESCALE_MAX_PERCENTAGE=120
|
RESCALE_MAX_PERCENTAGE=120
|
||||||
|
|
||||||
# Blink Low bat constants declaration
|
# Blink Low bat constants declaration
|
||||||
BLINK_ICON=0
|
BLINK_ICON=0
|
||||||
LOW_BAT_SECS_DISPLAYED=5
|
LOW_BAT_DISPLAY_TIMEOUT=5
|
||||||
LOW_BAT_SECS_NOT_DISPLAYED=5
|
|
||||||
|
|
||||||
# Files and commands declaration
|
# Files and commands declaration
|
||||||
USB_PRESENT_FILE=/sys/class/power_supply/axp20x-usb/present
|
USB_PRESENT_FILE="/sys/class/power_supply/axp20x-usb/present"
|
||||||
|
|
||||||
# Cheat for no USB present simulation when debugging
|
# Cheat for no USB present simulation when debugging
|
||||||
#USB_PRESENT_FILE=/sys/class/power_supply/axp20x-ac/present
|
BAT_PRESENT_FILE="/sys/class/power_supply/axp20x-battery/present"
|
||||||
BAT_PRESENT_FILE=/sys/class/power_supply/axp20x-battery/present
|
BAT_PERCENT_FILE="/sys/class/power_supply/axp20x-battery/capacity"
|
||||||
BAT_PERCENT_FILE=/sys/class/power_supply/axp20x-battery/capacity
|
BAT_PERCENT_RESCALED_FILE="/tmp/current_battery_percentage"
|
||||||
BAT_PERCENT_RESCALED_FILE=/tmp/current_battery_percentage
|
LOW_BAT_ICON="/sys/class/graphics/fb0/low_battery"
|
||||||
LOW_BAT_ICON=/sys/class/graphics/fb0/low_battery
|
|
||||||
|
|
||||||
# Variables declaration
|
# Variables declaration
|
||||||
low_bat_status=0
|
low_bat_status=0
|
||||||
low_bat_displayed=0
|
low_bat_displayed=0
|
||||||
cur_secs_disp=0
|
cur_secs_disp=0
|
||||||
cur_nb_extremely_low_bat_before_shutdown=0
|
low_bat_count=0
|
||||||
|
|
||||||
# Default: Hide Low Bat Icon
|
# Default: Hide Low Bat Icon
|
||||||
echo 0 > ${LOW_BAT_ICON}
|
echo 0 > ${LOW_BAT_ICON}
|
||||||
|
@ -71,7 +69,7 @@ while true; do
|
||||||
|
|
||||||
# Reset status
|
# Reset status
|
||||||
low_bat_status=0
|
low_bat_status=0
|
||||||
cur_nb_extremely_low_bat_before_shutdown=0
|
low_bat_count=0
|
||||||
echo 0 > ${LOW_BAT_ICON}
|
echo 0 > ${LOW_BAT_ICON}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -80,7 +78,7 @@ while true; do
|
||||||
|
|
||||||
# Reset status
|
# Reset status
|
||||||
low_bat_status=0
|
low_bat_status=0
|
||||||
cur_nb_extremely_low_bat_before_shutdown=0
|
low_bat_count=0
|
||||||
echo 0 > ${LOW_BAT_ICON}
|
echo 0 > ${LOW_BAT_ICON}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -90,24 +88,24 @@ while true; do
|
||||||
|
|
||||||
# Check extremely low bat for clean shutdown
|
# Check extremely low bat for clean shutdown
|
||||||
if [ ${cur_bat_percent} -le ${THRESHOLD_PERCENT_EXTREMELY_LOW_BAT} ]; then
|
if [ ${cur_bat_percent} -le ${THRESHOLD_PERCENT_EXTREMELY_LOW_BAT} ]; then
|
||||||
let cur_nb_extremely_low_bat_before_shutdown++
|
let low_bat_count++
|
||||||
echo "cur_nb_extremely_low_bat_before_shutdown = ${cur_nb_extremely_low_bat_before_shutdown}"
|
echo "low_bat_count = ${low_bat_count}"
|
||||||
|
|
||||||
# Clean shutdown
|
# Clean shutdown
|
||||||
if [ ${cur_nb_extremely_low_bat_before_shutdown} -ge ${MAX_EXTREMELY_LOW_BAT_BEFORE_SHUTDOWN} ]; then
|
if [ ${low_bat_count} -ge ${MAX_LOW_BAT_COUNT} ]; then
|
||||||
echo "Battery extremely low, shutting down now..."
|
echo "Battery extremely low, shutting down now..."
|
||||||
sched_shutdown 1 & signal_usr1_to_emulators
|
powerdown schedule 1
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Blinking process
|
# Blinking process
|
||||||
if [ ${BLINK_ICON} -eq 1 ]; then
|
if [ ${BLINK_ICON} -eq 1 ]; then
|
||||||
if [ ${low_bat_displayed} -eq 1 -a ${cur_secs_disp} -ge ${LOW_BAT_SECS_DISPLAYED} ]; then
|
if [ ${low_bat_displayed} -eq 1 -a ${cur_secs_disp} -ge ${LOW_BAT_DISPLAY_TIMEOUT} ]; then
|
||||||
low_bat_displayed=0
|
low_bat_displayed=0
|
||||||
cur_secs_disp=0
|
cur_secs_disp=0
|
||||||
echo 0 > ${LOW_BAT_ICON}
|
echo 0 > ${LOW_BAT_ICON}
|
||||||
elif [ ${low_bat_displayed} -eq 0 -a ${cur_secs_disp} -ge ${LOW_BAT_SECS_NOT_DISPLAYED} ]; then
|
elif [ ${low_bat_displayed} -eq 0 -a ${cur_secs_disp} -ge ${LOW_BAT_DISPLAY_TIMEOUT} ]; then
|
||||||
low_bat_displayed=1
|
low_bat_displayed=1
|
||||||
cur_secs_disp=0
|
cur_secs_disp=0
|
||||||
echo 1 > ${LOW_BAT_ICON}
|
echo 1 > ${LOW_BAT_ICON}
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Uncomment the following line to get debug info
|
||||||
|
#set -x
|
||||||
|
|
||||||
|
SELF="$(basename ${0})"
|
||||||
|
PID_FILE="/var/run/funkey.pid"
|
||||||
|
REBOOTING_FILE="/run/rebooting"
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
>&2 echo "Usage: ${SELF} schedule delay"
|
||||||
|
>&2 echo " ${SELF} handle"
|
||||||
|
>&2 echo " ${SELF} now"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
schedule_powerdown() {
|
||||||
|
|
||||||
|
# Send USR1 signal to the running FunKey process to warn about
|
||||||
|
# impending shutdown
|
||||||
|
pkill -USR1 -F "${PID_FILE}" > /dev/null 2>&1
|
||||||
|
|
||||||
|
# Delay for the given grace period seconds to catch signal USR2.
|
||||||
|
# If the signal is caught, then it means the running FunKey
|
||||||
|
# process canceled this shutdown and will handle it by itself.
|
||||||
|
sleep ${1}
|
||||||
|
|
||||||
|
# Delay expired, initiate final powerdown
|
||||||
|
powerdown_now
|
||||||
|
}
|
||||||
|
|
||||||
|
handle_powerdown() {
|
||||||
|
pkill -f "powerdown schedule"
|
||||||
|
}
|
||||||
|
|
||||||
|
powerdown_now() {
|
||||||
|
|
||||||
|
# Sync before all else
|
||||||
|
sync
|
||||||
|
|
||||||
|
# Notif fullscreen "Shutting down"
|
||||||
|
notif set 0 "^^^^^^^^ SHUTTING DOWN...^^^^^^^^"
|
||||||
|
|
||||||
|
# Notify system, reboot in progress
|
||||||
|
touch "${REBOOTING_FILE}"
|
||||||
|
|
||||||
|
# Shutdown amp
|
||||||
|
audio_amp off >/dev/null 2>&1
|
||||||
|
|
||||||
|
# Force Read Only
|
||||||
|
ro
|
||||||
|
|
||||||
|
# Poweroff
|
||||||
|
poweroff
|
||||||
|
}
|
||||||
|
|
||||||
|
action="${1:-now}"
|
||||||
|
case "${action}" in
|
||||||
|
schedule)
|
||||||
|
if [ ${#} != 2 -o "${2}" -eq 0 ]; then
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
schedule_powerdown
|
||||||
|
;;
|
||||||
|
|
||||||
|
handle)
|
||||||
|
if [ ${#} -ne 1 ]; then
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
handle_powerdown
|
||||||
|
;;
|
||||||
|
|
||||||
|
now)
|
||||||
|
if [ ${#} -gt 1 ]; then
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
powerdown_now
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
exit 0
|
|
@ -1,22 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# Uncomment the following line to get debug info
|
|
||||||
#set -x
|
|
||||||
|
|
||||||
if [ ${#} != 1 -o "${1}" -eq 0 ]; then
|
|
||||||
echo "Usage: $(basename ${0}) grace_delay"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Send USR1 signal to the running FunKey process to warn about
|
|
||||||
# impending shutdown
|
|
||||||
pkill -USR1 -F /var/run/funkey.pid > /dev/null 2>&1
|
|
||||||
|
|
||||||
# Delay for the given grace period seconds to catch signal USR2.
|
|
||||||
# If the signal is caught, then it means the running FunKey process
|
|
||||||
# canceled this shutdown and will handle it by itself.
|
|
||||||
sleep ${1}
|
|
||||||
|
|
||||||
# Delay expired, initiate shutdown
|
|
||||||
shutdown_funkey
|
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# Sync before all else
|
|
||||||
sync
|
|
||||||
|
|
||||||
# Notif fullscreen "Shutting down"
|
|
||||||
notif set 0 "^^^^^^^^ SHUTTING DOWN...^^^^^^^^"
|
|
||||||
|
|
||||||
# Notify system, reboot in progress
|
|
||||||
REBOOTING_FILE="/run/rebooting"
|
|
||||||
touch $REBOOTING_FILE
|
|
||||||
|
|
||||||
# Shutdown amp
|
|
||||||
audio_amp off >/dev/null 2>&1
|
|
||||||
|
|
||||||
# Force Read Only
|
|
||||||
ro
|
|
||||||
|
|
||||||
# Poweroff
|
|
||||||
poweroff
|
|
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
FCEUX_VERSION = c3ae7fa
|
FCEUX_VERSION = 336090c
|
||||||
FCEUX_SITE_METHOD = git
|
FCEUX_SITE_METHOD = git
|
||||||
FCEUX_SITE = https://github.com/FunKey-Project/fceux.git
|
FCEUX_SITE = https://github.com/FunKey-Project/fceux.git
|
||||||
FCEUX_LICENSE = GPL-2.0
|
FCEUX_LICENSE = GPL-2.0
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
PCSX_REARMED_VERSION = 2cc6248
|
PCSX_REARMED_VERSION = 1888d71
|
||||||
PCSX_REARMED_SITE_METHOD = git
|
PCSX_REARMED_SITE_METHOD = git
|
||||||
PCSX_REARMED_SITE = https://github.com/FunKey-Project/pcsx_rearmed.git
|
PCSX_REARMED_SITE = https://github.com/FunKey-Project/pcsx_rearmed.git
|
||||||
PCSX_REARMED_LICENSE = GPL-2.0
|
PCSX_REARMED_LICENSE = GPL-2.0
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
POCKETSNES_VERSION = c3de812
|
POCKETSNES_VERSION = 5d8490f
|
||||||
POCKETSNES_SITE_METHOD = git
|
POCKETSNES_SITE_METHOD = git
|
||||||
POCKETSNES_SITE = https://github.com/FunKey-Project/PocketSNES.git
|
POCKETSNES_SITE = https://github.com/FunKey-Project/PocketSNES.git
|
||||||
POCKETSNES_LICENSE = GPL-2.0
|
POCKETSNES_LICENSE = GPL-2.0
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
PRODSCREENS_VERSION = e58f3a6
|
PRODSCREENS_VERSION = 96d5ac1
|
||||||
PRODSCREENS_SITE_METHOD = git
|
PRODSCREENS_SITE_METHOD = git
|
||||||
PRODSCREENS_SITE = https://github.com/FunKey-Project/FunKey-ProdScreens.git
|
PRODSCREENS_SITE = https://github.com/FunKey-Project/FunKey-ProdScreens.git
|
||||||
PRODSCREENS_SITE_LICENSE = GPL-2.1+
|
PRODSCREENS_SITE_LICENSE = GPL-2.1+
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
FKGPIOD_VERSION = 0efd7f0
|
FKGPIOD_VERSION = 4df43ea
|
||||||
FKGPIOD_SITE_METHOD = git
|
FKGPIOD_SITE_METHOD = git
|
||||||
FKGPIOD_SITE = https://github.com/FunKey-Project/fkgpiod.git
|
FKGPIOD_SITE = https://github.com/FunKey-Project/fkgpiod.git
|
||||||
FKGPIOD_SITE_LICENSE = GPL-2.1+
|
FKGPIOD_SITE_LICENSE = GPL-2.1+
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# gmenu2x
|
# gmenu2x
|
||||||
#
|
#
|
||||||
#############################################################
|
#############################################################
|
||||||
GMENU2X_VERSION = 2250648
|
GMENU2X_VERSION = 737b86e
|
||||||
GMENU2X_SITE_METHOD = git
|
GMENU2X_SITE_METHOD = git
|
||||||
GMENU2X_SITE = https://github.com/FunKey-Project/gmenu2x.git
|
GMENU2X_SITE = https://github.com/FunKey-Project/gmenu2x.git
|
||||||
GMENU2X_LICENSE = GPL-2.0
|
GMENU2X_LICENSE = GPL-2.0
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
GNUBOY_VERSION = f6b8feb
|
GNUBOY_VERSION = dcd6186
|
||||||
GNUBOY_SITE_METHOD = git
|
GNUBOY_SITE_METHOD = git
|
||||||
GNUBOY_SITE = https://github.com/FunKey-Project/gnuboy.git
|
GNUBOY_SITE = https://github.com/FunKey-Project/gnuboy.git
|
||||||
GNUBOY_LICENSE = GPL-2.0
|
GNUBOY_LICENSE = GPL-2.0
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
GPSP_VERSION = 5ab34a8
|
GPSP_VERSION = 80bf9c6
|
||||||
GPSP_SITE_METHOD = git
|
GPSP_SITE_METHOD = git
|
||||||
GPSP_SITE = https://github.com/FunKey-Project/gpsp.git
|
GPSP_SITE = https://github.com/FunKey-Project/gpsp.git
|
||||||
GPSP_LICENSE = GPL-2.0
|
GPSP_LICENSE = GPL-2.0
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
MEDNAFEN_VERSION = 2d9ca9d
|
MEDNAFEN_VERSION = cbcdbd8
|
||||||
MEDNAFEN_SITE_METHOD = git
|
MEDNAFEN_SITE_METHOD = git
|
||||||
MEDNAFEN_SITE = https://github.com/FunKey-Project/mednafen-git.git
|
MEDNAFEN_SITE = https://github.com/FunKey-Project/mednafen-git.git
|
||||||
MEDNAFEN_LICENSE = GPL-2.0+
|
MEDNAFEN_LICENSE = GPL-2.0+
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
PICODRIVE_VERSION = 4c09c0b
|
PICODRIVE_VERSION = 74bc7cb
|
||||||
PICODRIVE_SITE_METHOD = git
|
PICODRIVE_SITE_METHOD = git
|
||||||
PICODRIVE_SITE = https://github.com/FunKey-Project/picodrive.git
|
PICODRIVE_SITE = https://github.com/FunKey-Project/picodrive.git
|
||||||
PICODRIVE_LICENSE = MAME
|
PICODRIVE_LICENSE = MAME
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
RETROFE_VERSION = b319dba
|
RETROFE_VERSION = 9184665
|
||||||
RETROFE_SITE_METHOD = git
|
RETROFE_SITE_METHOD = git
|
||||||
RETROFE_SITE = https://github.com/FunKey-Project/RetroFE.git
|
RETROFE_SITE = https://github.com/FunKey-Project/RetroFE.git
|
||||||
RETROFE_DEPENDENCIES = gstreamer1 gst1-plugins-base sdl sdl_image sdl_mixer sdl_sound sdl_ttf libglib2 sqlite zlib
|
RETROFE_DEPENDENCIES = gstreamer1 gst1-plugins-base sdl sdl_image sdl_mixer sdl_sound sdl_ttf libglib2 sqlite zlib
|
||||||
|
|
|
@ -3,30 +3,28 @@
|
||||||
# General constants declaration
|
# General constants declaration
|
||||||
THRESHOLD_PERCENT_LOW_BAT=5
|
THRESHOLD_PERCENT_LOW_BAT=5
|
||||||
THRESHOLD_PERCENT_EXTREMELY_LOW_BAT=2
|
THRESHOLD_PERCENT_EXTREMELY_LOW_BAT=2
|
||||||
MAX_EXTREMELY_LOW_BAT_BEFORE_SHUTDOWN=5
|
MAX_LOW_BAT_COUNT=5
|
||||||
SLEEP_SECS=2
|
SLEEP_SECS=2
|
||||||
RESCALE_MAX_PERCENTAGE=120
|
RESCALE_MAX_PERCENTAGE=120
|
||||||
|
|
||||||
# Blink Low bat constants declaration
|
# Blink Low bat constants declaration
|
||||||
BLINK_ICON=0
|
BLINK_ICON=0
|
||||||
LOW_BAT_SECS_DISPLAYED=5
|
LOW_BAT_DISPLAY_TIMEOUT=5
|
||||||
LOW_BAT_SECS_NOT_DISPLAYED=5
|
|
||||||
|
|
||||||
# Files and commands declaration
|
# Files and commands declaration
|
||||||
USB_PRESENT_FILE=/sys/class/power_supply/axp20x-usb/present
|
USB_PRESENT_FILE="/sys/class/power_supply/axp20x-usb/present"
|
||||||
#USB_PRESENT_FILE=/sys/class/power_supply/axp20x-ac/present # Cheat for no USB present simulation when debugging
|
|
||||||
BAT_PRESENT_FILE=/sys/class/power_supply/axp20x-battery/present
|
# Cheat for no USB present simulation when debugging
|
||||||
BAT_PERCENT_FILE=/sys/class/power_supply/axp20x-battery/capacity
|
BAT_PRESENT_FILE="/sys/class/power_supply/axp20x-battery/present"
|
||||||
BAT_PERCENT_RESCALED_FILE=/tmp/current_battery_percentage
|
BAT_PERCENT_FILE="/sys/class/power_supply/axp20x-battery/capacity"
|
||||||
LOW_BAT_ICON=/sys/class/graphics/fb0/low_battery
|
BAT_PERCENT_RESCALED_FILE="/tmp/current_battery_percentage"
|
||||||
SCHEDULE_SHUTDOWN_CMD=sched_shutdown
|
LOW_BAT_ICON="/sys/class/graphics/fb0/low_battery"
|
||||||
SIGNAL_URS1_TO_EMULATORS_CMD=signal_usr1_to_emulators
|
|
||||||
|
|
||||||
# Variables declaration
|
# Variables declaration
|
||||||
low_bat_status=0
|
low_bat_status=0
|
||||||
low_bat_displayed=0
|
low_bat_displayed=0
|
||||||
cur_secs_disp=0
|
cur_secs_disp=0
|
||||||
cur_nb_extremely_low_bat_before_shutdown=0
|
low_bat_count=0
|
||||||
|
|
||||||
# Default: Hide Low Bat Icon
|
# Default: Hide Low Bat Icon
|
||||||
echo 0 > ${LOW_BAT_ICON}
|
echo 0 > ${LOW_BAT_ICON}
|
||||||
|
@ -55,64 +53,64 @@ while true; do
|
||||||
# Low bat status detection
|
# Low bat status detection
|
||||||
if [ "$(cat ${USB_PRESENT_FILE})" -eq "0" ]; then
|
if [ "$(cat ${USB_PRESENT_FILE})" -eq "0" ]; then
|
||||||
|
|
||||||
# Value of 0 means wrong i2c reading
|
# Value of 0 means wrong i2c reading
|
||||||
if [ "${cur_bat_percent}" -ne "0" ]; then
|
if [ "${cur_bat_percent}" -ne "0" ]; then
|
||||||
|
|
||||||
# Check if we must change state
|
# Check if we must change state
|
||||||
if [ ${cur_bat_percent} -le ${THRESHOLD_PERCENT_LOW_BAT} -a ${low_bat_status} -eq 0 ]; then
|
if [ ${cur_bat_percent} -le ${THRESHOLD_PERCENT_LOW_BAT} -a ${low_bat_status} -eq 0 ]; then
|
||||||
|
|
||||||
# Set Low Bat status
|
# Set Low Bat status
|
||||||
low_bat_status=1
|
low_bat_status=1
|
||||||
low_bat_displayed=1
|
low_bat_displayed=1
|
||||||
cur_secs_disp=0
|
cur_secs_disp=0
|
||||||
echo 1 > ${LOW_BAT_ICON}
|
echo 1 > ${LOW_BAT_ICON}
|
||||||
|
|
||||||
elif [ ${cur_bat_percent} -gt ${THRESHOLD_PERCENT_LOW_BAT} -a ${low_bat_status} -eq 1 ]; then
|
elif [ ${cur_bat_percent} -gt ${THRESHOLD_PERCENT_LOW_BAT} -a ${low_bat_status} -eq 1 ]; then
|
||||||
|
|
||||||
# Reset status
|
# Reset status
|
||||||
low_bat_status=0
|
low_bat_status=0
|
||||||
cur_nb_extremely_low_bat_before_shutdown=0
|
low_bat_count=0
|
||||||
echo 0 > ${LOW_BAT_ICON}
|
echo 0 > ${LOW_BAT_ICON}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ ${low_bat_status} -eq 1 ]; then
|
if [ ${low_bat_status} -eq 1 ]; then
|
||||||
|
|
||||||
# Reset status
|
# Reset status
|
||||||
low_bat_status=0
|
low_bat_status=0
|
||||||
cur_nb_extremely_low_bat_before_shutdown=0
|
low_bat_count=0
|
||||||
echo 0 > ${LOW_BAT_ICON}
|
echo 0 > ${LOW_BAT_ICON}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Low bat processing
|
# Low bat processing
|
||||||
if [ ${low_bat_status} -eq 1 ]; then
|
if [ ${low_bat_status} -eq 1 ]; then
|
||||||
|
|
||||||
# Check extremely low bat for clean shutdown
|
# Check extremely low bat for clean shutdown
|
||||||
if [ ${cur_bat_percent} -le ${THRESHOLD_PERCENT_EXTREMELY_LOW_BAT} ]; then
|
if [ ${cur_bat_percent} -le ${THRESHOLD_PERCENT_EXTREMELY_LOW_BAT} ]; then
|
||||||
let cur_nb_extremely_low_bat_before_shutdown++
|
let low_bat_count++
|
||||||
echo "cur_nb_extremely_low_bat_before_shutdown = ${cur_nb_extremely_low_bat_before_shutdown}"
|
echo "low_bat_count = ${low_bat_count}"
|
||||||
|
|
||||||
# Clean shutdown
|
# Clean shutdown
|
||||||
if [ ${cur_nb_extremely_low_bat_before_shutdown} -ge ${MAX_EXTREMELY_LOW_BAT_BEFORE_SHUTDOWN} ]; then
|
if [ ${low_bat_count} -ge ${MAX_LOW_BAT_COUNT} ]; then
|
||||||
echo "Battery extremely low, shutting down now..."
|
echo "Battery extremely low, shutting down now..."
|
||||||
sched_shutdown 1 & signal_usr1_to_emulators
|
powerdown schedule 1
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Blinking process
|
# Blinking process
|
||||||
if [ ${BLINK_ICON} -eq 1 ]; then
|
if [ ${BLINK_ICON} -eq 1 ]; then
|
||||||
if [ ${low_bat_displayed} -eq 1 -a ${cur_secs_disp} -ge ${LOW_BAT_SECS_DISPLAYED} ]; then
|
if [ ${low_bat_displayed} -eq 1 -a ${cur_secs_disp} -ge ${LOW_BAT_DISPLAY_TIMEOUT} ]; then
|
||||||
low_bat_displayed=0
|
low_bat_displayed=0
|
||||||
cur_secs_disp=0
|
cur_secs_disp=0
|
||||||
echo 0 > ${LOW_BAT_ICON}
|
echo 0 > ${LOW_BAT_ICON}
|
||||||
elif [ ${low_bat_displayed} -eq 0 -a ${cur_secs_disp} -ge ${LOW_BAT_SECS_NOT_DISPLAYED} ]; then
|
elif [ ${low_bat_displayed} -eq 0 -a ${cur_secs_disp} -ge ${LOW_BAT_DISPLAY_TIMEOUT} ]; then
|
||||||
low_bat_displayed=1
|
low_bat_displayed=1
|
||||||
cur_secs_disp=0
|
cur_secs_disp=0
|
||||||
echo 1 > ${LOW_BAT_ICON}
|
echo 1 > ${LOW_BAT_ICON}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Sleep before next check
|
# Sleep before next check
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Uncomment the following line to get debug info
|
||||||
|
#set -x
|
||||||
|
|
||||||
|
SELF="$(basename ${0})"
|
||||||
|
PID_FILE="/var/run/funkey.pid"
|
||||||
|
REBOOTING_FILE="/run/rebooting"
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
>&2 echo "Usage: ${SELF} schedule delay"
|
||||||
|
>&2 echo " ${SELF} handle"
|
||||||
|
>&2 echo " ${SELF} now"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
schedule_powerdown() {
|
||||||
|
|
||||||
|
# Send USR1 signal to the running FunKey process to warn about
|
||||||
|
# impending shutdown
|
||||||
|
pkill -USR1 -F "${PID_FILE}" > /dev/null 2>&1
|
||||||
|
|
||||||
|
# Delay for the given grace period seconds to catch signal USR2.
|
||||||
|
# If the signal is caught, then it means the running FunKey
|
||||||
|
# process canceled this shutdown and will handle it by itself.
|
||||||
|
sleep ${1}
|
||||||
|
|
||||||
|
# Delay expired, initiate final powerdown
|
||||||
|
powerdown_now
|
||||||
|
}
|
||||||
|
|
||||||
|
handle_powerdown() {
|
||||||
|
pkill -f "powerdown schedule"
|
||||||
|
}
|
||||||
|
|
||||||
|
powerdown_now() {
|
||||||
|
|
||||||
|
# Sync before all else
|
||||||
|
sync
|
||||||
|
|
||||||
|
# Notif fullscreen "Shutting down"
|
||||||
|
notif set 0 "^^^^^^^^ SHUTTING DOWN...^^^^^^^^"
|
||||||
|
|
||||||
|
# Notify system, reboot in progress
|
||||||
|
touch "${REBOOTING_FILE}"
|
||||||
|
|
||||||
|
# Shutdown amp
|
||||||
|
audio_amp off >/dev/null 2>&1
|
||||||
|
|
||||||
|
# Force Read Only
|
||||||
|
ro
|
||||||
|
|
||||||
|
# Poweroff
|
||||||
|
poweroff
|
||||||
|
}
|
||||||
|
|
||||||
|
action="${1:-now}"
|
||||||
|
case "${action}" in
|
||||||
|
schedule)
|
||||||
|
if [ ${#} != 2 -o "${2}" -eq 0 ]; then
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
schedule_powerdown
|
||||||
|
;;
|
||||||
|
|
||||||
|
handle)
|
||||||
|
if [ ${#} -ne 1 ]; then
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
handle_powerdown
|
||||||
|
;;
|
||||||
|
|
||||||
|
now)
|
||||||
|
if [ ${#} -gt 1 ]; then
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
powerdown_now
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
exit 0
|
|
@ -1,5 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# No waiting period in Recovery
|
|
||||||
|
|
||||||
shutdown_funkey
|
|
|
@ -1,22 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# Notif fullscreen "Shutting down"
|
|
||||||
notif set 0 "^^^^^^^^ SHUTTING DOWN...^^^^^^^^"
|
|
||||||
|
|
||||||
# Kill Emulators
|
|
||||||
#kill_emulators >/dev/null 2>&1
|
|
||||||
|
|
||||||
# Kill Retrofe
|
|
||||||
#pkill retrofe
|
|
||||||
|
|
||||||
# Sync filesystems (useful in case poweroff could not finish)
|
|
||||||
sync
|
|
||||||
|
|
||||||
# Unmount Roms partition
|
|
||||||
#umount /mnt
|
|
||||||
|
|
||||||
# Shutdown amp
|
|
||||||
start_audio_amp 0 >/dev/null 2>&1
|
|
||||||
|
|
||||||
# Poweroff
|
|
||||||
poweroff
|
|
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
FKGPIOD_VERSION = 20b1a37
|
FKGPIOD_VERSION = 4df43ea
|
||||||
FKGPIOD_SITE_METHOD = git
|
FKGPIOD_SITE_METHOD = git
|
||||||
FKGPIOD_SITE = https://github.com/FunKey-Project/fkgpiod.git
|
FKGPIOD_SITE = https://github.com/FunKey-Project/fkgpiod.git
|
||||||
FKGPIOD_SITE_LICENSE = GPL-2.1+
|
FKGPIOD_SITE_LICENSE = GPL-2.1+
|
||||||
|
|
Loading…
Reference in New Issue