dokutan / mouse_m908

Control various Redragon gaming mice from Linux, BSD and Haiku
GNU General Public License v3.0
199 stars 35 forks source link

Redragon M686 Support #29

Open MaxHarwell opened 2 years ago

MaxHarwell commented 2 years ago

I am using a M686 Vampire Elite mouse and I am inquiring about possible support for this mouse and am willing to help contribute, I play Roblox daily and do general web browsing, so this mouse sees frequent use on my part.

dokutan commented 2 years ago

Please run lsusb and attach the output, with that information i can add initial support for the M686. This would allow you to try some simple things like changing the profile to check if the protocol is compatible before working on the model specific features.

For this later stage any information about the mouse would be helpful, e.g. a list of buttons, the DPI range, screenshots of the official software if possible.

MaxHarwell commented 2 years ago

information

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 005: ID 0408:a060 Quanta Computer, Inc. HD Webcam
Bus 001 Device 004: ID 04ca:3016 Lite-On Technology Corp. 
Bus 001 Device 006: ID 25a7:fa35 Compx 2.4G Dual Mode Mouse
Bus 001 Device 007: ID 062a:8519 MosArt Semiconductor Corp. USB Keyboard
Bus 001 Device 002: ID 25a7:fa34 Compx 2.4G Wireless Receiver
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Its a wireless/wired mouse, specifically the compx wireless receiver and compx dual mode mouse.

dokutan commented 2 years ago

Thanks, i have added an experimental backend for the M686 in 8066172567d8d7bfe0b74a911c4367da3f697afd. You could try to build from the master branch and then run mouse_m908 -R - to see if the mouse gets detected properly.

I am guessing that the M686 uses the same protocol as the M913, therefore i copied the backend for the M686 from the M913. However this protocol is not yet fully implemented and some features (DPI, button mapping) will need modification for the M686.

MaxHarwell commented 2 years ago

As im still somewhat new to linux, i will run into issues that may seem obvious when it comes to fixes, but i just ran into the error of libusb-1.0 was not found in the pkg-config search path and libusb.h does not exist when running the make command.

Package libusb-1.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libusb-1.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libusb-1.0' found
c++ -c include/m607/constructor.cpp -std=c++17 -Wall -Wextra -O2 `pkg-config --cflags libusb-1.0` -o constructor_m607.o
Package libusb-1.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libusb-1.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libusb-1.0' found
In file included from include/m607/constructor.cpp:19:
include/m607/../rd_mouse.h:23:10: fatal error: libusb.h: No such file or directory
   23 | #include <libusb.h>
      |          ^~~~~~~~~~
compilation terminated.
make: *** [makefile:114: constructor_m607.o] Error 1
dokutan commented 2 years ago

libusb-1.0 was not found in the pkg-config search path and libusb.h does not exist when running the make command.

It seems like you haven't installed libusb, on many distros you will need a *-dev package. I might be able to help you further if you tell me the distro you are using.

MaxHarwell commented 2 years ago

i am using the latest version of Linux Mint Cinnamon.

dokutan commented 2 years ago

It seems like Mint doesn't provide libusb in the repos: http://packages.linuxmint.com/search.php?release=any&section=any&keyword=libusb

You could search for a libusb deb package or build it yourself: https://libusb.info/

Edit: I also found this: https://community.linuxmint.com/software/view/libusb-1.0-0-dev

MaxHarwell commented 2 years ago
Couldn't open mouse.
- Check hardware and permissions (maybe you need to be root?)
- Try with or without the --kernel-driver option
- Try with the --model option
- Try with the --bus and --device options
If nothing works please report this as a bug.

the software link worked, this is what i got when running mouse_m908 -R -

dokutan commented 2 years ago

Try rebooting to load the udev rule or run as root: sudo mouse_m908 -R -

MaxHarwell commented 2 years ago

sudo worked and it identified it as the correct model.

dokutan commented 2 years ago

Could you post the output and tell me what features where handled correctly?

MaxHarwell commented 2 years ago
# Model: 686
# Configuration created with mouse_m908 -R.
# This configuration can be send to the mouse with mouse_m908 -c.
# Note: this feature is incomplete for the m686.

