Skip to content

Commit 6027f34

Browse files
CTCaeryellows8
authored andcommitted
[hid] Notification led example update and add effects (#54)
* [hid] Notification led example update and add effects
1 parent 1d7a5f0 commit 6027f34

File tree

1 file changed

+59
-13
lines changed
  • hid/notification-led/source

1 file changed

+59
-13
lines changed

hid/notification-led/source/main.c

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ int main(int argc, char* argv[])
2525
u64 UniquePadIds[2];
2626
HidsysNotificationLedPattern pattern;
2727

28-
memset(&pattern, 0, sizeof(pattern));
29-
30-
// Setup the pattern data.
31-
pattern.globalMiniCycleDuration = 0xf;
32-
pattern.totalMiniCycles = 0xf;
33-
pattern.totalFullCycles = 0xf;
34-
pattern.startIntensity = 0xf;
35-
3628
printf("notification-led example\n");
3729

3830
rc = hidsysInitialize();
@@ -42,8 +34,9 @@ int main(int argc, char* argv[])
4234
}
4335
else {
4436
initflag = 1;
45-
printf("Press A to set the notification-LED pattern.\n");
46-
printf("Press + to exit.\n");
37+
printf("Press A to set a Breathing effect notification-LED pattern.\n");
38+
printf("Press B to set a Heartbeat effect notification-LED pattern.\n");
39+
printf("Press + to disable notification-LED and exit.\n");
4740
}
4841

4942
// Main loop
@@ -56,10 +49,60 @@ int main(int argc, char* argv[])
5649
// just pressed in this frame compared to the previous one
5750
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
5851

59-
if (kDown & KEY_PLUS)
60-
break; // break in order to return to hbmenu
52+
if (kDown & KEY_PLUS) {
53+
// Disable notification led.
54+
memset(&pattern, 0, sizeof(pattern));
55+
}
56+
else if (kDown & KEY_A) {
57+
memset(&pattern, 0, sizeof(pattern));
58+
59+
// Setup Breathing effect pattern data.
60+
pattern.baseMiniCycleDuration = 0x8; // 100ms.
61+
pattern.totalMiniCycles = 0x2; // 3 mini cycles. Last one 12.5ms.
62+
pattern.totalFullCycles = 0x0; // Repeat forever.
63+
pattern.startIntensity = 0x2; // 13%.
64+
65+
pattern.miniCycles[0].ledIntensity = 0xF; // 100%.
66+
pattern.miniCycles[0].transitionSteps = 0xF; // 15 steps. Transition time 1.5s.
67+
pattern.miniCycles[0].finalStepDuration = 0x0; // Forced 12.5ms.
68+
pattern.miniCycles[1].ledIntensity = 0x2; // 13%.
69+
pattern.miniCycles[1].transitionSteps = 0xF; // 15 steps. Transition time 1.5s.
70+
pattern.miniCycles[1].finalStepDuration = 0x0; // Forced 12.5ms.
71+
}
72+
else if (kDown & KEY_B) {
73+
memset(&pattern, 0, sizeof(pattern));
74+
75+
// Setup Heartbeat effect pattern data.
76+
pattern.baseMiniCycleDuration = 0x1; // 12.5ms.
77+
pattern.totalMiniCycles = 0xF; // 16 mini cycles.
78+
pattern.totalFullCycles = 0x0; // Repeat forever.
79+
pattern.startIntensity = 0x0; // 0%.
80+
81+
// First beat.
82+
pattern.miniCycles[0].ledIntensity = 0xF; // 100%.
83+
pattern.miniCycles[0].transitionSteps = 0xF; // 15 steps. Total 187.5ms.
84+
pattern.miniCycles[0].finalStepDuration = 0x0; // Forced 12.5ms.
85+
pattern.miniCycles[1].ledIntensity = 0x0; // 0%.
86+
pattern.miniCycles[1].transitionSteps = 0xF; // 15 steps. Total 187.5ms.
87+
pattern.miniCycles[1].finalStepDuration = 0x0; // Forced 12.5ms.
88+
89+
// Second beat.
90+
pattern.miniCycles[2].ledIntensity = 0xF;
91+
pattern.miniCycles[2].transitionSteps = 0xF;
92+
pattern.miniCycles[2].finalStepDuration = 0x0;
93+
pattern.miniCycles[3].ledIntensity = 0x0;
94+
pattern.miniCycles[3].transitionSteps = 0xF;
95+
pattern.miniCycles[3].finalStepDuration = 0x0;
96+
97+
// Led off wait time.
98+
for(i=2; i<15; i++) {
99+
pattern.miniCycles[i].ledIntensity = 0x0; // 0%.
100+
pattern.miniCycles[i].transitionSteps = 0xF; // 15 steps. Total 187.5ms.
101+
pattern.miniCycles[i].finalStepDuration = 0xF; // 187.5ms.
102+
}
103+
}
61104

62-
if (kDown & KEY_A) {
105+
if (kDown & (KEY_A | KEY_B | KEY_PLUS)) {
63106
total_entries = 0;
64107
memset(UniquePadIds, 0, sizeof(UniquePadIds));
65108

@@ -81,6 +124,9 @@ int main(int argc, char* argv[])
81124

82125
// Update the console, sending a new frame to the display
83126
consoleUpdate(NULL);
127+
128+
if (kDown & KEY_PLUS)
129+
break; // break in order to return to hbmenu
84130
}
85131

86132
if (initflag) hidsysExit();

0 commit comments

Comments
 (0)