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

Adds reconnect button combo #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 3DS/include/input.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once

extern unsigned char reconn;
int inputIP(void);
22 changes: 12 additions & 10 deletions 3DS/source/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,54 @@

#include "input.h"

unsigned char reconn = true;

int inputIP(void) {
touchPosition touch;
hidTouchRead(&touch);

//Draw Keypad
drawString(160-20,50, "1");
drawString(160, 50, "2");
drawString(160+20, 50, "3");

drawString(160-20, 50+20, "4");
drawString(160, 50+20, "5");
drawString(160+20, 50+20, "6");

drawString(160-20, 50+40, "7");
drawString(160, 50+40, "8");
drawString(160+20, 50+40, "9");

drawString(160-10, 50+60, ".");
drawString(160+10, 50+60, "0");

//Bottom Strip
if(touch.py > 50+50 && touch.py < 50+70) {
if(touch.px < 160 && touch.px > 160-20) return 11; // Dot
else if(touch.px < 160+20 && touch.px > 160) return 0; // Zero
}

//First Column
else if(touch.px < 160-10 && touch.px > 160-30) {
if(touch.py < 50+10 && touch.py > 50-10) return 1; // One
else if(touch.py < 50+30 && touch.py > 50+10) return 4; // Four
else if(touch.py < 50+50 && touch.py > 50+30) return 7; // Seven
}

// Second Column
else if(touch.px < 160+10 && touch.px > 160-10) {
if(touch.py < 50+10 && touch.py > 50-10) return 2; // Two
else if(touch.py < 50+30 && touch.py > 50+10) return 5; // Five
else if(touch.py < 50+50 && touch.py > 50+30) return 8; // Eight
}

// Third Column
else if(touch.px < 160+30 && touch.px > 160+10) {
if(touch.py < 50+10 && touch.py > 50-10) return 3; // Three
else if(touch.py < 50+30 && touch.py > 50+10) return 6; // Six
else if(touch.py < 50+50 && touch.py > 50+30) return 9; // Nine
}

return 10;
}
}
104 changes: 62 additions & 42 deletions 3DS/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ static jmp_buf exitJmp;
void hang(char *message) {
while(aptMainLoop()) {
hidScanInput();

clearScreen();
drawString(10, 10, "%s", message);
drawString(10, 20, "Press Start and Select to exit.");

u32 kHeld = hidKeysHeld();
if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) longjmp(exitJmp, 1);

gfxFlushBuffers();
gspWaitForVBlank();
gfxSwapBuffers();
Expand All @@ -33,144 +33,164 @@ void hang(char *message) {
int main(void) {
acInit();
gfxInitDefault();

gfxSetDoubleBuffering(GFX_TOP, false);
gfxSetDoubleBuffering(GFX_BOTTOM, false);

if(setjmp(exitJmp)) goto exit;

preRenderKeyboard();

clearScreen();
drawString(10, 10, "Initialising FS...");
gfxFlushBuffers();
gfxSwapBuffers();

fsInit();

clearScreen();
drawString(10, 10, "Initialising SOC...");
gfxFlushBuffers();
gfxSwapBuffers();

socInit((u32 *)memalign(0x1000, 0x100000), 0x100000);

while(aptMainLoop()) { /* Wait for WiFi; break when WiFiStatus is truthy */
u32 wifiStatus = 0;
ACU_GetWifiStatus(&wifiStatus);
if(wifiStatus) break;

hidScanInput();
clearScreen();
drawString(10, 10, "Waiting for WiFi connection...");
drawString(10, 20, "Ensure you are in range of an access point,");
drawString(10, 30, "and that wireless communications are enabled.");
drawString(10, 50, "You can alternatively press Start and Select to exit.");

u32 kHeld = hidKeysHeld();
if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) longjmp(exitJmp, 1);

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

clearScreen();
drawString(10, 10, "Reading settings...");
gfxFlushBuffers();
gfxSwapBuffers();

if(!readSettings()) {
hang("Could not read 3DSController.ini!");
}

clearScreen();
drawString(10, 10, "Connecting to %s on port %d...", settings.IPString, settings.port);
gfxFlushBuffers();
gfxSwapBuffers();

openSocket(settings.port);
sendConnectionRequest();

clearScreen();
gfxFlushBuffers();
gfxSwapBuffers();

disableBacklight();

while(aptMainLoop()) {
hidScanInput();
irrstScanInput();

u32 kHeld = hidKeysHeld();
circlePosition circlePad;
circlePosition cStick;
hidCstickRead(&cStick);
hidCircleRead(&circlePad);
touchPosition touch;
touchRead(&touch);

clearScreen();

if((kHeld & KEY_L) && (kHeld & KEY_R) && (kHeld & KEY_X)) {
if(keyboardToggle) {
keyboardActive = !keyboardActive;
keyboardToggle = false;

if(keyboardActive) enableBacklight();
}
}
else keyboardToggle = true;


if((kHeld & KEY_L) && (kHeld & KEY_R) && (kHeld & KEY_Y)) {
if (reconn) {
//Reconnect
clearScreen();
drawString(10, 10, "Connecting to %s on port %d...", settings.IPString, settings.port);
gfxFlushBuffers();
gfxSwapBuffers();

openSocket(settings.port);
sendConnectionRequest();

clearScreen();
gfxFlushBuffers();
gfxSwapBuffers();

reconn = false;
}
}
else reconn = true;

if(keyboardActive) {
drawKeyboard();

if(touch.px >= 1 && touch.px <= 312 && touch.py >= 78 && touch.py <= 208) {
int x = (int)((float)touch.px * 12.0f / 320.0f);
int y = (int)((float)(touch.py - 78) * 12.0f / 320.0f);
int width = 24;
int height = 24;

if(keyboardChars[x + y * 12] == ' ') {
while(keyboardChars[(x - 1) + y * 12] == ' ') x--;

width = (int)(5.0f * 320.0f / 12.0f) - 1;
}

else if(keyboardChars[x + y * 12] == '\13') {
while(keyboardChars[(x - 1) + y * 12] == '\13') x--;
while(keyboardChars[x + (y - 1) * 12] == '\13') y--;

width = (int)(2.0f * 320.0f / 12.0f) - 1;
height = (int)(3.0f * 320.0f / 12.0f) - 1;
}

if(keyboardChars[x + y * 12]) drawBox((int)((float)x * 320.0f / 12.0f) + 1, (int)(78.0f + (float)y * 320.0f / 12.0f) + 1, width, height, 31, 31, 0);
}
}

sendKeys(kHeld, circlePad, touch, cStick);

//receiveBuffer(sizeof(struct packet));

if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) longjmp(exitJmp, 1);

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

exit:

enableBacklight();

SOCU_ShutdownSockets();

svcCloseHandle(fileHandle);
fsExit();

gfxExit();
acExit();

return 0;
}
Loading