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

Roccat Kone AIMO driver #1003

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

daegalus
Copy link

@daegalus daegalus commented Jun 8, 2020

Deciphered as much as I could figure out and updated the driver as a copy of the current Roccat driver.

Checksum passes, and the data is pulled correctly.

LED support isn't added, but I have the profile struct updated for it. Added comments to the struct for the unknown stuff and for the known stuff.

Added a gitignore for the builddir and build folders that were created and the one by .vscode, but i can remove that if you don't want it in the codebase.

Also updated the version constraint for meson_version as it was spamming me with warning about version incompatibilities with something.

@lgtm-com
Copy link

lgtm-com bot commented Jun 8, 2020

This pull request introduces 10 alerts when merging 2fbb089 into 9fc6d12 - view on LGTM.com

new alerts:

  • 10 for FIXME comment

@stephanlachnit
Copy link
Member

Thanks, I'll give it a look later! Also, please remove the Meson and gitignore changes, this is intended.

.gitignore Outdated Show resolved Hide resolved
data/devices/roccat-kone-aimo-remastered.device Outdated Show resolved Hide resolved
meson.build Outdated Show resolved Hide resolved
meson.build Outdated Show resolved Hide resolved
src/driver-roccat-kone-aimo.c Outdated Show resolved Hide resolved
src/driver-roccat-kone-aimo.c Outdated Show resolved Hide resolved
@lgtm-com
Copy link

lgtm-com bot commented Jun 9, 2020

This pull request introduces 9 alerts when merging 50a941f into b88be0a - view on LGTM.com

new alerts:

  • 9 for FIXME comment

Copy link
Member

@stephanlachnit stephanlachnit left a comment

Choose a reason for hiding this comment

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

Thanks for fixing. Also, please don't forget to add the driver to libratbag-data.c, else it won't be detected. See here: #1006 (comment)

meson.build Outdated Show resolved Hide resolved
@lgtm-com
Copy link

lgtm-com bot commented Jun 13, 2020

This pull request introduces 9 alerts when merging 481bb10 into b88be0a - view on LGTM.com

new alerts:

  • 9 for FIXME comment

Copy link
Member

@stephanlachnit stephanlachnit left a comment

Choose a reason for hiding this comment

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

LGTM, did you test it? Does it work?

@daegalus
Copy link
Author

I did with ratbagdctl.devel. I couldn't get piper.devel to work.

I'm actually going to test one more time before I'm comfortable this being merged

@stephanlachnit
Copy link
Member

I did with ratbagdctl.devel. I couldn't get piper.devel to work.

What I usually do is kill my system ratbagd daemon if running, and then just run the compiled ratbagd. Works with Piper. But you need to place the .device files manually into /usr/local/libratbag.

@lgtm-com
Copy link

lgtm-com bot commented Jun 14, 2020

This pull request introduces 9 alerts when merging 18ca742 into b88be0a - view on LGTM.com

new alerts:

  • 9 for FIXME comment

@daegalus
Copy link
Author

daegalus commented Jun 14, 2020

Ok, I tested it with piper, and was able to remap my scrollwheel successfully. But things I noticed:

  • The UI only allows 500 or 1000 for poll rate.
  • Only a small portion of the buttons are mappable from Piper.
  • Picture is obviously missing, which is fine, as I assume thats added later.
  • I assume the LED stuff will show up if i implement the appropriate LED stuff?

Finally, for the space/tab diff thing. VSCode wont show it as anything other than a tab, so I am having trouble fixing it. I considered just running the convert everything to tabs feature in VSCode, but i found the file is a mishmash of spaces and tabs. While I honestly don't care which is used, we need to choose one and stick with it (tabs seems to be the predominant one.)

Button Mapping: https://ocean.yuli.dev/f/4656ff71064d47eda3dd/
DPI/Report Rate: https://ocean.yuli.dev/f/ae0f3e62be97407aabd3/

@mweisshaupt1988
Copy link

The code looks fine so far, you already mentioned the tab and space mix. Sadly I was not yet able to get it to run, I always get the error "ratbag error: ROCCAT ROCCAT Kone Aimo 16K: driver 'roccat-kone-aimo' does not exist". I checked the installed binary, it does contain the code. At least objdump says it does 😃

