From c9e16e4888c28927df82e94bb9140e4067c6224d Mon Sep 17 00:00:00 2001 From: "Hairo R. Carela" Date: Tue, 12 Aug 2025 21:34:17 -0400 Subject: [PATCH] rgnano: Sleep timer and idle poweroff support Actually power off the handheld with the sleep timer and idle poweroff functions instead of closing rockbox. This commit also moves setting system volume to max from the launch script to system-sdl.c so it works when running rockbox via instant play. Change-Id: I174b67c6abef451faa05f4a8f52b8d9eeed98a22 --- .../target/hosted/anbernic/instant_play.c | 41 +++++++++++-------- .../target/hosted/anbernic/instant_play.h | 3 +- firmware/target/hosted/sdl/button-sdl.c | 12 +++--- firmware/target/hosted/sdl/system-sdl.c | 6 +++ packaging/rgnano/config.cfg | 1 - packaging/rgnano/run.sh | 3 -- 6 files changed, 38 insertions(+), 28 deletions(-) diff --git a/firmware/target/hosted/anbernic/instant_play.c b/firmware/target/hosted/anbernic/instant_play.c index 0dab3c5b26..50d34618ea 100644 --- a/firmware/target/hosted/anbernic/instant_play.c +++ b/firmware/target/hosted/anbernic/instant_play.c @@ -80,27 +80,32 @@ void ip_reset_values(void) } } +void ip_power_off(void) +{ + /* Stop the powerdown countdown */ + system("powerdown handle"); + + /* Write the instant_play file */ + char buf[60]; + size_t nbytes; + int fd; + + fd = open("/mnt/instant_play", O_WRONLY | O_CREAT, 0640); + + strcpy(buf, "'/opk/rockbox' &\npid record $!\nwait $!\npid erase\n"); + nbytes = strlen(buf); + write(fd, buf, nbytes); + + close(fd); + + /* Powerdown the handheld after writting the file */ + system("powerdown now"); +} + void ip_handle_sigusr1(int sig) { if (sig == SIGUSR1) { - /* Stop the powerdown countdown */ - system("powerdown handle"); - - /* Write the instant_play file */ - char buf[60]; - size_t nbytes; - int fd; - - fd = open("/mnt/instant_play", O_WRONLY | O_CREAT, 0640); - - strcpy(buf, "'/opk/rockbox' &\npid record $!\nwait $!\npid erase\n"); - nbytes = strlen(buf); - write(fd, buf, nbytes); - - close(fd); - - /* Powerdown the handheld after writting the file */ - system("powerdown now"); + ip_power_off(); } } diff --git a/firmware/target/hosted/anbernic/instant_play.h b/firmware/target/hosted/anbernic/instant_play.h index 97ce67907e..51cde6958e 100644 --- a/firmware/target/hosted/anbernic/instant_play.h +++ b/firmware/target/hosted/anbernic/instant_play.h @@ -20,6 +20,7 @@ #ifndef _INSTANT_PLAY_H_ #define _INSTANT_PLAY_H_ -void ip_handle_sigusr1(int sig); void ip_reset_values(void); +void ip_power_off(void); +void ip_handle_sigusr1(int sig); #endif /* _INSTANT_PLAY_H_ */ diff --git a/firmware/target/hosted/sdl/button-sdl.c b/firmware/target/hosted/sdl/button-sdl.c index 74019f9970..d8564e12f6 100644 --- a/firmware/target/hosted/sdl/button-sdl.c +++ b/firmware/target/hosted/sdl/button-sdl.c @@ -586,16 +586,18 @@ static void button_event(int key, bool pressed) return; #endif #endif -#if (CONFIG_PLATFORM & PLATFORM_PANDORA) || defined(RG_NANO) -#ifdef RG_NANO - case SDLK_q: -#else +#if (CONFIG_PLATFORM & PLATFORM_PANDORA) case SDLK_LCTRL: -#endif /* Will post SDL_USEREVENT in shutdown_hw() if successful. */ sys_poweroff(); break; #endif +#ifdef RG_NANO + case SDLK_q: + /* Use reboot to exit without shutting down */ + sys_reboot(); + break; +#endif #ifdef HAS_BUTTON_HOLD case SDLK_h: if(pressed) diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c index 365f06f1ff..ec7ba8f36c 100644 --- a/firmware/target/hosted/sdl/system-sdl.c +++ b/firmware/target/hosted/sdl/system-sdl.c @@ -202,6 +202,7 @@ void power_off(void) #if defined(RG_NANO) && !defined(SIMULATOR) /* Reset volume/brightness to the values before launching rockbox */ ip_reset_values(); + ip_power_off(); #endif #ifdef HAVE_SDL_THREADS @@ -252,6 +253,9 @@ void system_init(void) #endif #if defined(RG_NANO) && !defined(SIMULATOR) + /* Set system volume to max with amixer */ + system("amixer -q sset 'Headphone' 63 unmute"); + /* Instant play handling */ struct sigaction ip_sa; ip_sa.sa_handler = ip_handle_sigusr1; @@ -305,6 +309,8 @@ void system_reboot(void) #if defined(RG_NANO) && !defined(SIMULATOR) /* Reset volume/brightness to the values before launching rockbox */ ip_reset_values(); + SDL_Quit(); + exit(EXIT_SUCCESS); #endif #ifdef HAVE_SDL_THREADS diff --git a/packaging/rgnano/config.cfg b/packaging/rgnano/config.cfg index cea2221712..b41f7bad72 100644 --- a/packaging/rgnano/config.cfg +++ b/packaging/rgnano/config.cfg @@ -1,6 +1,5 @@ # .cfg file created by rockbox c145f41658-250621 - http://www.rockbox.org -idle poweroff: 0 font: /FunKey/.rockbox/fonts/16-GNU-Unifont.fnt database scan paths: /Music qs top: brightness diff --git a/packaging/rgnano/run.sh b/packaging/rgnano/run.sh index e0b9d40f75..79c51808a9 100755 --- a/packaging/rgnano/run.sh +++ b/packaging/rgnano/run.sh @@ -39,9 +39,6 @@ if [ ! -f $CFGFILE ]; then cp ./config.cfg $CFGFILE fi -# Set volume to max with amixer so it's not permanent -amixer -q sset 'Headphone' 63 unmute - # Need to send SIGUSR1 to the rockbox process for instant play support trap _send_sigusr1 SIGUSR1