diff --git a/hid/abstracted-pad/source/main.c b/hid/abstracted-pad/source/main.c index b778ad1..3a64ea9 100644 --- a/hid/abstracted-pad/source/main.c +++ b/hid/abstracted-pad/source/main.c @@ -6,7 +6,7 @@ // Include the main libnx system header, for Switch development #include -// This example shows how to use AbstractedPad, see also libnx hiddbg.h. Depending on state type2, either a new virtual controller can be registered, or the state can be merged with an existing controller. +// This example shows how to use AbstractedPad, see also libnx hiddbg.h. Depending on state npadInterfaceType, either a new virtual controller can be registered, or the state can be merged with an existing controller. // This is deprecated, use Hdls instead when running on compatible system-versions. // Main program entrypoint @@ -27,7 +27,7 @@ int main(int argc, char* argv[]) hidScanInput(); - // When hiddbgSetAutoPilotVirtualPadState runs a new controller may become available, depending on the specified type2 field. If CONTROLLER_HANDHELD is being internally, CONTROLLER_P1_AUTO would use the new controller. Check which controller we're currently using and don't use CONTROLLER_P1_AUTO, so it doesn't switch to using the new controller later. + // When hiddbgSetAutoPilotVirtualPadState runs a new controller may become available, depending on the specified npadInterfaceType field. If CONTROLLER_HANDHELD is being internally, CONTROLLER_P1_AUTO would use the new controller. Check which controller we're currently using and don't use CONTROLLER_P1_AUTO, so it doesn't switch to using the new controller later. HidControllerID conID = hidGetHandheldMode() ? CONTROLLER_HANDHELD : CONTROLLER_PLAYER_1; printf("Connected controllers: "); @@ -86,7 +86,7 @@ int main(int argc, char* argv[]) if (R_SUCCEEDED(rc) && tmpout>=1) { for (u32 i=0; i JOYSTICK_MAX) state.joysticks[JOYSTICK_LEFT].dx = JOYSTICK_MIN; state.joysticks[JOYSTICK_RIGHT].dy -= 0x10; if (state.joysticks[JOYSTICK_LEFT].dy < JOYSTICK_MIN) state.joysticks[JOYSTICK_LEFT].dy = JOYSTICK_MAX; } - if (R_SUCCEEDED(rc) && (kDown & KEY_A)) { + if (R_SUCCEEDED(rc) && (kDown & (KEY_A | KEY_X))) { printf("Connected controllers:\n"); for(i=0; i<10; i++) { if (hidIsControllerConnected(i)) { JoystickPosition tmpjoy[2]; hidJoystickRead(&tmpjoy[0], i, JOYSTICK_LEFT); hidJoystickRead(&tmpjoy[1], i, JOYSTICK_RIGHT); - printf("%d: type = 0x%x, buttons = 0x%lx, stickL.dx = 0x%x, stickL.dy = 0x%x, stickR.dx = 0x%x, stickR.dy = 0x%x\n", i, hidGetControllerType(i), hidKeysHeld(i), tmpjoy[0].dx, tmpjoy[0].dy, tmpjoy[1].dx, tmpjoy[1].dy); + + u8 interfacetype=0; + rc2 = hidGetNpadInterfaceType(i, &interfacetype); + if (R_FAILED(rc2)) printf("hidGetNpadInterfaceType(): 0x%x\n", rc2); + + HidPowerInfo powerinfo[3]={0}; + hidGetControllerPowerInfo(i, &powerinfo[0], 1); + hidGetControllerPowerInfo(i, &powerinfo[1], 2); + + printf("%d: type = 0x%x, devicetype = 0x%x, buttons = 0x%lx, stickL.dx = 0x%x, stickL.dy = 0x%x, stickR.dx = 0x%x, stickR.dy = 0x%x, interface = %d\n", i, hidGetControllerType(i), hidGetControllerDeviceType(i), hidKeysHeld(i), tmpjoy[0].dx, tmpjoy[0].dy, tmpjoy[1].dx, tmpjoy[1].dy, interfacetype); + + for (u32 poweri=0; poweri<3; poweri++) + printf("%d powerinfo[%d]: powerConnected = %d, isCharging = %d, batteryCharge = %d\n", i, poweri, powerinfo[poweri].powerConnected, powerinfo[poweri].isCharging, powerinfo[poweri].batteryCharge); } } printf("\n");