tdakhran / razer-ctl

A tray icon for controlling Razer Blade 16
MIT License
19 stars 4 forks source link

Support Razer Blade 14 2023 #1

Closed tdakhran closed 5 months ago

tdakhran commented 9 months ago

User confirmed in Reddit discussion that all commands work on Razer Blade 14 2023.

PID is 0x029d.

Enable Razer Blade 14 2023 for razer-tray.exe.

jacobgelling commented 6 months ago

I have a Blade 14 2023 and the binary given in the PR does not work for me:

image

The latest version of razer-cli gives this output:

image

jacobgelling commented 6 months ago

Haven't used Rust for a long time, and have had no experience with HID devices, so my debugging skills/ideas are very lacking. Any help is appreciated.

So far, I've found this is the point at which the hidapi error happens:

https://github.com/tdakhran/razer-ctl/blob/c316393f2514ceca2b206665ef521a9078c19a94/librazer/src/device.rs#L16

If I comment out that line and uncomment the prints in send function, this is the output:

Report Packet { status: 0, id: 226, remaining_packets: 0, protocol_type: 0, data_size: 4, command_class: 13, command_id: 130, args: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], crc: 0, reserved: 0 }
Report Packet { status: 0, id: 57, remaining_packets: 0, protocol_type: 0, data_size: 4, command_class: 13, command_id: 130, args: [0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], crc: 0, reserved: 0 }
Error: Failed to get performance mode and fan mode: Err(Failed to send feature report

Caused by:
    hidapi error: HidD_SetFeature: (0x00000001) Incorrect function.) Err(Failed to send feature report

Caused by:
    hidapi error: HidD_SetFeature: (0x00000001) Incorrect function.)
tdakhran commented 6 months ago

Thanks for the testing and initial debugging @jacobgelling ! I think the set of USB HID "commands" supported by Blade 16 and Blade 14 differs. Do you have an "Overclock" section in Synapse? Do you have an AMD or Intel version of Blade 14?

Let me prepare a tool to probe the commands, would be great if you could execute it on Blade 14, and I can then adjust implementation not to use unsupported ones.

For now, may I ask you to execute these two commands (make sure Synapse is not running) and post the output

cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x0d82 0 1 0 0
cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x0d82 0 2 0 0
jacobgelling commented 6 months ago

Thanks for investigating! Prepare for a big comment...

This is an AMD 7940HS, Blade 14 (2023), in mercury colour (so it does not have a logo backlight on the lid, unlike the black version).

Here are all the options exposed by Synapse: Screenshot 2024-05-31 215334 Screenshot 2024-05-31 215343 Screenshot 2024-05-31 215350 Screenshot 2024-05-31 215419 Screenshot 2024-05-31 215426 Screenshot 2024-05-31 215434 Screenshot 2024-05-31 215442 Screenshot 2024-05-31 215446

cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x0d82 0 1 0 0
cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x0d82 0 2 0 0

Both of these commands output this on the Blade 14 branch, with no Synapse or other Razer service running:

Error: hidapi error: HidD_SetFeature: (0x00000001) Incorrect function.

I have used Wireshark to capture the traffic between Synapse and the USB HID, changing most of the options in Synapse:

blade14.csv

I've looked at the commands and the ones that do exist seem to match between your capture and mine.

Finally, I'm not sure if Wireshark does not capture unsuccessful feature requests, but it does not capture anything from razer-ctl on my system. This makes me suspicious that something else could be going wrong?

tdakhran commented 6 months ago

Thanks for a detailed information @jacobgelling !

I removed initial &[0, 0] feature request that was causing Error: hidapi error: HidD_SetFeature: (0x00000001) Incorrect function..

Pushed as well few changes to https://github.com/tdakhran/razer-ctl/compare/main...tarek/feat/support_razer_blade_14_2023. You can try buiding it and running simple commands like

cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x0d82 0 1 0 0
cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli info

Even if they work, they might not provide complete functionality. E.g. for Blade 16 to change performance mode to silent it was enough to send

cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x0d82 0 1 0 0
cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x0d02 0 1 5 0
cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x0d82 0 2 0 0
cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x0d02 0 2 5 0

From your capture I see that something like this happening

cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x0d82 0 1 0 0
cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x0d02 0 1 5 0
cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x0d82 0 2 0 0
cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x0d02 0 2 5 0
cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x0d82 0 3 0 0
cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x0d02 0 3 5 0
cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x0d82 0 4 0 0
cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x0d02 0 4 5 0

