Skip to content

Commit 23e2929

Browse files
committed
add Instant Play to fix nast opkrun bug, change menu label and reorder exit menu
Signed-off-by: Michel-FK <[email protected]>
1 parent 81cd447 commit 23e2929

File tree

5 files changed

+139
-6
lines changed

5 files changed

+139
-6
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ set(DinguxCommander_SRCS
2727
dialog.cpp
2828
fileLister.cpp
2929
fileutils.cpp
30+
fk_instant_play.c
3031
fk_menu.c
3132
keyboard.cpp
3233
main.cpp

fk_instant_play.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
FK - FunKey retro gaming console library
3+
Copyright (C) 2020-2021 Vincent Buso
4+
Copyright (C) 2020-2021 Michel Stempin
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with this library; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
20+
Vincent Buso
21+
22+
Michel Stempin
23+
24+
*/
25+
26+
/**
27+
* @file FK_Instant_Play.c
28+
* This is the Instant Play API for the FunKey retro gaming console library
29+
*/
30+
31+
#include <stdio.h>
32+
#include <unistd.h>
33+
#include "fk_menu.h"
34+
#include "fk_instant_play.h"
35+
36+
#ifndef SHELL_CMD_POWERDOWN
37+
#define SHELL_CMD_POWERDOWN "shutdown_funkey"
38+
#define SHELL_CMD_SCHEDULE_POWERDOWN "sched_shutdown"
39+
#define SHELL_CMD_CANCEL_SCHED_POWERDOWN "cancel_sched_powerdown"
40+
#endif
41+
42+
/* Handler for SIGUSR1, caused by closing the console */
43+
static void handle_sigusr1(int signal)
44+
{
45+
printf("Caught signal USR1(%d)\n", signal);
46+
47+
/* Exit menu if it was launched */
48+
FK_EndMenu();
49+
50+
/* Send command to cancel any previously scheduled powerdown */
51+
if (popen(SHELL_CMD_CANCEL_SCHED_POWERDOWN, "r") == NULL)
52+
{
53+
/* Countdown is still ticking, so better do nothing
54+
than start writing and get interrupted!
55+
*/
56+
printf("Failed to cancel scheduled shutdown\n");
57+
exit(0);
58+
}
59+
60+
/* Perform Instant Play save and shutdown */
61+
execlp(SHELL_CMD_POWERDOWN, SHELL_CMD_POWERDOWN);
62+
63+
/* Should not be reached */
64+
printf("Failed to perform shutdown\n");
65+
66+
/* Exit application */
67+
exit(0);
68+
}
69+
70+
void FK_InitInstantPlay(void)
71+
{
72+
signal(SIGUSR1, handle_sigusr1);
73+
}
74+

fk_instant_play.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
FK - FunKey retro gaming console library
3+
Copyright (C) 2020-2021 Vincent Buso
4+
Copyright (C) 2020-2021 Michel Stempin
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with this library; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
20+
Vincent Buso
21+
22+
Michel Stempin
23+
24+
*/
25+
26+
/**
27+
* @file FK_Instant_Play.h
28+
* This is the Instant Play API for the FunKey retro gaming console library
29+
*/
30+
31+
#ifndef _FK_instant_play_h
32+
#define _FK_instant_play_h
33+
34+
/* Set up for C function definitions, even when using C++ */
35+
#ifdef __cplusplus
36+
extern "C" {
37+
#endif
38+
39+
#include <signal.h>
40+
41+
extern void FK_InitInstantPlay(void);
42+
43+
/* Ends C function definitions when using C++ */
44+
#ifdef __cplusplus
45+
}
46+
#endif
47+
48+
#endif /* _FK_instant_play_h */

fk_menu.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,14 @@ static void add_menu_zone(ENUM_MENU_TYPE menu_type)
341341
SDL_BlitSurface(text_surface, NULL, surface, &text_pos);
342342
break;
343343
#endif
344-
#ifdef HAS_MENU_POWERDOWN
344+
#ifdef HAS_MENU_RO_RW
345345
case MENU_TYPE_RO_RW:
346+
MENU_DEBUG_PRINTF("Init MENU_TYPE_RO_RW\n");
347+
/// ------ Text ------
348+
text_surface = TTF_RenderText_Blended(menu_title_font, "SET SYSTEM:", text_color);
349+
text_pos.x = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
350+
text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 - padding_y_from_center_menu_zone*2;
351+
SDL_BlitSurface(text_surface, NULL, surface, &text_pos);
346352
break;
347353
#endif
348354
default:
@@ -371,6 +377,9 @@ static void init_menu_zones(void)
371377
#ifdef HAS_MENU_ASPECT_RATIO
372378
add_menu_zone(MENU_TYPE_ASPECT_RATIO);
373379
#endif
380+
#ifdef HAS_MENU_RO_RW
381+
add_menu_zone(MENU_TYPE_RO_RW);
382+
#endif
374383
#ifdef HAS_MENU_EXIT
375384
add_menu_zone(MENU_TYPE_EXIT);
376385
#endif
@@ -386,9 +395,6 @@ static void init_menu_zones(void)
386395
#ifdef HAS_MENU_POWERDOWN
387396
add_menu_zone(MENU_TYPE_POWERDOWN);
388397
#endif
389-
#ifdef HAS_MENU_RO_RW
390-
add_menu_zone(MENU_TYPE_RO_RW);
391-
#endif
392398
}
393399

394400

@@ -795,7 +801,7 @@ static void menu_screen_refresh(SDL_Surface *screen, int menuItem, int prevItem,
795801
#endif
796802
#ifdef HAS_MENU_RO_RW
797803
case MENU_TYPE_RO_RW:
798-
sprintf(text_tmp, "SYS %s", read_write?"READ-ONLY":"READ-WRITE");
804+
sprintf(text_tmp, "%s", read_write?"READ-ONLY":"READ-WRITE");
799805
text_surface = TTF_RenderText_Blended(menu_title_font, text_tmp, text_color);
800806
text_pos.x = (screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
801807
text_pos.y = screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2;
@@ -1303,7 +1309,7 @@ int FK_RunMenu(SDL_Surface *screen)
13031309
#endif
13041310
#ifdef HAS_MENU_RO_RW
13051311
if(idx_menus[menuItem] == MENU_TYPE_RO_RW){
1306-
MENU_DEBUG_PRINTF("SYSTEM %s\n", read_write?"RO":"RW");
1312+
MENU_DEBUG_PRINTF("%s\n", read_write?"RO":"RW");
13071313
if(menu_confirmation){
13081314
MENU_DEBUG_PRINTF("SYSTEM %s - confirmed\n", read_write?"RO":"RW");
13091315
/// ----- Refresh screen ----

main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "screen.h"
1515
#include "sdlutils.h"
1616
#include "fk_menu.h"
17+
#include "fk_instant_play.h"
1718

1819
// Globals
1920
const SDL_Color Globals::g_colorTextNormal = {COLOR_TEXT_NORMAL};
@@ -67,6 +68,9 @@ int main(int argc, char** argv)
6768
// Init menu
6869
FK_InitMenu();
6970

71+
// Init Instant Play
72+
FK_InitInstantPlay();
73+
7074
// Create instances
7175
CResourceManager::instance();
7276

0 commit comments

Comments
 (0)