Skip to content

Commit 2dea2fd

Browse files
authored
Merge pull request #1343 from chrisj951/development-chrisj951
Fix sleep/power button on miyoo mini flip
2 parents c7f9fe9 + 0f3c8fe commit 2dea2fd

8 files changed

Lines changed: 57 additions & 325 deletions

File tree

App/PyUI/py-ui-config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"gameSystemSortMode": "SortOrderKey",
99
"includeStockOsLaunchOption": false,
1010
"allowPyUiGameSwitcher": true,
11+
"mimicMiyooMainUiMode": true,
1112
"gameSwitcherPath": "/mnt/SDCARD/Saves/gameswitcher.json",
1213
"cfwTasks": "/mnt/SDCARD/App/PyUI/spruce-tasks.json",
1314
"wpaSupplicantConfigFileLocation": "/mnt/SDCARD/Saves/spruce/wpa_supplicant.conf",

spruce/scripts/helperFunctions.sh

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,6 @@ auto_regen_tmp_update() {
6464
fi
6565
}
6666

67-
EMULATORS="ra32.miyoo ra64.miyoo ra64.trimui_${PLATFORM} retroarch retroarch.${PLATFORM} retroarch.trimui drastic drastic32 drastic64 PPSSPPSDL_${PLATFORM} PPSSPPSDL_TrimUI MainUI flycast flycast-stock yabasanshiro yabasanshiro.trimui mupen64plus"
68-
pause_emulators() {
69-
for EMU in $EMULATORS; do
70-
if killall -q -19 "$EMU" 2>/dev/null; then
71-
break
72-
fi
73-
done
74-
}
75-
76-
unpause_emulators() {
77-
for EMU in $EMULATORS; do
78-
if killall -q -18 "$EMU" 2>/dev/null; then
79-
break
80-
fi
81-
done
82-
}
83-
84-
8567
confirm() {
8668
timeout=${1:-0} # Default to 0 (no timeout)
8769
timeout_return=${2:-1} # Default to 1 (usually 'No' or 'Cancel')

spruce/scripts/platform/MiyooMini.cfg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ export DEVICE_USES_64_BIT_RA="false"
6868
##### KEY CODES AND INPUT EVENTS #####
6969
######################################
7070

71-
export EVENT_PATH_SEND_TO_DRASTIC="/dev/input/event0"
72-
export EVENT_PATH_SEND_TO_RA_AND_PPSSPP="/dev/input/event0"
73-
export EVENT_PATH_READ_INPUTS_SPRUCE="/dev/input/event0"
74-
export EVENT_PATH_POWER="/dev/input/event0"
71+
export EVENT_PATH_SEND_TO_DRASTIC="/dev/input/event0" #unused on mm today
72+
export EVENT_PATH_SEND_TO_RA_AND_PPSSPP="/dev/input/event0" #unused on mm today
73+
export EVENT_PATH_READ_INPUTS_SPRUCE="/dev/input/event0" #unused on mm today
74+
export EVENT_PATH_POWER="/dev/input/event0" #unused on mm today
7575

7676
export B_POWER="B_POWER"
7777

spruce/scripts/platform/device_functions/A30.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,36 @@ take_screenshot() {
209209

210210
WAKE_ALARM_PATH="/sys/class/rtc/rtc0/wakealarm"
211211
DISPLAY_ENHANCE_PATH="/sys/devices/virtual/disp/disp/attr/enhance"
212+
EMULATORS="ra32.miyoo ra64.miyoo ra64.trimui_${PLATFORM} retroarch retroarch.${PLATFORM} retroarch.trimui drastic drastic32 drastic64 PPSSPPSDL_${PLATFORM} PPSSPPSDL_TrimUI MainUI flycast flycast-stock yabasanshiro yabasanshiro.trimui mupen64plus"
213+
pause_emulators() {
214+
for EMU in $EMULATORS; do
215+
if killall -q -19 "$EMU" 2>/dev/null; then
216+
log_message "$EMU was paused"
217+
break
218+
fi
219+
done
220+
}
221+
222+
unpause_emulators() {
223+
for EMU in $EMULATORS; do
224+
if killall -q -18 "$EMU" 2>/dev/null; then
225+
log_message "$EMU was unpaused"
226+
break
227+
fi
228+
done
229+
}
212230

213231
device_enter_sleep() {
232+
pause_emulators
233+
sleep 0.5
234+
# Kill exclusive getevent to prevent buffered wake button events
235+
# from causing a re-sleep loop. The power watchdog's outer loop
236+
# will restart getevent fresh after sleep_helper exits.
237+
if [ "$(device_uses_pseudo_sleep)" != "true" ]; then
238+
kill $(pgrep -f "getevent.*-exclusive") 2>/dev/null
239+
sleep 0.3
240+
fi
241+
214242
IDLE_TIMEOUT="$1"
215243
log_message "Entering sleep w/ IDLE_TIMEOUT of $IDLE_TIMEOUT"
216244

@@ -228,6 +256,7 @@ device_exit_sleep() {
228256

229257
touch /tmp/audio_reinit_needed
230258
clear_wake_alarm "$WAKE_ALARM_PATH"
259+
unpause_emulators
231260
}
232261

233262
device_lid_open() {
@@ -378,3 +407,5 @@ device_system_handles_sdcard_unmount() {
378407
# return non-zero = false
379408
return 1 # A30 leaves dirty bit set?
380409
}
410+
411+

spruce/scripts/platform/device_functions/MiyooMini.sh

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -99,37 +99,11 @@ enable_or_disable_rgb() {
9999
}
100100

101101
enter_sleep() {
102-
log_message "Entering pseudo-sleep (wait for power)"
103-
104-
# Block until power button is pressed to wake
105-
local wake_fifo="/tmp/sleep_wake_fifo.$$"
106-
rm -f "$wake_fifo"
107-
mkfifo "$wake_fifo"
108-
getevent "$EVENT_PATH_POWER" > "$wake_fifo" 2>/dev/null &
109-
local gev_pid=$!
110-
exec 4< "$wake_fifo"
111-
while IFS= read -r line <&4; do
112-
case "$line" in
113-
*"key $B_POWER 1"*)
114-
break
115-
;;
116-
esac
117-
done
118-
exec 4<&-
119-
kill "$gev_pid" 2>/dev/null
120-
wait "$gev_pid" 2>/dev/null
121-
rm -f "$wake_fifo"
122-
123-
log_message "Exiting pseudo-sleep"
102+
log_message "Keymon handles sleep, not spruce" -v
124103
}
125104

126105
get_current_volume() {
127-
# Return config-level volume (0-20) to match what set_volume expects
128-
jq -r '.vol' "$SYSTEM_JSON"
129-
}
130-
131-
device_specific_wake_from_sleep() {
132-
log_message "MiyooMini wake - nothing extra needed" -v
106+
log_message "Intentionally do not let spruce modify volume" -v
133107
}
134108

135109
reset_playback_pack() {
@@ -174,25 +148,11 @@ post_pyui_exit(){
174148
}
175149

176150
launch_startup_watchdogs(){
177-
log_message "Launching MiyooMini startup watchdogs (using proven sleep watchdog)"
178-
179-
# Kill keymon — spruce watchdogs fully replace its functionality.
180-
# keymon conflicts with the power button watchdog on the Mini since
181-
# there is only a single input device (/dev/input/event0).
182-
killall -9 keymon 2>/dev/null
183-
184-
/mnt/SDCARD/spruce/scripts/homebutton_watchdog.sh &
185-
/mnt/SDCARD/spruce/scripts/applySetting/idlemon_mm.sh &
186-
/mnt/SDCARD/spruce/scripts/low_power_warning.sh &
187-
/mnt/SDCARD/spruce/scripts/powerbutton_watchdog.sh &
188-
/mnt/SDCARD/spruce/scripts/buttons_watchdog.sh &
189-
190-
SYSTEM_CPU=${DEVICE_MAX_CORES_ONLINE%"${DEVICE_MAX_CORES_ONLINE#?}"}
191-
pin_cpu "$SYSTEM_CPU" -n homebutton_watchdog.sh &
192-
pin_cpu "$SYSTEM_CPU" -n idlemon_mm.sh &
193-
pin_cpu "$SYSTEM_CPU" -n low_power_warning.sh &
194-
pin_cpu "$SYSTEM_CPU" -n powerbutton_watchdog.sh &
195-
pin_cpu "$SYSTEM_CPU" -n buttons_watchdog.sh &
151+
if [ "$(get_miyoo_mini_variant)" = "MIYOO_MINI_FLIP" ]; then
152+
launch_common_startup_watchdogs_v2 "true"
153+
else
154+
launch_common_startup_watchdogs_v2 "false"
155+
fi
196156
}
197157

198158
perform_fw_check(){

spruce/scripts/power_button_watchdog_v2.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ log_message "power_button_watchdog_v2.sh: Started up."
77

88

99
power_key_up () {
10-
log_message "Power button released at $(date +%s)"
1110
if [ -e /tmp/powerbtn ]; then
11+
log_message "Power button released at $(date +%s)"
1212
rm -f /tmp/powerbtn
1313

1414
was_cancelled=false
@@ -27,6 +27,8 @@ power_key_up () {
2727
if [ "$was_cancelled" = false ]; then
2828
/mnt/SDCARD/spruce/scripts/sleep_helper.sh
2929
fi
30+
else
31+
log_message "Power button released during cooldown at $(date +%s)"
3032
fi
3133

3234
}
@@ -54,33 +56,37 @@ power_key_down () {
5456
fi
5557
) &
5658
power_hold_pid=$!
59+
else
60+
log_message "Power button pressed during cooldown at $power_btn_press_time"
5761
fi
5862
}
5963

64+
LAST_POWER_DOWN=0
65+
PREV_WAS_POWER=0
6066
while true; do
61-
LAST_POWER_DOWN=0
6267
log_message "power_button_watchdog_v2.sh: Monitoring power button events on $EVENT_PATH_POWER"
6368
getevent -exclusive -pid $$ $EVENT_PATH_POWER | while read line; do
64-
if [ -e /tmp/sleep_helper_started ]; then
65-
log_message "power_button_watchdog_v2.sh: Sleep helper active, skipping power button event."
66-
continue
67-
fi
68-
6969
now=$(date +%s)
70+
# If last loop contained B_POWER, update LAST_POWER_DOWN now
71+
if [ "$PREV_WAS_POWER" -eq 1 ]; then
72+
LAST_POWER_DOWN=$now
73+
PREV_WAS_POWER=0
74+
fi
7075
case $line in
7176
# Power key down
7277
*"key $B_POWER 1"*)
7378
if [ $((now - LAST_POWER_DOWN)) -ge 1 ]; then
7479
log_message "power_button_watchdog_v2.sh: power_key_down"
7580
power_key_down
76-
LAST_POWER_DOWN=$now
81+
PREV_WAS_POWER=1
7782
fi
7883
;;
7984

8085
# Power key up
8186
*"key $B_POWER 0"*)
8287
log_message "power_button_watchdog_v2.sh: power_key_up"
8388
power_key_up
89+
PREV_WAS_POWER=1
8490
;;
8591
esac
8692
done

0 commit comments

Comments
 (0)