Skip to content

Conversation

@openaiken
Copy link
Contributor

@openaiken openaiken commented Nov 8, 2020

Hello! I have added Nightsword RGB support. All critical functionality has been added (all lighting zones, and binding for all[*] keys).

This does not add support for some of the model specific features seen in iCUE, such as the visual mapping of the consumer-configurable counter-weights (accessed from a panel on the bottom of the device), or the calibration feature (where you drag the cursor in a spiral to adjust x/y sensitivity after adjusting counter-weights). This is due to both A) these features not being supported by the version of the corsair protocol that ckb-next uses, and B) not having these features designed in the GUI (and hooboy do I NOT want to be the one to do that!).

[*] The key that there is not binding for yet is the Profile Up/Down switches. The Profile Up switch is detected as "profswitch" (see /src/daemon/keymap.c) as verified by monitoring /dev/input/ckbX/notify1, and the Profile Down switch is not detected at all. This is probably not a terribly complicated fix, but it involves touching stuff related to the daemon and the protocol, which I'm not familiar with yet. On my personal profile for the mouse I just set the Profile Up key to cycle through profiles.

Hayden Aiken added 4 commits November 5, 2020 18:45
…urrently as profswitch, and profdn is not detected) and adjusted pos/size values for the gui. All features accounted for except for aforementioned profile switching issue.
@openaiken
Copy link
Contributor Author

related to #520
also S/O to @egberts for doing a little bit of the grunt work up front (see first commit).

@Ravenslofty
Copy link
Member

Could you poke me in IRC? I want to at least figure out what the scancodes are for the profile buttons.

@Ravenslofty
Copy link
Member

Ping @openaiken, we still need to get that scancode added.

@egberts
Copy link

egberts commented Nov 17, 2020

I’ll take a stab with my USB sniffer tonight

@egberts
Copy link

egberts commented Nov 17, 2020

Nightsword USB Scan Code
=====================+
The following details of scan code were captured for each button/wheel action of the Corsair Nightsword mouse.

Usual C code:

C Ii:1:002:1 0:1 10 = 01010000 00000000 0000
                      ^^^^^^^^ ^^^^     ^^^^

or

C Ii:1:002:1 0:1 64 = 03800000 00000000 00000000 0000 0000 00000000 00000000 00000000 00000000
                      ^^^^^^^^ ^^^^

The scan codes for the wheel activity is:

Action Type Description
01000000 00000000 00ff wheel roll closer to you
01000000 00000000 0001 wheel roll away from you

The scan codes for the button activities are:

Press Release Type Description
01010000 0000 01000000 0000 button left (standard PS/2 mouse)
01020000 0000 01000000 0000 button right (standard PS/2 mouse)
01040000 0000 01000000 0000 wheel middle button (standard PS/2 mouse)
01080000 0000 01000000 0000 button left side, midsection, closer to you
01100000 0000 01000000 0000 button left side, midsection, away from you
03000000 0100 03000000 0000 button middle, away from you
03000000 0200 03000000 0000 button middle, closer to you
03200000 0000 03000000 0000 button top, left, away from you
03400000 0000 03000000 0000 button top, left, closer to you
03800000 0000 03000000 0000 button left side, biggest

USB Monitoring

To collect a raw text trace, execute following steps.

  1. Prepare

Mount debugfs (it has to be enabled in your kernel configuration), and
load the usbmon module (if built as module). The second step is skipped
if usbmon is built into the kernel.

# mount -t debugfs none_debugs /sys/kernel/debug
# modprobe usbmon
#

Verify that bus sockets are present.

# ls /sys/kernel/debug/usb/usbmon
0s  0u  1s  1t  1u  2s  2t  2u  3s  3t  3u  4s  4t  4u
#

Now you can choose to either use the socket '0u' (to capture packets on all
buses), and skip to step #3, or find the bus used by your device with step #2.
This allows to filter away annoying devices that talk continuously.

  1. Find which bus connects to the desired device

Run "cat /sys/kernel/debug/usb/devices", and find the "T:"-line which corresponds
to the device. Usually you do it by looking for the vendor string. If you have
many similar devices, unplug one and compare the two
/sys/kernel/debug/usb/devices outputs. The T:-line will have a bus number.

