From 40ec7134528567c73724f4ba36b6dae8b17dbf0f Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 8 Dec 2020 12:56:11 -0500 Subject: [PATCH] hid/abstracted-pad: Updated for hid-refactor. --- hid/abstracted-pad/source/main.c | 60 +++++++++++++------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/hid/abstracted-pad/source/main.c b/hid/abstracted-pad/source/main.c index 3a64ea9..1247194 100644 --- a/hid/abstracted-pad/source/main.c +++ b/hid/abstracted-pad/source/main.c @@ -19,23 +19,18 @@ int main(int argc, char* argv[]) // take a look at the graphics/opengl set of examples, which uses EGL instead. consoleInit(NULL); + // Configure our supported input layout: all players with standard controller styles + padConfigureInput(8, HidNpadStyleSet_NpadStandard); + + // Initialize the gamepad for reading all controllers + PadState pad; + padInitializeAny(&pad); + Result rc=0; bool initflag=0; - u32 i; printf("abstracted-pad example\n"); - hidScanInput(); - - // 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: "); - for(i=0; i<10; i++) { - if (hidIsControllerConnected(i)) printf("%d ", i); - } - printf("\n"); - rc = hiddbgInitialize(); if (R_FAILED(rc)) { printf("hiddbgInitialize(): 0x%x\n", rc); @@ -44,7 +39,7 @@ int main(int argc, char* argv[]) initflag = 1; } - u64 pads[8]={0}; + HiddbgAbstractedPadHandle pads[8]={0}; HiddbgAbstractedPadState states[8]={0}; s32 tmpout=0; @@ -57,26 +52,24 @@ int main(int argc, char* argv[]) // Main loop while (appletMainLoop()) { - // Scan all the inputs. This should be done once for each frame - hidScanInput(); + // Scan the gamepad. This should be done once for each frame + padUpdate(&pad); - // hidKeysDown returns information about which buttons have been - // just pressed in this frame compared to the previous one - u64 kDown = hidKeysDown(conID); + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - 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, devicetype = 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), hidGetControllerDeviceType(i), hidKeysHeld(i), tmpjoy[0].dx, tmpjoy[0].dy, tmpjoy[1].dx, tmpjoy[1].dy); - } - } + if (kDown & HidNpadButton_Plus) + break; // break in order to return to hbmenu + + if (R_SUCCEEDED(rc) && (kDown & (HidNpadButton_A | HidNpadButton_X))) { + printf("Controllers state:\n"); + HidAnalogStickState analog_stick_l = padGetStickPos(&pad, 0); + HidAnalogStickState analog_stick_r = padGetStickPos(&pad, 1); + printf("buttons = 0x%lx, analog_stick_l.x = 0x%x, analog_stick_l.y = 0x%x, analog_stick_r.x = 0x%x, analog_stick_r.y = 0x%x\n", padGetButtons(&pad), analog_stick_l.x, analog_stick_l.y, analog_stick_r.x, analog_stick_r.y); } - if (R_SUCCEEDED(rc) && (kDown & KEY_A)) { + if (R_SUCCEEDED(rc) && (kDown & HidNpadButton_A)) { tmpout = 0; rc = hiddbgGetAbstractedPadsState(pads, states, sizeof(pads)/sizeof(u64), &tmpout); printf("hiddbgGetAbstractedPadsState(): 0x%x, 0x%x\n", rc, tmpout); @@ -86,7 +79,7 @@ int main(int argc, char* argv[]) if (R_SUCCEEDED(rc) && tmpout>=1) { for (u32 i=0; i