Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

rgnano: Instant play support and proper system brightness/volume handling

Instant play is a Funkey OS feature that allows it to relaunch at boot the last program it was running before shutting down, which means that if the handheld is powered off (holding the power button) while rockbox is running the next time it's powered on rockbox will launch at boot.

This commit also handles system brightness/volume in rockbox itself instead of the launch script, so the values are properly reset when powering off the handheld while rockbox is running.

Change-Id: Ie1adbf71069aeed5fbf6670971718a2f718716a3

authored by

Hairo R. Carela and committed by
Solomon Peachy
46d10dda 16a6ad03

+167 -7
+1
firmware/SOURCES
··· 230 230 target/hosted/sysfs.c 231 231 target/hosted/power-linux.c 232 232 target/hosted/backlight-unix.c 233 + target/hosted/anbernic/instant_play.c 233 234 target/hosted/anbernic/power-rgnano.c 234 235 target/hosted/anbernic/button-rgnano.c 235 236 target/hosted/anbernic/powermgmt-rgnano.c
+106
firmware/target/hosted/anbernic/instant_play.c
··· 1 + /*************************************************************************** 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 + * 9 + * Copyright (C) 2025 Hairo R. Carela 10 + * 11 + * This program is free software; you can redistribute it and/or 12 + * modify it under the terms of the GNU General Public License 13 + * as published by the Free Software Foundation; either version 2 14 + * of the License, or (at your option) any later version. 15 + * 16 + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 + * KIND, either express or implied. 18 + * 19 + ****************************************************************************/ 20 + 21 + #include <stdio.h> 22 + #include <stdlib.h> 23 + #include <signal.h> 24 + #include <fcntl.h> 25 + #include <unistd.h> 26 + #include <string.h> 27 + 28 + static int get_value(const char *cmd) 29 + { 30 + /* Read values with the brightness/volume tools, stored in 31 + bootloader variables */ 32 + char line[4]; 33 + int value; 34 + 35 + char full_cmd[18]; 36 + snprintf(full_cmd, 18, "%s get", cmd); 37 + 38 + FILE* fp = popen(full_cmd, "r"); 39 + 40 + if (fp == NULL) { 41 + value = -1; 42 + } 43 + 44 + if (fgets(line, sizeof(line), fp) != NULL) 45 + { 46 + value = strtol(line, NULL, 10); 47 + } 48 + else 49 + { 50 + value = -1; 51 + } 52 + 53 + pclose(fp); 54 + return value; 55 + } 56 + 57 + static void set_value(const char *cmd, const int value) 58 + { 59 + /* Set values with the brightness/volume tools, stored in 60 + bootloader variables. */ 61 + char full_cmd[22]; 62 + snprintf(full_cmd, 22, "%s set %d", cmd, value); 63 + system(full_cmd); 64 + } 65 + 66 + void ip_reset_values(void) 67 + { 68 + /* Use the brightness/volume tools to reset to their previous 69 + values before launching rockbox */ 70 + int volume_level = get_value("volume"); 71 + if (volume_level > -1) 72 + { 73 + set_value("volume", volume_level); 74 + } 75 + 76 + int brightness_level = get_value("brightness"); 77 + if (brightness_level > -1) 78 + { 79 + set_value("brightness", brightness_level); 80 + } 81 + } 82 + 83 + void ip_handle_sigusr1(int sig) 84 + { 85 + if (sig == SIGUSR1) 86 + { 87 + /* Stop the powerdown countdown */ 88 + system("powerdown handle"); 89 + 90 + /* Write the instant_play file */ 91 + char buf[60]; 92 + size_t nbytes; 93 + int fd; 94 + 95 + fd = open("/mnt/instant_play", O_WRONLY | O_CREAT, 0640); 96 + 97 + strcpy(buf, "'/opk/rockbox' &\npid record $!\nwait $!\npid erase\n"); 98 + nbytes = strlen(buf); 99 + write(fd, buf, nbytes); 100 + 101 + close(fd); 102 + 103 + /* Powerdown the handheld after writting the file */ 104 + system("powerdown now"); 105 + } 106 + }
+25
firmware/target/hosted/anbernic/instant_play.h
··· 1 + /*************************************************************************** 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 + * 9 + * Copyright (C) 2025 Hairo R. Carela 10 + * 11 + * This program is free software; you can redistribute it and/or 12 + * modify it under the terms of the GNU General Public License 13 + * as published by the Free Software Foundation; either version 2 14 + * of the License, or (at your option) any later version. 15 + * 16 + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 + * KIND, either express or implied. 18 + * 19 + ****************************************************************************/ 20 + #ifndef _INSTANT_PLAY_H_ 21 + #define _INSTANT_PLAY_H_ 22 + 23 + void ip_handle_sigusr1(int sig); 24 + void ip_reset_values(void); 25 + #endif /* _INSTANT_PLAY_H_ */
+22
firmware/target/hosted/sdl/system-sdl.c
··· 50 50 #include "maemo-thread.h" 51 51 #endif 52 52 53 + #ifdef RG_NANO 54 + #include <signal.h> 55 + #include "instant_play.h" 56 + #endif 57 + 53 58 #define SIMULATOR_DEFAULT_ROOT "simdisk" 54 59 55 60 #if SDL_MAJOR_VERSION == 1 ··· 193 198 /* wait for event thread to finish */ 194 199 SDL_WaitThread(evt_thread, NULL); 195 200 201 + #ifdef RG_NANO 202 + /* Reset volume/brightness to the values before launching rockbox */ 203 + ip_reset_values(); 204 + #endif 205 + 196 206 #ifdef HAVE_SDL_THREADS 197 207 /* lock again before entering the scheduler */ 198 208 sim_thread_lock(t); ··· 240 250 g_type_init(); 241 251 #endif 242 252 253 + #ifdef RG_NANO 254 + /* Instant play handling */ 255 + struct sigaction ip_sa; 256 + ip_sa.sa_handler = ip_handle_sigusr1; 257 + sigaction(SIGUSR1, &ip_sa, NULL); 258 + #endif 259 + 243 260 if (SDL_InitSubSystem(SDL_INIT_TIMER)) 244 261 panicf("%s", SDL_GetError()); 245 262 ··· 284 301 285 302 void system_reboot(void) 286 303 { 304 + #ifdef RG_NANO 305 + /* Reset volume/brightness to the values before launching rockbox */ 306 + ip_reset_values(); 307 + #endif 308 + 287 309 #ifdef HAVE_SDL_THREADS 288 310 sim_thread_exception_wait(); 289 311 #else
+13 -7
packaging/rgnano/run.sh
··· 4 4 CFGFILE=$RBDIR/config.cfg 5 5 BLPATH=/sys/class/backlight/backlight/brightness 6 6 7 + _send_sigusr1() 8 + { 9 + kill -s USR1 "$rb_pid" 2>/dev/null 10 + } 11 + 7 12 # Install the rockbox folder 8 13 if [ ! -d $RBDIR ]; then 9 14 notif set 0 " Installing rockbox..." ··· 27 32 cp ./config.cfg $CFGFILE 28 33 fi 29 34 30 - # Get current volume/brightness -> launch rockbox -> restore previous values 31 - CUR_VOL=$(volume get) 32 - CUR_BL=$(cat $BLPATH) 33 - volume set 100 35 + # Set volume to max with amixer so it's not permanent 36 + amixer -q sset 'Headphone' 63 unmute 37 + 38 + # Need to send SIGUSR1 to the rockbox process for instant play support 39 + trap _send_sigusr1 SIGUSR1 34 40 35 - ./rockbox 41 + ./rockbox & 36 42 37 - volume set $CUR_VOL 38 - echo $CUR_BL > $BLPATH 43 + rb_pid=$! 44 + wait "$rb_pid"