|
| 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 | +} |
0 commit comments