Skip to content

Commit 153f64a

Browse files
committed
update late
1 parent d7f70a6 commit 153f64a

4 files changed

Lines changed: 172 additions & 42 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ INCLUDES := include
3838
EXEFS_SRC := exefs_src
3939
APP_TITLE := Lock-Logs
4040
APP_AUTHOR := Kronos2308
41-
APP_VERSION := 1.0
41+
APP_VERSION := 1.1
4242
#ROMFS := romfs
4343

4444
#---------------------------------------------------------------------------------

source/led.cpp

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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+

source/led.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
void flash_led_connect();
2+
void flash_led_disconnect();
3+
void led_on(int inter);

source/main.cpp

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
#include <stdlib.h>
2424
#include <stdlib.h>
2525
#include "FileSystem.hpp"
26-
26+
#include "led.hpp"
2727
using namespace std;
28-
FsFileSystem loc;
2928
//traduction
3029
bool isSpanish = false;
3130
void set_LANG()
@@ -60,39 +59,6 @@ bool fileExists(const char* path)
6059
}
6160

6261

63-
bool led_on(void)
64-
{
65-
Result rc=0;
66-
s32 i;
67-
s32 total_entries;
68-
u64 UniquePadIds[2];
69-
HidsysNotificationLedPattern pattern;
70-
hidsysExit();
71-
rc = hidsysInitialize();
72-
if (R_FAILED(rc)) {printf("hidsysInitialize(): 0x%x\n", rc);}
73-
74-
memset(&pattern, 0, sizeof(pattern));
75-
// Setup Breathing effect pattern data.
76-
pattern.baseMiniCycleDuration = 0x8; // 100ms.
77-
pattern.totalMiniCycles = 0x2; // 3 mini cycles. Last one 12.5ms.
78-
pattern.totalFullCycles = 0x6; // Repeat Time.
79-
pattern.startIntensity = 0x2; // 13%.
80-
81-
pattern.miniCycles[0].ledIntensity = 0xF; // 100%.
82-
pattern.miniCycles[0].transitionSteps = 0xF; // 15 steps. Transition time 1.5s.
83-
pattern.miniCycles[0].finalStepDuration = 0x0; // Forced 12.5ms.
84-
pattern.miniCycles[1].ledIntensity = 0x2; // 13%.
85-
pattern.miniCycles[1].transitionSteps = 0xF; // 15 steps. Transition time 1.5s.
86-
pattern.miniCycles[1].finalStepDuration = 0x0; // Forced 12.5ms.
87-
88-
rc = hidsysGetUniquePadsFromNpad(hidGetHandheldMode() ? CONTROLLER_HANDHELD : CONTROLLER_PLAYER_1, UniquePadIds, 2, &total_entries);
89-
if (R_SUCCEEDED(rc))
90-
{for(i=0; i<total_entries; i++) { rc = hidsysSetNotificationLedPattern(&pattern, UniquePadIds[i]);}}
91-
92-
hidsysExit();
93-
return 0;
94-
}
95-
9662
void espera(u32 timeS)
9763
{
9864
u32 cout = 0;
@@ -130,8 +96,6 @@ void Lock(u64 TID)
13096

13197
fsdevCommitDevice("save");
13298
fsdevUnmountDevice("save");
133-
fsFsClose(&loc);
134-
13599
}
136100

137101
void install()
@@ -148,7 +112,7 @@ void install()
148112
Lock(0x80000000000000A2);
149113
printf("\x1b[32;1m*\x1b[0m W COMPLETE\n");
150114
consoleUpdate(NULL);
151-
led_on();
115+
led_on(1);
152116
espera(5);
153117
bpcInitialize();
154118
bpcRebootSystem();
@@ -224,11 +188,21 @@ void uninstall()
224188
int main(int argc, char **argv)
225189
{
226190
set_LANG();
191+
PadState pad;
192+
padConfigureInput(8, HidNpadStyleSet_NpadStandard);
193+
padInitializeDefault(&pad);
194+
195+
227196
while (appletMainLoop())
228197
{
198+
/*
229199
hidScanInput();
230200
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
231201
u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
202+
*/
203+
padUpdate(&pad);
204+
u64 kDown = padGetButtonsDown(&pad);
205+
u64 kHeld = padGetButtons(&pad);
232206

233207
consoleInit(NULL);
234208
printf("\x1b[32;1m*\x1b[0m %s v%s Kronos2308, BCAT LOCKER\n",TITLE, VERSION);
@@ -258,20 +232,20 @@ set_LANG();
258232
}
259233
consoleUpdate(NULL);
260234

261-
if (kDown & KEY_A)
235+
if (kDown & HidNpadButton_A)
262236
{
263237
install();
264238
break;
265239
}
266240

267-
if ((kDown & KEY_MINUS || kDown & KEY_PLUS) && (kHeld & KEY_MINUS && kHeld & KEY_PLUS))
241+
if ((kDown & HidNpadButton_Minus || kDown & HidNpadButton_Plus) && (kHeld & HidNpadButton_Minus && kHeld & HidNpadButton_Plus))
268242
{
269243
uninstall();
270244
break;
271245
}
272246

273247

274-
if (kDown & KEY_B || kDown & KEY_Y || kDown & KEY_X)
248+
if (kDown & HidNpadButton_B || kDown & HidNpadButton_Y || kDown & HidNpadButton_X)
275249
{
276250
break;
277251
}

0 commit comments

Comments
 (0)