Repository navigation
feat: "Rumble strength" setting + stop the motor on exit/sleep (all platforms) #899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
| { | ||
|
|
@@ -4291,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) | ||
| { | ||
|
|
||
|
|
@@ -4341,6 +4362,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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a user holds the power button (going into the "Quicksave created, powering off" screen) wouldn't the vibrate continue to happen through that screen? I think we probably need
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, added in e8d8c0f for now. Depending on #899 (comment), we may want to move this to a new PR. |
||
| #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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,17 @@ void CFG_setHaptics(bool enable) | |
| CFG_sync(); | ||
| } | ||
|
|
||
| int CFG_getRumbleStrength(void) | ||
| { | ||
| return settings.rumbleStrength; | ||
| } | ||
|
|
||
| void CFG_setRumbleStrength(int percent) | ||
| { | ||
| settings.rumbleStrength = clamp(percent, 0, 100); | ||
| CFG_sync(); | ||
| } | ||
|
Comment on lines
+906
to
+910
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you doing this manually instead of using
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to avoid relying on C++17 unnecessarily and didn't notice that Let's use
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in a6635eb, thanks. |
||
|
|
||
| int CFG_getSaveFormat(void) | ||
| { | ||
| return settings.saveFormat; | ||
|
|
@@ -1458,6 +1475,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 +1671,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 +1747,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); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could probably be a PR on its own, since it fixes an issue with the current logic here (we could probably also drop the
VIB_setStrength(0);above too)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I only included it in this PR since the change is rather small, but we could definitely move it into a separate PR. What do you prefer?