Skip to content
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

Fix ROGAlly inputs #801

Merged
merged 1 commit into from
Oct 26, 2023
Merged

Fix ROGAlly inputs #801

merged 1 commit into from
Oct 26, 2023

Conversation

Valkirie
Copy link
Owner

@Valkirie Valkirie commented Oct 26, 2023

Summary by CodeRabbit

  • New Feature: Enhanced the responsiveness of the ASUS ROG Ally handheld companion device. The device now responds more accurately to different key presses, improving the overall user experience.
  • Improvement: Implemented a delay mechanism for key press and release operations, reducing the chance of unintended actions and enhancing the device's reliability.
  • Bug Fix: Updated the default case to include keys 56, 165, and 166, fixing an issue where these keys were not recognized correctly.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 26, 2023

Walkthrough

The changes primarily focus on enhancing the HandleEvent method in the ROGAlly.cs file. The switch statement has been restructured to handle different key values more efficiently, with asynchronous key press and release operations and a delay mechanism introduced for improved performance.

Changes

File Path Summary
.../Devices/ASUS/ROGAlly.cs The HandleEvent method has been updated. The switch statement now handles different key values more efficiently. Asynchronous key press and release operations have been introduced, along with a delay mechanism (KeyPressDelay). The default case now includes keys 56, 165, and 166.

🐇

In the land of code, where logic is king,

A rabbit hopped in, changes to bring.

With keys and switches, and delays in sight,

The code now runs, both day and night.

So here's to the code, may it run with glee,

As smooth and swift, as a rabbit's spree. 🎉


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.json

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 64f5a0d and 514d427.
Files selected for processing (1)
  • HandheldCompanion/Devices/ASUS/ROGAlly.cs (1} hunks)

Comment on lines 214 to 234
switch (key)
{
case 236:
return;

case 0:
{
KeyRelease(ButtonFlags.OEM3);
}
return;

case 56:
case 166:
{
// OEM1 and OEM2 key needs a key press delay based on emulated controller
Task.Run(async () =>
{
KeyPress(button);
await Task.Delay(KeyPressDelay);
KeyRelease(button);
});
}
break;

case 165:
case 167:
case 167: // Armory crate: Hold
KeyPress(button);
break;

case 168:
case 168: // Armory crate: Hold, released
KeyRelease(button);
break;

default:
case 56: // Armory crate: Click
case 165: // Back paddles: Click
case 166: // Command center: Click
{
Task.Run(async () =>
{
KeyPress(button);
await Task.Delay(20);
await Task.Delay(KeyPressDelay);
KeyRelease(button);
});
}
break;
}
}
} No newline at end of file
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The new hunk has restructured the switch statement to handle different key values. The changes include:

  • Removal of cases for keys 236 and 0.
  • Addition of a new case for key 167.
  • Modification of the default case to handle keys 56, 165, and 166.

The changes also include the implementation of asynchronous key press and release operations, which are now accompanied by a delay. This delay is determined by the KeyPressDelay value.

However, there is a potential issue with the use of Task.Run() in the switch statement. Task.Run() is used to offload work to a ThreadPool thread, but in this case, it's being used to perform a short-lived operation (pressing and releasing a key). This could lead to unnecessary overhead and potential performance issues, as creating and scheduling tasks is not free. It would be more efficient to use Task.Delay() directly without Task.Run(), as Task.Delay() already returns a task that completes after a specified time delay.

Here's a suggested change:

- Task.Run(async () =>
- {
-     KeyPress(button);
-     await Task.Delay(KeyPressDelay);
-     KeyRelease(button);
- });
+ KeyPress(button);
+ await Task.Delay(KeyPressDelay);
+ KeyRelease(button);
Committable suggestion (Beta)
Suggested change
switch (key)
{
case 236:
return;
case 0:
{
KeyRelease(ButtonFlags.OEM3);
}
return;
case 56:
case 166:
{
// OEM1 and OEM2 key needs a key press delay based on emulated controller
Task.Run(async () =>
{
KeyPress(button);
await Task.Delay(KeyPressDelay);
KeyRelease(button);
});
}
break;
case 165:
case 167:
case 167: // Armory crate: Hold
KeyPress(button);
break;
case 168:
case 168: // Armory crate: Hold, released
KeyRelease(button);
break;
default:
case 56: // Armory crate: Click
case 165: // Back paddles: Click
case 166: // Command center: Click
{
Task.Run(async () =>
{
KeyPress(button);
await Task.Delay(20);
await Task.Delay(KeyPressDelay);
KeyRelease(button);
});
}
break;
}
}
}
\ No newline at end of file
}
// get button
var button = keyMapping[key];
switch (key)
{
case 167: // Armory crate: Hold
KeyPress(button);
break;
case 168: // Armory crate: Hold, released
KeyRelease(button);
break;
default:
case 56: // Armory crate: Click
case 165: // Back paddles: Click
case 166: // Command center: Click
KeyPress(button);
await Task.Delay(KeyPressDelay);
KeyRelease(button);
break;
}
}
}

@Valkirie Valkirie merged commit 455a73a into main Oct 26, 2023
1 check passed
@Valkirie Valkirie deleted the RogAlly-patch-1-1 branch October 26, 2023 07:02
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.

1 participant