Also there is an extra switch for "CPU Voltage Optimizer", that I don't have. It's likely AMD CPU related difference. I think capturing events in WireShark and making sure razer-ctl/razer-tray does exactly same is the only path to move forward.

jacobgelling commented 6 months ago

Ok, with the latest changes in the Blade 14 branch, every command still results in:

Error: hidapi error: HidD_SetFeature: (0x00000001) Incorrect function.

Even when the command exactly matches Synapse (for example the battery health optimization), it gives the same error.

And Wireshark still does not capture any feature report from razer-ctl. It's as if it's not even sending any. It does capture the device info requests etc.

jacobgelling commented 6 months ago

I thought it might be possible that Windows is blocking the feature reports somehow, but even with Windows Security real-time protection disabled, it makes no difference.

I am running Windows 11 23H2.

tdakhran commented 6 months ago

Interesting, can it be that the PID for the Ryzen version is different? Could you please post the output of

cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli enumerate
jacobgelling commented 6 months ago
cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli enumerate
RazerDevice { pid: 0x029d }

So it is the same PID.

tdakhran commented 6 months ago

Ok, PID is correct. I'm out of ideas at this point. One last thing to try is to run razer-cli not from WSL, but directly from the Windows command line, may be worth trying as well with admin privileges.

I am running Windows 11 23H2.

I'm running the same OS.

upd: try always specifying -p 0x029d just in case I have a bug in device autodetect logic

jacobgelling commented 6 months ago

Sadly I've already tried specifying the PID and running as admin from outside WSL.

The PID detection does work as if I put non existing PID like your Blade 16 one, I get the error:

Error: hidapi error: No HID devices with requested VID/PID found in the system.
tdakhran commented 6 months ago

Here is my end to end capture blade16.csv from WireShark (filter: usb.src==1.3.0 || usb.dst==1.3.0) for a random command

❯ cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli cmd 0x9999
    Finished `release` profile [optimized] target(s) in 0.08s
     Running `target/x86_64-pc-windows-gnu/release/razer-cli.exe cmd 0x9999`
Report   Packet { status: 0, id: 156, remaining_packets: 0, protocol_type: 0, data_size: 0, command_class: 153, command_id: 153, args: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], crc: 0, reserved: 0 }
Report Packet { status: 0, id: 156, remaining_packets: 0, protocol_type: 0, data_size: 0, command_class: 153, command_id: 153, args: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], crc: 0, reserved: 0 }
Error: Command not supported

Notice that there is some communication happening before the SET_REPORT request. It might be that an error happens before it. Could you please post yours?

tdakhran commented 6 months ago

Got some time to dig deeper, and it might be the right direction. There are multiple devices with the same VID/PID, and I was using https://docs.rs/hidapi/2.6.1/hidapi/struct.HidApi.html#method.open to open the device but might be that I will need a full "path" to the device to make it work. I guess I got lucky that it worked for me, because first entry in the enumeration list was "correct" one.

❯ cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli enumerate
   Compiling librazer v0.6.0 (/data/git/razer-ctl/librazer)
   Compiling razer-cli v0.6.0 (/data/git/razer-ctl/razer-cli)
    Finished `release` profile [optimized] target(s) in 5.97s
     Running `target/x86_64-pc-windows-gnu/release/razer-cli.exe enumerate`
