Skip to content

Commit

Permalink
Implement led flashing on connection
Browse files Browse the repository at this point in the history
  • Loading branch information
tgkokk authored and jakibaki committed Jul 1, 2019
1 parent 7c4789a commit e420c9b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 5 deletions.
5 changes: 3 additions & 2 deletions .vscode/settings.json
Expand Up @@ -14,6 +14,7 @@
"string": "c",
"string_view": "c",
"ios": "c",
"ftp.h": "c"
"ftp.h": "c",
"util.h": "c"
}
}
}
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -158,4 +158,4 @@ $(OFILES_SRC) : $(HFILES_BIN)

#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------
2 changes: 2 additions & 0 deletions source/ftp.c
Expand Up @@ -38,6 +38,7 @@
#define BIT(x) (1 << (x))
#endif
#include "console.h"
#include "led.h"
#include "util.h"

#define POLL_UNKNOWN (~(POLLIN | POLLPRI | POLLOUT))
Expand Down Expand Up @@ -2176,6 +2177,7 @@ ftp_loop(void)
{
return LOOP_RESTART;
}
flash_led_connect();
playMp3("/ftpd/connect.mp3");
}
else
Expand Down
35 changes: 35 additions & 0 deletions source/led.c
@@ -0,0 +1,35 @@
#include <string.h>
#include <switch.h>

#include "console.h"
#include "util.h"

void flash_led_connect()
{
HidsysNotificationLedPattern pattern;
memset(&pattern, 0, sizeof(pattern));

pattern.baseMiniCycleDuration = 0x2;
pattern.totalMiniCycles = 0x2;
pattern.totalFullCycles = 0x1;
pattern.startIntensity = 0x0;

pattern.miniCycles[0].ledIntensity = 0xF;
pattern.miniCycles[0].transitionSteps = 0xF;
pattern.miniCycles[0].finalStepDuration = 0x0;
pattern.miniCycles[1].ledIntensity = 0x0;
pattern.miniCycles[1].transitionSteps = 0xF;
pattern.miniCycles[1].finalStepDuration = 0x0;

u64 uniquePadIds[2];
memset(uniquePadIds, 0, sizeof(uniquePadIds));

size_t total_entries = 0;

Result rc = hidsysGetUniquePadsFromNpad(hidGetHandheldMode() ? CONTROLLER_HANDHELD : CONTROLLER_PLAYER_1, uniquePadIds, 2, &total_entries);
if (R_FAILED(rc))
fatalLater(rc);

for (int i = 0; i < total_entries; i++)
hidsysSetNotificationLedPattern(&pattern, uniquePadIds[i]);
}
1 change: 1 addition & 0 deletions source/led.h
@@ -0,0 +1 @@
void flash_led_connect();
16 changes: 14 additions & 2 deletions source/main.c
Expand Up @@ -58,6 +58,18 @@ void __appInit(void)
rc = hidInitialize();
if (R_FAILED(rc))
fatalLater(rc);
rc = hidsysInitialize();
if (R_FAILED(rc))
fatalLater(rc);
rc = setsysInitialize();
if (R_SUCCEEDED(rc))
{
SetSysFirmwareVersion fw;
rc = setsysGetFirmwareVersion(&fw);
if (R_SUCCEEDED(rc))
hosversionSet(MAKEHOSVERSION(fw.major, fw.minor, fw.micro));
setsysExit();
}
}

void __appExit(void)
Expand All @@ -67,6 +79,8 @@ void __appExit(void)
smExit();
audoutExit();
timeExit();
hidExit();
hidsysExit();
}

static loop_status_t loop(loop_status_t (*callback)(void))
Expand Down Expand Up @@ -125,10 +139,8 @@ int main(int argc, char **argv)
if (R_FAILED(rc))
fatalLater(rc);


loop_status_t status = LOOP_RESTART;


ftp_pre_init();
while (status == LOOP_RESTART)
{
Expand Down

0 comments on commit e420c9b

Please sign in to comment.