diff --git a/account/source/main.c b/account/source/main.c index e2db68b..9fe4793 100644 --- a/account/source/main.c +++ b/account/source/main.c @@ -18,6 +18,13 @@ int main(int argc, char **argv) consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + memset(&userdata, 0, sizeof(userdata)); memset(&profilebase, 0, sizeof(profilebase)); @@ -68,13 +75,13 @@ 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 (and they weren't in the previous frame) - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu consoleUpdate(NULL); } diff --git a/alarm-notifications/source/main.c b/alarm-notifications/source/main.c index cef1670..073d760 100644 --- a/alarm-notifications/source/main.c +++ b/alarm-notifications/source/main.c @@ -37,6 +37,13 @@ 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: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + printf("alarm-notifications example\n"); Result rc=0, rc2=0; @@ -75,14 +82,14 @@ 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(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu if (R_SUCCEEDED(rc) && R_SUCCEEDED(eventWait(&alarmevent, 0))) { // Some official apps don't use this. See libnx notif.h for this. @@ -96,7 +103,7 @@ int main(int argc, char* argv[]) } if (R_SUCCEEDED(rc)) { - if (kDown & KEY_A) { + if (kDown & HidNpadButton_A) { // Setup an alarm with {current local-time} + {2 minutes}. You can use any weekday/time you want. // See libnx notif.h for more notifAlarmSetting*() funcs. @@ -121,7 +128,7 @@ int main(int argc, char* argv[]) if (R_SUCCEEDED(rc)) printf("alarm_setting_id = 0x%x\n", alarm_setting_id); } } - else if (kDown & KEY_B) { + else if (kDown & HidNpadButton_B) { // List the Alarms. total_out=0; @@ -160,8 +167,8 @@ int main(int argc, char* argv[]) } } } - else if ((kDown & KEY_X) && alarm_setting_id) { - // Delete the AlarmSetting which was registered with the KEY_A block. + else if ((kDown & HidNpadButton_X) && alarm_setting_id) { + // Delete the AlarmSetting which was registered with the HidNpadButton_A block. // If wanted, you can also use this with alarm_settings[alarmi].alarm_setting_id with the output from notifListAlarmSettings. rc = notifDeleteAlarmSetting(alarm_setting_id); printf("notifDeleteAlarmSetting(): 0x%x\n", rc); diff --git a/app_controldata/source/main.c b/app_controldata/source/main.c index a5f82c9..7962a1f 100644 --- a/app_controldata/source/main.c +++ b/app_controldata/source/main.c @@ -19,6 +19,13 @@ int main(int argc, char **argv) consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + buf = (NsApplicationControlData*)malloc(sizeof(NsApplicationControlData)); if (buf==NULL) { rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory); @@ -69,13 +76,13 @@ 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 (and they weren't in the previous frame) - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu consoleUpdate(NULL); } diff --git a/applet/app-playstats/source/main.c b/applet/app-playstats/source/main.c index 5e1ecdc..ff901b2 100644 --- a/applet/app-playstats/source/main.c +++ b/applet/app-playstats/source/main.c @@ -20,6 +20,13 @@ 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: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + printf("application play-stats example\n"); Result rc=0; @@ -53,17 +60,17 @@ 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(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu - if (kDown & KEY_A) { + if (kDown & HidNpadButton_A) { // Use appletQueryApplicationPlayStatisticsByUid if you want playstats for a specific userID. memset(stats, 0, sizeof(stats)); @@ -84,7 +91,7 @@ int main(int argc, char* argv[]) } } - if (initflag && (kDown & KEY_X)) { + if (initflag && (kDown & HidNpadButton_X)) { memset(events, 0, sizeof(events)); total_out = 0; diff --git a/applet/libapplets/error/source/main.c b/applet/libapplets/error/source/main.c index 0b731dd..4987159 100644 --- a/applet/libapplets/error/source/main.c +++ b/applet/libapplets/error/source/main.c @@ -24,6 +24,13 @@ 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: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + printf("error example\n"); consoleUpdate(NULL); @@ -34,17 +41,17 @@ 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(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu - if (kDown & KEY_A) { + if (kDown & HidNpadButton_A) { printf("Running errorResultRecordShow()...\n"); consoleUpdate(NULL); rc = errorResultRecordShow(MAKERESULT(16, 250), time(NULL)); diff --git a/applet/libapplets/pctlauth/source/main.c b/applet/libapplets/pctlauth/source/main.c index d085fde..1895cdd 100644 --- a/applet/libapplets/pctlauth/source/main.c +++ b/applet/libapplets/pctlauth/source/main.c @@ -23,6 +23,13 @@ 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: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + printf("pctlauth example\n"); consoleUpdate(NULL); @@ -47,17 +54,17 @@ 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(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu - if (pctlflag && (kDown & KEY_A)) { + if (pctlflag && (kDown & HidNpadButton_A)) { printf("Running pctlauthShow()...\n"); consoleUpdate(NULL); rc = pctlauthShow(true); // Launch the applet for validating the PIN. diff --git a/applet/libapplets/software-keyboard/source/main.c b/applet/libapplets/software-keyboard/source/main.c index ddfced1..145df49 100644 --- a/applet/libapplets/software-keyboard/source/main.c +++ b/applet/libapplets/software-keyboard/source/main.c @@ -57,6 +57,13 @@ 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: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + printf("swkbd example\n"); consoleUpdate(NULL); @@ -142,21 +149,21 @@ 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(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu // Your code goes here if (R_SUCCEEDED(rc)) { - if (kDown & KEY_ZR) swkbdInlineDisappear(&kbdinline); //Optional, you can have swkbd (dis)appear whenever. - if (kDown & KEY_Y) swkbdInlineAppear(&kbdinline, &appearArg); // If you use swkbdInlineAppear again after text was submitted, you may want to use swkbdInlineSetInputText since the current-text will be the same as when it was submitted otherwise. + if (kDown & HidNpadButton_ZR) swkbdInlineDisappear(&kbdinline); //Optional, you can have swkbd (dis)appear whenever. + if (kDown & HidNpadButton_Y) swkbdInlineAppear(&kbdinline, &appearArg); // If you use swkbdInlineAppear again after text was submitted, you may want to use swkbdInlineSetInputText since the current-text will be the same as when it was submitted otherwise. rc = swkbdInlineUpdate(&kbdinline, NULL); // Handles updating SwkbdInline state, this should be called periodically. if (R_FAILED(rc)) printf("swkbdInlineUpdate(): 0x%x\n", rc); diff --git a/applet/libapplets/web/source/main.c b/applet/libapplets/web/source/main.c index 9212c43..a3f9839 100644 --- a/applet/libapplets/web/source/main.c +++ b/applet/libapplets/web/source/main.c @@ -23,6 +23,13 @@ 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: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + printf("web example\n"); consoleUpdate(NULL); @@ -33,17 +40,17 @@ 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(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu - if (kDown & KEY_A) { + if (kDown & HidNpadButton_A) { WebCommonConfig config; WebCommonReply reply; WebExitReason exitReason=0; diff --git a/applet/light-sensor/source/main.c b/applet/light-sensor/source/main.c index dd33e8b..51d657a 100644 --- a/applet/light-sensor/source/main.c +++ b/applet/light-sensor/source/main.c @@ -18,6 +18,13 @@ 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: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + printf("light-sensor example\n"); printf("Press A to check light-sensor.\n"); printf("Press + to exit.\n"); @@ -25,17 +32,17 @@ 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(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu - if (kDown & KEY_A) { + if (kDown & HidNpadButton_A) { Result rc = 0; float fLux=0; bool availableflag=0; diff --git a/applet/lockexit/source/main.c b/applet/lockexit/source/main.c index cad7a63..4e6a52d 100644 --- a/applet/lockexit/source/main.c +++ b/applet/lockexit/source/main.c @@ -22,19 +22,26 @@ 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: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + printf("applet exit-locking example.\n"); // Main loop while (appletMainLoop())//This loop will automatically exit when applet requests exit. { - // 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(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu // Your code goes here diff --git a/applet/recording/source/main.c b/applet/recording/source/main.c index ce8af12..4385fcf 100644 --- a/applet/recording/source/main.c +++ b/applet/recording/source/main.c @@ -28,22 +28,29 @@ int main(int argc, char **argv) appletInitializeGamePlayRecording();//Normally this is only recording func you need to call. + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + u32 cnt = 0; 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 (and they weren't in the previous frame) - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu - if (kDown & KEY_Y) { + if (kDown & HidNpadButton_Y) { appletSetGamePlayRecordingState(0);//Disable recording. } - else if (kDown & KEY_X) { + else if (kDown & HidNpadButton_X) { appletSetGamePlayRecordingState(1);//Enable recording. } diff --git a/applet/screenshot-overlay/source/main.c b/applet/screenshot-overlay/source/main.c index 1068896..512c1d8 100644 --- a/applet/screenshot-overlay/source/main.c +++ b/applet/screenshot-overlay/source/main.c @@ -18,6 +18,13 @@ 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: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + printf("screenshot-overlay example\n"); // Setup the RGBA8 image. @@ -56,14 +63,14 @@ 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(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu // Update the console, sending a new frame to the display diff --git a/applet/vrmode/source/main.c b/applet/vrmode/source/main.c index 1906726..11337cf 100644 --- a/applet/vrmode/source/main.c +++ b/applet/vrmode/source/main.c @@ -24,6 +24,13 @@ 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: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + printf("VrMode example\n"); // Using pctl is optional. @@ -43,18 +50,18 @@ 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(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu if (pctlinit) { - if (kDown & KEY_A) { + if (kDown & HidNpadButton_A) { // Not sure what this is. /*rc = pctlConfirmStereoVisionPermission(); if (R_FAILED(rc)) printf("pctlConfirmStereoVisionPermission(): 0x%x\n", rc);*/ @@ -70,7 +77,7 @@ int main(int argc, char* argv[]) printf("appletSetVrModeEnabled(true): 0x%x\n", rc); } } - else if (kDown & KEY_B) { + else if (kDown & HidNpadButton_B) { rc = appletSetVrModeEnabled(false); printf("appletSetVrModeEnabled(false): 0x%x\n", rc); @@ -78,7 +85,7 @@ int main(int argc, char* argv[]) /*rc = pctlResetConfirmedStereoVisionPermission(); printf("pctlResetConfirmedStereoVisionPermission(): 0x%x\n", rc);*/ } - else if (kDown & KEY_X) { + else if (kDown & HidNpadButton_X) { bool flag=0; rc = appletIsVrModeEnabled(&flag); printf("appletIsVrModeEnabled(): 0x%x", rc); diff --git a/audio/audren-simple/source/main.c b/audio/audren-simple/source/main.c index 8647d1a..351621f 100644 --- a/audio/audren-simple/source/main.c +++ b/audio/audren-simple/source/main.c @@ -13,6 +13,13 @@ int main(void) { consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + printf("Simple audren demonstration program\n"); static const AudioRendererConfig arConfig = @@ -57,7 +64,7 @@ int main(void) audrvMemPoolAttach(&drv, mpid); static const u8 sink_channels[] = { 0, 1 }; - int sink = audrvDeviceSinkAdd(&drv, AUDREN_DEFAULT_DEVICE_NAME, 2, sink_channels); + /*int sink =*/ audrvDeviceSinkAdd(&drv, AUDREN_DEFAULT_DEVICE_NAME, 2, sink_channels); res = audrvUpdate(&drv); printf("audrvUpdate: %" PRIx32 "\n", res); @@ -77,16 +84,16 @@ int main(void) // Main loop while (appletMainLoop()) { - hidScanInput(); + padUpdate(&pad); - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; if (initedDriver) { - if (kDown & KEY_A) + if (kDown & HidNpadButton_A) { audrvVoiceStop(&drv, 0); audrvVoiceAddWaveBuf(&drv, 0, &wavebuf); diff --git a/audio/echo/source/main.c b/audio/echo/source/main.c index a8fab36..9ff880c 100644 --- a/audio/echo/source/main.c +++ b/audio/echo/source/main.c @@ -22,6 +22,13 @@ int main(int argc, char **argv) // Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one. consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + AudioInBuffer audin_buf; AudioOutBuffer audout_buf; AudioInBuffer *released_in_buffer; @@ -108,13 +115,13 @@ int main(int argc, char **argv) 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 (and they weren't in the previous frame) - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu // Wait for audio capture and playback to finish. audinWaitCaptureFinish(&released_in_buffer, &released_in_count, UINT64_MAX); diff --git a/audio/hwopus-decoder/source/main.c b/audio/hwopus-decoder/source/main.c index f89de68..8ffcb3a 100644 --- a/audio/hwopus-decoder/source/main.c +++ b/audio/hwopus-decoder/source/main.c @@ -53,6 +53,13 @@ int main(void) { consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + printf("Simple hwopus-decoder example with audren\n"); static const AudioRendererConfig arConfig = @@ -122,7 +129,7 @@ int main(void) audrvMemPoolAttach(&drv, mpid); static const u8 sink_channels[] = { 0, 1 }; - int sink = audrvDeviceSinkAdd(&drv, AUDREN_DEFAULT_DEVICE_NAME, 2, sink_channels); + /*int sink =*/ audrvDeviceSinkAdd(&drv, AUDREN_DEFAULT_DEVICE_NAME, 2, sink_channels); res = audrvUpdate(&drv); printf("audrvUpdate: %" PRIx32 "\n", res); @@ -163,16 +170,16 @@ int main(void) // Main loop while (appletMainLoop()) { - hidScanInput(); + padUpdate(&pad); - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; if (initedDriver) { - if (kDown & KEY_A) + if (kDown & HidNpadButton_A) { //Close the opus-file if needed and (re)open it, since libopusfile doesn't support seek-to-beginning. if (of) diff --git a/audio/playtone/source/main.c b/audio/playtone/source/main.c index c0a8814..3c587b9 100644 --- a/audio/playtone/source/main.c +++ b/audio/playtone/source/main.c @@ -38,6 +38,13 @@ int main(int argc, char **argv) // Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one. consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + AudioOutBuffer audout_buf; AudioOutBuffer *audout_released_buf; @@ -82,57 +89,57 @@ int main(int argc, char **argv) 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 (and they weren't in the previous frame) - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu - if (kDown & KEY_A) + if (kDown & HidNpadButton_A) { fill_audio_buffer(out_buf_data, 0, data_size, notefreq[0]); play_tone = true; } - if (kDown & KEY_B) + if (kDown & HidNpadButton_B) { fill_audio_buffer(out_buf_data, 0, data_size, notefreq[1]); play_tone = true; } - if (kDown & KEY_Y) + if (kDown & HidNpadButton_Y) { fill_audio_buffer(out_buf_data, 0, data_size, notefreq[2]); play_tone = true; } - if (kDown & KEY_X) + if (kDown & HidNpadButton_X) { fill_audio_buffer(out_buf_data, 0, data_size, notefreq[3]); play_tone = true; } - if (kDown & KEY_DLEFT) + if (kDown & HidNpadButton_Left) { fill_audio_buffer(out_buf_data, 0, data_size, notefreq[4]); play_tone = true; } - if (kDown & KEY_DUP) + if (kDown & HidNpadButton_Up) { fill_audio_buffer(out_buf_data, 0, data_size, notefreq[5]); play_tone = true; } - if (kDown & KEY_DRIGHT) + if (kDown & HidNpadButton_Right) { fill_audio_buffer(out_buf_data, 0, data_size, notefreq[6]); play_tone = true; } - if (kDown & KEY_DDOWN) + if (kDown & HidNpadButton_Down) { fill_audio_buffer(out_buf_data, 0, data_size, notefreq[7]); play_tone = true; @@ -150,13 +157,13 @@ int main(int argc, char **argv) play_tone = true; } - if (kDown & KEY_ZL) + if (kDown & HidNpadButton_ZL) { fill_audio_buffer(out_buf_data, 0, data_size, notefreq[10]); play_tone = true; } - if (kDown & KEY_ZR) + if (kDown & HidNpadButton_ZR) { fill_audio_buffer(out_buf_data, 0, data_size, notefreq[11]); play_tone = true; diff --git a/audio/sdl2-audio/source/main.c b/audio/sdl2-audio/source/main.c index 5892289..905a518 100644 --- a/audio/sdl2-audio/source/main.c +++ b/audio/sdl2-audio/source/main.c @@ -17,6 +17,13 @@ int main(int argc, char *argv[]) consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + Result rc = romfsInit(); if (R_FAILED(rc)) printf("romfsInit: %08X\n", rc); @@ -41,17 +48,17 @@ 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(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu - if (kDown & KEY_A) + if (kDown & HidNpadButton_A) Mix_PlayMusic(audio, 1); //Play the audio file // Update the console, sending a new frame to the display diff --git a/exception-handler/source/main.c b/exception-handler/source/main.c index 5d22d81..c7e320d 100644 --- a/exception-handler/source/main.c +++ b/exception-handler/source/main.c @@ -47,6 +47,13 @@ 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: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + printf("Triggering crash...\n"); consoleUpdate(NULL); @@ -56,14 +63,14 @@ 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(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu // Your code goes here diff --git a/fs/romfs/source/main.c b/fs/romfs/source/main.c index 5d2f64f..ef29d6e 100644 --- a/fs/romfs/source/main.c +++ b/fs/romfs/source/main.c @@ -32,6 +32,13 @@ int main(int argc, char **argv) { consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + Result rc = romfsInit(); if (R_FAILED(rc)) printf("romfsInit: %08X\n", rc); @@ -46,13 +53,13 @@ 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 (and they weren't in the previous frame) - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu consoleUpdate(NULL); } diff --git a/fs/save/source/main.c b/fs/save/source/main.c index d465778..097b451 100644 --- a/fs/save/source/main.c +++ b/fs/save/source/main.c @@ -51,6 +51,13 @@ int main(int argc, char **argv) consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + //Get the userID for save mounting. To mount common savedata, use an all-zero userID. //Try to find savedata to use with get_save() first, otherwise fallback to the above hard-coded TID + the userID from accountGetPreselectedUser(). Note that you can use either method. @@ -113,13 +120,13 @@ 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 (and they weren't in the previous frame) - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu consoleUpdate(NULL); } diff --git a/fs/sdmc/source/main.c b/fs/sdmc/source/main.c index 0c4da0d..eb37a3d 100644 --- a/fs/sdmc/source/main.c +++ b/fs/sdmc/source/main.c @@ -11,6 +11,13 @@ int main(int argc, char **argv) { consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + DIR* dir; struct dirent* ent; @@ -33,13 +40,13 @@ 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 (and they weren't in the previous frame) - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu consoleUpdate(NULL); } diff --git a/graphics/deko3d/deko_basic/source/main.c b/graphics/deko3d/deko_basic/source/main.c index 22d2e61..03cf846 100644 --- a/graphics/deko3d/deko_basic/source/main.c +++ b/graphics/deko3d/deko_basic/source/main.c @@ -209,12 +209,19 @@ int main(int argc, char* argv[]) romfsInit(); graphicsInitialize(); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + while (appletMainLoop()) { - hidScanInput(); + padUpdate(&pad); - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) + u64 kDown = padGetButtonsDown(&pad); + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu graphicsUpdate(); diff --git a/graphics/deko3d/deko_console/source/main.c b/graphics/deko3d/deko_console/source/main.c index 81d7863..71b60a9 100644 --- a/graphics/deko3d/deko_console/source/main.c +++ b/graphics/deko3d/deko_console/source/main.c @@ -7,6 +7,13 @@ int main(int argc, char **argv) { consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + // clear screen and home cursor printf( CONSOLE_ESC(2J) ); @@ -61,15 +68,15 @@ 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); // Your code goes here - //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu consoleUpdate(NULL); } diff --git a/graphics/deko3d/deko_examples/source/Example01_SimpleSetup.cpp b/graphics/deko3d/deko_examples/source/Example01_SimpleSetup.cpp index 904dcb3..4857cd8 100644 --- a/graphics/deko3d/deko_examples/source/Example01_SimpleSetup.cpp +++ b/graphics/deko3d/deko_examples/source/Example01_SimpleSetup.cpp @@ -24,6 +24,8 @@ class CExample01 final : public CApplication static constexpr uint32_t FramebufferHeight = 720; static constexpr unsigned StaticCmdSize = 0x1000; + PadState pad; + dk::UniqueDevice device; dk::UniqueQueue queue; @@ -59,6 +61,10 @@ public: // Create the framebuffer resources createFramebufferResources(); + + // Initialize gamepad + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + padInitializeDefault(&pad); } ~CExample01() @@ -159,9 +165,9 @@ public: bool onFrame(u64 ns) override { - hidScanInput(); - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) + padUpdate(&pad); + u64 kDown = padGetButtonsDown(&pad); + if (kDown & HidNpadButton_Plus) return false; render(); diff --git a/graphics/deko3d/deko_examples/source/Example02_Triangle.cpp b/graphics/deko3d/deko_examples/source/Example02_Triangle.cpp index 97eaa35..2c514ea 100644 --- a/graphics/deko3d/deko_examples/source/Example02_Triangle.cpp +++ b/graphics/deko3d/deko_examples/source/Example02_Triangle.cpp @@ -51,6 +51,8 @@ class CExample02 final : public CApplication static constexpr uint32_t FramebufferHeight = 720; static constexpr unsigned StaticCmdSize = 0x10000; + PadState pad; + dk::UniqueDevice device; dk::UniqueQueue queue; @@ -101,6 +103,10 @@ public: // Create the framebuffer resources createFramebufferResources(); + + // Initialize gamepad + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + padInitializeDefault(&pad); } ~CExample02() @@ -214,9 +220,9 @@ public: bool onFrame(u64 ns) override { - hidScanInput(); - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) + padUpdate(&pad); + u64 kDown = padGetButtonsDown(&pad); + if (kDown & HidNpadButton_Plus) return false; render(); diff --git a/graphics/deko3d/deko_examples/source/Example03_Cube.cpp b/graphics/deko3d/deko_examples/source/Example03_Cube.cpp index 18effe0..273a236 100644 --- a/graphics/deko3d/deko_examples/source/Example03_Cube.cpp +++ b/graphics/deko3d/deko_examples/source/Example03_Cube.cpp @@ -104,6 +104,8 @@ class CExample03 final : public CApplication static constexpr unsigned StaticCmdSize = 0x10000; static constexpr unsigned DynamicCmdSize = 0x10000; + PadState pad; + dk::UniqueDevice device; dk::UniqueQueue queue; @@ -169,6 +171,10 @@ public: // Load the vertex buffer vertexBuffer = pool_data->allocate(sizeof(CubeVertexData), alignof(Vertex)); memcpy(vertexBuffer.getCpuAddr(), CubeVertexData.data(), vertexBuffer.getSize()); + + // Initialize gamepad + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + padInitializeDefault(&pad); } ~CExample03() @@ -339,9 +345,9 @@ public: bool onFrame(u64 ns) override { - hidScanInput(); - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) + padUpdate(&pad); + u64 kDown = padGetButtonsDown(&pad); + if (kDown & HidNpadButton_Plus) return false; float time = ns / 1000000000.0; // double precision division; followed by implicit cast to single precision diff --git a/graphics/deko3d/deko_examples/source/Example04_TexturedCube.cpp b/graphics/deko3d/deko_examples/source/Example04_TexturedCube.cpp index c1a5962..a3a9982 100644 --- a/graphics/deko3d/deko_examples/source/Example04_TexturedCube.cpp +++ b/graphics/deko3d/deko_examples/source/Example04_TexturedCube.cpp @@ -109,6 +109,8 @@ class CExample04 final : public CApplication static constexpr unsigned MaxImages = 1; static constexpr unsigned MaxSamplers = 1; + PadState pad; + dk::UniqueDevice device; dk::UniqueQueue queue; @@ -210,6 +212,10 @@ public: queue.waitIdle(); cmdbuf.clear(); } + + // Initialize gamepad + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + padInitializeDefault(&pad); } ~CExample04() @@ -381,9 +387,9 @@ public: bool onFrame(u64 ns) override { - hidScanInput(); - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) + padUpdate(&pad); + u64 kDown = padGetButtonsDown(&pad); + if (kDown & HidNpadButton_Plus) return false; float time = ns / 1000000000.0; // double precision division; followed by implicit cast to single precision diff --git a/graphics/deko3d/deko_examples/source/Example05_Tessellation.cpp b/graphics/deko3d/deko_examples/source/Example05_Tessellation.cpp index a456436..910f6bd 100644 --- a/graphics/deko3d/deko_examples/source/Example05_Tessellation.cpp +++ b/graphics/deko3d/deko_examples/source/Example05_Tessellation.cpp @@ -52,6 +52,8 @@ class CExample05 final : public CApplication static constexpr uint32_t FramebufferHeight = 720; static constexpr unsigned StaticCmdSize = 0x10000; + PadState pad; + dk::UniqueDevice device; dk::UniqueQueue queue; @@ -106,6 +108,10 @@ public: // Create the framebuffer resources createFramebufferResources(); + + // Initialize gamepad + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + padInitializeDefault(&pad); } ~CExample05() @@ -236,9 +242,9 @@ public: bool onFrame(u64 ns) override { - hidScanInput(); - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) + padUpdate(&pad); + u64 kDown = padGetButtonsDown(&pad); + if (kDown & HidNpadButton_Plus) return false; render(); diff --git a/graphics/deko3d/deko_examples/source/Example06_Multisampling.cpp b/graphics/deko3d/deko_examples/source/Example06_Multisampling.cpp index 639dddd..90e826f 100644 --- a/graphics/deko3d/deko_examples/source/Example06_Multisampling.cpp +++ b/graphics/deko3d/deko_examples/source/Example06_Multisampling.cpp @@ -104,6 +104,8 @@ class CExample06 final : public CApplication static constexpr unsigned DynamicCmdSize = 0x10000; static constexpr DkMsMode MultisampleMode = DkMsMode_4x; + PadState pad; + dk::UniqueDevice device; dk::UniqueQueue queue; @@ -171,6 +173,10 @@ public: // Load the vertex buffer vertexBuffer = pool_data->allocate(sizeof(CubeVertexData), alignof(Vertex)); memcpy(vertexBuffer.getCpuAddr(), CubeVertexData.data(), vertexBuffer.getSize()); + + // Initialize gamepad + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + padInitializeDefault(&pad); } ~CExample06() @@ -375,9 +381,9 @@ public: bool onFrame(u64 ns) override { - hidScanInput(); - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) + padUpdate(&pad); + u64 kDown = padGetButtonsDown(&pad); + if (kDown & HidNpadButton_Plus) return false; float time = ns / 1000000000.0; // double precision division; followed by implicit cast to single precision diff --git a/graphics/deko3d/deko_examples/source/Example07_MeshLighting.cpp b/graphics/deko3d/deko_examples/source/Example07_MeshLighting.cpp index 9c3089d..fda8ea2 100644 --- a/graphics/deko3d/deko_examples/source/Example07_MeshLighting.cpp +++ b/graphics/deko3d/deko_examples/source/Example07_MeshLighting.cpp @@ -74,6 +74,8 @@ class CExample07 final : public CApplication static constexpr unsigned DynamicCmdSize = 0x10000; static constexpr DkMsMode MultisampleMode = DkMsMode_4x; + PadState pad; + dk::UniqueDevice device; dk::UniqueQueue queue; @@ -154,6 +156,10 @@ public: // Load the teapot mesh vertexBuffer = LoadFile(*pool_data, "romfs:/teapot-vtx.bin", alignof(Vertex)); indexBuffer = LoadFile(*pool_data, "romfs:/teapot-idx.bin", alignof(u16)); + + // Initialize gamepad + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + padInitializeDefault(&pad); } ~CExample07() @@ -368,9 +374,9 @@ public: bool onFrame(u64 ns) override { - hidScanInput(); - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) + padUpdate(&pad); + u64 kDown = padGetButtonsDown(&pad); + if (kDown & HidNpadButton_Plus) return false; float time = ns / 1000000000.0; // double precision division; followed by implicit cast to single precision diff --git a/graphics/deko3d/deko_examples/source/Example08_DeferredShading.cpp b/graphics/deko3d/deko_examples/source/Example08_DeferredShading.cpp index 7a24662..008c927 100644 --- a/graphics/deko3d/deko_examples/source/Example08_DeferredShading.cpp +++ b/graphics/deko3d/deko_examples/source/Example08_DeferredShading.cpp @@ -76,6 +76,8 @@ class CExample08 final : public CApplication static constexpr unsigned MaxImages = 3; static constexpr unsigned MaxSamplers = 1; + PadState pad; + dk::UniqueDevice device; dk::UniqueQueue queue; @@ -188,6 +190,10 @@ public: queue.waitIdle(); cmdbuf.clear(); } + + // Initialize gamepad + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + padInitializeDefault(&pad); } void createFramebufferResources() @@ -449,9 +455,9 @@ public: bool onFrame(u64 ns) override { - hidScanInput(); - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) + padUpdate(&pad); + u64 kDown = padGetButtonsDown(&pad); + if (kDown & HidNpadButton_Plus) return false; float time = ns / 1000000000.0; // double precision division; followed by implicit cast to single precision diff --git a/graphics/deko3d/deko_examples/source/Example09_SimpleCompute.cpp b/graphics/deko3d/deko_examples/source/Example09_SimpleCompute.cpp index 324ca8a..1235a3f 100644 --- a/graphics/deko3d/deko_examples/source/Example09_SimpleCompute.cpp +++ b/graphics/deko3d/deko_examples/source/Example09_SimpleCompute.cpp @@ -69,6 +69,8 @@ class CExample09 final : public CApplication static constexpr unsigned DynamicCmdSize = 0x10000; static constexpr unsigned NumVertices = 256; + PadState pad; + dk::UniqueDevice device; dk::UniqueQueue queue; @@ -138,6 +140,10 @@ public: // Create the framebuffer resources createFramebufferResources(); + + // Initialize gamepad + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + padInitializeDefault(&pad); } ~CExample09() @@ -291,9 +297,9 @@ public: bool onFrame(u64 ns) override { - hidScanInput(); - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) + padUpdate(&pad); + u64 kDown = padGetButtonsDown(&pad); + if (kDown & HidNpadButton_Plus) return false; float time = ns / 1000000000.0; // double precision division; followed by implicit cast to single precision diff --git a/graphics/deko3d/deko_examples/source/main.cpp b/graphics/deko3d/deko_examples/source/main.cpp index 2e68447..bf861d3 100644 --- a/graphics/deko3d/deko_examples/source/main.cpp +++ b/graphics/deko3d/deko_examples/source/main.cpp @@ -46,6 +46,8 @@ class CMainMenu final : public CApplication static constexpr unsigned EntriesPerScreen = 39; static constexpr unsigned EntryPageLength = 10; + PadState pad; + int screenPos; int selectPos; @@ -69,6 +71,10 @@ class CMainMenu final : public CApplication { consoleInit(NULL); renderMenu(); + + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + padInitializeDefault(&pad); + padUpdate(&pad); } ~CMainMenu() @@ -79,23 +85,23 @@ class CMainMenu final : public CApplication bool onFrame(u64 ns) override { int oldPos = selectPos; - hidScanInput(); + padUpdate(&pad); - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) + u64 kDown = padGetButtonsDown(&pad); + if (kDown & HidNpadButton_Plus) { selectPos = -1; return false; } - if (kDown & KEY_A) + if (kDown & HidNpadButton_A) return false; - if (kDown & KEY_UP) + if (kDown & HidNpadButton_AnyUp) selectPos -= 1; - if (kDown & KEY_DOWN) + if (kDown & HidNpadButton_AnyDown) selectPos += 1; - if (kDown & KEY_LEFT) + if (kDown & HidNpadButton_AnyLeft) selectPos -= EntryPageLength; - if (kDown & KEY_RIGHT) + if (kDown & HidNpadButton_AnyRight) selectPos += EntryPageLength; if (selectPos < 0) diff --git a/graphics/opengl/dynamic_resolution/source/main.cpp b/graphics/opengl/dynamic_resolution/source/main.cpp index a800cf8..98aa17c 100644 --- a/graphics/opengl/dynamic_resolution/source/main.cpp +++ b/graphics/opengl/dynamic_resolution/source/main.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -430,16 +430,16 @@ static void sceneUpdate(u32 kHeld) float deltaTime = curTime - s_updTime; s_updTime = curTime; - if (kHeld & KEY_LEFT) + if (kHeld & HidNpadButton_AnyLeft) s_cameraAngle = fract(s_cameraAngle - deltaTime/4); - else if (kHeld & KEY_RIGHT) + else if (kHeld & HidNpadButton_AnyRight) s_cameraAngle = fract(s_cameraAngle + deltaTime/4); - if (kHeld & (KEY_UP|KEY_DOWN)) + if (kHeld & (HidNpadButton_AnyUp|HidNpadButton_AnyDown)) { glm::vec3 front = deltaTime * glm::rotate(glm::vec3{0.0f, 0.0f, -1.0f}, s_cameraAngle * TAU, glm::vec3{0.0f, -1.0f, 0.0f}); - if (kHeld & KEY_UP) + if (kHeld & HidNpadButton_AnyUp) s_cameraPos += front; - else if (kHeld & KEY_DOWN) + else if (kHeld & HidNpadButton_AnyDown) s_cameraPos -= front; } @@ -525,17 +525,24 @@ int main(int argc, char* argv[]) // Initialize our scene sceneInit(); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + // Main graphics loop while (appletMainLoop()) { // Get and process input - hidScanInput(); - u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - u32 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) + padUpdate(&pad); + u32 kDown = padGetButtonsDown(&pad); + u32 kHeld = padGetButtons(&pad); + if (kDown & HidNpadButton_Plus) break; - bool shouldHalveResolution = !!(kHeld & KEY_A); + bool shouldHalveResolution = !!(kHeld & HidNpadButton_A); // Configure the resolution used to render the scene, which // will be different in handheld mode/docked mode. diff --git a/graphics/opengl/es2gears/source/main.c b/graphics/opengl/es2gears/source/main.c index a82e061..075463b 100644 --- a/graphics/opengl/es2gears/source/main.c +++ b/graphics/opengl/es2gears/source/main.c @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -855,13 +855,20 @@ int main(int argc, char* argv[]) gears_init(); gears_reshape(1280, 720); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + // Main graphics loop while (appletMainLoop()) { // Get and process input - hidScanInput(); - u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) + padUpdate(&pad); + u32 kDown = padGetButtonsDown(&pad); + if (kDown & HidNpadButton_Plus) break; // Render stuff! diff --git a/graphics/opengl/gpu_console/source/main.c b/graphics/opengl/gpu_console/source/main.c index 83c1525..023e877 100644 --- a/graphics/opengl/gpu_console/source/main.c +++ b/graphics/opengl/gpu_console/source/main.c @@ -7,6 +7,13 @@ int main(int argc, char **argv) { consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + // clear screen and home cursor printf( CONSOLE_ESC(2J) ); @@ -46,15 +53,15 @@ 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); // Your code goes here - //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu consoleUpdate(NULL); } diff --git a/graphics/opengl/lenny/source/main.cpp b/graphics/opengl/lenny/source/main.cpp index 8cd29c1..09328d6 100644 --- a/graphics/opengl/lenny/source/main.cpp +++ b/graphics/opengl/lenny/source/main.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -414,13 +414,20 @@ int main(int argc, char* argv[]) // Initialize our scene sceneInit(); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + // Main graphics loop while (appletMainLoop()) { // Get and process input - hidScanInput(); - u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) + padUpdate(&pad); + u32 kDown = padGetButtonsDown(&pad); + if (kDown & HidNpadButton_Plus) break; // Update our scene diff --git a/graphics/opengl/simple_triangle/source/main.cpp b/graphics/opengl/simple_triangle/source/main.cpp index b93cdc0..391c3e3 100644 --- a/graphics/opengl/simple_triangle/source/main.cpp +++ b/graphics/opengl/simple_triangle/source/main.cpp @@ -325,13 +325,20 @@ int main(int argc, char* argv[]) // Initialize our scene sceneInit(); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + // Main graphics loop while (appletMainLoop()) { // Get and process input - hidScanInput(); - u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) + padUpdate(&pad); + u32 kDown = padGetButtonsDown(&pad); + if (kDown & HidNpadButton_Plus) break; // Render stuff! diff --git a/graphics/opengl/textured_cube/source/main.cpp b/graphics/opengl/textured_cube/source/main.cpp index 1e9c91d..9eab9ec 100644 --- a/graphics/opengl/textured_cube/source/main.cpp +++ b/graphics/opengl/textured_cube/source/main.cpp @@ -514,13 +514,20 @@ int main(int argc, char* argv[]) // Initialize our scene sceneInit(); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + // Main graphics loop while (appletMainLoop()) { // Get and process input - hidScanInput(); - u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) + padUpdate(&pad); + u32 kDown = padGetButtonsDown(&pad); + if (kDown & HidNpadButton_Plus) break; // Update our scene diff --git a/graphics/printing/hello-world/source/main.c b/graphics/printing/hello-world/source/main.c index 488701b..aaad996 100644 --- a/graphics/printing/hello-world/source/main.c +++ b/graphics/printing/hello-world/source/main.c @@ -8,6 +8,13 @@ int main(int argc, char **argv) //Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one. consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + //Move the cursor to row 16 and column 20 and then prints "Hello World!" //To move the cursor you have to print "\x1b[r;cH", where r and c are respectively //the row and column where you want your cursor to move @@ -15,13 +22,13 @@ int main(int argc, char **argv) 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 (and they weren't in the previous frame) - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu consoleUpdate(NULL); } diff --git a/graphics/printing/vt52-demo/source/main.c b/graphics/printing/vt52-demo/source/main.c index dd70da9..7171df8 100644 --- a/graphics/printing/vt52-demo/source/main.c +++ b/graphics/printing/vt52-demo/source/main.c @@ -7,6 +7,13 @@ int main(int argc, char **argv) { consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + // clear screen and home cursor printf( CONSOLE_ESC(2J) ); @@ -61,15 +68,15 @@ 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); // Your code goes here - //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu consoleUpdate(NULL); } diff --git a/graphics/shared_font/source/main.c b/graphics/shared_font/source/main.c index 1c32d95..f61c475 100644 --- a/graphics/shared_font/source/main.c +++ b/graphics/shared_font/source/main.c @@ -18,6 +18,8 @@ static u32 framebuf_width=0; +static PadState pad; + //Note that this doesn't handle any blending. void draw_glyph(FT_Bitmap* bitmap, u32* framebuf, u32 x, u32 y) { @@ -102,8 +104,8 @@ static int error_screen(const char* fmt, ...) printf("Press PLUS to exit\n"); while (appletMainLoop()) { - hidScanInput(); - if (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_PLUS) + padUpdate(&pad); + if (padGetButtonsDown(&pad) & HidNpadButton_Plus) break; consoleUpdate(NULL); } @@ -149,6 +151,12 @@ int main(int argc, char **argv) Result rc=0; FT_Error ret=0; + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + padInitializeDefault(&pad); + //Use this when using multiple shared-fonts. /* PlFontData fonts[PlSharedFontType_Total]; @@ -198,13 +206,13 @@ int main(int argc, char **argv) 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 (and they weren't in the previous frame) - u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u32 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu u32 stride; u32* framebuf = (u32*)framebufferBegin(&fb, &stride); diff --git a/graphics/simplegfx/source/main.c b/graphics/simplegfx/source/main.c index c879ace..c7edaad 100644 --- a/graphics/simplegfx/source/main.c +++ b/graphics/simplegfx/source/main.c @@ -35,19 +35,26 @@ int main(int argc, char* argv[]) u8* imageptr = (u8*)image_bin; #endif + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + u32 cnt = 0; // 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(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu // Retrieve the framebuffer diff --git a/graphics/simplegfx_moviemaker/source/main.c b/graphics/simplegfx_moviemaker/source/main.c index 382b26d..ac6c12c 100644 --- a/graphics/simplegfx_moviemaker/source/main.c +++ b/graphics/simplegfx_moviemaker/source/main.c @@ -104,19 +104,26 @@ int main(int argc, char* argv[]) u8* imageptr = (u8*)image_bin; #endif + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + u32 cnt = 0; // 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(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu // Retrieve the framebuffer. diff --git a/jit/source/main.c b/jit/source/main.c index d30fae9..2fba345 100644 --- a/jit/source/main.c +++ b/jit/source/main.c @@ -15,13 +15,23 @@ int main(int argc, char **argv) consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + rc = jitCreate(&j, 0x100000);//Adjust size as needed. printf("jitCreate() returned: 0x%x\n", rc); + printf("jit type: %d\n", j.type); if (R_SUCCEEDED(rc)) { jit_rwaddr = jitGetRwAddr(&j); jit_rxaddr = jitGetRxAddr(&j); + printf("jitGetRwAddr(): %p\n", jit_rwaddr); + printf("jitGetRxAddr(): %p\n", jit_rxaddr); rc = jitTransitionToWritable(&j); printf("jitTransitionToWritable() returned: 0x%x\n", rc); @@ -47,15 +57,15 @@ 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); // Your code goes here - //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu consoleUpdate(NULL); } diff --git a/misc/barrier/source/main.c b/misc/barrier/source/main.c index 095de6d..5ba93fb 100644 --- a/misc/barrier/source/main.c +++ b/misc/barrier/source/main.c @@ -35,6 +35,13 @@ int main(int argc, char **argv) { consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + mutexInit(&g_PrintMutex); barrierInit(&g_Barrier, 4); @@ -61,11 +68,11 @@ int main(int argc, char **argv) while(appletMainLoop()) { - hidScanInput(); + padUpdate(&pad); - u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + u32 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; mutexLock(&g_PrintMutex); diff --git a/misc/user_events/source/main.c b/misc/user_events/source/main.c index cc07c5a..ef34b2b 100644 --- a/misc/user_events/source/main.c +++ b/misc/user_events/source/main.c @@ -54,6 +54,13 @@ int main(int argc, char **argv) { consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + mutexInit(&g_PrintMutex); ueventCreate(&g_Event, false); ueventCreate(&g_ExitEvent, false); @@ -88,11 +95,11 @@ int main(int argc, char **argv) while (appletMainLoop()) { - hidScanInput(); + padUpdate(&pad); - u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + u32 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; consoleUpdate(NULL); diff --git a/misc/user_timers/source/main.c b/misc/user_timers/source/main.c index 3db3108..08efc27 100644 --- a/misc/user_timers/source/main.c +++ b/misc/user_timers/source/main.c @@ -50,6 +50,13 @@ int main(int argc, char **argv) { consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + mutexInit(&g_PrintMutex); utimerCreate(&g_Timer, 2000000000, TimerType_Repeating); // 2s utimerCreate(&g_FastTimer, 1000000000, TimerType_Repeating); // 1s @@ -93,11 +100,11 @@ int main(int argc, char **argv) while(appletMainLoop()) { - hidScanInput(); + padUpdate(&pad); - u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + u32 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; consoleUpdate(NULL); diff --git a/network/curl/source/main.c b/network/curl/source/main.c index 21cbc74..e5d896e 100644 --- a/network/curl/source/main.c +++ b/network/curl/source/main.c @@ -48,6 +48,13 @@ 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: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + socketInitializeDefault(); printf("curl example\n"); @@ -57,14 +64,14 @@ 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(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu // Your code goes here diff --git a/network/ldn/source/main.c b/network/ldn/source/main.c index 6b161e4..78fbb63 100644 --- a/network/ldn/source/main.c +++ b/network/ldn/source/main.c @@ -112,6 +112,13 @@ 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: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + // Initialise sockets socketInitializeDefault(); @@ -208,23 +215,23 @@ 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 (and they weren't in the previous frame) - u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u32 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu - if (R_SUCCEEDED(rc) && (kDown & (KEY_A|KEY_B))) { + if (R_SUCCEEDED(rc) && (kDown & (HidNpadButton_A|HidNpadButton_B))) { Result rc2 = ldnGetState(&state); printf("ldnGetState(): 0x%x, %d\n", rc, state); if (R_SUCCEEDED(rc2) && state==LdnState_Initialized) { - if (kDown & KEY_A) { + if (kDown & HidNpadButton_A) { rc2 = create_network(&sec_config, &user_config, &netconfig, advert, sizeof(advert)); printf("create_network(): 0x%x\n", rc2); } - if (kDown & KEY_B) { + if (kDown & HidNpadButton_B) { rc2 = connect_network(&filter, &sec_config, &user_config, advert, sizeof(advert)); printf("connect_network(): 0x%x\n", rc2); } @@ -274,7 +281,7 @@ int main(int argc, char **argv) } } - if (R_SUCCEEDED(rc) && (kDown & KEY_X)) { + if (R_SUCCEEDED(rc) && (kDown & HidNpadButton_X)) { if (sockfd >= 0) { close(sockfd); sockfd = -1; @@ -282,14 +289,14 @@ int main(int argc, char **argv) leave_network(); } - if (R_SUCCEEDED(rc) && sockfd>=0 && (kDown & (KEY_DLEFT|KEY_DRIGHT|KEY_DUP|KEY_DDOWN))) { + if (R_SUCCEEDED(rc) && sockfd>=0 && (kDown & (HidNpadButton_Left|HidNpadButton_Right|HidNpadButton_Up|HidNpadButton_Down))) { char tmpstr[32]; memset(tmpstr, 0, sizeof(tmpstr)); - if (kDown & KEY_DLEFT) strncpy(tmpstr, "Button DLEFT pressed.", sizeof(tmpstr)-1); - else if (kDown & KEY_DRIGHT) strncpy(tmpstr, "Button DRIGHT pressed.", sizeof(tmpstr)-1); - else if (kDown & KEY_DUP) strncpy(tmpstr, "Button DUP pressed.", sizeof(tmpstr)-1); - else if (kDown & KEY_DDOWN) strncpy(tmpstr, "Button DDOWN pressed.", sizeof(tmpstr)-1); + if (kDown & HidNpadButton_Left) strncpy(tmpstr, "Button DLEFT pressed.", sizeof(tmpstr)-1); + else if (kDown & HidNpadButton_Right) strncpy(tmpstr, "Button DRIGHT pressed.", sizeof(tmpstr)-1); + else if (kDown & HidNpadButton_Up) strncpy(tmpstr, "Button DUP pressed.", sizeof(tmpstr)-1); + else if (kDown & HidNpadButton_Down) strncpy(tmpstr, "Button DDOWN pressed.", sizeof(tmpstr)-1); ssize_t ret = sendto(sockfd, tmpstr, sizeof(tmpstr), 0, (struct sockaddr*) &serv_addr, sizeof(struct sockaddr_in)); int tmp = errno; diff --git a/network/nxlink_stdio/source/main.c b/network/nxlink_stdio/source/main.c index e474d9d..27e0063 100644 --- a/network/nxlink_stdio/source/main.c +++ b/network/nxlink_stdio/source/main.c @@ -20,6 +20,13 @@ int main(int argc, char **argv) { consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + // Initialise sockets socketInitializeDefault(); @@ -44,20 +51,20 @@ 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); // Your code goes here - //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) - u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u32 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu - if (kDown & KEY_A) { + if (kDown & HidNpadButton_A) { printf("A Pressed\n"); } - if (kDown & KEY_B) { + if (kDown & HidNpadButton_B) { printf("B Pressed\n"); } diff --git a/nfc/source/main.c b/nfc/source/main.c index 66d4879..d3631b5 100644 --- a/nfc/source/main.c +++ b/nfc/source/main.c @@ -9,14 +9,16 @@ // See also libnx nfc.h. +static PadState pad; + // Indefinitely wait for an event to be signaled // Break when + is pressed, or if the application should quit (in this case, return value will be non-zero) Result eventWaitLoop(Event *event) { Result rc = 1; while (appletMainLoop()) { rc = eventWait(event, 0); - hidScanInput(); - if (R_SUCCEEDED(rc) || (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_PLUS)) + padUpdate(&pad); + if (R_SUCCEEDED(rc) || (padGetButtonsDown(&pad) & HidNpadButton_Plus)) break; consoleUpdate(NULL); } @@ -181,6 +183,12 @@ 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: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + padInitializeDefault(&pad); + printf("NFC example program.\n"); printf("Scan an amiibo tag to display information about it.\n\n"); consoleUpdate(NULL); @@ -223,12 +231,12 @@ 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 - if (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_A) { + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + if (padGetButtonsDown(&pad) & HidNpadButton_A) { rc = process_amiibo(app_id); // If an error happened, print it. @@ -239,7 +247,7 @@ int main(int argc, char* argv[]) } // If + was pressed to exit an eventWaitLoop(), we also catch it here. - if (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_PLUS) + if (padGetButtonsDown(&pad) & HidNpadButton_Plus) break; // break in order to return to hbmenu // Update the console, sending a new frame to the display diff --git a/power/source/main.c b/power/source/main.c index 5c53d82..55e0272 100644 --- a/power/source/main.c +++ b/power/source/main.c @@ -9,22 +9,30 @@ const char* const chargers[3] = {"None", "Official", "Generic"}; int main(int argc, char **argv) { consoleInit(NULL); + Result rc = psmInitialize(); if (R_FAILED(rc)) goto cleanup; + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + printf("\x1b[16;16HPress PLUS to exit."); // 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 (and they weren't in the previous frame) - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu u32 charge; double rawCharge; diff --git a/settings/get_system_language/source/main.c b/settings/get_system_language/source/main.c index 81837bb..5969d80 100644 --- a/settings/get_system_language/source/main.c +++ b/settings/get_system_language/source/main.c @@ -12,6 +12,13 @@ int main(int argc, char **argv) consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + Result rc = setInitialize(); if (R_FAILED(rc)) printf("setInitialize() failed: 0x%x.\n", rc); @@ -47,15 +54,15 @@ 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); // Your code goes here - //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu consoleUpdate(NULL); } diff --git a/time/source/main.c b/time/source/main.c index dc07f0e..1ed114b 100644 --- a/time/source/main.c +++ b/time/source/main.c @@ -12,18 +12,25 @@ int main(int argc, char **argv) { consoleInit(NULL); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + printf("\x1b[16;16HPress PLUS to exit."); // 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 (and they weren't in the previous frame) - u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu //Print current time time_t unixTime = time(NULL); diff --git a/usb/usbhs/source/main.c b/usb/usbhs/source/main.c index 88af272..6277543 100644 --- a/usb/usbhs/source/main.c +++ b/usb/usbhs/source/main.c @@ -31,6 +31,13 @@ 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: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleSet_NpadStandard); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + PadState pad; + padInitializeDefault(&pad); + printf("usbhs example\n"); memset(&inf_event, 0, sizeof(inf_event)); @@ -58,14 +65,14 @@ 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(CONTROLLER_P1_AUTO); + // padGetButtonsDown returns the set of buttons that have been + // newly pressed in this frame compared to the previous one + u64 kDown = padGetButtonsDown(&pad); - if (kDown & KEY_PLUS) + if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu if (R_SUCCEEDED(rc2)) rc = eventWait(&inf_event, 0);