Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
QoL fixes
Browse files Browse the repository at this point in the history
- configure IP and port within the app
- fix backlight not turning on when exiting
  • Loading branch information
Ryuzaki-MrL committed Jun 4, 2018
1 parent b38db7d commit 5f2a54f
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 12 deletions.
3 changes: 3 additions & 0 deletions 3DS/include/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ extern unsigned char keyboardGfx[320 * 240 * 3];

void preRenderKeyboard(void);
extern void drawKeyboard(void);

int swkbd(char* out, const char* htext, const char* def, int maxlength);
int swkbd_int(int* out, const char* htext, int def);
1 change: 1 addition & 0 deletions 3DS/include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ extern struct settings defaultSettings;
extern Handle fileHandle;

bool readSettings(void);
void writeSettings(void);
30 changes: 30 additions & 0 deletions 3DS/source/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,33 @@ inline void drawKeyboard(void) {
drawBox((int)((float)10 * 320.0f / 12.0f) + 1, (int)(78.0f + (float)1 * 320.0f / 12.0f) + 1, (int)(2.0f * 320.0f / 12.0f) - 1, (int)(3.0f * 320.0f / 12.0f) - 1, 31, 0, 0);
*/
}

int swkbd(char* out, const char* htext, const char* def, int maxlength) {
SwkbdState kb;
swkbdInit(&kb, SWKBD_TYPE_QWERTY, 2, maxlength);
swkbdSetInitialText(&kb, def);
swkbdSetHintText(&kb, htext);
swkbdSetButton(&kb, SWKBD_BUTTON_LEFT, "Cancel", false);
swkbdSetButton(&kb, SWKBD_BUTTON_RIGHT, "Confirm", true);
swkbdSetValidation(&kb, SWKBD_NOTEMPTY_NOTBLANK, 0, 0);
swkbdInputText(&kb, out, maxlength);
SwkbdResult result = swkbdGetResult(&kb);
return (result==SWKBD_D1_CLICK1);
}

int swkbd_int(int* out, const char* htext, int def) {
static char buffer[11] = "";
SwkbdState kb;
swkbdInit(&kb, SWKBD_TYPE_NUMPAD, 2, sizeof(buffer) - 1);
snprintf(buffer, sizeof(buffer)-1, "%d", def);
swkbdSetInitialText(&kb, buffer);
swkbdSetHintText(&kb, htext);
swkbdSetButton(&kb, SWKBD_BUTTON_LEFT, "Cancel", false);
swkbdSetButton(&kb, SWKBD_BUTTON_RIGHT, "Confirm", true);
swkbdSetFeatures(&kb, SWKBD_FIXED_WIDTH);
swkbdSetValidation(&kb, SWKBD_NOTEMPTY_NOTBLANK, 0, 0);
swkbdInputText(&kb, buffer, sizeof(buffer));
SwkbdResult result = swkbdGetResult(&kb);
*out = atoi(buffer);
return (result==SWKBD_D1_CLICK1);
}
30 changes: 30 additions & 0 deletions 3DS/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,30 @@ int main(void) {
if(!readSettings()) {
hang("Could not read 3DSController.ini!");
}

gfxFlushBuffers();
gfxSwapBuffers();

while(aptMainLoop()) {
hidScanInput();
u32 kDown = hidKeysHeld();
if(kDown & KEY_X) {
swkbd(settings.IPString, "IPString", settings.IPString, sizeof(settings.IPString));
swkbd_int(&settings.port, "Port", settings.port);
inet_pton4(settings.IPString, (unsigned char *)&(saout.sin_addr));
writeSettings();
}
if(kDown & KEY_START) break;

clearScreen();
drawString(10, 10, "IP: %s, port: %d", settings.IPString, settings.port);
drawString(10, 20, "Press X to configure IP and port.");
drawString(10, 30, "Press START to continue.");

gfxFlushBuffers();
gspWaitForVBlank();
gfxSwapBuffers();
}

clearScreen();
drawString(10, 10, "Connecting to %s on port %d...", settings.IPString, settings.port);
Expand Down Expand Up @@ -163,6 +187,12 @@ int main(void) {
exit:

enableBacklight();
while(aptMainLoop()) {
gfxFlushBuffers();
gspWaitForVBlank();
gfxSwapBuffers();
break;
}

SOCU_ShutdownSockets();

Expand Down
37 changes: 25 additions & 12 deletions 3DS/source/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,29 @@ bool readSettings(void) {
u64 size;
u32 bytesRead;

FS_Path filePath = fsMakePath(PATH_ASCII, "/3DSController.ini");
//FS_Path filePath = fsMakePath(PATH_ASCII, "/3DSController.ini");
FILE* f = fopen("3DSController.ini", "rb");
if (!f) return 0;

Result ret = FSUSER_OpenFileDirectly(&fileHandle, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, ""), filePath, FS_OPEN_READ, 0x00000000);
if(ret) return false;
//Result ret = FSUSER_OpenFileDirectly(&fileHandle, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, ""), filePath, FS_OPEN_READ, 0x00000000);
//if(ret) return false;

ret = FSFILE_GetSize(fileHandle, &size);
if(ret) return false;
//ret = FSFILE_GetSize(fileHandle, &size);
//if(ret) return false;

fseek(f, 0, SEEK_END);
size = ftell(f);
buffer = malloc(size);
if(!buffer) return false;
rewind(f);
if(!buffer) return 0;

ret = FSFILE_Read(fileHandle, &bytesRead, 0x0, buffer, size);
if(ret || size != bytesRead) return false;
//ret = FSFILE_Read(fileHandle, &bytesRead, 0x0, buffer, size);
//if(ret || size != bytesRead) return 0;
fread(buffer, 1, size, f);

ret = FSFILE_Close(fileHandle);
if(ret) return false;
//ret = FSFILE_Close(fileHandle);
//if(ret) return false;
fclose(f);

memcpy(&settings, &defaultSettings, sizeof(struct settings));

Expand All @@ -67,7 +74,7 @@ bool readSettings(void) {
}
else {
free(buffer);
return false;
return 0;
}

if(getSetting("Port: ", buffer, setting)) {
Expand All @@ -76,5 +83,11 @@ bool readSettings(void) {

free(buffer);

return true;
return 1;
}

void writeSettings(void) {
FILE* f = fopen("3DSController.ini", "w");
fprintf(f, "IP: %s\r\nPort: %d", settings.IPString, settings.port);
fclose(f);
}

0 comments on commit 5f2a54f

Please sign in to comment.