Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions skeleton/BASE/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ TRIMUI SMART PRO / TRIMUI BRICK
"TrimUI" button: Quick menu
Select button: Game switcher

TRIMUI BRICK / BRICK PRO / SMART PRO S

Buttons with no action of their own can be assigned a pak to launch: L3/R3 on the Brick, L4/R4 on the Brick Pro, and HOME on the Brick Pro and Smart Pro S. Assign them under Settings > Assignments. Assignments only apply in the main menu, not in-game. HOME no longer acts as a second menu button.

----------------------------------------
Quicksave & auto-resume

Expand Down
8 changes: 4 additions & 4 deletions workspace/all/common/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -3386,8 +3386,8 @@ FALLBACK_IMPLEMENTATION void PLAT_pollInput(void)
}
else if (code == CODE_MENU_ALT)
{
btn = BTN_MENU;
id = BTN_ID_MENU;
btn = BTN_HOME;
id = BTN_ID_HOME;
}
else if (code == CODE_L1)
{
Expand Down Expand Up @@ -3512,8 +3512,8 @@ FALLBACK_IMPLEMENTATION void PLAT_pollInput(void)
}
else if (joy == JOY_MENU_ALT)
{
btn = BTN_MENU;
id = BTN_ID_MENU;
btn = BTN_HOME;
id = BTN_ID_HOME;
}
else if (joy == JOY_MENU_ALT2)
{
Expand Down
59 changes: 59 additions & 0 deletions workspace/all/common/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ void CFG_defaults(NextUISettings *cfg)

.muteLeds = CFG_DEFAULT_MUTELEDS,

.fnAction = {CFG_DEFAULT_FN_ACTION, CFG_DEFAULT_FN_ACTION, CFG_DEFAULT_FN_ACTION},

.screenTimeoutSecs = CFG_DEFAULT_SCREENTIMEOUTSECS,
.suspendTimeoutSecs = CFG_DEFAULT_SUSPENDTIMEOUTSECS,
.powerOffProtection = CFG_DEFAULT_POWEROFFPROTECTION,
Expand Down Expand Up @@ -343,6 +345,27 @@ void CFG_init(FontLoad_callback_t cb, ColorSet_callback_t ccb)
CFG_setMuteLEDs(temp_value);
continue;
}
if (strncmp(line, "fn1action=", 10) == 0)
{
char *value = line + 10;
value[strcspn(value, "\r\n")] = 0;
CFG_setFnAction(0, value);
continue;
}
if (strncmp(line, "fn2action=", 10) == 0)
{
char *value = line + 10;
value[strcspn(value, "\r\n")] = 0;
CFG_setFnAction(1, value);
continue;
}
if (strncmp(line, "fn3action=", 10) == 0)
{
char *value = line + 10;
value[strcspn(value, "\r\n")] = 0;
CFG_setFnAction(2, value);
continue;
}
if (sscanf(line, "artWidth=%i", &temp_value) == 1)
{
CFG_setGameArtWidth((double)temp_value / 100.0);
Expand Down Expand Up @@ -907,6 +930,24 @@ void CFG_setMuteLEDs(bool on)
CFG_sync();
}

const char* CFG_getFnAction(int index)
{
if (index < 0 || index >= FN_BUTTON_COUNT)
return "";
return settings.fnAction[index];
}

void CFG_setFnAction(int index, const char* action)
{
if (index < 0 || index >= FN_BUTTON_COUNT)
return;
if (!action)
action = "";
strncpy(settings.fnAction[index], action, sizeof(settings.fnAction[index]) - 1);
settings.fnAction[index][sizeof(settings.fnAction[index]) - 1] = '\0';
CFG_sync();
}

