switchbrew / libnx

Library for Switch Homebrew

Home Page:https://switchbrew.github.io/libnx/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hidSetNpadJoyAssignmentModeDual not working in 1.6.0

rsn8887 opened this issue · comments

The functions hidSetNpadJoyAssignmentModeDual followed by hidMergeSingleJoyAsDualJoy are not working anymore in latest release 1.6.0.

However, this was working fine in 1.5.0.

This can be observed even on app start: if the controllers are in single joy con mode, they are not automatically put into dual mode anymore, like it used to be in 1.5.0.

In an app, there is no way to change from single back into dual mode now. It used to work in the following way:

		for (int id=0; id<8; id++) {
			hidSetNpadJoyAssignmentModeDual((HidControllerID) id);
		}
		for (int id=0; id<8; id+=2) {
			hidMergeSingleJoyAsDualJoy((HidControllerID) id, (HidControllerID) (id + 1));
		}

but now this doesn't result in any dual controllers.

Never mind it didn't even work before. I could swear it worked at some point.

Is there a piece of example code how to properly coalesce controllers from single into dual mode?

Did you try moving the second loop before the first one?

I think I tried everything let me check...

FWIW libnx does use hidSetNpadJoyAssignmentModeDual automatically at init/exit, not hidMergeSingleJoyAsDualJoy.

I see. I tried switching the loops, still didn't work. I can make it work by sequentially attaching/detaching controllers to the rails. I think that "resets" them somehow.

There must be a way to make the "coalescing" of two joycons into one work. I had it working at some point. However it always went from four single JoyCons to player 1 dual and player 3 dual, which was useless.

There are some subtleties. I am making progress. This at least joins player 1, but player 2 and 3 are not joined:

		for (int id1=0; id1<8; id1++) {
			hidSetNpadJoyAssignmentModeDual((HidControllerID) id1);
			if (hidGetControllerType((HidControllerID) id1) == TYPE_JOYCON_LEFT) {
				for (int id2=0; id2<8; id2++) {
					if (hidGetControllerType((HidControllerID) id2) == TYPE_JOYCON_RIGHT) {
						hidMergeSingleJoyAsDualJoy ((HidControllerID) id1, (HidControllerID) id2);
						break;
					}
				}
			}	
		}

So I think one has to be careful to merge a left one with a right one, not a right one with a left one, or two left ones, etc.

Ok this works:

		// find all left/right single JoyCon pairs and join them together
		int lastRightId = -1;		
		for (int leftId=0; leftId<8; leftId++) {
			hidSetNpadJoyAssignmentModeDual((HidControllerID) leftId);
			if (hidGetControllerType((HidControllerID) leftId) == TYPE_JOYCON_LEFT) {
				for (int rightId=lastRightId+1; rightId<8; rightId++) {
					if (hidGetControllerType((HidControllerID) rightId) == TYPE_JOYCON_RIGHT) {
						lastRightId=rightId;
						hidMergeSingleJoyAsDualJoy ((HidControllerID) leftId, (HidControllerID) rightId);
						break;
					}
				}
			}	
		}

Correction, we can merge left and right or right and left, but not left and left etc.

The id of the joint controller is the id of the first argument.