Example:

T:  Bus=01 Lev=01 Prnt=01 Port=01 Cnt=01 Dev#=  2 Spd=12   MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=1b1c ProdID=1b5c Rev= 3.35
S:  Manufacturer=Corsair
S:  Product=CORSAIR NIGHTSWORD RGB Gaming Mouse
S:  SerialNumber=02027026AF4C18865CC0F81CF5001BC0
C:* #Ifs= 2 Cfg#= 1 Atr=a0 MxPwr=500mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=01 Prot=02 Driver=usbhid
E:  Ad=81(I) Atr=03(Int.) MxPS=  64 Ivl=1ms
I:* If#= 1 Alt= 0 #EPs= 2 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid
E:  Ad=82(I) Atr=03(Int.) MxPS=  64 Ivl=1ms
E:  Ad=02(O) Atr=03(Int.) MxPS=  64 Ivl=1ms

"Bus=01" means it's bus 1. Alternatively, you can look at the output from
"lsusb" and get the bus number from the appropriate line. Example:

Bus 001 Device 002: ID 1b1c:1b5c Corsair CORSAIR NIGHTSWORD RGB Gaming Mouse
  1. Start 'cat'
# cat /sys/kernel/debug/usb/usbmon/1u > /tmp/1.mon.out

to listen on a single bus, otherwise, to listen on all buses, type:

# cat /sys/kernel/debug/usb/usbmon/0u > /tmp/1.mon.out

This process will read until it is killed. Naturally, the output can be
redirected to a desirable location. This is preferred, because it is going
to be quite long.

  1. Perform the desired operation on the USB bus

This is where you do something that creates the traffic: plug in a flash key,
copy files, control a webcam, etc.

  1. Kill cat

Usually it's done with a keyboard interrupt (Control-C).

At this point the output file (/tmp/1.mon.out in this example) can be saved,
sent by e-mail, or inspected with a text editor. In the last case make sure
that the file size is not excessive for your favorite editor.

USB Raw Dump Output

All USB scan code capture were done by performing each specific actions three times.

usb-bus1-mouse-left-button

ffff95a543223780 448005372 C Ii:1:002:1 0:1 10 = 01010000 00000000 0000
ffff95a543223780 448005423 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 448254370 C Ii:1:002:1 0:1 10 = 01000000 00000000 0000
ffff95a543223780 448254417 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 449476370 C Ii:1:002:1 0:1 10 = 01010000 00000000 0000
ffff95a543223780 449476415 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 449656370 C Ii:1:002:1 0:1 10 = 01000000 00000000 0000
ffff95a543223780 449656417 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 450962372 C Ii:1:002:1 0:1 10 = 01010000 00000000 0000
ffff95a543223780 450962417 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 451102371 C Ii:1:002:1 0:1 10 = 01000000 00000000 0000
ffff95a543223780 451102415 S Ii:1:002:1 -115:1 64 <

usb-bus1-mouse-left-side-away.txt

ffff95a543223780 823168470 C Ii:1:002:1 0:1 10 = 01100000 00000000 0000
ffff95a543223780 823168523 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 823369472 C Ii:1:002:1 0:1 10 = 01000000 00000000 0000
ffff95a543223780 823369518 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 824550473 C Ii:1:002:1 0:1 10 = 01100000 00000000 0000
ffff95a543223780 824550517 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 824731472 C Ii:1:002:1 0:1 10 = 01000000 00000000 0000
ffff95a543223780 824731516 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 826009472 C Ii:1:002:1 0:1 10 = 01100000 00000000 0000
ffff95a543223780 826009516 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 826184472 C Ii:1:002:1 0:1 10 = 01000000 00000000 0000
ffff95a543223780 826184512 S Ii:1:002:1 -115:1 64 <

usb-bus1-mouse-left-side-big.txt

