Skip to content

Commit 1e59bd0

Browse files
committed
Update all non-HID examples for hid-refactor
1 parent 4272e28 commit 1e59bd0

File tree

57 files changed

+717
-322
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+717
-322
lines changed

account/source/main.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ int main(int argc, char **argv)
1818

1919
consoleInit(NULL);
2020

21+
// Configure our supported input layout: a single player with standard controller styles
22+
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
23+
24+
// Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller)
25+
PadState pad;
26+
padInitializeDefault(&pad);
27+
2128
memset(&userdata, 0, sizeof(userdata));
2229
memset(&profilebase, 0, sizeof(profilebase));
2330

@@ -68,13 +75,13 @@ int main(int argc, char **argv)
6875
// Main loop
6976
while(appletMainLoop())
7077
{
71-
//Scan all the inputs. This should be done once for each frame
72-
hidScanInput();
78+
// Scan the gamepad. This should be done once for each frame
79+
padUpdate(&pad);
7380

74-
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
75-
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
81+
// padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one
82+
u64 kDown = padGetButtonsDown(&pad);
7683

77-
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
84+
if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu
7885

7986
consoleUpdate(NULL);
8087
}

alarm-notifications/source/main.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ int main(int argc, char* argv[])
3737
// take a look at the graphics/opengl set of examples, which uses EGL instead.
3838
consoleInit(NULL);
3939

40+
// Configure our supported input layout: a single player with standard controller styles
41+
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
42+
43+
// Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller)
44+
PadState pad;
45+
padInitializeDefault(&pad);
46+
4047
printf("alarm-notifications example\n");
4148

4249
Result rc=0, rc2=0;
@@ -75,14 +82,14 @@ int main(int argc, char* argv[])
7582
// Main loop
7683
while (appletMainLoop())
7784
{
78-
// Scan all the inputs. This should be done once for each frame
79-
hidScanInput();
85+
// Scan the gamepad. This should be done once for each frame
86+
padUpdate(&pad);
8087

81-
// hidKeysDown returns information about which buttons have been
82-
// just pressed in this frame compared to the previous one
83-
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
88+
// padGetButtonsDown returns the set of buttons that have been
89+
// newly pressed in this frame compared to the previous one
90+
u64 kDown = padGetButtonsDown(&pad);
8491

85-
if (kDown & KEY_PLUS)
92+
if (kDown & HidNpadButton_Plus)
8693
break; // break in order to return to hbmenu
8794

8895
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[])
96103
}
97104

