Page 1 of 1

Detect controller type and read accordingly

Posted: Fri Jun 07, 2024 11:39 pm
by Komali
Hi! I'm working on an input display program using libnx and want to add in support for gamecube controllers and their analog triggers. Unfortunately, initial attempts to use `padConfigureInput(8, HidNpadStyleTag_NpadGc);`only works if ALL controllers are gamecube; it does not read pro controller inputs and actually crashes the sysmodule if no gamecube controllers are connected (seemingly). I'm using ` padGetStickPos`, ` padGetButtons`, and (ideally) `padGetGcTriggerPos` to fill out a struct so I can pass along data to a connected server; procons would just have the trigger values set to 0. Is there any way to either detect the current controller without having it set or read gamecube trigger data while being on a non-gc configuration setting? Not that it helps but the main bit of my code is this which shows things I've tried

Code: Select all

PadState pads[8];
HidAnalogStickState l, r;
volatile rt_config rt_conf = {0};
t_conf.multicap = config_multicap_enabled(config);
for (int i = 0; i < 8; i++) {
	padInitialize(&pads[i], i);
	rt_conf.pads_enabled[i] = config_player_enabled(config, i);
}
Thread t;
threadCreate(&t, service_scope_func, (void *)&rt_conf, NULL, 0x1000, 0x20, -2);
threadStart(&t);
server_setup();
char client_msg[10];
int client_len;
char payload[810] = {'[', 0};
int payload_len = 1;
u64 down;
u32 to_send;
while (true) {
    /* ... */
	for (int i = 0; i < 8; i++) {
	        // comments illustrate attempts, none of which worked
	    
                // padConfigureInput(8, HidNpadStyleSet_NpadStandard);
                // hidSetSupportedNpadStyleSet(HidNpadStyleTag_NpadGc);
                padUpdate(&pads[i]);
                down = padGetButtons(&pads[i]);
		l = padGetStickPos(&pads[i], 0);
		r = padGetStickPos(&pads[i], 1);
                HidNpadGcState state;
                hidGetNpadStatesGc(i, &state, 1); 
                // hidGetNpadStatesGc(i, &state, 1);
                // hidGetNpadStatesGc(__builtin_ffs(pads[i].id_mask) - 1, &state, 1);
                // u32 gcl = state.trigger_l;
                // padConfigureInput(8, HidNpadStyleTag_NpadGc);
		// padUpdate(&pads[i]);
                u32 gcr = pads[i].gc_triggers[0];//__builtin_ffs(pads[i].id_mask) - 1;//padGetGcTriggerPos(&pads[i], 0);
                u32 gcl =  HidNpadIdType_No1 +  __builtin_ffs(pads[i].id_mask)-1;//padGetGcTriggerPos(&pads[i], 1);
                
                // (prepare and send payload)
	}
}

Re: Detect controller type and read accordingly

Posted: Sat Jun 08, 2024 4:03 pm
by yellows8
Pass the ORRed bitfield for the styleset, for example: padConfigureInput(..., HidNpadStyleSet_NpadStandard | HidNpadStyleTag_NpadGc)
You probably also want to use padInitializeAny instead of padInitialize.