Probing "\\\\?\\HID#VID_1532&PID_029F&MI_02#7&6319c81&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"  and result is Ok(())
Probing "\\\\?\\HID#VID_1532&PID_029F&MI_00&Col03&Col01#8&16481244&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"  and result is Err(IoError { error: Os { code: 1, kind: Uncategorized, message: "Incorrect function." } })
Probing "\\\\?\\HID#VID_1532&PID_029F&MI_00&Col03&Col02#8&16481244&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}"  and result is Err(IoError { error: Os { code: 1, kind: Uncategorized, message: "Incorrect function." } })
Probing "\\\\?\\HID#VID_1532&PID_029F&MI_01&Col02#7&2e9c4a4a&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}"  and result is Err(IoError { error: Os { code: 1, kind: Uncategorized, message: "Incorrect function." } })
Probing "\\\\?\\HID#VID_1532&PID_029F&MI_01&Col03#7&2e9c4a4a&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}"  and result is Err(IoError { error: Os { code: 1, kind: Uncategorized, message: "Incorrect function." } })
Probing "\\\\?\\HID#VID_1532&PID_029F&MI_01&Col04#7&2e9c4a4a&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}"  and result is Err(IoError { error: Os { code: 1, kind: Uncategorized, message: "Incorrect function." } })
Probing "\\\\?\\HID#VID_1532&PID_029F&MI_01&Col05#7&2e9c4a4a&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}"  and result is Err(IoError { error: Os { code: 1, kind: Uncategorized, message: "Incorrect function." } })
Probing "\\\\?\\HID#VID_1532&PID_029F&MI_01&Col01#7&2e9c4a4a&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\\KBD"  and result is Err(IoError { error: Os { code: 1, kind: Uncategorized, message: "Incorrect function." } })
Probing "\\\\?\\HID#VID_1532&PID_029F&MI_00#7&1b6c2e0c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\\KBD"  and result is Err(IoError { error: Os { code: 1, kind: Uncategorized, message: "Incorrect function." } })
RazerDevice { pid: 0x029f }

I enabled verbose printing and pushed changes to https://github.com/tdakhran/razer-ctl/commit/de5edf99c82c1551fe90fab00ecd790b3bbb5c92. @jacobgelling if you have a chance to probe, that would be nice.

jacobgelling commented 6 months ago

I enabled verbose printing and pushed changes to de5edf9. @jacobgelling if you have a chance to probe, that would be nice.

$ cargo run --release --target x86_64-pc-windows-gnu --bin razer-cli enumerate
    Finished `release` profile [optimized] target(s) in 0.23s
     Running `target/x86_64-pc-windows-gnu/release/razer-cli.exe enumerate`
Probing "\\\\?\\HID#VID_1532&PID_029D&MI_01&Col02#8&22673ca&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}"  and result is Err(IoError { error: Os { code: 1, kind: Uncategorized, message: "Incorrect function." } })
Probing "\\\\?\\HID#VID_1532&PID_029D&MI_01&Col01#8&22673ca&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\\kbd"  and result is Err(IoError { error: Os { code: 1, kind: Uncategorized, message: "Incorrect function." } })
Probing "\\\\?\\HID#VID_1532&PID_029D&MI_01&Col03#8&22673ca&0&0002#{4d1e55b2-f16f-11cf-88cb-001111000030}"  and result is Err(IoError { error: Os { code: 1, kind: Uncategorized, message: "Incorrect function." } })
Probing "\\\\?\\HID#VID_1532&PID_029D&MI_01&Col04#8&22673ca&0&0003#{4d1e55b2-f16f-11cf-88cb-001111000030}"  and result is Err(IoError { error: Os { code: 1, kind: Uncategorized, message: "Incorrect function." } })
Probing "\\\\?\\HID#VID_1532&PID_029D&MI_00#8&25fdb18c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\\kbd"  and result is Err(IoError { error: Os { code: 1, kind: Uncategorized, message: "Incorrect function." } })
Probing "\\\\?\\HID#VID_1532&PID_029D&MI_01&Col05#8&22673ca&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}"  and result is Err(IoError { error: Os { code: 1, kind: Uncategorized, message: "Incorrect function." } })
Probing "\\\\?\\HID#VID_1532&PID_029D&MI_02#8&19ea000f&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"  and result is Ok(())
Probing "\\\\?\\HID#VID_1532&PID_029D&MI_00&Col03&Col01#9&38b8fdc6&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"  and result is Err(IoError { error: Os { code: 1, kind: Uncategorized, message: "Incorrect function." } })
Probing "\\\\?\\HID#VID_1532&PID_029D&MI_00&Col03&Col02#9&38b8fdc6&0&0001#{4d1e55b2-f16f-11cf-88cb-001111000030}"  and result is Err(IoError { error: Os { code: 1, kind: Uncategorized, message: "Incorrect function." } })
RazerDevice { pid: 0x029d }

I'm pretty sure that is the problem then - it is not the first VID!

Thanks for your work debugging this.

tdakhran commented 6 months ago

Thank you @jacobgelling for debugging and testing!

I pushed changes that now select the first device with the given PID that supports a feature report. Theoretically, razer-cli now should work on your laptop. No guarantee though that functionality is complete or correct.