# The m686 has two profiles that can be switched using the 'mode switch' button on the bottom of the mouse.
# Reading the settings can only be done for the active profile, therefore only profile1 is used in this config.
[profile1]

report_rate=unknown

# DPI settings
# Currently active DPI level: 9
dpi1=0x0000ff
dpi2=0xffff00
dpi3=0x000080
dpi4=0xb83f16
dpi5=0xee7f00

# Button mapping
button_left=unknown, please report as bug:  ab  16  ee  7f
button_right=unknown, please report as bug:  0  0  2e  7c
button_middle=unknown, please report as bug:  0  0  0  1
button_fire=unknown, please report as bug:  7f  db  52  65
button_1=unknown, please report as bug:  1  ab  16  ee
button_2=unknown, please report as bug:  0  0  0  0
button_3=unknown, please report as bug:  0  0  0  0
button_4=unknown, please report as bug:  0  0  55  0
button_5=unknown, please report as bug:  0  b8  3f  8a
button_6=unknown, please report as bug:  16  ee  7f  0
button_7=unknown, please report as bug:  0  0  0  1f
button_8=unknown, please report as bug:  0  0  0  0
button_9=unknown, please report as bug:  7a  55  0  0
button_10=unknown, please report as bug:  80  47  0  0
button_11=unknown, please report as bug:  0  0  0  0
button_12=unknown, please report as bug:  0  0  0  0
dokutan commented 2 years ago

That is not exactly what i had expected, try the same with sudo mouse_m908 -D - please.

MaxHarwell commented 2 years ago

ah apologies, here you go.

09 03 00 00 00 01 00 00 00 00 00 00 00 00 00 00 48 
09 01 00 00 00 04 68 a8 3b 90 00 00 00 00 00 00 6c 
09 01 00 00 00 04 68 a8 3b 90 00 00 00 00 00 00 6c 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 04 00 00 00 02 09 01 00 00 00 00 00 00 00 00 3c 
dokutan commented 2 years ago

Sadly that attempt at learning more about the mouse failed completely. This means you would have to capture the usb communication with the official software, at least while opening the software and while applying the default settings. These tutorials might be helpful:

MaxHarwell commented 2 years ago

so i got wireshark set up and from looking at the guide, the UI looks pretty different compared to what i have, i got the device passed through, and macros and stuff work as expected on the virtual machine, but they do not carry over to the host machine sadly, nor does the DPI. only thing that saves is the lighting options. as for the sniffing, i dont seem to notice anything going on, not sure what my issue is. image

MaxHarwell commented 2 years ago

if theres anything you can do to get me started with looking at the traffic, that would be great, and would screenshots of what the default profile is help out in any way either?

dokutan commented 2 years ago

if theres anything you can do to get me started with looking at the traffic

You are looking for traffic on the wrong interface, load the usbmon kernel module (sudo modprobe usbmon) then choose usbmon1 in wireshark if the mouse is on bus 1. Additionally i would recommend removing either the wireless receiver or the usb cable to make sure the data gets send over the connection that you are actually capturing on. Edit: you might need to start wireshark as root if you can't see the usbmon interfaces.

would screenshots of what the default profile is help out in any way either?

Absolutely yes, especially of the available buttons, LED effects and DPI.

MaxHarwell commented 2 years ago

do you have anything besides this so we can communicate easier like discord? if you do my user is Max Harwell#2648

dokutan commented 2 years ago

do you have anything besides this so we can communicate easier like discord? if you do my user is Max Harwell#2648

Sorry i don't have discord, however you could write me an email at dokutan <at> tutanota <dot> com.

MaxHarwell commented 2 years ago

i have wireshark open as root and the modprobe command doesnt do anything, though i got this pulled up if this is what you are referring to image

MaxHarwell commented 2 years ago

i set the display filter to usb.bus_id==1&&usb.device_address==6, which is the device for the mouse in question. now what? just poke around with the device software?

dokutan commented 2 years ago

i set the display filter to usb.bus_id==1&&usb.device_address==6, which is the device for the mouse in question. now what? just poke around with the device software?

