From 206f2ec0fe03815bd740e56cdca08df2bc039bd6 Mon Sep 17 00:00:00 2001 From: TheNightman Date: Mon, 20 Mar 2017 00:59:38 -0400 Subject: [PATCH 1/2] Adds reconnect button combo --- 3DS/include/input.h | 1 + 3DS/source/input.c | 22 +++++----- 3DS/source/main.c | 104 ++++++++++++++++++++++++++------------------ 3 files changed, 75 insertions(+), 52 deletions(-) diff --git a/3DS/include/input.h b/3DS/include/input.h index 90ba655..8d44a9c 100644 --- a/3DS/include/input.h +++ b/3DS/include/input.h @@ -1,3 +1,4 @@ #pragma once +extern unsigned char reconn; int inputIP(void); diff --git a/3DS/source/input.c b/3DS/source/input.c index e79248e..5c2d59c 100644 --- a/3DS/source/input.c +++ b/3DS/source/input.c @@ -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; -} \ No newline at end of file +} diff --git a/3DS/source/main.c b/3DS/source/main.c index c444347..17f71b6 100644 --- a/3DS/source/main.c +++ b/3DS/source/main.c @@ -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(); @@ -33,75 +33,75 @@ 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; @@ -109,68 +109,88 @@ int main(void) { 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; } From 084db9392ef7482fb5f26dc00112093663b2ecf3 Mon Sep 17 00:00:00 2001 From: TheNightman Date: Sun, 2 Apr 2017 19:09:13 -0400 Subject: [PATCH 2/2] Adds linux support for OP2 fork --- Linux/3DSController.py | 39 +++++++++++++++++----------------- Linux/3DSController_gamepad.py | 21 +++++++++--------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/Linux/3DSController.py b/Linux/3DSController.py index 8ae386c..da9a60c 100755 --- a/Linux/3DSController.py +++ b/Linux/3DSController.py @@ -99,7 +99,7 @@ def currentKeyboardKey(x, y): "ASDFGHJKL-\13\13"+ "ZXCVBNM,.?\13\13"+ "\0\0\0 \0\0\0\0") - + if x>=1 and x<=312 and y>=78 and y<=208: xi = int(x*12/320) yi = int((y-78)*12/320) @@ -108,13 +108,13 @@ def currentKeyboardKey(x, y): def key_to_keysym(key): if not key: return 0 - + if isinstance(key,str): if key=="\x08": return Xlib.XK.XK_BackSpace if key=="\13": return Xlib.XK.XK_Return if key==" ": return Xlib.XK.XK_space return Xlib.XK.string_to_keysym(key) - + return key def action_key(key, action): @@ -123,7 +123,7 @@ def action_key(key, action): if action: x_action = Xlib.X.ButtonPress x_action2 = Xlib.X.KeyPress - + if key is LMouse or key is RMouse: if key is LMouse: button = 1 if key is RMouse: button = 3 @@ -131,17 +131,17 @@ def action_key(key, action): disp.xtest_fake_input(x_action, button) disp.sync() return - + keysym = key_to_keysym(key) if not keysym: return - + keycode = disp.keysym_to_keycode(keysym) disp.xtest_fake_input(x_action2, keycode) disp.sync() - + def press_key(key): action_key(key,True) - + def release_key(key): action_key(key,False) @@ -149,14 +149,14 @@ def move_mouse(x,y): x=int(x) y=int(y) if not x and not y: return - + disp.warp_pointer(x,y) disp.sync() def move_mouse_abs_frac(x,y): root = disp.screen().root geom = root.get_geometry() - + root.warp_pointer(int(x*geom.width), int(y*geom.height)) disp.sync() @@ -184,13 +184,13 @@ def move_mouse_abs_frac(x,y): rawdata, addr = sock.recvfrom(4096) rawdata = bytearray(rawdata) #print("received message", rawdata, "from", addr) - + if rawdata[0]==command.CONNECT: pass # CONNECT packets are empty - + if rawdata[0]==command.KEYS: - fields = struct.unpack("=16 or abs(data["circleY"])>=16: move_mouse(data["circleX"]*mouse_speed/32.0, -data["circleY"]*mouse_speed/32.0) - + if rawdata[0]==command.SCREENSHOT: pass # unused by both 3DS and PC applications diff --git a/Linux/3DSController_gamepad.py b/Linux/3DSController_gamepad.py index 0c1e45b..4ad6525 100644 --- a/Linux/3DSController_gamepad.py +++ b/Linux/3DSController_gamepad.py @@ -100,10 +100,10 @@ class x: pass keys.CLeft = 1<<29 # circle pad keys.CUp = 1<<30 # circle pad keys.CDown = 1<<31 # circle pad - + def press_key(key): device.emit(key, 1) - + def release_key(key): device.emit(key,0) @@ -119,14 +119,14 @@ def release_key(key): while True: rawdata, addr = sock.recvfrom(4096) rawdata = bytearray(rawdata) - #print("received message", rawdata, "from", addr) - + if rawdata[0]==command.CONNECT: + print("3DS Connected!") pass # CONNECT packets are empty - + if rawdata[0]==command.KEYS: - fields = struct.unpack("