Skip to content

Commit b10af7c

Browse files
committed
code update to work on latest atmosphere
1 parent 96df198 commit b10af7c

File tree

2 files changed

+250
-45
lines changed

2 files changed

+250
-45
lines changed

main-old.c

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
5+
// Include the main libnx system header, for Switch development
6+
#include <switch.h>
7+
8+
9+
int main(int argc, char* argv[])
10+
{
11+
12+
consoleInit(NULL);
13+
Result rc=0;
14+
bool initflag=0;
15+
size_t i;
16+
size_t total_entries;
17+
u64 UniquePadIds[2];
18+
HidsysNotificationLedPattern pattern;
19+
20+
printf("notification-led example - Ely's test codes\n");
21+
22+
rc = hidsysInitialize();
23+
if (R_FAILED(rc)) {
24+
printf("hidsysInitialize(): 0x%x\n", rc);
25+
printf("Init failed, press + to exit.\n");
26+
}
27+
else {
28+
initflag = 1;
29+
printf("Press X for Ely's flashing notification-LED pattern.\n");
30+
printf("Press Y for Ely's faster flashing notification-LED pattern.\n");
31+
printf("Press A to set a Breathing effect notification-LED pattern.\n");
32+
printf("Press B to set a Heartbeat effect notification-LED pattern.\n");
33+
printf("Press - to disable notification-LED only\n");
34+
printf("Press + to disable notification-LED and exit.\n");
35+
}
36+
37+
// Main loop
38+
while (appletMainLoop())
39+
{
40+
// Scan all the inputs. This should be done once for each frame
41+
hidScanInput();
42+
43+
// hidKeysDown returns information about which buttons have been
44+
// just pressed in this frame compared to the previous one
45+
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
46+
47+
if (kDown & KEY_PLUS) {
48+
// Disable notification led.
49+
memset(&pattern, 0, sizeof(pattern));
50+
}
51+
52+
//only turn off all leds!
53+
else if (kDown & KEY_MINUS) {
54+
// Disable notification led.
55+
memset(&pattern, 0, sizeof(pattern));
56+
}
57+
58+
//my testing code
59+
else if (kDown & KEY_X) {
60+
memset(&pattern, 0, sizeof(pattern));
61+
62+
//Ely's test code for flashing led on the home button on the joycons//
63+
pattern.baseMiniCycleDuration = 0x1; // 12.5 ms
64+
pattern.totalMiniCycles = 0x2; // 3 mini cycles. Last one 12.5ms.
65+
pattern.totalFullCycles = 0x0; // Repeat forever.
66+
pattern.startIntensity = 0xF; // 100%.
67+
68+
69+
pattern.miniCycles[0].ledIntensity = 0xF; // 100%.
70+
pattern.miniCycles[0].transitionSteps = 0xF; // 15 steps. Total 187.5ms.
71+
pattern.miniCycles[0].finalStepDuration = 0x0; // Forced 12.5ms.
72+
pattern.miniCycles[1].ledIntensity = 0x0; // 0%.
73+
pattern.miniCycles[1].transitionSteps = 0xF; // 15 steps. Total 187.5ms.
74+
pattern.miniCycles[1].finalStepDuration = 0x0; // Forced 12.5ms.
75+
76+
pattern.miniCycles[2].ledIntensity = 0xF; // 100%
77+
pattern.miniCycles[2].transitionSteps = 0xF; // 15 steps. Total 187.5ms.
78+
pattern.miniCycles[2].finalStepDuration = 0x0; // Forced 12.5ms.
79+
pattern.miniCycles[3].ledIntensity = 0x0; // 0%
80+
pattern.miniCycles[3].transitionSteps = 0xF; // 15 steps. Total 187.5ms.
81+
pattern.miniCycles[3].finalStepDuration = 0x0; // Forced 12.5ms.
82+
83+
84+
85+
}
86+
87+
88+
else if (kDown & KEY_Y) {
89+
memset(&pattern, 0, sizeof(pattern));
90+
91+
//Ely's test code for very fast strobe-like flashing led on the home button on the joycons//
92+
//it is strobe-like!!! :) - very sweet, I love this pattern! :) ELY M.
93+
94+
pattern.baseMiniCycleDuration = 0x1; // 12.5 ms
95+
pattern.totalMiniCycles = 0x2; // 3 mini cycles. Last one 12.5ms.
96+
pattern.totalFullCycles = 0x0; // Repeat forever.
97+
pattern.startIntensity = 0xF; // 100%.
98+
99+
pattern.miniCycles[0].ledIntensity = 0xF; // 100%.
100+
pattern.miniCycles[0].transitionSteps = 0x0; // Forced 12.5ms.
101+
pattern.miniCycles[0].finalStepDuration = 0x0; // Forced 12.5ms.
102+
pattern.miniCycles[1].ledIntensity = 0x0; // 0%.
103+
pattern.miniCycles[1].transitionSteps = 0x0; // Forced 12.5ms.
104+
pattern.miniCycles[1].finalStepDuration = 0x0; // Forced 12.5ms.
105+
106+
pattern.miniCycles[2].ledIntensity = 0xF; // 100%
107+
pattern.miniCycles[2].transitionSteps = 0x0; // Forced 12.5ms.
108+
pattern.miniCycles[2].finalStepDuration = 0x0; // Forced 12.5ms.
109+
pattern.miniCycles[3].ledIntensity = 0x0; // 0%
110+
pattern.miniCycles[3].transitionSteps = 0x0; // Forced 12.5ms.
111+
pattern.miniCycles[3].finalStepDuration = 0x0; // Forced 12.5ms.
112+
113+
114+
115+
}
116+
117+
else if (kDown & KEY_A) {
118+
memset(&pattern, 0, sizeof(pattern));
119+
120+
// Setup Breathing effect pattern data.
121+
pattern.baseMiniCycleDuration = 0x8; // 100ms.
122+
pattern.totalMiniCycles = 0x2; // 3 mini cycles. Last one 12.5ms.
123+
pattern.totalFullCycles = 0x0; // Repeat forever.
124+
pattern.startIntensity = 0x2; // 13%.
125+
126+
pattern.miniCycles[0].ledIntensity = 0xF; // 100%.
127+
pattern.miniCycles[0].transitionSteps = 0xF; // 15 steps. Transition time 1.5s.
128+
pattern.miniCycles[0].finalStepDuration = 0x0; // Forced 12.5ms.
129+
pattern.miniCycles[1].ledIntensity = 0x2; // 13%.
130+
pattern.miniCycles[1].transitionSteps = 0xF; // 15 steps. Transition time 1.5s.
131+
pattern.miniCycles[1].finalStepDuration = 0x0; // Forced 12.5ms.
132+
}
133+
else if (kDown & KEY_B) {
134+
memset(&pattern, 0, sizeof(pattern));
135+
136+
// Setup Heartbeat effect pattern data.
137+
pattern.baseMiniCycleDuration = 0x1; // 12.5ms.
138+
pattern.totalMiniCycles = 0xF; // 16 mini cycles.
139+
pattern.totalFullCycles = 0x0; // Repeat forever.
140+
pattern.startIntensity = 0x0; // 0%.
141+
142+
// First beat.
143+
pattern.miniCycles[0].ledIntensity = 0xF; // 100%.
144+
pattern.miniCycles[0].transitionSteps = 0xF; // 15 steps. Total 187.5ms.
145+
pattern.miniCycles[0].finalStepDuration = 0x0; // Forced 12.5ms.
146+
pattern.miniCycles[1].ledIntensity = 0x0; // 0%.
147+
pattern.miniCycles[1].transitionSteps = 0xF; // 15 steps. Total 187.5ms.
148+
pattern.miniCycles[1].finalStepDuration = 0x0; // Forced 12.5ms.
149+
150+
// Second beat.
151+
pattern.miniCycles[2].ledIntensity = 0xF;
152+
pattern.miniCycles[2].transitionSteps = 0xF;
153+
pattern.miniCycles[2].finalStepDuration = 0x0;
154+
pattern.miniCycles[3].ledIntensity = 0x0;
155+
pattern.miniCycles[3].transitionSteps = 0xF;
156+
pattern.miniCycles[3].finalStepDuration = 0x0;
157+
158+
// Led off wait time.
159+
for(i=2; i<15; i++) {
160+
pattern.miniCycles[i].ledIntensity = 0x0; // 0%.
161+
pattern.miniCycles[i].transitionSteps = 0xF; // 15 steps. Total 187.5ms.
162+
pattern.miniCycles[i].finalStepDuration = 0xF; // 187.5ms.
163+
}
164+
}
165+
166+
if (kDown & (KEY_X | KEY_Y | KEY_A | KEY_B | KEY_MINUS | KEY_PLUS)) {
167+
total_entries = 0;
168+
memset(UniquePadIds, 0, sizeof(UniquePadIds));
169+
170+
// Get the UniquePadIds for the specified controller, which will then be used with hidsysSetNotificationLedPattern.
171+
// If you want to get the UniquePadIds for all controllers, you can use hidsysGetUniquePadIds instead.
172+
rc = hidsysGetUniquePadsFromNpad(hidGetHandheldMode() ? CONTROLLER_HANDHELD : CONTROLLER_PLAYER_1, UniquePadIds, 2, &total_entries);
173+
printf("hidsysGetUniquePadsFromNpad(): 0x%x", rc);
174+
if (R_SUCCEEDED(rc)) printf(", %ld", total_entries);
175+
printf("\n");
176+
177+
if (R_SUCCEEDED(rc)) {
178+
for(i=0; i<total_entries; i++) { // System will skip sending the subcommand to controllers where this isn't available.
179+
printf("[%ld] = 0x%lx ", i, UniquePadIds[i]);
180+
rc = hidsysSetNotificationLedPattern(&pattern, UniquePadIds[i]);
181+
printf("hidsysSetNotificationLedPattern(): 0x%x\n", rc);
182+
}
183+
}
184+
}
185+
186+
// Update the console, sending a new frame to the display
187+
consoleUpdate(NULL);
188+
189+
if (kDown & KEY_PLUS)
190+
break; // break in order to return to hbmenu
191+
}
192+
193+
if (initflag) hidsysExit();
194+
195+
// Deinitialize and clean up resources used by the console (important!)
196+
consoleExit(NULL);
197+
return 0;
198+
}