double CFG_getGameArtWidth(void)
{
return settings.gameArtWidth;
Expand Down Expand Up @@ -1400,6 +1441,18 @@ void CFG_get(const char *key, char *value)
{
sprintf(value, "%i", CFG_getMuteLEDs());
}
else if (strcmp(key, "fn1action") == 0)
{
sprintf(value, "%s", CFG_getFnAction(0));
}
else if (strcmp(key, "fn2action") == 0)
{
sprintf(value, "%s", CFG_getFnAction(1));
}
else if (strcmp(key, "fn3action") == 0)
{
sprintf(value, "%s", CFG_getFnAction(2));
}
else if (strcmp(key, "artWidth") == 0)
{
sprintf(value, "%i", (int)(CFG_getGameArtWidth()) * 100);
Expand Down Expand Up @@ -1581,6 +1634,9 @@ void CFG_sync(void)
fprintf(file, "stateFormat=%i\n", settings.stateFormat);
fprintf(file, "useExtractedFileName=%i\n", settings.useExtractedFileName);
fprintf(file, "muteLeds=%i\n", settings.muteLeds);
fprintf(file, "fn1action=%s\n", settings.fnAction[0]);
fprintf(file, "fn2action=%s\n", settings.fnAction[1]);
fprintf(file, "fn3action=%s\n", settings.fnAction[2]);
fprintf(file, "artWidth=%i\n", (int)(settings.gameArtWidth * 100));
fprintf(file, "wifi=%i\n", settings.wifi);
fprintf(file, "defaultView=%i\n", settings.defaultView);
Expand Down Expand Up @@ -1652,6 +1708,9 @@ void CFG_print(void)
printf("\t\"stateFormat\": %i,\n", settings.stateFormat);
printf("\t\"useExtractedFileName\": %i,\n", settings.useExtractedFileName);
printf("\t\"muteLeds\": %i,\n", settings.muteLeds);
printf("\t\"fn1action\": \"%s\",\n", settings.fnAction[0]);
printf("\t\"fn2action\": \"%s\",\n", settings.fnAction[1]);
printf("\t\"fn3action\": \"%s\",\n", settings.fnAction[2]);
printf("\t\"artWidth\": %i,\n", (int)(settings.gameArtWidth * 100));
printf("\t\"wifi\": %i,\n", settings.wifi);
printf("\t\"defaultView\": %i,\n", settings.defaultView);
Expand Down
23 changes: 23 additions & 0 deletions workspace/all/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ enum {
COLOR_BACKGROUND = 7
};

// Number of user-assignable button slots (FN1/FN2/FN3). Slots are fixed and global,
// not per-device: which of them a given device actually exposes is a UI question.
#define FN_BUTTON_COUNT 3

// Prefix for the "launch a Tools pak" action, followed by a path relative to
// Tools/<PLATFORM> (e.g. "pak:Bootlogo.pak"). The platform dir is resolved at launch
// time rather than stored, so settings stay portable when a card moves between devices.
#define FN_ACTION_PAK_PREFIX "pak:"

// Input hint styles
enum {
INPUT_STYLE_TEXT = -1, // Rendered text
Expand Down Expand Up @@ -135,6 +144,10 @@ typedef struct
// Mute switch
bool muteLeds;

// User-assignable buttons (see BTN_FN1/BTN_FN2/BTN_FN3 in platform.h).
// Action strings, "" == unassigned. See CFG_getFnAction().
char fnAction[FN_BUTTON_COUNT][256];

// Power
uint32_t screenTimeoutSecs;
uint32_t suspendTimeoutSecs;
Expand Down Expand Up @@ -223,6 +236,7 @@ typedef struct
#define CFG_DEFAULT_STATEFORMAT STATE_FORMAT_SAV
#define CFG_DEFAULT_EXTRACTEDFILENAME false
#define CFG_DEFAULT_MUTELEDS false
#define CFG_DEFAULT_FN_ACTION "" // unassigned
#define CFG_DEFAULT_GAMEARTWIDTH 0.45
#define CFG_DEFAULT_WIFI false
#define CFG_DEFAULT_VIEW SCREEN_GAMELIST
Expand Down Expand Up @@ -370,6 +384,15 @@ void CFG_setUseExtractedFileName(bool);
// Enable/disable mute also shutting off LEDs.
bool CFG_getMuteLEDs(void);
void CFG_setMuteLEDs(bool);
// The action bound to a user-assignable button, where `index` is 0 (FN1), 1 (FN2) or
// 2 (FN3, the "HOME" button).
// The value is a "<kind>:<arg>" action string so more kinds can be added later without
// migrating existing settings; "" means unassigned. The only kind today is
// FN_ACTION_PAK_PREFIX. Callers must ignore kinds they don't recognise, so a card
// configured on a newer build degrades to "does nothing" on an older one.
// Returns "" for an out of range index.
const char* CFG_getFnAction(int index);
void CFG_setFnAction(int index, const char* action);
// Set game art width percentage.
double CFG_getGameArtWidth(void);
void CFG_setGameArtWidth(double zeroToOne);
Expand Down
3 changes: 3 additions & 0 deletions workspace/all/common/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ enum {
BTN_ID_ANALOG_LEFT,
BTN_ID_ANALOG_RIGHT,

BTN_ID_HOME,

BTN_ID_COUNT,
};
enum {
Expand Down Expand Up @@ -225,6 +227,7 @@ enum {
BTN_ANALOG_DOWN = 1 << BTN_ID_ANALOG_DOWN,
BTN_ANALOG_LEFT = 1 << BTN_ID_ANALOG_LEFT,
BTN_ANALOG_RIGHT= 1 << BTN_ID_ANALOG_RIGHT,
BTN_HOME = 1 << BTN_ID_HOME,

BTN_UP = BTN_DPAD_UP | BTN_ANALOG_UP,
BTN_DOWN = BTN_DPAD_DOWN | BTN_ANALOG_DOWN,
Expand Down
44 changes: 44 additions & 0 deletions workspace/all/nextui/nextui.c
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,41 @@ static void openPak(char* path) {
sprintf(cmd, "'%s/launch.sh'", escapeSingleQuotes(path));
queueNext(cmd);
}

// Run the action bound to a user-assignable button (0 == FN1, 1 == FN2).
// Returns 1 if something was launched.
static int runFnAction(int index) {
const char* action = CFG_getFnAction(index);
if (!action || !action[0]) return 0; // unassigned

// only "launch a Tools pak" exists so far; ignore kinds we don't know so a card
// configured on a newer build just does nothing here instead of misfiring
size_t prefix_len = strlen(FN_ACTION_PAK_PREFIX);
if (strncmp(action, FN_ACTION_PAK_PREFIX, prefix_len)!=0) return 0;

const char* rel = action + prefix_len;
if (!rel[0]) return 0;

char pak_path[256];
snprintf(pak_path, sizeof(pak_path), "%s/Tools/%s/%s", SDCARD_PATH, PLATFORM, rel);

char launch_path[256];
snprintf(launch_path, sizeof(launch_path), "%s/launch.sh", pak_path);
if (!exists(launch_path)) return 0; // stale binding, eg. the pak was deleted

// unlike openPak() we save where the user *is*, not the pak itself, so exiting
// the pak comes back to the same spot in the list
if (top && top->entries->count>0) {
Entry* entry = top->entries->items[top->selected];
saveLast(entry->path);
}

char cmd[256];
// NOTE: escapeSingleQuotes() modifies pak_path in place
snprintf(cmd, sizeof(cmd), "'%s/launch.sh'", escapeSingleQuotes(pak_path));
queueNext(cmd);
return 1;
}
static void openRom(char* path, char* last) {
LOG_info("openRom(%s,%s)\n", path, last);

Expand Down Expand Up @@ -2300,6 +2335,15 @@ int main (int argc, char *argv[]) {

PWR_update(&dirty, &show_setting, NULL, NULL);

// user-assignable buttons, handled before the per-screen input so they work
// from the game list, the game switcher and the quick menu alike.
// skipped while the brightness/volume overlay owns input, same as L1/R1 below.
if (!show_setting) {
if (PAD_justPressed(BTN_FN1)) runFnAction(0);
else if (PAD_justPressed(BTN_FN2)) runFnAction(1);
else if (PAD_justPressed(BTN_FN3)) runFnAction(2);
}

int is_online = PWR_isOnline();
if (was_online!=is_online)
dirty = 1;
Expand Down
Loading
Loading