Skip to content

Commit 7d80bc7

Browse files
committed
use single powerdown script
Signed-off-by: Michel-FK <michel.stempin@funkey-project.com>
1 parent cefbb58 commit 7d80bc7

File tree

23 files changed

+261
-177
lines changed

23 files changed

+261
-177
lines changed

FunKey/board/funkey/rootfs-overlay/usr/local/sbin/assembly_tests

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ QR_CODE_IMG="/root/logs/assembly_tests/qrcode.png"
4242
## Function called when SIGURS1 is caught while waiting for it
4343
function function_magnet_detected_ok {
4444
## Kill scheduled shutdown
45-
pkill sched_shutdown
45+
pkill -f "powerdown schedule"
4646

4747
## Write magnet_detected file
4848
if $test_failed; then
@@ -55,7 +55,7 @@ function function_magnet_detected_ok {
5555
## Clean shutdown
5656
echo " Caught SIGUSR1 signal: magnet detected"
5757
echo " Rebooting now..."
58-
shutdown_funkey
58+
powerdown now
5959
exit 0
6060
}
6161

@@ -370,6 +370,6 @@ if ! $test_failed; then
370370
exit 0
371371
else
372372
## Shutdown
373-
shutdown_funkey &
373+
powerdown now &
374374
exit 1
375375
fi

FunKey/board/funkey/rootfs-overlay/usr/local/sbin/cancel_sched_powerdown

Lines changed: 0 additions & 11 deletions
This file was deleted.

FunKey/board/funkey/rootfs-overlay/usr/local/sbin/instant_play

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pid erase
6363
EOF
6464

6565
# Now terminate gracefully
66-
exec shutdown_funkey
66+
exec powerdown now
6767
;;
6868

6969
*)

FunKey/board/funkey/rootfs-overlay/usr/local/sbin/low_bat_check

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,28 @@
33
# General constants declaration
44
THRESHOLD_PERCENT_LOW_BAT=5
55
THRESHOLD_PERCENT_EXTREMELY_LOW_BAT=2
6-
MAX_EXTREMELY_LOW_BAT_BEFORE_SHUTDOWN=5
6+
MAX_LOW_BAT_COUNT=5
77
SLEEP_SECS=2
88
RESCALE_MAX_PERCENTAGE=120
99

1010
# Blink Low bat constants declaration
1111
BLINK_ICON=0
12-
LOW_BAT_SECS_DISPLAYED=5
13-
LOW_BAT_SECS_NOT_DISPLAYED=5
12+
LOW_BAT_DISPLAY_TIMEOUT=5
1413

1514
# Files and commands declaration
16-
USB_PRESENT_FILE=/sys/class/power_supply/axp20x-usb/present
15+
USB_PRESENT_FILE="/sys/class/power_supply/axp20x-usb/present"
1716

1817
# Cheat for no USB present simulation when debugging
19-
#USB_PRESENT_FILE=/sys/class/power_supply/axp20x-ac/present
20-
BAT_PRESENT_FILE=/sys/class/power_supply/axp20x-battery/present
21-
BAT_PERCENT_FILE=/sys/class/power_supply/axp20x-battery/capacity
22-
BAT_PERCENT_RESCALED_FILE=/tmp/current_battery_percentage
23-
LOW_BAT_ICON=/sys/class/graphics/fb0/low_battery
18+
BAT_PRESENT_FILE="/sys/class/power_supply/axp20x-battery/present"
19+
BAT_PERCENT_FILE="/sys/class/power_supply/axp20x-battery/capacity"
20+
BAT_PERCENT_RESCALED_FILE="/tmp/current_battery_percentage"
21+
LOW_BAT_ICON="/sys/class/graphics/fb0/low_battery"
2422

2523
# Variables declaration
2624
low_bat_status=0
2725
low_bat_displayed=0
2826
cur_secs_disp=0
29-
cur_nb_extremely_low_bat_before_shutdown=0
27+
low_bat_count=0
3028

3129
# Default: Hide Low Bat Icon
3230
echo 0 > ${LOW_BAT_ICON}
@@ -71,7 +69,7 @@ while true; do
7169

7270
# Reset status
7371
low_bat_status=0
74-
cur_nb_extremely_low_bat_before_shutdown=0
72+
low_bat_count=0
7573
echo 0 > ${LOW_BAT_ICON}
7674
fi
7775
fi
@@ -80,7 +78,7 @@ while true; do
8078

8179
# Reset status
8280
low_bat_status=0
83-
cur_nb_extremely_low_bat_before_shutdown=0
81+
low_bat_count=0
8482
echo 0 > ${LOW_BAT_ICON}
8583
fi
8684
fi
@@ -90,24 +88,24 @@ while true; do
9088

9189
# Check extremely low bat for clean shutdown
9290
if [ ${cur_bat_percent} -le ${THRESHOLD_PERCENT_EXTREMELY_LOW_BAT} ]; then
93-
let cur_nb_extremely_low_bat_before_shutdown++
94-
echo "cur_nb_extremely_low_bat_before_shutdown = ${cur_nb_extremely_low_bat_before_shutdown}"
91+
let low_bat_count++
92+
echo "low_bat_count = ${low_bat_count}"
9593

9694
# Clean shutdown
97-
if [ ${cur_nb_extremely_low_bat_before_shutdown} -ge ${MAX_EXTREMELY_LOW_BAT_BEFORE_SHUTDOWN} ]; then
95+
if [ ${low_bat_count} -ge ${MAX_LOW_BAT_COUNT} ]; then
9896
echo "Battery extremely low, shutting down now..."
99-
sched_shutdown 1 & signal_usr1_to_emulators
97+
powerdown schedule 1
10098
exit 0
10199
fi
102100
fi
103101

104102
# Blinking process
105103
if [ ${BLINK_ICON} -eq 1 ]; then
106-
if [ ${low_bat_displayed} -eq 1 -a ${cur_secs_disp} -ge ${LOW_BAT_SECS_DISPLAYED} ]; then
104+
if [ ${low_bat_displayed} -eq 1 -a ${cur_secs_disp} -ge ${LOW_BAT_DISPLAY_TIMEOUT} ]; then
107105
low_bat_displayed=0
108106
cur_secs_disp=0
109107
echo 0 > ${LOW_BAT_ICON}
110-
elif [ ${low_bat_displayed} -eq 0 -a ${cur_secs_disp} -ge ${LOW_BAT_SECS_NOT_DISPLAYED} ]; then
108+
elif [ ${low_bat_displayed} -eq 0 -a ${cur_secs_disp} -ge ${LOW_BAT_DISPLAY_TIMEOUT} ]; then
111109
low_bat_displayed=1
112110
cur_secs_disp=0
113111
echo 1 > ${LOW_BAT_ICON}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/sh
2+
3+
# Uncomment the following line to get debug info
4+
#set -x
5+
6+
SELF="$(basename ${0})"
7+
PID_FILE="/var/run/funkey.pid"
8+
REBOOTING_FILE="/run/rebooting"
9+
10+
usage() {
11+
>&2 echo "Usage: ${SELF} schedule delay"
12+
>&2 echo " ${SELF} handle"
13+
>&2 echo " ${SELF} now"
14+
exit 1
15+
}
16+
17+
schedule_powerdown() {
18+
19+
# Send USR1 signal to the running FunKey process to warn about
20+
# impending shutdown
21+
pkill -USR1 -F "${PID_FILE}" > /dev/null 2>&1
22+
23+
# Delay for the given grace period seconds to catch signal USR2.
24+
# If the signal is caught, then it means the running FunKey
25+
# process canceled this shutdown and will handle it by itself.
26+
sleep ${1}
27+
28+
# Delay expired, initiate final powerdown
29+
powerdown_now
30+
}
31+
32+
handle_powerdown() {
33+
pkill -f "powerdown schedule"
34+
}
35+
36+
powerdown_now() {
37+
38+
# Sync before all else
39+
sync
40+
41+
# Notif fullscreen "Shutting down"
42+
notif set 0 "^^^^^^^^ SHUTTING DOWN...^^^^^^^^"
43+
44+
# Notify system, reboot in progress
45+
touch "${REBOOTING_FILE}"
46+
47+
# Shutdown amp
48+
audio_amp off >/dev/null 2>&1
49+
50+
# Force Read Only
51+
ro
52+
53+
# Poweroff
54+
poweroff
55+
}
56+
57+
action="${1:-now}"
58+
case "${action}" in
59+
schedule)
60+
if [ ${#} != 2 -o "${2}" -eq 0 ]; then
61+
usage
62+
fi
63+
schedule_powerdown
64+
;;
65+
66+
handle)
67+
if [ ${#} -ne 1 ]; then
68+
usage
69+
fi
70+
handle_powerdown
71+
;;
72+
73+
now)
74+
if [ ${#} -gt 1 ]; then
75+
usage
76+
fi
77+
powerdown_now
78+
;;
79+
80+
*)
81+
usage
82+
;;
83+
esac
84+
exit 0

FunKey/board/funkey/rootfs-overlay/usr/local/sbin/sched_shutdown

Lines changed: 0 additions & 22 deletions
This file was deleted.

FunKey/board/funkey/rootfs-overlay/usr/local/sbin/shutdown_funkey

Lines changed: 0 additions & 20 deletions
This file was deleted.

FunKey/package/FCEUX/FCEUX.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
################################################################################
66

7-
FCEUX_VERSION = c3ae7fa
7+
FCEUX_VERSION = 336090c
88
FCEUX_SITE_METHOD = git
99
FCEUX_SITE = https://github.com/FunKey-Project/fceux.git
1010
FCEUX_LICENSE = GPL-2.0

FunKey/package/PCSX-ReARMed/PCSX-ReARMed.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
################################################################################
66

7-
PCSX_REARMED_VERSION = 2cc6248
7+
PCSX_REARMED_VERSION = 1888d71
88
PCSX_REARMED_SITE_METHOD = git
99
PCSX_REARMED_SITE = https://github.com/FunKey-Project/pcsx_rearmed.git
1010
PCSX_REARMED_LICENSE = GPL-2.0

FunKey/package/PocketSNES/PocketSNES.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
################################################################################
66

7-
POCKETSNES_VERSION = c3de812
7+
POCKETSNES_VERSION = 5d8490f
88
POCKETSNES_SITE_METHOD = git
99
POCKETSNES_SITE = https://github.com/FunKey-Project/PocketSNES.git
1010
POCKETSNES_LICENSE = GPL-2.0

0 commit comments

Comments
 (0)