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 issues with Rog Ally buttons #800

Closed
wants to merge 1 commit into from
Closed

fix issues with Rog Ally buttons #800

wants to merge 1 commit into from

Conversation

Valkirie
Copy link
Owner

@Valkirie Valkirie commented Oct 26, 2023

Summary by CodeRabbit

  • New Feature: Enhanced LED control for ASUS ROG devices. Users can now customize their device's LED status, brightness, and color, providing a more personalized experience.
  • Improvement: Updated key event handling. This update improves the responsiveness and reliability of key events, leading to a smoother user interaction.
  • New Feature: Introduced an 'Apply Color' function. This allows users to easily apply their chosen LED color settings, enhancing usability and customization.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 26, 2023

Walkthrough

The changes primarily focus on enhancing the LED control capabilities of the ROGAlly class in the ASUS device code. This includes the addition of LED initialization, control, and color setting methods, as well as modifications to handle different key events.

Changes

File Path Summary
.../Devices/ASUS/ROGAlly.cs Introduced LED initialization byte arrays and control capabilities. Modified HandleEvent method to handle different key events. Added methods for setting LED status, brightness, and color. Introduced ApplyColor method for applying LED color settings.

🐇💻

In the realm of code, where the bits do play,

A rabbit hopped by, tweaking LEDs today.

With colors so bright, and keys that respond,

The ROGAlly class, of which we've grown fond.

So here's to the changes, may they shine bright,

In the world of code, bringing delight! 🌈💡


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

@Valkirie Valkirie closed this Oct 26, 2023
@Valkirie Valkirie deleted the RogAlly-patch-1 branch October 26, 2023 06:59
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 cd3bd78.
Files selected for processing (1)
  • HandheldCompanion/Devices/ASUS/ROGAlly.cs (5} hunks)
Additional comments: 8
HandheldCompanion/Devices/ASUS/ROGAlly.cs (8)
  • 1-4: The using statements have been changed to non-aliased versions. This change is minor and does not affect the functionality of the code. However, it's important to ensure that the rest of the codebase is updated to reflect this change if necessary.

  • 36-48: New constants and byte arrays have been introduced for LED initialization and message setting. These constants and byte arrays are used in the new methods for LED control. The changes are consistent with the PR's objective of adding LED control capabilities.

  • 99-99: The DeviceCapabilities.LEDControl capability has been added to the Capabilities variable. This change is consistent with the PR's objective of adding LED control capabilities.

  • 220-240: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [223-247]

The HandleEvent method has been modified to handle different key events. The changes improve the responsiveness and versatility of the ROGAlly class. However, it's important to ensure that these changes do not introduce any unexpected behavior or side effects.

  • 249-260: The SetLedStatus method has been introduced to set the LED status based on the provided boolean value. The method uses the SetLedBrightness and SetLedColor methods to set the LED brightness and color respectively. The changes are consistent with the PR's objective of adding LED control capabilities.

  • 307-319: The SetLedColor method has been introduced to set the LED color. The method uses the ApplyColor method to apply the color settings to the device. The changes are consistent with the PR's objective of adding LED control capabilities.

  • 321-338: The ApplyColor method has been introduced to apply the color settings to the device. The method uses the HidDevice class to write the color settings to the device. The changes are consistent with the PR's objective of adding LED control capabilities.

  • 340-357: The AuraMessage method has been introduced to create a byte array representing an Aura message. The method is used in the ApplyColor method to create the message to be written to the device. The changes are consistent with the PR's objective of adding LED control capabilities.

Comment on lines +262 to +305
public override bool SetLedBrightness(int brightness)
{
//ROG ALly brightness range is: 0 - 3 range, 0 is off, convert from 0 - 100 % range
brightness = (int)Math.Round(brightness / 33.33);

default:
Task.Run(async () =>
{
byte[] msg = { AURA_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness };
byte[] msgBackup = { INPUT_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness };

IEnumerable<HidDevice> devices = GetHidDevices(_vid, _pid);
foreach (HidDevice device in devices)
{
if (device is null || !device.IsConnected)
return false;

device.OpenDevice();

if (device.ReadFeatureData(out byte[] data, AURA_HID_ID))
{
Task.Run(async () =>
{
KeyPress(button);
await Task.Delay(20);
KeyRelease(button);
});
device.WriteFeatureData(msg);
}
break;
else
{
return false;
}

if (device.ReadFeatureData(out byte[] dataBackkup, INPUT_HID_ID))
{
device.WriteFeatureData(msgBackup);
}
else
{
return false;
}

device.CloseDevice();
}

return true;
});

return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The SetLedBrightness method has been introduced to set the LED brightness. The method uses the HidDevice class to write the brightness value to the device. The changes are consistent with the PR's objective of adding LED control capabilities. However, the method returns false at the end, which means it will always return false regardless of whether the operation was successful or not. This should be corrected.

- return false;
+ return true;
Committable suggestion (Beta)
Suggested change
public override bool SetLedBrightness(int brightness)
{
//ROG ALly brightness range is: 0 - 3 range, 0 is off, convert from 0 - 100 % range
brightness = (int)Math.Round(brightness / 33.33);
default:
Task.Run(async () =>
{
byte[] msg = { AURA_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness };
byte[] msgBackup = { INPUT_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness };
IEnumerable<HidDevice> devices = GetHidDevices(_vid, _pid);
foreach (HidDevice device in devices)
{
if (device is null || !device.IsConnected)
return false;
device.OpenDevice();
if (device.ReadFeatureData(out byte[] data, AURA_HID_ID))
{
Task.Run(async () =>
{
KeyPress(button);
await Task.Delay(20);
KeyRelease(button);
});
device.WriteFeatureData(msg);
}
break;
else
{
return false;
}
if (device.ReadFeatureData(out byte[] dataBackkup, INPUT_HID_ID))
{
device.WriteFeatureData(msgBackup);
}
else
{
return false;
}
device.CloseDevice();
}
return true;
});
return false;
}
public override bool SetLedBrightness(int brightness)
{
//ROG ALly brightness range is: 0 - 3 range, 0 is off, convert from 0 - 100 % range
brightness = (int)Math.Round(brightness / 33.33);
Task.Run(async () =>
{
byte[] msg = { AURA_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness };
byte[] msgBackup = { INPUT_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness };
IEnumerable<HidDevice> devices = GetHidDevices(_vid, _pid);
foreach (HidDevice device in devices)
{
if (device is null || !device.IsConnected)
return false;
device.OpenDevice();
if (device.ReadFeatureData(out byte[] data, AURA_HID_ID))
{
device.WriteFeatureData(msg);
}
else
{
return false;
}
if (device.ReadFeatureData(out byte[] dataBackkup, INPUT_HID_ID))
{
device.WriteFeatureData(msgBackup);
}
else
{
return false;
}
device.CloseDevice();
}
return true;
});
return true;
}

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