diff --git a/.gitignore b/.gitignore index 8366875..d059877 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ 3DS/build/ 3DS/*.elf 3DS/*stripped.elf -3DS/*.3dsx 3DS/*.smdh 3DS/*.3ds 3DS/*.cia PC/build/ -PC/*.exe \ No newline at end of file +*.pnproj +*.pnps +*.ppg diff --git a/3DS/3DSController.3dsx b/3DS/3DSController.3dsx new file mode 100644 index 0000000..3ec81d1 Binary files /dev/null and b/3DS/3DSController.3dsx differ diff --git a/3DS/include/wireless.h b/3DS/include/wireless.h index 27efcae..6ad6983 100644 --- a/3DS/include/wireless.h +++ b/3DS/include/wireless.h @@ -59,6 +59,8 @@ struct packet { short x; short y; } cStick; + + unsigned int volume; //way longer than needed, but it works. }; struct keysPacket keysPacket; }; @@ -84,4 +86,4 @@ bool openSocket(int port); void sendBuf(int length); int receiveBuffer(int length); void sendConnectionRequest(void); -void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch, circlePosition cStick); +void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch, circlePosition cStick, unsigned int volume); diff --git a/3DS/source/main.c b/3DS/source/main.c index e61954b..e26a7c2 100644 --- a/3DS/source/main.c +++ b/3DS/source/main.c @@ -34,8 +34,8 @@ int main(void) { acInit(); gfxInitDefault(); - gfxSetDoubleBuffering(GFX_TOP, false); - gfxSetDoubleBuffering(GFX_BOTTOM, false); + gfxSetDoubleBuffering(GFX_TOP, true); + gfxSetDoubleBuffering(GFX_BOTTOM, true); if(setjmp(exitJmp)) goto exit; @@ -91,8 +91,12 @@ int main(void) { u32 kHeld = hidKeysHeld(); circlePosition circlePad; circlePosition cStick; + u8 vol8; + u8* volp = &vol8; //As a test for pointing at things. hidCstickRead(&cStick); hidCircleRead(&circlePad); + HIDUSER_GetSoundVolume(volp); + u32 volume = (u32)vol8; //Upscale to 32 for transmission touchPosition touch; touchRead(&touch); @@ -103,7 +107,11 @@ int main(void) { keyboardActive = !keyboardActive; keyboardToggle = false; - if(keyboardActive) enableBacklight(); + if(keyboardActive) { + enableBacklight(); + } else { + disableBacklight(); + } } } else keyboardToggle = true; @@ -135,12 +143,12 @@ int main(void) { } } - sendKeys(kHeld, circlePad, touch, cStick); - + sendKeys(kHeld, circlePad, touch, cStick, volume); + drawString(10, 10, "Volume: %x", volume); //receiveBuffer(sizeof(struct packet)); if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) { - sendKeys(0, circlePad, touch, cStick); + sendKeys(0, circlePad, touch, cStick, volume); longjmp(exitJmp, 1); } diff --git a/3DS/source/wireless.c b/3DS/source/wireless.c index 0c9bc38..8abe2c8 100644 --- a/3DS/source/wireless.c +++ b/3DS/source/wireless.c @@ -38,12 +38,13 @@ void sendConnectionRequest(void) { sendBuf(offsetof(struct packet, connectPacket) + sizeof(struct connectPacket)); } -void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch, circlePosition cStick) { +void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch, circlePosition cStick, unsigned int volume) { outBuf.command = KEYS; outBuf.keyboardActive = keyboardActive; memcpy(&outBuf.keys, &keys, 4); memcpy(&outBuf.circlePad, &circlePad, 4); memcpy(&outBuf.touch, &touch, 4); memcpy(&outBuf.cStick, &cStick, 4); + memcpy(&outBuf.volume, &volume, 4); sendBuf(offsetof(struct packet, keysPacket) + sizeof(struct keysPacket)); } diff --git a/PC/3DSController.exe b/PC/3DSController.exe new file mode 100644 index 0000000..82ad4a9 Binary files /dev/null and b/PC/3DSController.exe differ diff --git a/PC/include/joystick.h b/PC/include/joystick.h index 0681214..6101009 100644 --- a/PC/include/joystick.h +++ b/PC/include/joystick.h @@ -13,6 +13,10 @@ #define joyY iReport.wAxisY #define joyRX iReport.wAxisXRot #define joyRY iReport.wAxisYRot +//#define joyVolume iReport.wSlider +#define joyVolume iReport.wAxisZ +#define povHat iReport.bHats + #define joyButtons iReport.lButtons #define JOY_MIDDLE (128 * 128) diff --git a/PC/include/keyboard.h b/PC/include/keyboard.h index accab67..a69601d 100644 --- a/PC/include/keyboard.h +++ b/PC/include/keyboard.h @@ -3,4 +3,4 @@ extern unsigned char keyboardActive; extern unsigned char keyboardToggle; -inline char currentKeyboardKey(void); +char currentKeyboardKey(void); diff --git a/PC/include/keys.h b/PC/include/keys.h index 7d12ca6..ad152bf 100644 --- a/PC/include/keys.h +++ b/PC/include/keys.h @@ -101,12 +101,14 @@ struct touch { extern unsigned int lastKeys; extern unsigned int currentKeys; +extern unsigned int volume; + extern struct circlePad circlePad; extern struct cStick cStick; extern struct touch lastTouch; extern struct touch currentTouch; -inline unsigned int mapVirtualKey(unsigned int key); +unsigned int mapVirtualKey(unsigned int key); void simulateKeyNewpress(unsigned int key); void simulateKeyRelease(unsigned int key); void handleHat(unsigned int hat); diff --git a/PC/include/settings.h b/PC/include/settings.h index 5865770..cab0c6f 100644 --- a/PC/include/settings.h +++ b/PC/include/settings.h @@ -20,6 +20,7 @@ struct settings { int mouseSpeed; UINT vJoyDevice; struct keyMapping A, B, X, Y, L, R, ZL, ZR, Start, Select, Tap, Left, Right, Up, Down, PadLeft, PadRight, PadUp, PadDown, CSLeft, CSRight, CSUp, CSDown; + bool isUsingPov; }; extern struct settings settings; diff --git a/PC/include/wireless.h b/PC/include/wireless.h index 772a194..4bff563 100644 --- a/PC/include/wireless.h +++ b/PC/include/wireless.h @@ -51,6 +51,8 @@ struct packet { short x; short y; } cStick; + + unsigned int volume; }; struct keysPacket keysPacket; diff --git a/PC/source/keys.c b/PC/source/keys.c index 9e68c97..56a074b 100644 --- a/PC/source/keys.c +++ b/PC/source/keys.c @@ -7,6 +7,7 @@ unsigned int lastKeys; unsigned int currentKeys; +unsigned int volume; //slider struct circlePad circlePad; struct cStick cStick; @@ -84,4 +85,4 @@ void handleHat(unsigned int hat) { else if(hat & BIT(2)) iReport.bHats = 2; else if(hat & BIT(3)) iReport.bHats = 3; else iReport.bHats = -1; -} \ No newline at end of file +} diff --git a/PC/source/main.c b/PC/source/main.c index 2e8952e..f769ca8 100644 --- a/PC/source/main.c +++ b/PC/source/main.c @@ -121,15 +121,19 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow) memcpy(&circlePad, &buffer.circlePad, 4); memcpy(¤tTouch, &buffer.touch, 4); memcpy(&cStick, &buffer.cStick, 4); + memcpy(&volume, &buffer.volume, 4); + //printf("\rVolume is currently: %x ", volume); //test handleKey(KEY_A, settings.A); handleKey(KEY_B, settings.B); handleKey(KEY_SELECT, settings.Select); handleKey(KEY_START, settings.Start); - handleKey(KEY_DRIGHT, settings.Right); - handleKey(KEY_DLEFT, settings.Left); - handleKey(KEY_DUP, settings.Up); - handleKey(KEY_DDOWN, settings.Down); + if(!settings.isUsingPov) { //Handle normally if not using POV in settings. + handleKey(KEY_DRIGHT, settings.Right); + handleKey(KEY_DLEFT, settings.Left); + handleKey(KEY_DUP, settings.Up); + handleKey(KEY_DDOWN, settings.Down); + } handleKey(KEY_R, settings.R); handleKey(KEY_L, settings.L); handleKey(KEY_ZR, settings.ZR); @@ -180,18 +184,28 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow) SetCursorPos((int)((double)currentTouch.x * widthMultiplier), (int)((double)currentTouch.y * heightMultiplier)); } } - else if(settings.touch == joystick1) { - joyX = (currentTouch.x) * 128; - joyY = (currentTouch.y) * 128; + else if(settings.touch == joystick1) { //made a little bit more accurate to the screen size. + joyX = (int)((float)(currentTouch.x) * 102.3f); + joyY = (int)((float)(currentTouch.y) * 136.5f); } else if(settings.touch == joystick2) { - joyRX = (currentTouch.x) * 128; - joyRY = (currentTouch.y) * 128; + joyRX = (int)((float)(currentTouch.x) * 102.3f); + joyRY = (int)((float)(currentTouch.y) * 136.5f); } else { handleKey(KEY_TOUCH, settings.Tap); } + } else { //If we are not touching, move to center (Like if you release the joystick on a normal controller). + if(settings.touch == joystick1) { + joyX = 16383; //Halfway between the x + joyY = 16383; //Halfway between the y + } + + else if(settings.touch == joystick2) { + joyRX = 16383; //Halfway between the rx + joyRY = 16383; //Halfway between the ry + } } if(settings.circlePad == mouse) { @@ -231,6 +245,43 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow) joyRY = (128 - cStick.y) * 128; } + + if(settings.isUsingPov) { + if((currentKeys & KEY_DUP) && !(currentKeys & KEY_DLEFT)) { + if((currentKeys & KEY_DRIGHT)) { + povHat = 4500; + } else { + povHat = 0; + } + } else if((currentKeys & KEY_DRIGHT)) { + if((currentKeys & KEY_DDOWN)) { + povHat = 13500; + } else { + povHat = 9000; + } + } else if((currentKeys & KEY_DDOWN)) { + if((currentKeys & KEY_DLEFT)) { + povHat = 22500; + } else { + povHat = 18000; + } + } else if((currentKeys & KEY_DLEFT)) { + if ((currentKeys & KEY_DUP)) { + povHat = 31500; + } else { + povHat = 27000; + } + } + + if(!((currentKeys & KEY_DUP) || (currentKeys & KEY_DRIGHT) || (currentKeys & KEY_DDOWN) || (currentKeys & KEY_DLEFT))) { + //If none are pressed, reset the POV hat + povHat = -1; + } + + } + + joyVolume = volume * 512; + break; } diff --git a/PC/source/settings.c b/PC/source/settings.c index 2a8298e..572c550 100644 --- a/PC/source/settings.c +++ b/PC/source/settings.c @@ -32,6 +32,7 @@ struct settings defaultSettings = { Start: { 1, {VK_RETURN} }, Select: { 1, {VK_BACK} }, Tap: { 1, {'T'} }, + isUsingPov: false, }; static bool getSetting(char *name, char *src, char *dest) { @@ -92,6 +93,9 @@ static struct keyMapping getButton(char *string) { else if(strcmp(string, "JOY14") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 5; } else if(strcmp(string, "JOY15") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 6; } else if(strcmp(string, "JOY16") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 7; } + else if(strcmp(string, "POV") == 0) {settings.isUsingPov = true;} + //No matter what the others are, if any are set to true then we are using the POV hat for the DPad + //This would mean if any setting at all is POV then the dpad is suddenly a POV. else if(strcmp(string, "NORTH") == 0) { k.useJoypad = 3; k.joypadButton = 1 << 0; } else if(strcmp(string, "EAST") == 0) { k.useJoypad = 3; k.joypadButton = 1 << 1; }