Joycon attach/detach function
jonyluke opened this issue · comments
Is there a function for detecting when joycons have been attach or detach?
There's hidIsControllerConnected (next stable libnx release will have it), but if you want events libnx doesn't have that atm.
EDIT: Or do you mean something else?
I want to do an action when joycon is attach and joycon is detach.
Attached to handheld?
Yes
hidGetHandheldMode
I don't want to know if it it in Handheld mode, i want to know for example, when attaching the right Joycon, playing a sound, and the same when detaching, is that possible?
I think that is not exactly what I need.
Something like this:
https://www.youtube.com/watch?v=zUDSW22_cOQ
Just use hidGetHandheldMode() or hidIsControllerConnected({handheld})
But if you attach or detach the joycon you are not still in HandHeldMode?
hidGetHandheldMode willl change when you attach/detach a joycon from the handheld when there's a different joycon attached. hidIsControllerConnected({handheld}) will change for {no joycons attached} / {any joycons attached}.
With hidIsControllerConnected({handheld}) do you mean hidIsControllerConnected(CONTROLLER_P1_AUTO); ?
CONTROLLER_HANDHELD
What do you think of this?
bool mode = hidIsControllerConnected(CONTROLLER_HANDHELD);
if(mode){
//attach
}
else{
//detach
}
*connected.
You probably want to compare that with a cached value from the last hidIsControllerConnected call as well.
Nothing happens
bool rfirst = true;
bool attach = false;
while (appletMainLoop())
{
if(rfirst)
{
rfirst = false;
attach = (hidIsControllerConnected(CONTROLLER_HANDHELD));
}
bool nattach = (hidIsControllerConnected(CONTROLLER_HANDHELD));
if(nattach != attach)
{
attach = nattach;
if(nattach){
playMp3("attach.mp3");
}
else{
playMp3("dettach.mp3");
}
}
}
hidScan + other main-loop stuff missing.
Okay that is working when the two joycons are connected or not, but how i do it with only one?
Maybe with CONTROLLER_PLAYER_1?
Don't really support detecting which joycons are connected when there's at least one connected already.
FWIW, appletMainLoop should not be used when applet is not initialized (didn't realize this was for a sysmodule eariler).
I'll have to keep looking for an alternative, because when the joycon connects, a few seconds pass, and does not give the effect I want to give, like detachin the joycon.
There doesn't seem to be an Event for this with the hid service, dunno for hid:sys (but we don't impl the latter service at all atm).
I managed to do it using gpio
ugh