From f626f886229cb1b3f0de565324a4a785be4e41dc Mon Sep 17 00:00:00 2001 From: puchupala Date: Sun, 8 Nov 2026 13:56:06 +0900 Subject: [PATCH 1/3] feat: "Rumble strength" setting, applied to all rumble/haptics Add a rumbleStrength percentage (default 100 = unchanged behaviour) to minuisettings.txt and expose it in Settings > System next to "Haptic feedback" as Off/10%..100%. The scale is applied in VIB_thread right before PLAT_setRumble, so vib.strength stays in core units and the in-game menu save/restore keeps working; every platform benefits (tg5040 already had to hard-cap Brick Pro voltage for the same complaint). Two small VIB hardenings that the stuck-motor testing exposed: - VIB_quit now writes a final PLAT_setRumble(0) after joining; the queued 0 before pthread_cancel was usually lost. - PWR_enterSleep zeroes rumble first; with haptics off (the default) a core mid-rumble at lid close kept the motor on through suspend. Known, intentionally left alone: VIB_doublePulse/triplePulse double-scale their strength, and set_rumble_state ignores strong/weak motor effects. Co-Authored-By: Claude Fable 5.1 --- workspace/all/common/api.c | 22 +++++++++++++++++++++- workspace/all/common/config.c | 27 +++++++++++++++++++++++++++ workspace/all/common/config.h | 5 +++++ workspace/all/settings/settings.cpp | 9 +++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/workspace/all/common/api.c b/workspace/all/common/api.c index e107225da5..1037d72f5e 100644 --- a/workspace/all/common/api.c +++ b/workspace/all/common/api.c @@ -3957,6 +3957,18 @@ static struct VIB_Context int queued_strength; int strength; } vib = {0}; +// User-facing "Rumble strength" setting, applied to every request right before it +// reaches the platform. vib.strength stays in core units (0..0xFFFF) so +// VIB_getStrength() and the change detection above are unaffected. +static int VIB_applyScale(int strength) +{ + int percent = CFG_getRumbleStrength(); + if (percent >= 100) + return strength; + if (percent <= 0) + return 0; + return (int)(((long long)strength * percent) / 100); +} static void *VIB_thread(void *arg) { #define DEFER_FRAMES 3 @@ -3974,7 +3986,7 @@ static void *VIB_thread(void *arg) vib.strength = vib.queued_strength; defer = 0; - PLAT_setRumble(vib.strength); + PLAT_setRumble(VIB_applyScale(vib.strength)); } } return 0; @@ -3993,6 +4005,11 @@ void VIB_quit(void) VIB_setStrength(0); pthread_cancel(vib.pt); pthread_join(vib.pt, NULL); + // the queued 0 above is usually lost (the thread is cancelled inside its + // SDL_Delay or still deferring the drop), so stop the motor ourselves + vib.strength = vib.queued_strength = 0; + PLAT_setRumble(0); + vib.initialized = 0; } void VIB_setStrength(int strength) { @@ -4341,6 +4358,9 @@ void PWR_powerOff(int reboot) static void PWR_enterSleep(void) { + // a core may be mid-rumble when the lid closes; without haptics the sleep + // pulse below never runs, and the motor would stay on through suspend + VIB_setStrength(0); #if defined(SND_CLOSE_ON_SLEEP) && SND_CLOSE_ON_SLEEP // On H700, fully close the audio device before sleeping: a PCM left open // across suspend-to-RAM ends up in a state SDL takes ~10s to close on diff --git a/workspace/all/common/config.c b/workspace/all/common/config.c index aea4cb4967..c18f875245 100644 --- a/workspace/all/common/config.c +++ b/workspace/all/common/config.c @@ -73,6 +73,7 @@ void CFG_defaults(NextUISettings *cfg) .keepAwakeWhenUSB = CFG_DEFAULT_KEEPAWAKEWHENUSB, .haptics = CFG_DEFAULT_HAPTICS, + .rumbleStrength = CFG_DEFAULT_RUMBLESTRENGTH, .romsUseFolderBackground = CFG_DEFAULT_ROMSUSEFOLDERBACKGROUND, .saveFormat = CFG_DEFAULT_SAVEFORMAT, .stateFormat = CFG_DEFAULT_STATEFORMAT, @@ -321,6 +322,11 @@ void CFG_init(FontLoad_callback_t cb, ColorSet_callback_t ccb) CFG_setHaptics((bool)temp_value); continue; } + if (sscanf(line, "rumbleStrength=%i", &temp_value) == 1) + { + CFG_setRumbleStrength(temp_value); + continue; + } if (sscanf(line, "romfolderbg=%i", &temp_value) == 1) { CFG_setRomsUseFolderBackground((bool)temp_value); @@ -892,6 +898,21 @@ void CFG_setHaptics(bool enable) CFG_sync(); } +int CFG_getRumbleStrength(void) +{ + return settings.rumbleStrength; +} + +void CFG_setRumbleStrength(int percent) +{ + if (percent < 0) + percent = 0; + else if (percent > 100) + percent = 100; + settings.rumbleStrength = percent; + CFG_sync(); +} + int CFG_getSaveFormat(void) { return settings.saveFormat; @@ -1458,6 +1479,10 @@ void CFG_get(const char *key, char *value) { sprintf(value, "%i", CFG_getMuteLEDs()); } + else if (strcmp(key, "rumbleStrength") == 0) + { + sprintf(value, "%i", CFG_getRumbleStrength()); + } else if (strcmp(key, "fn1action") == 0) { sprintf(value, "%s", CFG_getFnAction(0)); @@ -1650,6 +1675,7 @@ void CFG_sync(void) fprintf(file, "keepAwakeWhenUSB=%i\n", settings.keepAwakeWhenUSB); fprintf(file, "switcherscale=%i\n", settings.gameSwitcherScaling); fprintf(file, "haptics=%i\n", settings.haptics); + fprintf(file, "rumbleStrength=%i\n", settings.rumbleStrength); fprintf(file, "romfolderbg=%i\n", settings.romsUseFolderBackground); fprintf(file, "saveFormat=%i\n", settings.saveFormat); fprintf(file, "stateFormat=%i\n", settings.stateFormat); @@ -1725,6 +1751,7 @@ void CFG_print(void) printf("\t\"keepAwakeWhenUSB\": %i,\n", settings.keepAwakeWhenUSB); printf("\t\"switcherscale\": %i,\n", settings.gameSwitcherScaling); printf("\t\"haptics\": %i,\n", settings.haptics); + printf("\t\"rumbleStrength\": %i,\n", settings.rumbleStrength); printf("\t\"romfolderbg\": %i,\n", settings.romsUseFolderBackground); printf("\t\"saveFormat\": %i,\n", settings.saveFormat); printf("\t\"stateFormat\": %i,\n", settings.stateFormat); diff --git a/workspace/all/common/config.h b/workspace/all/common/config.h index bad3f5fc00..df8024d00c 100644 --- a/workspace/all/common/config.h +++ b/workspace/all/common/config.h @@ -161,6 +161,7 @@ typedef struct // Haptic bool haptics; + int rumbleStrength; // percent, 0 = off, 100 = full // Networking bool ntp; @@ -232,6 +233,7 @@ typedef struct #define CFG_DEFAULT_POWEROFFPROTECTION true #define CFG_DEFAULT_KEEPAWAKEWHENUSB false #define CFG_DEFAULT_HAPTICS false +#define CFG_DEFAULT_RUMBLESTRENGTH 100 #define CFG_DEFAULT_ROMSUSEFOLDERBACKGROUND true #define CFG_DEFAULT_SAVEFORMAT SAVE_FORMAT_SAV #define CFG_DEFAULT_STATEFORMAT STATE_FORMAT_SAV @@ -370,6 +372,9 @@ void CFG_setGameSwitcherScaling(int enumValue); // Enable/disable haptics. bool CFG_getHaptics(void); void CFG_setHaptics(bool enable); +// Scale applied to every rumble/haptic request, in percent (0 = off, 100 = full). +int CFG_getRumbleStrength(void); +void CFG_setRumbleStrength(int percent); // Save format to use for libretro cores // 0 - .sav // 1 - .srm (compressed rzip) diff --git a/workspace/all/settings/settings.cpp b/workspace/all/settings/settings.cpp index f9f740470e..3ab6ea03f5 100644 --- a/workspace/all/settings/settings.cpp +++ b/workspace/all/settings/settings.cpp @@ -156,6 +156,10 @@ static const std::vector transition_mode_labels = {"Off", "Snappy", static const std::vector curtain_opacity_values = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100}; static const std::vector curtain_opacity_labels = {"Off", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"}; +// Rumble strength options (percent, 0 = off) +static const std::vector rumble_strength_values = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100}; +static const std::vector rumble_strength_labels = {"Off", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"}; + // Input prompt style options static const std::vector input_prompt_style_values = {(int)INPUT_STYLE_TEXT, (int)INPUT_STYLE_ABXY, (int)INPUT_STYLE_CARDINALS, (int)INPUT_STYLE_SHAPES}; static const std::vector input_prompt_style_labels = {"Text", "ABXY", "Cardinals", "Shapes"}; @@ -657,6 +661,11 @@ int main(int argc, char *argv[]) { return CFG_getHaptics(); }, [](const std::any &value) { CFG_setHaptics(std::any_cast(value)); }, []() { CFG_setHaptics(CFG_DEFAULT_HAPTICS);}}, + new MenuItem{ListItemType::Generic, "Rumble strength", "Strength of game rumble and haptic pulses (Off disables rumble)", rumble_strength_values, rumble_strength_labels, []() -> std::any + { // snap to the 10% grid so a hand-edited value still matches a list entry + return (CFG_getRumbleStrength() + 5) / 10 * 10; }, [](const std::any &value) + { CFG_setRumbleStrength(std::any_cast(value)); }, + []() { CFG_setRumbleStrength(CFG_DEFAULT_RUMBLESTRENGTH);}}, new MenuItem{ListItemType::Generic, "Default view", "The initial view to show on boot", {(int)SCREEN_GAMELIST, (int)SCREEN_GAMESWITCHER, (int)SCREEN_QUICKMENU}, {"Content List","Game Switcher","Quick Menu"}, From a6635eb02df1d3650ef2f60bfb7c9dae14451b54 Mon Sep 17 00:00:00 2001 From: puchupala Date: Tue, 24 Nov 2026 01:02:20 +0900 Subject: [PATCH 2/3] fix: use clamp() in CFG_setRumbleStrength Review feedback on #899: use the existing utils.h helper instead of a hand-written range check, matching the other setters in config.c. Co-Authored-By: Claude Fable 5.1 --- workspace/all/common/config.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/workspace/all/common/config.c b/workspace/all/common/config.c index c18f875245..cb8411b001 100644 --- a/workspace/all/common/config.c +++ b/workspace/all/common/config.c @@ -905,11 +905,7 @@ int CFG_getRumbleStrength(void) void CFG_setRumbleStrength(int percent) { - if (percent < 0) - percent = 0; - else if (percent > 100) - percent = 100; - settings.rumbleStrength = percent; + settings.rumbleStrength = clamp(percent, 0, 100); CFG_sync(); } From e8d8c0fd207602100864518d78ea805126cb8862 Mon Sep 17 00:00:00 2001 From: puchupala Date: Tue, 24 Nov 2026 01:13:53 +0900 Subject: [PATCH 3/3] fix: stop rumble before the power-off screen A power-button hold mid-rumble reaches PWR_powerOff with the core still blocked in PWR_update, so its last request stayed queued and the motor ran through the "powering off" screen until VIB_quit. Zero it first, as PWR_enterSleep already does. Review feedback on #899. Co-Authored-By: Claude Fable 5.1 --- workspace/all/common/api.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/workspace/all/common/api.c b/workspace/all/common/api.c index 1037d72f5e..6a9eef8186 100644 --- a/workspace/all/common/api.c +++ b/workspace/all/common/api.c @@ -4308,6 +4308,10 @@ void PWR_disablePowerOff(void) } void PWR_powerOff(int reboot) { + // the core is blocked in PWR_update, so its last rumble request would stay + // queued and the motor would run through the power-off screen + VIB_setStrength(0); + if (pwr.can_poweroff) {