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