|
| 1 | +#include <string.h> |
| 2 | +#include <switch.h> |
| 3 | +#include <stdio.h> |
| 4 | + |
| 5 | +void led_on(int inter) |
| 6 | +{ |
| 7 | + // Configure our supported input layout: a single player with standard controller styles |
| 8 | + |
| 9 | + Result rc=0; |
| 10 | + s32 i; |
| 11 | + s32 total_entries; |
| 12 | + HidsysUniquePadId unique_pad_ids[2]={0}; |
| 13 | + HidsysNotificationLedPattern pattern; |
| 14 | + |
| 15 | + rc = hidsysInitialize(); |
| 16 | + if (R_FAILED(rc)) { |
| 17 | + printf("hidsysInitialize(): 0x%x\n", rc); |
| 18 | + } |
| 19 | + // Scan the gamepad. This should be done once for each frame |
| 20 | + PadState pad; |
| 21 | + padInitializeDefault(&pad); |
| 22 | + padUpdate(&pad); |
| 23 | + |
| 24 | + // padGetButtonsDown returns the set of buttons that have been |
| 25 | + // newly pressed in this frame compared to the previous one |
| 26 | + //u64 kDown = padGetButtonsDown(&pad); |
| 27 | + |
| 28 | + switch(inter) |
| 29 | + { |
| 30 | + case 1: |
| 31 | + |
| 32 | + memset(&pattern, 0, sizeof(pattern)); |
| 33 | + // Setup Breathing effect pattern data. |
| 34 | + pattern.baseMiniCycleDuration = 0x8; // 100ms. |
| 35 | + pattern.totalMiniCycles = 0x2; // 3 mini cycles. Last one 12.5ms. |
| 36 | + pattern.totalFullCycles = 0x0; // Repeat forever. |
| 37 | + pattern.startIntensity = 0x2; // 13%. |
| 38 | + |
| 39 | + pattern.miniCycles[0].ledIntensity = 0xF; // 100%. |
| 40 | + pattern.miniCycles[0].transitionSteps = 0xF; // 15 steps. Transition time 1.5s. |
| 41 | + pattern.miniCycles[0].finalStepDuration = 0x0; // Forced 12.5ms. |
| 42 | + pattern.miniCycles[1].ledIntensity = 0x2; // 13%. |
| 43 | + pattern.miniCycles[1].transitionSteps = 0xF; // 15 steps. Transition time 1.5s. |
| 44 | + pattern.miniCycles[1].finalStepDuration = 0x0; // Forced 12.5ms. |
| 45 | + |
| 46 | + break; |
| 47 | + |
| 48 | + |
| 49 | + case 2: |
| 50 | + memset(&pattern, 0, sizeof(pattern)); |
| 51 | + // Setup Heartbeat effect pattern data. |
| 52 | + pattern.baseMiniCycleDuration = 0x1; // 12.5ms. |
| 53 | + pattern.totalMiniCycles = 0xF; // 16 mini cycles. |
| 54 | + pattern.totalFullCycles = 0x0; // Repeat forever. |
| 55 | + pattern.startIntensity = 0x0; // 0%. |
| 56 | + |
| 57 | + // First beat. |
| 58 | + pattern.miniCycles[0].ledIntensity = 0xF; // 100%. |
| 59 | + pattern.miniCycles[0].transitionSteps = 0xF; // 15 steps. Total 187.5ms. |
| 60 | + pattern.miniCycles[0].finalStepDuration = 0x0; // Forced 12.5ms. |
| 61 | + pattern.miniCycles[1].ledIntensity = 0x0; // 0%. |
| 62 | + pattern.miniCycles[1].transitionSteps = 0xF; // 15 steps. Total 187.5ms. |
| 63 | + pattern.miniCycles[1].finalStepDuration = 0x0; // Forced 12.5ms. |
| 64 | + |
| 65 | + // Second beat. |
| 66 | + pattern.miniCycles[2].ledIntensity = 0xF; |
| 67 | + pattern.miniCycles[2].transitionSteps = 0xF; |
| 68 | + pattern.miniCycles[2].finalStepDuration = 0x0; |
| 69 | + pattern.miniCycles[3].ledIntensity = 0x0; |
| 70 | + pattern.miniCycles[3].transitionSteps = 0xF; |
| 71 | + pattern.miniCycles[3].finalStepDuration = 0x0; |
| 72 | + |
| 73 | + // Led off wait time. |
| 74 | + for(i=2; i<4; i++) { |
| 75 | + pattern.miniCycles[i].ledIntensity = 0x0; // 0%. |
| 76 | + pattern.miniCycles[i].transitionSteps = 0xF; // 15 steps. Total 187.5ms. |
| 77 | + pattern.miniCycles[i].finalStepDuration = 0xF; // 187.5ms. |
| 78 | + } |
| 79 | + break; |
| 80 | + |
| 81 | + case 3: |
| 82 | + memset(&pattern, 0, sizeof(pattern)); |
| 83 | + // Setup Beacon effect pattern data. |
| 84 | + pattern.baseMiniCycleDuration = 0x1; // 12.5ms. |
| 85 | + pattern.totalMiniCycles = 0xF; // 16 mini cycles. |
| 86 | + pattern.totalFullCycles = 0x0; // Repeat forever. |
| 87 | + pattern.startIntensity = 0x0; // 0%. |
| 88 | + |
| 89 | + // First beat. |
| 90 | + pattern.miniCycles[0].ledIntensity = 0xF; // 100%. |
| 91 | + pattern.miniCycles[0].transitionSteps = 0xF; // 15 steps. Total 187.5ms. |
| 92 | + pattern.miniCycles[0].finalStepDuration = 0x0; // Forced 12.5ms. |
| 93 | + pattern.miniCycles[1].ledIntensity = 0x0; // 0%. |
| 94 | + pattern.miniCycles[1].transitionSteps = 0xF; // 15 steps. Total 187.5ms. |
| 95 | + pattern.miniCycles[1].finalStepDuration = 0x0; // Forced 12.5ms. |
| 96 | + |
| 97 | + // Second beat. |
| 98 | + pattern.miniCycles[2].ledIntensity = 0xF; |
| 99 | + pattern.miniCycles[2].transitionSteps = 0xF; |
| 100 | + pattern.miniCycles[2].finalStepDuration = 0x0; |
| 101 | + pattern.miniCycles[3].ledIntensity = 0x0; |
| 102 | + pattern.miniCycles[3].transitionSteps = 0xF; |
| 103 | + pattern.miniCycles[3].finalStepDuration = 0x0; |
| 104 | + |
| 105 | + // Led off wait time. |
| 106 | + for(i=4; i<4; i++) { |
| 107 | + pattern.miniCycles[i].ledIntensity = 0x0; // 0%. |
| 108 | + pattern.miniCycles[i].transitionSteps = 0xF; // 15 steps. Total 187.5ms. |
| 109 | + pattern.miniCycles[i].finalStepDuration = 0xF; // 187.5ms. |
| 110 | + } |
| 111 | + break; |
| 112 | + case 0: |
| 113 | + default: |
| 114 | + memset(&pattern, 0, sizeof(pattern)); |
| 115 | + break; |
| 116 | + } |
| 117 | + |
| 118 | + total_entries = 0; |
| 119 | + memset(unique_pad_ids, 0, sizeof(unique_pad_ids)); |
| 120 | + |
| 121 | + // Get the UniquePadIds for the specified controller, which will then be used with hidsysSetNotificationLedPattern*. |
| 122 | + // If you want to get the UniquePadIds for all controllers, you can use hidsysGetUniquePadIds instead. |
| 123 | + rc = hidsysGetUniquePadsFromNpad(padIsHandheld(&pad) ? HidNpadIdType_Handheld : HidNpadIdType_No1, unique_pad_ids, 2, &total_entries); |
| 124 | + printf("hidsysGetUniquePadsFromNpad(): 0x%x", rc); |
| 125 | + if (R_SUCCEEDED(rc)) printf(", %d", total_entries); |
| 126 | + printf("\n"); |
| 127 | + |
| 128 | + if (R_SUCCEEDED(rc)) { |
| 129 | + for(i=0; i<total_entries; i++) { // System will skip sending the subcommand to controllers where this isn't available. |
| 130 | + printf("[%d] = 0x%lx ", i, unique_pad_ids[i].id); |
| 131 | + |
| 132 | + // 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. |
| 133 | + rc = hidsysSetNotificationLedPatternWithTimeout(&pattern, unique_pad_ids[i], 10000000000ULL); |
| 134 | + printf("hidsysSetNotificationLedPatternWithTimeout(): 0x%x\n", rc); |
| 135 | + if (R_FAILED(rc)) { |
| 136 | + rc = hidsysSetNotificationLedPattern(&pattern, unique_pad_ids[i]); |
| 137 | + printf("hidsysSetNotificationLedPattern(): 0x%x\n", rc); |
| 138 | + } |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | +} |
| 143 | + |
| 144 | +void flash_led_connect() |
| 145 | +{ |
| 146 | + led_on(1); |
| 147 | +} |
| 148 | + |
| 149 | +void flash_led_disconnect() |
| 150 | +{ |
| 151 | + led_on(0); |
| 152 | +} |
| 153 | + |
0 commit comments