source/main.c

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
1+
// Include the most common headers from the C standard library
12
#include <stdio.h>
23
#include <stdlib.h>
34
#include <string.h>
45

56
// Include the main libnx system header, for Switch development
67
#include <switch.h>
78

9+
// This example shows how to use the HOME-button notification-LED, see also libnx hidsys.h.
810

11+
// Main program entrypoint
912
int main(int argc, char* argv[])
1013
{
11-
14+
// This example uses a text console, as a simple way to output text to the screen.
15+
// If you want to write a software-rendered graphics application,
16+
// take a look at the graphics/simplegfx example, which uses the libnx Framebuffer API instead.
17+
// If on the other hand you want to write an OpenGL based application,
18+
// take a look at the graphics/opengl set of examples, which uses EGL instead.
1219
consoleInit(NULL);
20+
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+
1328
Result rc=0;
14-
bool initflag=0;
15-
size_t i;
16-
size_t total_entries;
17-
u64 UniquePadIds[2];
29+
s32 i;
30+
s32 total_entries;
31+
HidsysUniquePadId unique_pad_ids[2]={0};
1832
HidsysNotificationLedPattern pattern;
1933

2034
printf("notification-led example - Ely's test codes\n");
@@ -25,7 +39,6 @@ int main(int argc, char* argv[])
2539
printf("Init failed, press + to exit.\n");
2640
}
2741
else {
28-
initflag = 1;
2942
printf("Press X for Ely's flashing notification-LED pattern.\n");
3043
printf("Press Y for Ely's faster flashing notification-LED pattern.\n");
3144
printf("Press A to set a Breathing effect notification-LED pattern.\n");
@@ -37,26 +50,20 @@ int main(int argc, char* argv[])
3750
// Main loop
3851
while (appletMainLoop())
3952
{
40-
// Scan all the inputs. This should be done once for each frame
41-
hidScanInput();
53+
// Scan the gamepad. This should be done once for each frame
54+
padUpdate(&pad);
4255

43-
// hidKeysDown returns information about which buttons have been
44-
// just pressed in this frame compared to the previous one
45-
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
56+
// padGetButtonsDown returns the set of buttons that have been
57+
// newly pressed in this frame compared to the previous one
58+
u64 kDown = padGetButtonsDown(&pad);
4659

47-
if (kDown & KEY_PLUS) {
48-
// Disable notification led.
60+
if (kDown & HidNpadButton_Plus) {
61+
// Disable notification led. Only needed with hidsysSetNotificationLedPattern, with hidsysSetNotificationLedPatternWithTimeout the LED will be automatically disabled via the timeout.
4962
memset(&pattern, 0, sizeof(pattern));
5063
}
5164

52-
//only turn off all leds!
53-
else if (kDown & KEY_MINUS) {
54-
// Disable notification led.
55-
memset(&pattern, 0, sizeof(pattern));
56-
}
57-
58-
//my testing code
59-
else if (kDown & KEY_X) {
65+
66+
else if (kDown & HidNpadButton_X) {
6067
memset(&pattern, 0, sizeof(pattern));
6168

6269
//Ely's test code for flashing led on the home button on the joycons//
@@ -79,13 +86,9 @@ int main(int argc, char* argv[])
7986
pattern.miniCycles[3].ledIntensity = 0x0; // 0%
8087
pattern.miniCycles[3].transitionSteps = 0xF; // 15 steps. Total 187.5ms.
8188
pattern.miniCycles[3].finalStepDuration = 0x0; // Forced 12.5ms.
82-
83-
84-
85-
}
86-
89+
}
8790

88-
else if (kDown & KEY_Y) {
91+
else if (kDown & HidNpadButton_Y) {
8992
memset(&pattern, 0, sizeof(pattern));
9093

9194
//Ely's test code for very fast strobe-like flashing led on the home button on the joycons//
@@ -109,12 +112,10 @@ int main(int argc, char* argv[])
109112
pattern.miniCycles[3].ledIntensity = 0x0; // 0%
110113
pattern.miniCycles[3].transitionSteps = 0x0; // Forced 12.5ms.
111114
pattern.miniCycles[3].finalStepDuration = 0x0; // Forced 12.5ms.
112-
113-
114-
115-
}
115+
}
116116

117-
else if (kDown & KEY_A) {
117+
118+
else if (kDown & HidNpadButton_A) {
118119
memset(&pattern, 0, sizeof(pattern));
119120

120121
// Setup Breathing effect pattern data.
@@ -130,7 +131,7 @@ int main(int argc, char* argv[])
130131
pattern.miniCycles[1].transitionSteps = 0xF; // 15 steps. Transition time 1.5s.
131132
pattern.miniCycles[1].finalStepDuration = 0x0; // Forced 12.5ms.
132133
}
133-
else if (kDown & KEY_B) {
134+
else if (kDown & HidNpadButton_B) {
134135
memset(&pattern, 0, sizeof(pattern));
135136

136137
// Setup Heartbeat effect pattern data.
@@ -163,34 +164,40 @@ int main(int argc, char* argv[])
163164
}
164165
}
165166

166-
if (kDown & (KEY_X | KEY_Y | KEY_A | KEY_B | KEY_MINUS | KEY_PLUS)) {
167+
if (kDown & (HidNpadButton_A | HidNpadButton_B | HidNpadButton_X | HidNpadButton_Y | HidNpadButton_Plus)) {
167168
total_entries = 0;
168-
memset(UniquePadIds, 0, sizeof(UniquePadIds));
169+
memset(unique_pad_ids, 0, sizeof(unique_pad_ids));
169170

170-
// Get the UniquePadIds for the specified controller, which will then be used with hidsysSetNotificationLedPattern.
171+
// Get the UniquePadIds for the specified controller, which will then be used with hidsysSetNotificationLedPattern*.
171172
// If you want to get the UniquePadIds for all controllers, you can use hidsysGetUniquePadIds instead.
172-
rc = hidsysGetUniquePadsFromNpad(hidGetHandheldMode() ? CONTROLLER_HANDHELD : CONTROLLER_PLAYER_1, UniquePadIds, 2, &total_entries);
173+
rc = hidsysGetUniquePadsFromNpad(padIsHandheld(&pad) ? HidNpadIdType_Handheld : HidNpadIdType_No1, unique_pad_ids, 2, &total_entries);
173174
printf("hidsysGetUniquePadsFromNpad(): 0x%x", rc);
174-
if (R_SUCCEEDED(rc)) printf(", %ld", total_entries);
175+
if (R_SUCCEEDED(rc)) printf(", %d", total_entries);
175176
printf("\n");
176177

177178
if (R_SUCCEEDED(rc)) {
178179
for(i=0; i<total_entries; i++) { // System will skip sending the subcommand to controllers where this isn't available.
179-
printf("[%ld] = 0x%lx ", i, UniquePadIds[i]);
180-
rc = hidsysSetNotificationLedPattern(&pattern, UniquePadIds[i]);
181-
printf("hidsysSetNotificationLedPattern(): 0x%x\n", rc);
180+
printf("[%d] = 0x%lx ", i, unique_pad_ids[i].id);
181+
182+
// Attempt to use hidsysSetNotificationLedPatternWithTimeout first with a 2 second timeout, then fallback to hidsysSetNotificationLedPattern on failure. See hidsys.h for the requirements for using these.
183+
rc = hidsysSetNotificationLedPatternWithTimeout(&pattern, unique_pad_ids[i], 2000000000ULL);
184+
printf("hidsysSetNotificationLedPatternWithTimeout(): 0x%x\n", rc);
185+
if (R_FAILED(rc)) {
186+
rc = hidsysSetNotificationLedPattern(&pattern, unique_pad_ids[i]);
187+
printf("hidsysSetNotificationLedPattern(): 0x%x\n", rc);
188+
}
182189
}
183190
}
184191
}
185192

193+
if (kDown & HidNpadButton_Plus)
194+
break; // break in order to return to hbmenu
195+
186196
// Update the console, sending a new frame to the display
187197
consoleUpdate(NULL);
188-
189-
if (kDown & KEY_PLUS)
190-
break; // break in order to return to hbmenu
191198
}
192199

193-
if (initflag) hidsysExit();
200+
hidsysExit();
194201

195202
// Deinitialize and clean up resources used by the console (important!)
196203
consoleExit(NULL);

0 commit comments

Comments
 (0)