98105
if (R_SUCCEEDED(rc)) {
99-
if (kDown & KEY_A) {
106+
if (kDown & HidNpadButton_A) {
100107
// Setup an alarm with {current local-time} + {2 minutes}. You can use any weekday/time you want.
101108
// See libnx notif.h for more notifAlarmSetting*() funcs.
102109

@@ -121,7 +128,7 @@ int main(int argc, char* argv[])
121128
if (R_SUCCEEDED(rc)) printf("alarm_setting_id = 0x%x\n", alarm_setting_id);
122129
}
123130
}
124-
else if (kDown & KEY_B) {
131+
else if (kDown & HidNpadButton_B) {
125132
// List the Alarms.
126133

127134
total_out=0;
@@ -160,8 +167,8 @@ int main(int argc, char* argv[])
160167
}
161168
}
162169
}
163-
else if ((kDown & KEY_X) && alarm_setting_id) {
164-
// Delete the AlarmSetting which was registered with the KEY_A block.
170+
else if ((kDown & HidNpadButton_X) && alarm_setting_id) {
171+
// Delete the AlarmSetting which was registered with the HidNpadButton_A block.
165172
// If wanted, you can also use this with alarm_settings[alarmi].alarm_setting_id with the output from notifListAlarmSettings.
166173
rc = notifDeleteAlarmSetting(alarm_setting_id);
167174
printf("notifDeleteAlarmSetting(): 0x%x\n", rc);

app_controldata/source/main.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ int main(int argc, char **argv)
1919

2020
consoleInit(NULL);
2121

22+
// Configure our supported input layout: a single player with standard controller styles
23+
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
24+
25+
// Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller)
26+
PadState pad;
27+
padInitializeDefault(&pad);
28+
2229
buf = (NsApplicationControlData*)malloc(sizeof(NsApplicationControlData));
2330
if (buf==NULL) {
2431
rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory);
@@ -69,13 +76,13 @@ int main(int argc, char **argv)
6976
// Main loop
7077
while(appletMainLoop())
7178
{
72-
//Scan all the inputs. This should be done once for each frame
73-
hidScanInput();
79+
// Scan the gamepad. This should be done once for each frame
80+
padUpdate(&pad);
7481

75-
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
76-
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
82+
// padGetButtonsDown returns the set of buttons that have been newly pressed in this frame compared to the previous one
83+
u64 kDown = padGetButtonsDown(&pad);
7784

78-
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
85+
if (kDown & HidNpadButton_Plus) break; // break in order to return to hbmenu
7986

8087
consoleUpdate(NULL);
8188
}

applet/app-playstats/source/main.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ int main(int argc, char* argv[])
2020
// take a look at the graphics/opengl set of examples, which uses EGL instead.
2121
consoleInit(NULL);
2222

23+
// Configure our supported input layout: a single player with standard controller styles
24+
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
25+
26+
// Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller)
27+
PadState pad;
28+
padInitializeDefault(&pad);
29+
2330
printf("application play-stats example\n");
2431

2532
Result rc=0;
@@ -53,17 +60,17 @@ int main(int argc, char* argv[])
5360
// Main loop
5461
while (appletMainLoop())
5562
{
56-
// Scan all the inputs. This should be done once for each frame
57-
hidScanInput();
63+
// Scan the gamepad. This should be done once for each frame
64+
padUpdate(&pad);
5865

59-
// hidKeysDown returns information about which buttons have been
60-
// just pressed in this frame compared to the previous one
61-
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
66+
// padGetButtonsDown returns the set of buttons that have been
67+
// newly pressed in this frame compared to the previous one
68+
u64 kDown = padGetButtonsDown(&pad);
6269

63-
if (kDown & KEY_PLUS)
70+
if (kDown & HidNpadButton_Plus)
6471
break; // break in order to return to hbmenu
6572

66-
if (kDown & KEY_A) {
73+
if (kDown & HidNpadButton_A) {
6774
// Use appletQueryApplicationPlayStatisticsByUid if you want playstats for a specific userID.
6875

6976
memset(stats, 0, sizeof(stats));
@@ -84,7 +91,7 @@ int main(int argc, char* argv[])
8491
}
8592
}
8693

87-
if (initflag && (kDown & KEY_X)) {
94+
if (initflag && (kDown & HidNpadButton_X)) {
8895
memset(events, 0, sizeof(events));
8996
total_out = 0;
9097

applet/libapplets/error/source/main.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ int main(int argc, char* argv[])
2424
// take a look at the graphics/opengl set of examples, which uses EGL instead.
2525
consoleInit(NULL);
2626

27+
// Configure our supported input layout: a single player with standard controller styles
28+
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
29+
30+
// Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller)
31+
PadState pad;
32+
padInitializeDefault(&pad);
33+
2734
printf("error example\n");
2835

2936
consoleUpdate(NULL);
@@ -34,17 +41,17 @@ int main(int argc, char* argv[])
3441
// Main loop
3542
while (appletMainLoop())
3643
{
37-
// Scan all the inputs. This should be done once for each frame
38-
hidScanInput();
44+
// Scan the gamepad. This should be done once for each frame
45+
padUpdate(&pad);
3946

40-
// hidKeysDown returns information about which buttons have been
41-
// just pressed in this frame compared to the previous one
42-
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
47+
// padGetButtonsDown returns the set of buttons that have been
48+
// newly pressed in this frame compared to the previous one
49+
u64 kDown = padGetButtonsDown(&pad);
4350

44-
if (kDown & KEY_PLUS)
51+
if (kDown & HidNpadButton_Plus)
4552
break; // break in order to return to hbmenu
4653

47-
if (kDown & KEY_A) {
54+
if (kDown & HidNpadButton_A) {
4855
printf("Running errorResultRecordShow()...\n");
4956
consoleUpdate(NULL);
5057
rc = errorResultRecordShow(MAKERESULT(16, 250), time(NULL));

applet/libapplets/pctlauth/source/main.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ int main(int argc, char* argv[])
2323
// take a look at the graphics/opengl set of examples, which uses EGL instead.
2424
consoleInit(NULL);
2525

26+
// Configure our supported input layout: a single player with standard controller styles
27+
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
28+
29+
// Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller)
30+
PadState pad;
31+
padInitializeDefault(&pad);
32+
2633
printf("pctlauth example\n");
2734
consoleUpdate(NULL);
2835

@@ -47,17 +54,17 @@ int main(int argc, char* argv[])
4754
// Main loop
4855
while (appletMainLoop())
4956
{
50-
// Scan all the inputs. This should be done once for each frame
51-
hidScanInput();
57+
// Scan the gamepad. This should be done once for each frame
58+
padUpdate(&pad);
5259

53-
// hidKeysDown returns information about which buttons have been
54-
// just pressed in this frame compared to the previous one
55-
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
60+
// padGetButtonsDown returns the set of buttons that have been
61+
// newly pressed in this frame compared to the previous one
62+
u64 kDown = padGetButtonsDown(&pad);
5663

57-
if (kDown & KEY_PLUS)
64+
if (kDown & HidNpadButton_Plus)
5865
break; // break in order to return to hbmenu
5966

60-
if (pctlflag && (kDown & KEY_A)) {
67+
if (pctlflag && (kDown & HidNpadButton_A)) {
6168
printf("Running pctlauthShow()...\n");
6269
consoleUpdate(NULL);
6370
rc = pctlauthShow(true); // Launch the applet for validating the PIN.

applet/libapplets/software-keyboard/source/main.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ int main(int argc, char* argv[])
5757
// take a look at the graphics/opengl set of examples, which uses EGL instead.
5858
consoleInit(NULL);
5959

60+
// Configure our supported input layout: a single player with standard controller styles
61+
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
62+
63+
// Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller)
64+
PadState pad;
65+
padInitializeDefault(&pad);
66+
6067
printf("swkbd example\n");
6168

6269
consoleUpdate(NULL);
@@ -142,21 +149,21 @@ int main(int argc, char* argv[])
142149
// Main loop
143150
while (appletMainLoop())
144151
{
145-
// Scan all the inputs. This should be done once for each frame
146-
hidScanInput();
152+
// Scan the gamepad. This should be done once for each frame
153+
padUpdate(&pad);
147154

148-
// hidKeysDown returns information about which buttons have been
149-
// just pressed in this frame compared to the previous one
150-
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
155+
// padGetButtonsDown returns the set of buttons that have been
156+
// newly pressed in this frame compared to the previous one
157+
u64 kDown = padGetButtonsDown(&pad);
151158

152-
if (kDown & KEY_PLUS)
159+
if (kDown & HidNpadButton_Plus)
153160
break; // break in order to return to hbmenu
154161

155162
// Your code goes here
156163

157164
if (R_SUCCEEDED(rc)) {
158-
if (kDown & KEY_ZR) swkbdInlineDisappear(&kbdinline); //Optional, you can have swkbd (dis)appear whenever.
159-
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.
165+
if (kDown & HidNpadButton_ZR) swkbdInlineDisappear(&kbdinline); //Optional, you can have swkbd (dis)appear whenever.
166+
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.
160167

161168
rc = swkbdInlineUpdate(&kbdinline, NULL); // Handles updating SwkbdInline state, this should be called periodically.
162169
if (R_FAILED(rc)) printf("swkbdInlineUpdate(): 0x%x\n", rc);

applet/libapplets/web/source/main.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ int main(int argc, char* argv[])
2323
// take a look at the graphics/opengl set of examples, which uses EGL instead.
2424
consoleInit(NULL);
2525

26+
// Configure our supported input layout: a single player with standard controller styles
27+
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
28+
29+
// Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller)
30+
PadState pad;
31+
padInitializeDefault(&pad);
32+
2633
printf("web example\n");
2734

2835
consoleUpdate(NULL);
@@ -33,17 +40,17 @@ int main(int argc, char* argv[])
3340
// Main loop
3441
while (appletMainLoop())
3542
{
36-
// Scan all the inputs. This should be done once for each frame
37-
hidScanInput();
43+
// Scan the gamepad. This should be done once for each frame
44+
padUpdate(&pad);
3845

39-
// hidKeysDown returns information about which buttons have been
40-
// just pressed in this frame compared to the previous one
41-
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
46+
// padGetButtonsDown returns the set of buttons that have been
47+
// newly pressed in this frame compared to the previous one
48+
u64 kDown = padGetButtonsDown(&pad);
4249

43-
if (kDown & KEY_PLUS)
50+
if (kDown & HidNpadButton_Plus)
4451
break; // break in order to return to hbmenu
4552

46-
if (kDown & KEY_A) {
53+
if (kDown & HidNpadButton_A) {
4754
WebCommonConfig config;
4855
WebCommonReply reply;
4956
WebExitReason exitReason=0;

applet/light-sensor/source/main.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,31 @@ int main(int argc, char* argv[])
1818
// take a look at the graphics/opengl set of examples, which uses EGL instead.
1919
consoleInit(NULL);
2020

21+
// Configure our supported input layout: a single player with standard controller styles
22+
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
23+
24+
// Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller)
25+
PadState pad;
26+
padInitializeDefault(&pad);
27+
2128
printf("light-sensor example\n");
2229
printf("Press A to check light-sensor.\n");
2330
printf("Press + to exit.\n");
2431

2532
// Main loop
2633
while (appletMainLoop())
2734
{
28-
// Scan all the inputs. This should be done once for each frame
29-
hidScanInput();
35+
// Scan the gamepad. This should be done once for each frame
36+
padUpdate(&pad);
3037

31-
// hidKeysDown returns information about which buttons have been
32-
// just pressed in this frame compared to the previous one
33-
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
38+
// padGetButtonsDown returns the set of buttons that have been
39+
// newly pressed in this frame compared to the previous one
40+
u64 kDown = padGetButtonsDown(&pad);
3441

35-
if (kDown & KEY_PLUS)
42+
if (kDown & HidNpadButton_Plus)
3643
break; // break in order to return to hbmenu
3744

38-
if (kDown & KEY_A) {
45+
if (kDown & HidNpadButton_A) {
3946
Result rc = 0;
4047
float fLux=0;
4148
bool availableflag=0;

0 commit comments

Comments
 (0)