ffff95a543223780 765281456 C Ii:1:002:1 0:1 64 = 03800000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 765281500 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 765468455 C Ii:1:002:1 0:1 64 = 03000000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 765468488 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 766619456 C Ii:1:002:1 0:1 64 = 03800000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 766619493 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 766811456 C Ii:1:002:1 0:1 64 = 03000000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 766811488 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 768048456 C Ii:1:002:1 0:1 64 = 03800000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 768048492 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 768210452 C Ii:1:002:1 0:1 64 = 03000000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 768210480 S Ii:1:002:1 -115:1 64 <

usb-bus1-mouse-left-side-closer.txt

ffff95a543223780 868313483 C Ii:1:002:1 0:1 10 = 01080000 00000000 0000
ffff95a543223780 868313536 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 868494484 C Ii:1:002:1 0:1 10 = 01000000 00000000 0000
ffff95a543223780 868494528 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 869673483 C Ii:1:002:1 0:1 10 = 01080000 00000000 0000
ffff95a543223780 869673529 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 869848485 C Ii:1:002:1 0:1 10 = 01000000 00000000 0000
ffff95a543223780 869848530 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 871053492 C Ii:1:002:1 0:1 10 = 01080000 00000000 0000
ffff95a543223780 871053532 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 871217484 C Ii:1:002:1 0:1 10 = 01000000 00000000 0000
ffff95a543223780 871217529 S Ii:1:002:1 -115:1 64 <

usb-bus1-mouse-middle-button-away.txt

ffff95a543223780 1440829637 C Ii:1:002:1 0:1 64 = 03000000 01000000 00000000 000
00000 00000000 00000000 00000000 00000000
ffff95a543223780 1440829678 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 1440995635 C Ii:1:002:1 0:1 64 = 03000000 00000000 00000000 000
00000 00000000 00000000 00000000 00000000
ffff95a543223780 1440995665 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 1442067638 C Ii:1:002:1 0:1 64 = 03000000 01000000 00000000 000
00000 00000000 00000000 00000000 00000000
ffff95a543223780 1442067672 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 1442226637 C Ii:1:002:1 0:1 64 = 03000000 00000000 00000000 000
00000 00000000 00000000 00000000 00000000
ffff95a543223780 1442226670 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 1443372640 C Ii:1:002:1 0:1 64 = 03000000 01000000 00000000 000
00000 00000000 00000000 00000000 00000000
ffff95a543223780 1443372673 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 1443531637 C Ii:1:002:1 0:1 64 = 03000000 00000000 00000000 000
00000 00000000 00000000 00000000 00000000
ffff95a543223780 1443531670 S Ii:1:002:1 -115:1 64 <

usb-bus1-mouse-middle-button-closer.txt

ffff95a543223780 624422417 C Ii:1:002:1 0:1 64 = 03000000 02000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 624422456 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 624573416 C Ii:1:002:1 0:1 64 = 03000000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 624573445 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 625538416 C Ii:1:002:1 0:1 64 = 03000000 02000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 625538449 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 625713415 C Ii:1:002:1 0:1 64 = 03000000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 625713444 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 626713418 C Ii:1:002:1 0:1 64 = 03000000 02000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 626713451 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 626832414 C Ii:1:002:1 0:1 64 = 03000000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 626832440 S Ii:1:002:1 -115:1 64 <

usb-bus1-mouse-right-button.txt

ffff95a543223780 486940382 C Ii:1:002:1 0:1 10 = 01020000 00000000 0000
ffff95a543223780 486940435 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 487106380 C Ii:1:002:1 0:1 10 = 01000000 00000000 0000
ffff95a543223780 487106426 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 488270382 C Ii:1:002:1 0:1 10 = 01020000 00000000 0000
ffff95a543223780 488270427 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 488406379 C Ii:1:002:1 0:1 10 = 01000000 00000000 0000
ffff95a543223780 488406423 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 489627382 C Ii:1:002:1 0:1 10 = 01020000 00000000 0000
ffff95a543223780 489627429 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 489776379 C Ii:1:002:1 0:1 10 = 01000000 00000000 0000
ffff95a543223780 489776423 S Ii:1:002:1 -115:1 64 <

usb-bus1-mouse-top-left-side-away.txt