Sorry for replying late, that is exactly right. You should see new packets appearing when you move the mouse or press apply in the software.

MaxHarwell commented 2 years ago

i have saved the packets as a pcapng, but i am unable to read the file now or upload it anywhere, how would i go about changing that?

dokutan commented 2 years ago

Even opening in wireshark fails? In that case the problem could be that the saved file is owned by the root user (if you ran wireshark as root), in that case change the ownership with chown <your username> packets.pcapng

If the problem lies elsewhere exporting the packets as json would be an option as well.

MaxHarwell commented 2 years ago

https://drive.google.com/file/d/1RGlI2zqhuJy8U17CbhaDOU44wtUrptdR/view?usp=sharing

heres the packets, sent through drive due to github not supporting the file format.

MaxHarwell commented 2 years ago

if you need screenshots of the device software for features i can send them soon.

dokutan commented 2 years ago

Sorry for replying so late, unfortunately i can't seem to access the google drive link you shared.

if you need screenshots of the device software for features i can send them soon.

That would be great

MaxHarwell commented 2 years ago

https://www.dropbox.com/s/z4ypc9zdt37f8r2/m686_test.pcapng?dl=0

here it is on dropbox, ill get screenshots of stuff in a moment.

MaxHarwell commented 2 years ago

image USB Polling rate goes in 4 increments: 125Hz, 250Hz, 500Hz, and 1000Hz. image image image Fire key Menu image Key combination Menu image DPI Menu: Each setting can have its own custom RGB value set as per this menu here. image The scroll wheel can have 2 modes of lighting, respiration and a steady color image Macro Menu with list of manual events you can add: image A macro recording sample, which has automatic delay recording, which can be disabled to add a predetermined delay wherever you want it. image And finally the lighting for the mouse, with full RGB color selection: image

I will most likely send another packet file going over each option extensively, once you get the info you need out of the other one and these screenshots.

MaxHarwell commented 2 years ago

the dropbox link should be working now if you didnt get it before the link died, please let me know of any updates.

dokutan commented 2 years ago

the dropbox link should be working now if you didnt get it before the link died, please let me know of any updates.

Yes the droppbox link worked. As i am currently quite busy with work i can't promise you when exactly, but i will keep you updated as soon as possible.

MaxHarwell commented 2 years ago

the dropbox link should be working now if you didnt get it before the link died, please let me know of any updates.

Yes the droppbox link worked. As i am currently quite busy with work i can't promise you when exactly, but i will keep you updated as soon as possible.

Its been about a month, any updates?

dokutan commented 2 years ago

I'm sorry for not keeping you updated, the current situation is as follows:

The M686 seems to be similar to the M913 (same vendor id, similar captured data). In commit 8066172567d8d7bfe0b74a911c4367da3f697afd i added an experimantal backend for the M686 by copying the existing one from the M913. This means you can now try out a few settings that are already implemented (please use the M913 example config for now), reporting which implemented features (don't) work would be helpful.

Sadly i don't fully understand the protocol of these mice and am encountering a lot of weird stuff (on the M913 at least), which further slows down the progress. My current approach is to work on the protocol primarily by examining the M913 as i have access to one, then implement the features for both mice, testing and maybe modifying would still be required for the M686. However, if you are interested in reverse engineering the protocol, i would definitely appreciate the help and gained speed.

MaxHarwell commented 2 years ago

i will try to look into messing with the 913 settings and seeing how well it works with the 686, this will take some time to figure out as i'm not the most knowledgeable on Linux, as I usually follow instructions and google stuff about issues i run into a lot. so please bear with me.

maxtimbo commented 2 years ago

Hello,

I just grabbed one of these mice, plugged it in, installed this software, and followed this thread to here. Note that the output of lsudb is different for me, though:

Bus 004 Device 003: ID 25a7:fa35 Areson Technology Corp 2.4G Dual Mode Mouse
Bus 008 Device 005: ID 25a7:fa34 Areson Technology Corp 2.4G Wireless Receiver

When I used the M913 config, everything was wacky. I used the output of mouse_m908 -R - and compared it the the example_m913.ini and matched the buttons as such:

[profile1]

lightmode=rainbow
color=00ff00
brightness=50

dpi1=1000
dpi2=3000
dpi3=4000
dpi4=6000
dpi5=16000

button_left=dpi-cycle
button_right=none
button_middle=dpi+
button_fire=dpi-
button_1=left
button_2=right
button_3=middle
button_4=none 
button_5=none 
button_6=none 
button_7=none 
button_8=none 
button_9=none 
button_10=none 
button_11=none 
button_12=none 

After that I tried messing around with the buttons to see which is which:

button_left=dpi-cycle
button_right=none
button_middle=dpi+
button_fire=dpi-
button_1=left
button_2=right
button_3=middle
button_4=A
button_5=B
button_6=C
button_7=D
button_8=e
button_9=f
button_10=g
button_11=h
button_12=i

That didn't change any of those buttons. I figured I'm probably giving the keys incorrect values.

I also tried plugging it in. This is the output of mouse_m908 -R - after plugging it in:

$ mouse_m908 -R -
# Model: 686
# Configuration created with mouse_m908 -R.
# This configuration can be send to the mouse with mouse_m908 -c.
# Note: this feature is incomplete for the m686.

# Battery level: 80 %

# The m686 has two profiles that can be switched using the 'mode switch' button on the bottom of the mouse.
# Reading the settings can only be done for the active profile, therefore only profile1 is used in this config.
[profile1]

report_rate=unknown

# DPI settings
# Currently active DPI level: 193
dpi1=0x000090
dpi2=0x78ad54
dpi3=0x547f00
dpi4=0xa8b9a4
dpi5=0xfc7f00

# Button mapping
button_left=unknown, please report as bug:  ad  9f  54  7f
button_right=unknown, please report as bug:  0  0  20  75
button_middle=unknown, please report as bug:  7f  0  0  4
button_fire=unknown, please report as bug:  c0  c4  57  a4
button_1=unknown, please report as bug:  0  0  0  0
button_2=unknown, please report as bug:  fc  7f  0  0
button_3=unknown, please report as bug:  ae  8a  ab  9f
button_4=unknown, please report as bug:  54  7f  0  0
button_5=unknown, please report as bug:  0  c0  16  80
button_6=unknown, please report as bug:  9f  54  7f  0
button_7=unknown, please report as bug:  0  0  0  a0
button_8=unknown, please report as bug:  5d  a4  9f  54
button_9=unknown, please report as bug:  fc  7f  0  0
button_10=unknown, please report as bug:  60  c4  f  ab
button_11=unknown, please report as bug:  9f  54  7f  0
button_12=unknown, please report as bug:  0  5  0  0

Here's the output of mouse_m908 -D -:

09 03 00 00 00 01 00 00 00 00 00 00 00 00 00 00 48 
09 01 00 00 00 04 68 a8 3b 90 00 00 00 00 00 00 6c 
09 01 00 00 00 04 68 a8 3b 90 00 00 00 00 00 00 6c 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 04 00 00 00 02 08 01 00 00 00 00 00 00 00 00 3d 

I'd like to be able to map the three buttons at least for backwards and forwards. Anything else would also be cool. But that'd be a start. Where should I go from here?

maxtimbo commented 2 years ago

Quick update:

I fired up a windows VM and installed the software so I could set the side buttons. I then ran mouse_m908 -R -:

$ mouse_m908 -R -
# Model: 686
# Configuration created with mouse_m908 -R.
# This configuration can be send to the mouse with mouse_m908 -c.
# Note: this feature is incomplete for the m686.

# Battery level: 90 %

# The m686 has two profiles that can be switched using the 'mode switch' button on the bottom of the mouse.
# Reading the settings can only be done for the active profile, therefore only profile1 is used in this config.
[profile1]

report_rate=1000

# DPI settings
# Currently active DPI level: 1
dpi1=1000
dpi2=3000
dpi3=4000
dpi4=6000
dpi5=7500

# Button mapping
button_left=none
button_right=none
button_middle=dpi+
button_fire=dpi-
button_1=left
button_2=right
button_3=middle
button_4=none
button_5=forward
button_6=unknown, please report as bug:  9  0  0  4c
button_7=backward
button_8=none
button_9=none
button_10=none
button_11=none
button_12=none

Note* button_6 is Button 8 and it's disabled in the sofware.

So I have inferred that:

Output of mouse_m908 -D -:

09 03 00 00 00 01 01 00 00 00 00 00 00 00 00 00 47 
09 01 00 00 00 04 68 a8 3b 90 00 00 00 00 00 00 6c 
09 08 00 00 04 02 00 55 00 00 00 00 00 00 00 00 e9 
09 02 00 00 00 01 01 00 00 00 00 00 00 00 00 00 48 
09 08 00 00 00 0a 01 54 05 50 00 55 00 55 00 55 91 
09 08 00 00 0a 0a 00 55 0b 0b 00 3f 23 23 00 0f 31 
09 08 00 00 14 0a 2f 2f 00 f7 47 47 00 c7 59 59 ca 
09 08 00 00 1e 0a 00 a3 bd bd 00 db bd bd 00 db cf 
09 08 00 00 28 0a bd bd 00 db ff 00 00 56 00 00 68 
09 08 00 00 32 0a ff 56 00 ff 00 56 ff ff 00 57 09 
09 08 00 00 3c 0a ff 55 7d 84 ff 00 ff 57 ff 7d d8 
09 08 00 00 46 0a 7d 5c 7d 7d ff 5c 01 54 1e 37 1c 
09 08 00 00 50 0a 03 52 00 55 ff 00 ff 57 03 52 96 
09 08 00 00 5a 0a 80 d5 03 52 00 55 01 01 00 53 8c 
09 08 00 00 64 0a 01 02 00 52 01 04 00 50 00 00 2c 
09 08 00 00 6e 0a 00 55 01 10 00 44 09 00 00 4c cd 
09 08 00 00 78 0a 00 00 00 55 00 00 00 55 01 08 0f 
09 08 00 00 82 0a 00 4c 00 00 00 55 02 02 00 51 c2 
09 08 00 00 8c 0a 02 03 00 50 00 00 00 55 00 00 04 
09 08 00 00 96 0a 00 55 00 00 00 55 00 00 00 55 a5 
09 08 00 01 00 0a ff ff ff ff ff ff ff ff ff ff 43 
09 08 00 01 0a 0a ff ff ff ff ff ff ff ff ff ff 39 
09 08 00 01 20 0a ff ff ff ff ff ff ff ff ff ff 23 
09 08 00 01 2a 0a ff ff ff ff ff ff ff ff ff ff 19 
09 08 00 01 40 0a ff ff ff ff ff ff ff ff ff ff 03 
09 08 00 01 4a 0a ff ff ff ff ff ff ff ff ff ff f9 
09 08 00 01 60 0a 02 81 21 00 41 21 00 4f ff ff 86 
09 08 00 01 6a 0a ff ff ff ff ff ff ff ff ff ff d9 
09 08 00 01 80 0a 02 81 22 00 41 22 00 4d ff ff 66 
09 08 00 01 8a 0a ff ff ff ff ff ff ff ff ff ff b9 
09 08 00 01 a0 0a 02 81 23 00 41 23 00 4b ff ff 46 
09 08 00 01 aa 0a ff ff ff ff ff ff ff ff ff ff 99 
09 08 00 01 c0 0a ff ff ff ff ff ff ff ff ff ff 83 
09 08 00 01 ca 0a ff ff ff ff ff ff ff ff ff ff 79 
09 08 00 01 e0 0a ff ff ff ff ff ff ff ff ff ff 63 
09 08 00 01 ea 0a ff ff ff ff ff ff ff ff ff ff 59 
09 08 00 02 00 0a 02 81 24 00 41 24 00 49 ff ff e5 
09 08 00 02 0a 0a ff ff ff ff ff ff ff ff ff ff 38 
09 08 00 02 20 0a 02 81 25 00 41 25 00 47 ff ff c5 
09 08 00 02 2a 0a ff ff ff ff ff ff ff ff ff ff 18 
09 08 00 02 40 0a ff ff ff ff ff ff ff ff ff ff 02 
09 08 00 02 4a 0a ff ff ff ff ff ff ff ff ff ff f8 
09 08 00 02 60 0a ff ff ff ff ff ff ff ff ff ff e2 
09 08 00 02 6a 0a ff ff ff ff ff ff ff ff ff ff d8 
09 08 00 02 80 0a 02 81 26 00 41 26 00 45 ff ff 65 
09 08 00 02 8a 0a ff ff ff ff ff ff ff ff ff ff b8 
09 08 00 02 a0 0a 02 81 27 00 41 27 00 43 ff ff 45 
09 08 00 02 aa 0a ff ff ff ff ff ff ff ff ff ff 98 
09 08 00 02 c0 0a 02 81 57 00 41 57 00 e3 ff ff 25 
09 08 00 02 ca 0a ff ff ff ff ff ff ff ff ff ff 78 
09 08 00 02 e0 0a 02 81 56 00 41 56 00 e5 ff ff 05 
09 08 00 02 ea 0a ff ff ff ff ff ff ff ff ff ff 58 
09 08 00 03 01 0a ff ff ff ff ff ff ff ff ff ff 40 
09 08 00 04 81 0a ff ff ff ff ff ff ff ff ff ff bf 
09 08 00 06 01 0a ff ff ff ff ff ff ff ff ff ff 3d 
09 08 00 07 81 0a ff ff ff ff ff ff ff ff ff ff bc 
09 08 00 09 01 0a ff ff ff ff ff ff ff ff ff ff 3a 
09 08 00 0a 81 0a ff ff ff ff ff ff ff ff ff ff b9 
09 08 00 0c 01 0a ff ff ff ff ff ff ff ff ff ff 37 
09 08 00 0d 81 0a ff ff ff ff ff ff ff ff ff ff b6 
09 08 00 0f 01 0a ff ff ff ff ff ff ff ff ff ff 34 
09 08 00 10 81 0a ff ff ff ff ff ff ff ff ff ff b3 
09 08 00 12 01 0a ff ff ff ff ff ff ff ff ff ff 31 
09 08 00 13 81 0a ff ff ff ff ff ff ff ff ff ff b0 
09 08 00 15 01 0a ff ff ff ff ff ff ff ff ff ff 2e 
09 08 00 16 81 0a ff ff ff ff ff ff ff ff ff ff ad 
09 08 00 18 01 0a ff ff ff ff ff ff ff ff ff ff 2b 
09 08 00 19 81 0a ff ff ff ff ff ff ff ff ff ff aa 
09 04 00 00 00 02 09 00 00 00 00 00 00 00 00 00 3d 
dokutan commented 2 years ago

@maxtimbo Thanks, i have updated the button names and added a config file example for the M686 to mostly match your description. The difference is that the buttons are identified by their name, not by their number.

Regarding your first comment, there are still a few open issues:

maxtimbo commented 2 years ago

hmm. well, i'd like macro/key press support. Can I get you one of these mice to hasten the support for m686 mice?

dokutan commented 2 years ago

Can I get you one of these mice to hasten the support for m686 mice?

I appreciate the offer, but would like to currently decline for two reasons:

i'd like macro/key press support

I have had another look at implementing support for keyboard keys, and now have a decent understanding of this part of the protocol (https://github.com/dokutan/mouse_m908/blob/master/documentation/m913-key-press.txt). The biggest problem is that some form of checksum gets used which is extremely annoying. The best thing you could do to get key press support is to help with the reverse engineering of the protocol.

maxtimbo commented 2 years ago

help with the reverse engineering of the protocol.

How do I do that? Is that the wireshark bit you mentioned earlier? Is there an easier way to get (i assume are) hex dumps? And then, what'll you want me to do? Program some macros and key presses, and just get the data being sent to the mouse?

dokutan commented 2 years ago

The idea is to use wireshark to capture the data sent by the official software (or this software for debugging) for different values, then compare the data. I found it useful to export the packets as json, then run

#!/usr/bin/env sh
grep usb.data_fragment "$1" | cut -d \" -f4 > "$1".data

on the exported json to obtain a format that is suitable for diff. Experimenting with the packets in the source code (include/m6868/data.cpp, mostly to confirm your assumptions) can be helpful as well.

The best thing woud be if you could find out how the checksum in the key press part of the protocol works.

maxtimbo commented 2 years ago

Where can I dump all this data? I went through and captured every alphabet letter as well as all possible modifier combinations. You can only have modifiers assigned at a time per button. I noticed that some combinations send two or three packets per key. I have all the json files trimmed using that bask script. There are 15 files in total. I could just copy-pasta all these since it's typically the first 7 packets that do stuff. Also, software doesn't allow you to not have a left click assigned. Here are my notes while I was doing all this:

filename b1 b2 b3 b4 b5 b6 b7 b8
s0 leftclick a b c d e f g
s1 leftclick h i j k l m n
s2 leftclick o p q r s t u
s3 leftclick v w x y z shift+a ctrl+a
s4 leftclick alt+a win+a shift+ctrl+a ctrl+alt+a alt+win+a shift+alt+a alt+win+a

Changing only button 6 as follows:

You cannot set more than two modifiers.

dokutan commented 2 years ago

I went through and captured every alphabet letter as well as all possible modifier combinations.

Thanks, that sounds promising.

Where can I dump all this data?

I think the easiest option would be for you to put everything in in a directory under documentation and create a pull request.

maxtimbo commented 2 years ago

Done. Also, I'm far more versed in python than I am in C++, but I have written C++ in the past (for an entry college course a few years back). That being said, I was looking at the bit that writes the config file to the mouse, I believe it's rd_mouse.cpp. I was thinking about the behavior when a wireless mouse is plugged in with both USB and the wireless dongle how it's very slow and sometimes returns erroneous data.

So around line 93, you get the vid and pid of the device. However, when it's plugged in, those would both return two values, correct? (If both wired and wireless interfaces are present.)

Continuing to read the rd_mouse.h file, it looks like the mouse must first be detached from the kernal driver before you can get/set values. So if there are two sets of vid/pid, why not detach both, write to one, and then reattach both?

I might be way off base here, so apologies if this only confuses things.

dokutan commented 2 years ago

So around line 93, you get the vid and pid of the device. However, when it's plugged in, those would both return two values, correct? (If both wired and wireless interfaces are present.)

What i am doing is iterating over all usb devices, for each device iterate over all mice and check if their vid and pid match. Getting the vid/pid ( e.g. uint16_t vid = descriptor.idVendor;) of a device will always return exactly one value. When multiple devices/PIDs are present the last one gets used.

Continuing to read the rd_mouse.h file, it looks like the mouse must first be detached from the kernal driver before you can get/set values. So if there are two sets of vid/pid, why not detach both, write to one, and then reattach both?

There is no need to detach both, only the driver for the actually used one needs to be detached.

The best way to prefer the wired over the wireless connection i currenty see is to remove or skip the wireless pid if the other one is present. Better suggestions or implementations are definitely welcome.

dokutan commented 2 years ago

@maxtimbo Mapping a button as a single key a-z is implemented with 877310edf0dcf3347768bbabb581720c08d07315, i will now work on the remaining keyboard keys and key combinations. It would be great if you could test the current implementation with the M686.

Edit: Remaining keys have been added with aa26e9780697074dc0569e069a810fa04fb4c0b4

maxtimbo commented 2 years ago

@dokutan Superb. I tried a handful of a-z as well as some other keys such as F1, slash, etc. All seem to be working. "Ro" didn't do anything (I was curious to see what it generated, It's likely that I don't have the font/language to handle that).

Also worth noting, when I mouse_m908 -R - after setting any keys, it reports default despite the button giving me the correct key press.

How can I help further with modifiers?

dokutan commented 2 years ago

@maxtimbo

Also worth noting, when I mouse_m908 -R - after setting any keys, it reports default despite the button giving me the correct key press.

I haven't looked into reading the keyboard keys, but plan to do that after the modifiers are working.

How can I help further with modifiers?

Basically the same as with individual keys, capture data and use it to figure out how the protocol works.

Here is what i already know:

epicfacethe3rd commented 1 year ago

i have no idea how useful i can be here, but i've also got an m686 i'm willing to help use to improve the project!