I'll try to get it to run and verify on my machine the next evenings.

@daegalus
Copy link
Author

The code looks fine so far, you already mentioned the tab and space mix. Sadly I was not yet able to get it to run, I always get the error "ratbag error: ROCCAT ROCCAT Kone Aimo 16K: driver 'roccat-kone-aimo' does not exist". I checked the installed binary, it does contain the code. At least objdump says it does smiley

I'll try to get it to run and verify on my machine the next evenings.

You can check if it works with ratbagd.devel if it doesn't might need a recompile.

@mweisshaupt1988
Copy link

Well, I don't know why git pull did not pull everything yesterday, but today it did. oO Nevermind, after a quick rebuild the service works now. I'm not shure what I did wrong since this was a fresh clone but it must have been something 😄

I could also verify that piper works with it, it does not show all buttons and while setting a macro to the back key my mouse crashed. I could reset it by unplugging and replugging it. I'll see if I can nail this down tomorrow.

This is how it looks on my machine. Obviously the SVG is not existing and the language is german :D
Bildschirmfoto von 2020-06-16 00-34-07

But pretty good so far. Thank you :)

@daegalus
Copy link
Author

daegalus commented Jun 15, 2020

Macros are definitely not something I explored too in-depth. I might need to adjust data structs or data sizes for it.

The goal for this was button mapping standard buttons and profile settings.

This will need a lot more work but it is a starting point for basic support for newer Roccat mice that Roccat tools doesn't support

@mweisshaupt1988 if you wish I can send you a quick guide on how I capture the data, or a video.

@mweisshaupt1988
Copy link

That would be great, I miserably failed xD

@daegalus
Copy link
Author

daegalus commented Aug 18, 2020

So, Ive been dealing with RL shit for a while so I apologize for the long silence. What are the expectations/goals of this PR? do we want to get just the mouse base functions working first and merge that, or are we waiting on LED support from me? I know I promised some guides but have been too busy to build anything. Just wanting to know what is expected/being waited on/etc.

@stephanlachnit @FFY00

@zefrof
Copy link

zefrof commented Sep 11, 2020

Would this driver support the Kona Aimo Remastered as well? I have a friend looking to switch (to Linux) and the mouse is the biggest block right now.

@daegalus
Copy link
Author

Would this driver support the Kona Aimo Remastered as well? I have a friend looking to switch (to Linux) and the mouse is the biggest block right now.

@zefrof yes, I built this driver against the Kone AIMO Remastered, as that is what I have, so it should have 100% support for the Kone AIMO Remastered.

@zefrof
Copy link

zefrof commented Sep 11, 2020

That’s great to hear. Any ideas on when it might get merged? I completely understand if the answer is “don’t know.”

@daegalus
Copy link
Author

@zefrof ya I don't know, I'm waiting on any feedback from the maintainers.

@D3SOX
Copy link

D3SOX commented Jan 4, 2021

@daegalus Can you also add support for the Kone AIMO (non-remastered)? We tried installing your branch and changing the DeviceMatch to the one listed from lsusb

Bus 001 Device 006: ID 1e7d:2e27 ROCCAT Kone AIMO Mouse

inside /usr/share/libratbag/roccat-kone-aimo-remastered.device
Changing profiles works but changing the DPI doesn't do anything and gives an error when clicking on apply.

@FFY00
Copy link
Member

FFY00 commented Jan 4, 2021

@daegalus sorry for the delay, I've been busy. I thought I would have an opening the past month but I didn't. Can you rebase on master? If there are any missing features, like there being no LED support, please set the number of LEDs to 0.

@daegalus
Copy link
Author

daegalus commented Jan 4, 2021

@D3SOX I don't have the mouse. Unless you can provide the dump of the mouse communication for me to look through, I can't make any changes as I don't know the format.

@FFY00 will do, give me a little bit, as I switched back to windows on my primary computer. I still have a secondary that I can use to confirm things, I just need to setup the build environment on there again.

@D3SOX
Copy link

D3SOX commented Jan 4, 2021

@daegalus If you tell me how I can do that I'll provide it

@daegalus
Copy link
Author

daegalus commented Jan 4, 2021

@D3SOX you can use a windows VM with swarm installed, but you need to use wireshark and usbpcap, to monitor the traffic of the USB connection. Once you find the right USB connection. You just need to monitor the packets for the Request and Response packets over usb. the remastered ones were around 190ish kb and 130ishkb, but you will see a pattern. Usually it will be a packet that changes only a little bit with every change you make in the swarm client.

Thats the only way I know of doing it.

@FFY00
Copy link
Member

FFY00 commented Jan 4, 2021

No worries! I am still limited in time so I am not in a hurry 😁

@lgtm-com
Copy link

lgtm-com bot commented Nov 2, 2022

This pull request introduces 9 alerts when merging 205643a into c39640d - view on LGTM.com

new alerts:

  • 9 for FIXME comment

@daegalus
Copy link
Author

daegalus commented Nov 2, 2022

@staticssleever668 Thank you for the patch, definitely saved me a lot of time getting the branch updated.

I am not sure who the current active maintainers are, but I am throwing in the towel on macros. I have been away from the code for too long, and I am just not good enough with C.

So, if I can just be advised on how we can proceed to getting this PR merged so someone more experienced with C and/or Ratbag can fill in the last little bit. All the data structures are accurate and commented to the best of my knowledge. I just couldn't figure out how to process 2 separate USB packets/reports as 1 for macros with what I knew. I can also be reached out to whoever picks this up for answering questions.

If you would like me to disable Macros, I can add a DISABLE flag, and leave the current code in, but short circuit it on the first line of the function returning -ENOSUP but leave my code as reference.

Anyways just let me know, and I will make the few changes needed to merge this in without macros working or with macros disabled. All other functionality should be working.

src/driver-roccat-kone-aimo.c Outdated Show resolved Hide resolved
src/driver-roccat-kone-aimo.c Outdated Show resolved Hide resolved
@staticssleever668
Copy link
Member

staticssleever668 commented Nov 2, 2022

If you would like me to disable Macros, I can add a DISABLE flag, and leave the current code in, but short circuit it on the first line of the function returning -ENOSUP but leave my code as reference.

Anyways just let me know, and I will make the few changes needed to merge this in without macros working or with macros disabled. All other functionality should be working.

For me it looks like you are already at the finish line, so let's just make a final push.


By the way, conversations opened by amfern still hold true, please, address them. If there is anything you don't understand there, I will help you out. :)


I just couldn't figure out how to process 2 separate USB packets/reports as 1 for macros with what I knew.

Start out by making macroP1, macroP2 and macroC on the stack, here are some changes I would do first:

diff --git a/src/driver-roccat-kone-aimo.c b/src/driver-roccat-kone-aimo.c
index 97d2fdc8..39aa933d 100644
--- a/src/driver-roccat-kone-aimo.c
+++ b/src/driver-roccat-kone-aimo.c
@@ -146,8 +146,8 @@ struct roccat_macro_page2 {
 } __attribute__((packed));
 
 struct roccat_macro_combined {
-	struct roccat_macro_page1 *page1;
-	struct roccat_macro_page2 *page2;
+	struct roccat_macro_page1 page1;
+	struct roccat_macro_page2 page2;
 } __attribute__((packed));
 
 enum roccat_macro_action_type {
@@ -591,31 +591,23 @@ roccat_write_macro(struct ratbag_button *button,
 {
 	struct ratbag_device *device;
 	struct roccat_macro *macro;
-	struct roccat_macro_page1 *macroP1 = malloc(sizeof(struct roccat_macro_page1));
-	struct roccat_macro_page2 *macroP2 = malloc(sizeof(struct roccat_macro_page2));
-	struct roccat_macro_combined *macroC = malloc(sizeof(struct roccat_macro_combined));
+	// TODO: rename this to `macro_combined` or whatever fits.
+	struct roccat_macro_combined macroC;
 	struct roccat_data *drv_data;
-	uint8_t *buf1;
-	uint8_t *buf2;
-	uint8_t *buf;
 	unsigned count = 0;
 	int rc;
 
+	// TODO: check of both of these actually make the code clearer,
+	// otherwise simply use `macroC.page1` and `macroC.page2` directly.
+	struct roccat_macro_page1* macroP1 = &macroC.page1;
+	struct roccat_macro_page2* macroP2 = &macroC.page2;
+
 	if (action->type != RATBAG_BUTTON_ACTION_TYPE_MACRO)
 		return 0;
 
 	device = button->profile->device;
 	drv_data = ratbag_get_drv_data(device);
 	macro = &drv_data->macros[button->profile->index][button->index];
-	macroC->page1 = macroP1;
-	macroC->page2 = macroP2;
-	buf1 = (uint8_t*)macroP1;
-	buf2 = (uint8_t*)macroP2;
-	buf = (uint8_t*)macroC;
-
-	memset(buf1, 0, ROCCAT_REPORT_SIZE_MACRO);
-	memset(buf2, 0, ROCCAT_REPORT_SIZE_MACRO);
-	memset(buf, 0, ROCCAT_REPORT_SIZE_MACRO * 2);
 
 	for (unsigned int i = 0; i < MAX_MACRO_EVENTS && count < ROCCAT_MAX_MACRO_LENGTH; i++) {
 		if (action->macro->events[i].type == RATBAG_MACRO_EVENT_INVALID)
@@ -675,22 +667,16 @@ roccat_write_macro(struct ratbag_button *button,
 	macroP2->profile = button->profile->index;
 	macroP2->page = 0x02;
 
-	macroP2->checksum = roccat_compute_crc(buf, ROCCAT_REPORT_SIZE_MACRO * 2);
+	macroP2->checksum = roccat_compute_crc((uint8_t*) &macroC, sizeof(macroC));
 	macroP2->terminator = 0x4A;
 
 	rc = ratbag_hidraw_set_feature_report(device, ROCCAT_REPORT_ID_MACRO,
-				buf1, ROCCAT_REPORT_SIZE_MACRO);
+				(uint8_t*)macroP1, ROCCAT_REPORT_SIZE_MACRO);
 	if (rc < 0) {
-		free(macroP1);
-		free(macroP2);
-		free(macroC);
 		return rc;
 	}
 
 	if (rc != ROCCAT_REPORT_SIZE_MACRO) {
-		free(macroP1);
-		free(macroP2);
-		free(macroC);
 		return -EIO;
 	}
 
@@ -699,25 +685,16 @@ roccat_write_macro(struct ratbag_button *button,
 		log_error(device->ratbag,
 			"Error while waiting for the device to be ready: %s (%d)\n",
 			strerror(-rc), rc);
-		free(macroP1);
-		free(macroP2);
-		free(macroC);
 		return rc;
 	}
 
 	rc = ratbag_hidraw_set_feature_report(device, ROCCAT_REPORT_ID_MACRO,
-				buf2, ROCCAT_REPORT_SIZE_MACRO);
+				(uint8_t*)macroP2, ROCCAT_REPORT_SIZE_MACRO);
 	if (rc < 0) {
-		free(macroP1);
-		free(macroP2);
-		free(macroC);
 		return rc;
 	}
 
 	if (rc != ROCCAT_REPORT_SIZE_MACRO) {
-		free(macroP1);
-		free(macroP2);
-		free(macroC);
 		return -EIO;
 	}
 
@@ -726,15 +703,9 @@ roccat_write_macro(struct ratbag_button *button,
 		log_error(device->ratbag,
 			"Error while waiting for the device to be ready: %s (%d)\n",
 			strerror(-rc), rc);
-		free(macroP1);
-		free(macroP2);
-		free(macroC);
 		return rc;
 	}
 
-	free(macroP1);
-	free(macroP2);
-	free(macroC);
 	return rc;
 }

@staticssleever668
Copy link
Member

The Add assert to make sure this struct size actually equals the 1026 comments by amfern are actually very important - do these first as right now the size of is 900-something, in other word it's different.
Because of this I feel like the code in it's current state doesn't work because at the very least the checksum calculation is going to be wrong.

@lgtm-com
Copy link

lgtm-com bot commented Nov 3, 2022

This pull request introduces 9 alerts when merging 26766fc into c39640d - view on LGTM.com

new alerts:

  • 9 for FIXME comment

@daegalus
Copy link
Author

daegalus commented Nov 3, 2022

The Add assert to make sure this struct size actually equals the 1026 comments by amfern are actually very important - do these first as right now the size of is 900-something, in other word it's different. Because of this I feel like the code in it's current state doesn't work because at the very least the checksum calculation is going to be wrong.

I believe I took care of that in my latest commit. added the asserts and unions. Fixed up some sizing after a secondary look at the USB packets.

For me it looks like you are already at the finish line, so let's just make a final push.

Ok, I will push through. I just committed what I believe should work. I am currently trying to setup my ratbagd and piper to see if it actually works.

My concerns currently are in the roccat_read_button function. I am not sure how it's getting 2 packets worth of data into 1 struct, unless drv_data has magic to take care of that.

Also macro.msg.page1.msg to access fields in each page seems....messy. Any thoughts? I could set the pointer to page msg to a variable and use that instead.

@staticssleever668
Copy link
Member

My concerns currently are in the roccat_read_button function. I am not sure how it's getting 2 packets worth of data into 1 struct, unless drv_data has magic to take care of that.

There is no magic at all, the data is received a single time on line 542 by a ratbag_hidraw_get_feature_report call.

rc = ratbag_hidraw_get_feature_report(device, ROCCAT_REPORT_ID_MACRO,

If I understood you right, official software receives two packets separately, if so, I imagine is should be something like this:

diff --git a/src/driver-roccat-kone-aimo.c b/src/driver-roccat-kone-aimo.c
index d6480133..4b2bae89 100644
--- a/src/driver-roccat-kone-aimo.c
+++ b/src/driver-roccat-kone-aimo.c
@@ -540,7 +540,16 @@ roccat_read_button(struct ratbag_button *button)
 		buf[0] = ROCCAT_REPORT_ID_MACRO;
 		buf[ROCCAT_REPORT_SIZE_MACRO] = ROCCAT_REPORT_ID_MACRO;
 		rc = ratbag_hidraw_get_feature_report(device, ROCCAT_REPORT_ID_MACRO,
-					buf, ROCCAT_REPORT_SIZE_MACRO);
+					(uint8_t*)macro->msg.page1.data, ROCCAT_REPORT_SIZE_MACRO);
+		if (rc != ROCCAT_REPORT_SIZE_MACRO) {
+			log_error(device->ratbag,
+				"Unable to retrieve the macro for button %d of profile %d: %s (%d)\n",
+				button->index, button->profile->index,
+				rc < 0 ? strerror(-rc) : "not read enough", rc);
+			// FIXME: return an error here or handle this somehow.
+		}
+		rc = ratbag_hidraw_get_feature_report(device, ROCCAT_REPORT_ID_MACRO,
+					(uint8_t*)macro->msg.page2.data, ROCCAT_REPORT_SIZE_MACRO);
 		if (rc != ROCCAT_REPORT_SIZE_MACRO) {
 			log_error(device->ratbag,
 				"Unable to retrieve the macro for button %d of profile %d: %s (%d)\n",

Also macro.msg.page1.msg to access fields in each page seems....messy. Any thoughts? I could set the pointer to page msg to a variable and use that instead.

I took a quick look, it's indeed quite messy... Your idea sounds good, but I'll take a more in-depth look once I have a bit more time.

@daegalus
Copy link
Author

daegalus commented Nov 4, 2022

So I was making the changes, and I noticed a Roccat device was added a year ago, the Kone EMP. I was looking through it's code, and it has a lot of the same value and settings, it also handles the 2 packet macros. And while the LEDs don't match, and a lot of the extra settings. Those just rely on me updating the structs and LED code.

My code was based on the Kone Pure driver, and its very very different.

I am going to do a local test on maybe reworking the Kone EMP code to work with the data from the Kone AIMO. Since the Kone EMP was already merged, I already know it passed the review bar.

That way, maybe some day they can be merged into the same generic Roccat driver and only the differences need to be handled.

@daegalus
Copy link
Author

daegalus commented Nov 10, 2022

Ok, I ported it to the new code. I made the appropriate changes. Profile, Settings, and LEDs work fine.

For some reason though, all the buttons show up as Unknown and I have yet to figure out why. So I can't check it macros work until buttons are parsed properly. This was an issue with the original code too.

@lgtm-com
Copy link

lgtm-com bot commented Nov 10, 2022

This pull request introduces 89 alerts when merging f5d9c37 into 925b2a2 - view on LGTM.com

new alerts:

  • 89 for FIXME comment

@lgtm-com
Copy link

lgtm-com bot commented Nov 10, 2022

This pull request introduces 89 alerts when merging 3c28552 into 925b2a2 - view on LGTM.com

new alerts:

  • 89 for FIXME comment

@daegalus
Copy link
Author

daegalus commented Nov 11, 2022

Ok, did a small amount of log debugging, and Macros and Buttons are being read correctly, and based on the logging entries i made, they are correctly being converted to and from ratbag actions. Not sure why ratbagctl is returning UNKNOWN for all for all of them.

but if I do ratbagctl bellowing-paca profile 4 button 0 action set button 1 it sets it and remembers it, and prints it out on profile 4 get. But it doesn't actually change anything on the mouse

@staticssleever668
Copy link
Member

staticssleever668 commented Nov 11, 2022

That's weird to say the least. How do you know they are read correctly?

@staticssleever668
Copy link
Member

As for writing, the code seems OK, so I don't know what may be the reason.
Did you make and compare USB dumps made with original software and with this driver?

@daegalus
Copy link
Author

daegalus commented Nov 11, 2022

That's weird to say the least. How do you know they are read correctly?

I added log_debug messages all over the place. One in read_profile inside the button loop. Then in read_button i added a bunch inbetween the calls to button_to_action and such. Then I went even further adding the log_debugs to the loops in those functions. The numbers that showed up made sense based on the maps.

Ill try to do some more debugging. I am seeing the logs by running sudo ratbagd.devel --verbose=raw

As for writing, the code seems OK, so I don't know what may be the reason.
Did you make and compare USB dumps made with original software and with this driver?

Yes, the dumps are correct. and it even is dumpng out Macro debug info. In my logs it prints out the name, group, and button sequence of the macro.

@staticssleever668
Copy link
Member

Could you post the dumps made with official software and with libratbag? Won't hurt to have more eyes comparing them.
Comparing the changes made against the original Kone EMP driver - the button reading/writing procedure seems to be the same, only the values for actions are different. I doubt this is a broken feature on the Kone EMP driver, so maybe there actually is some other difference.

Comment on lines 787 to 793
bank_buf[0] = ROCCAT_REPORT_ID_MACRO;
bank_buf[1] = ROCCAT_BANK_ID_2;
// The remaining macro structure is not big enough to fill the second bank
// Write the remaining, fill the end with 0
unsigned int remaining_to_write = sizeof(struct roccat_macro)-ROCCAT_REPORT_SIZE_MACRO_BANK;
memcpy(bank_buf+2, &((uint8_t*)macro)[ROCCAT_REPORT_SIZE_MACRO_BANK], remaining_to_write);
memset(bank_buf+2+remaining_to_write, 0, ROCCAT_REPORT_SIZE_MACRO_BANK-(2+remaining_to_write));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bank_buf[0] = ROCCAT_REPORT_ID_MACRO;
bank_buf[1] = ROCCAT_BANK_ID_2;
// The remaining macro structure is not big enough to fill the second bank
// Write the remaining, fill the end with 0
unsigned int remaining_to_write = sizeof(struct roccat_macro)-ROCCAT_REPORT_SIZE_MACRO_BANK;
memcpy(bank_buf+2, &((uint8_t*)macro)[ROCCAT_REPORT_SIZE_MACRO_BANK], remaining_to_write);
memset(bank_buf+2+remaining_to_write, 0, ROCCAT_REPORT_SIZE_MACRO_BANK-(2+remaining_to_write));
memset(bank_buf, 0, ROCCAT_REPORT_SIZE_MACRO_BANK);
bank_buf[0] = ROCCAT_REPORT_ID_MACRO;
bank_buf[1] = ROCCAT_BANK_ID_2;
unsigned int remaining_to_write = sizeof(struct roccat_macro)-ROCCAT_REPORT_SIZE_MACRO_BANK;
memcpy(bank_buf+2, &((uint8_t*)macro)[ROCCAT_REPORT_SIZE_MACRO_BANK], remaining_to_write);

Pointer arithmetic is dangerous and has to be done with great care - let's prevent it when possible.

Also, the sizeof(struct roccat_macro)-ROCCAT_REPORT_SIZE_MACRO_BANK and bank_buf+2 look dodgy, too. I would like to see USB dumps, maybe I could figure something out.

Copy link
Member

Choose a reason for hiding this comment

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

I may be misunderstanding something here, but if it works, replace &((uint8_t*)macro)[ROCCAT_REPORT_SIZE_MACRO_BANK] with memcpy(bank_buf+2, (uint8_t*)(macro + ROCCAT_REPORT_SIZE_MACRO_BANK), remaining_to_write); - makes the intent a bit clearer.

@daegalus
Copy link
Author

Ok, I dumped everything into the files below. The files without extensions are the hex dumps, they should just be binary files, any binary file editor should work with them.

I use ImHex (opensource, crossplatform), which lets me create pattern files that highlight and breakout the data for me to easily read it. All the .pat files can be imported into ImHex when the file is open and run against the file to highlight it and organize it.

Finally, the roccat_dumps_all.txt file has the roccat debug output for the 3 reports.

I was thinking that I didn't like all the pointer nonsense also, so I was wondering if maybe I copy over the structs I was using originally, using unions to combine them, and adjust the Macro code. I now realize how easy it is to get both banks. When I was wiresharking the usb packets, both banks got returned every time (though i realize these are writes). Now I can request each individual bank, and get the information as needed, making parsing it super easy using the old structs I had. Let me know if that would be better than this current 1 struct mangling situation. We also don't lose data from the 2nd packet this way.

dumps_and_patterns.zip

Screenshot from 2022-11-11 17-51-55
Screenshot from 2022-11-11 17-48-45
Screenshot from 2022-11-11 17-45-16

@staticssleever668
Copy link
Member

Let me know if that would be better than this current 1 struct mangling situation.

Sounds good.
By the way, looks like there may be no reason to have macros field in struct roccat_data as it's not accessed directly anywhere. When data is read from the mouse, it's put in this field, but parsing it just gets forgotten, and before writing it's even being filled with zeroes. So you can make them local variables in functions where it is used.

@daegalus
Copy link
Author

daegalus commented Nov 17, 2022

Let me know if that would be better than this current 1 struct mangling situation.

Sounds good. By the way, looks like there may be no reason to have macros field in struct roccat_data as it's not accessed directly anywhere. When data is read from the mouse, it's put in this field, but parsing it just gets forgotten, and before writing it's even being filled with zeroes. So you can make them local variables in functions where it is used.

It is accessed through &drv_data in the roccat_write_profile function when its writing macros. Not sure if that changes the validity of your statement.

Anyways, latest commit I have macros parsing better, and buttons/macros, and other info show up correctly in ratbagctl. The issues is that the Play, Pause, Next, Previous, Vol Up/Down buttons show up as Unknown still, even though being parsed correctly.

I have attached my logs of ratbagd.devel and ratbagctl for others to reference if they can find the issue.

I am also having a tough time getting Macro checksums to work. I can not find a combination of data that equals the expected checksum, its always off by about 130-160 in decimal. Since the checksum is not actual CRC, but just he sum of all the bytes into a uint16. but for example, the macro is expecting 0x8485 for the checksum, but i get 0x83b1 for example. It is like there is some data missing. There is example data in the logs, the hex output for macros is accurate to what the mouse returns, and I verified the "incorrect" checksum is what I get when calculating it in ImHex in the same manner.
ratbagd_verbose_raw.log
ratbagctl_profile_0.log

@lgtm-com
Copy link

lgtm-com bot commented Nov 17, 2022

This pull request introduces 90 alerts when merging 3c74e84 into 925b2a2 - view on LGTM.com

new alerts:

  • 89 for FIXME comment
  • 1 for Comparison result is always the same

Heads-up: LGTM.com's PR analysis will be disabled on the 5th of December, and LGTM.com will be shut down ⏻ completely on the 16th of December 2022. Please enable GitHub code scanning, which uses the same CodeQL engine ⚙️ that powers LGTM.com. For more information, please check out our post on the GitHub blog.

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.

None yet