ffff95a543223780 688691435 C Ii:1:002:1 0:1 64 = 03200000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 688691482 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 688872433 C Ii:1:002:1 0:1 64 = 03000000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 688872465 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 689828434 C Ii:1:002:1 0:1 64 = 03200000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 689828473 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 689980434 C Ii:1:002:1 0:1 64 = 03000000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 689980471 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 691131436 C Ii:1:002:1 0:1 64 = 03200000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 691131473 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 691283434 C Ii:1:002:1 0:1 64 = 03000000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 691283470 S Ii:1:002:1 -115:1 64 <

usb-bus1-mouse-top-left-side-closer.txt

ffff95a543223780 726345446 C Ii:1:002:1 0:1 64 = 03400000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 726345490 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 726560445 C Ii:1:002:1 0:1 64 = 03000000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 726560480 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 727543445 C Ii:1:002:1 0:1 64 = 03400000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 727543481 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 727750444 C Ii:1:002:1 0:1 64 = 03000000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 727750477 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 728731445 C Ii:1:002:1 0:1 64 = 03400000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 728731481 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 728901446 C Ii:1:002:1 0:1 64 = 03000000 00000000 00000000 0000
0000 00000000 00000000 00000000 00000000
ffff95a543223780 728901477 S Ii:1:002:1 -115:1 64 <

usb-bus1-mouse-wheel-down.txt

ffff95a543223780 286759326 C Ii:1:002:1 0:1 10 = 01000000 00000000 00ff
ffff95a543223780 286759374 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 287921327 C Ii:1:002:1 0:1 10 = 01000000 00000000 00ff
ffff95a543223780 287921368 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 289758329 C Ii:1:002:1 0:1 10 = 01000000 00000000 00ff
ffff95a543223780 289758371 S Ii:1:002:1 -115:1 64 <

usb-bus1-mouse-wheel-press.txt

ffff95a543223780 368546348 C Ii:1:002:1 0:1 10 = 01040000 00000000 0000
ffff95a543223780 368546394 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 368767350 C Ii:1:002:1 0:1 10 = 01000000 00000000 0000
ffff95a543223780 368767396 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 369938348 C Ii:1:002:1 0:1 10 = 01040000 00000000 0000
ffff95a543223780 369938394 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 370090348 C Ii:1:002:1 0:1 10 = 01000000 00000000 0000
ffff95a543223780 370090391 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 371317349 C Ii:1:002:1 0:1 10 = 01040000 00000000 0000
ffff95a543223780 371317395 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 371491350 C Ii:1:002:1 0:1 10 = 01000000 00000000 0000
ffff95a543223780 371491396 S Ii:1:002:1 -115:1 64 <

usb-bus1-mouse-wheel-up.txt

ffff95a543223780 204353305 C Ii:1:002:1 0:1 10 = 01000000 00000000 0001
ffff95a543223780 204353360 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 205768304 C Ii:1:002:1 0:1 10 = 01000000 00000000 0001
ffff95a543223780 205768350 S Ii:1:002:1 -115:1 64 <
ffff95a543223780 207230306 C Ii:1:002:1 0:1 10 = 01000000 00000000 0001
ffff95a543223780 207230350 S Ii:1:002:1 -115:1 64 <

@tatokis
Copy link
Member

tatokis commented Nov 20, 2020

With that, I was able to find the scancode. Someone please test the new code so that I can merge this.
You will need to delete your build directory (or at least text.qrc inside it) so that it regenerates the binary blob with the demo profiles.

@IceCupe123
Copy link

IceCupe123 commented Nov 20, 2020

seems to be working

@fauxmight
Copy link

Both lighting and mapping working here.

@tatokis tatokis merged commit eef033f into ckb-next:master Nov 20, 2020
@egberts
Copy link

egberts commented Nov 21, 2020

Works very well with my Nightsword (although there's some minor non-functional-impacting typo in the source code.

Also, the Corsair K95 Platinum with Brown Cherry MX works very well.

We should package this.

@openaiken
Copy link
Contributor Author

woohoo! Thank y'all so much for tying up the loose ends with this! Really glad it's officially supported now.

Sorry @Ravenslofty , I meant to drop in a second time but I neglected to. Thank you again for your help with this.

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.

6 participants