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

Merging HD Rumble support from fork? #58

Open
pengowray opened this issue Sep 3, 2023 · 1 comment
Open

Merging HD Rumble support from fork? #58

pengowray opened this issue Sep 3, 2023 · 1 comment

Comments

@pengowray
Copy link

There's a fork of this project by Mizushiki (MIZUSHIKI/JoyShockLibrary-plus-HDRumble) which has added HD Rumble support like the name suggests. This seems like what I was looking for but the fork is now 38 commits behind the mainline library.

It doesn't look like they attempted to create a PR. I'm not sure how easy it would be to merge the changes, but would appreciate if anyone had a look. Or otherwise has anyone looked at adding Rumble HD support?

(Rumble HD is a core feature I'm looking for, and trying to find a JoyCon library is hard)

@r57zone
Copy link
Contributor

r57zone commented Jan 11, 2025

Can also make a simple rumble on the joycons like this (based on code):

unsigned char PacketsCounter = 0;
...
// Left
unsigned char outputReportLeft[64] = { 0 };
outputReportLeft[0] = 0x10;
outputReportLeft[1] = (++PacketCounter) & 0xF; if (PacketCounter > 0xF) CurGamepad.PacketCounter = 0x0;
outputReportLeft[2] = std::clamp(OutState.SmallMotor - 0, 0, 229); // It seems that it is not recommended to use the Nintendo Switch motors at 100 % , there is a risk of damaging them, so we will limit ourselves to 90%
outputReportLeft[3] = 0x00;
outputReportLeft[4] = OutState.SmallMotor == 0 ? 0x00 : 0x01; 
outputReportLeft[5] = 0x40;

hid_write(HidHandle, outputReportLeft, 64); 

// Right JoyCon
if (CurGamepad.HidHandle2 != NULL) {
	unsigned char outputReportRight[64] = { 0 }; 
	outputReportRight[0] = 0x10;
	outputReportRight[1] = (CurGamepad.PacketCounter) & 0xF; 
	outputReportRight[2] = 0x00; 
	outputReportRight[3] = 0x00; 
	outputReportRight[4] = OutState.LargeMotor == 0 ? 0x00 : 0x01; 
	outputReportRight[5] = 0x40; 
	outputReportRight[6] = OutState.LargeMotor == 0 ? 0x00 : std::clamp(OutState.LargeMotor - 0, 0, 229);

	hid_write(HidHandle2, outputReportRight, 64);
}

if (OutState.SmallMotor == 0 && OutState.LargeMotor == 0) // Send one or two more empty packets to stop the rumble.

(tested on non-original joycons)

It might work for the Pro controller, but I don't have one to test.

unsigned char outputReport[64] = { 0 };

outputReport[0] = 0x10;
outputReport[1] = (++CurGamepad.PacketCounter) & 0xF; if (CurGamepad.PacketCounter > 0xF) CurGamepad.PacketCounter = 0x0;
outputReport[2] = std::clamp(OutState.SmallMotor - 0, 0, 229);
outputReport[6] = std::clamp(OutState.LargeMotor - 0, 0, 229);

// USB
if (CurGamepad.USBConnection) {
	outputReport[0] = 0x80;
	outputReport[1] = 0x92;
	outputReport[3] = 0x31;
	outputReport[8] = 0x10;
}

hid_write(CurGamepad.HidHandle, outputReport, 64);

BlueTooth detection

} else if (cur_dev->product_id == NINTENDO_SWITCH_PRO) {
	CurGamepad.HidHandle = hid_open(cur_dev->vendor_id, cur_dev->product_id, cur_dev->serial_number);
	CurGamepad.ControllerType = NINTENDO_SWITCH_PRO;
	hid_set_nonblocking(CurGamepad.HidHandle, 1);
	CurGamepad.USBConnection = true;

	// BT detection
	unsigned char buf[64];
	memset(buf, 0, sizeof(buf));
	int bytesRead = hid_read_timeout(CurGamepad.HidHandle, buf, sizeof(buf), 100);
	if (bytesRead > 0 && buf[0] == 0x11)
		CurGamepad.USBConnection = false;
}
cur_dev = cur_dev->next;

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

No branches or pull requests

2 participants