Skip to content

Fix rumble on devices such as Ayn Odin 2#538

Open
kiequoo wants to merge 1 commit intoutkarshdalal:masterfrom
kiequoo:fix-vibration-without-onscreen-controls
Open

Fix rumble on devices such as Ayn Odin 2#538
kiequoo wants to merge 1 commit intoutkarshdalal:masterfrom
kiequoo:fix-vibration-without-onscreen-controls

Conversation

@kiequoo
Copy link

@kiequoo kiequoo commented Feb 16, 2026

The rumble poller now always runs when the gamepad buffer exists, regardless of virtual gamepad mode or controller detection state. This ensures rumble works on devices with built-in controllers (like Ayn Odin 2) even when the on-screen controller overlay is disabled.

The existing fallback logic (try controller vibrator -> fall back to device rumble) ensures both external controllers and built-in controllers work correctly.


Summary by cubic

Fixes missing vibration when on-screen controls are disabled by always polling the rumble buffer. Restores haptics for built-in controllers like the Ayn Odin 2 while keeping a safe fallback to device vibration.

  • Bug Fixes
    • Always run rumble poller when gamepadBuffer exists, regardless of virtual gamepad or controller detection.
    • Fallback flow: try controller vibrator first; otherwise use device vibrator with haptic curve (renamed phoneVibrator to deviceVibrator and clarified comments).

Written for commit 990db2c. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes
    • Improved controller vibration and rumble reliability with enhanced polling logic
    • Refined vibration fallback mechanism to ensure consistent haptic feedback when physical controller is unavailable

The rumble poller now always runs when the gamepad buffer exists,
regardless of virtual gamepad mode or controller detection state.
This ensures vibration works on devices with built-in controllers
(like Ayn Odin 2) even when the on-screen controller overlay is disabled.

The existing fallback logic (try controller vibrator → fall back to
device vibration) ensures both external controllers and built-in
controllers work correctly.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 16, 2026

📝 Walkthrough

Walkthrough

The changes refactor vibration handling in WinHandler.java to always poll the rumble buffer when available, prioritize physical controller vibration attempts, and use device vibrator as the fallback mechanism instead of phone vibrator, with corresponding variable naming updates.

Changes

Cohort / File(s) Summary
Rumble and Vibration Logic
app/src/main/java/com/winlator/winhandler/WinHandler.java
Modified rumble polling condition to always poll when gamepadBuffer exists. Updated start vibration flow with immediate acknowledgment, prioritized physical controller attempt, replaced phone vibrator with device vibrator fallback, and renamed amplitude calculation variables from phone-specific to device-specific naming. Adjusted haptic curve logic to apply to device vibrator.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Whiskers twitch with vibrant glee,
Rumble flows now wild and free!
Physical controllers take the lead,
Device vibrator springs to speed!
No phone needed, just device care—
Haptic magic fills the air! 📳

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into master
Title check ✅ Passed The title 'Fix rumble on devices such as Ayn Odin 2' directly addresses the main objective of the PR, which is to fix vibration functionality on devices with built-in controllers.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
app/src/main/java/com/winlator/winhandler/WinHandler.java (2)

636-648: Naming inconsistency with stopVibration.

startVibration now uses deviceVibrator / finalDeviceAmplitude, but stopVibration (line 665) still uses phoneVibrator and the comment on line 664 says "phone's vibration." They reference the same system service, so there's no functional bug, but the inconsistent naming is confusing.

Suggested rename in stopVibration for consistency
         // Always attempt to stop the phone's vibration
-        Vibrator phoneVibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
-        if (phoneVibrator != null) {
-            phoneVibrator.cancel();
+        // Always attempt to stop the device's vibration
+        Vibrator deviceVibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
+        if (deviceVibrator != null) {
+            deviceVibrator.cancel();
         }

639-650: System service fetched on every vibration event.

activity.getSystemService(Context.VIBRATOR_SERVICE) is called every time startVibration fires (up to 50 times/second from the poller). The same applies to stopVibration. Consider caching the Vibrator instance as a field during construction, similar to how activity is already stored.

Example
 private Context activity;
+private Vibrator deviceVibrator;
 ...
 // In constructor:
 this.activity = xServerView.getContext();
+this.deviceVibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);

Then use the cached field directly in startVibration and stopVibration.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file


Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

@utkarshdalal
Copy link
Owner

Can you clarify if this is for rumble or vibration? Right now the only thing we have connected to vibration for onscreen controls is a small vibration when you press a button on screen.
If it's for rumble, can you clarify what the issue was?

@kiequoo
Copy link
Author

kiequoo commented Feb 17, 2026

Can you clarify if this is for rumble or vibration? Right now the only thing we have connected to vibration for onscreen controls is a small vibration when you press a button on screen. If it's for rumble, can you clarify what the issue was?

Hi! this is for rumble (to clarfiy: when the game itself wants the device to shake). The problem was that on devices such as the Odin 2 (which has a built-in controller) rumble didn't work. There is a trick to make it work, which is to enable the on-screen controls and then edit it, deleting all the individual elements. But this is a bit of a hack and most people wouldn't know to do this (plus it seems you need to turn on the on screen controller each time you load a game)

By removing the currentController check, the rumble works without this hack. FYI winlator (coffincolors version) also doesn't check the currentController and rumble works there, which is where I got my inspiration for this PR.

@kiequoo kiequoo changed the title Fix vibration on devices such as Ayn Odin 2 Fix rumble on devices such as Ayn Odin 2 Feb 17, 2026
@xXJSONDeruloXx
Copy link
Contributor

just tried this on my AYN Thor, worked like a charm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants