#include #include #include #include #include <3ds.h> #include "3ds/services/gsplcd.h" #include "3ds/services/hid.h" #include "3ds/services/soc.h" #include "drawing.h" #include "input.h" // #include "keyboard.h" #include "settings.h" #include "wireless.h" static jmp_buf exitJmp; void hang(char *message) { while (aptMainLoop()) { hidScanInput(); clearScreen(); drawString(10, 10, "%s", message); drawString(10, 20, "Start and Select to exit"); u32 kHeld = hidKeysHeld(); if ((kHeld & KEY_START) && (kHeld & KEY_SELECT)) longjmp(exitJmp, 1); gfxFlushBuffers(); gspWaitForVBlank(); gfxSwapBuffers(); } } int main(void) { acInit(); gfxInitDefault(); gfxSetDoubleBuffering(GFX_TOP, true); gfxSetDoubleBuffering(GFX_BOTTOM, true); if (setjmp(exitJmp)) goto exit; // preRenderKeyboard(); // clearScreen(); drawString(10, 10, "Initing FS..."); gfxFlushBuffers(); gfxSwapBuffers(); fsInit(); // clearScreen(); drawString(10, 10, "Initing SOC..."); gfxFlushBuffers(); gfxSwapBuffers(); socInit((u32 *)memalign(0x1000, 0x100000), 0x100000); u32 wifiStatus = 0; ACU_GetWifiStatus(&wifiStatus); if (!wifiStatus) { hang("No WiFi! Is your wireless slider on?"); } 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(); drawString(10, 10, "Sending data to %s on port %d...", settings.IPString, settings.port); gfxFlushBuffers(); gfxSwapBuffers(); GSPLCD_PowerOffAllBacklights(); while (aptMainLoop()) { hidScanInput(); irrstScanInput(); u32 kHeld = hidKeysHeld(); circlePosition circlePad; circlePosition cStick; angularRate gyro; accelVector accel; u8 vol8; u8 *volPointer = &vol8; // As a test for pointing at things. // u8 threeD; // u8 *threeDPointer = &threeD; hidCstickRead(&cStick); hidCircleRead(&circlePad); HIDUSER_EnableGyroscope(); hidGyroRead(&gyro); HIDUSER_EnableAccelerometer(); hidAccelRead(&accel); HIDUSER_GetSoundVolume(volPointer); // MCUHWC_GetSoundSliderLevel(threeDPointer); u32 volume = (u32)vol8; // Upscale to 32 for transmission // u32 threeD32 = (u32)threeD; touchPosition touch; touchRead(&touch); clearScreen(); sendKeys(kHeld, circlePad, touch, cStick, volume, gyro, accel); // drawString(10, 10, "Volume: %x", volume); // receiveBuffer(sizeof(struct packet)); if ((kHeld & KEY_START) && (kHeld & KEY_SELECT)) { sendKeys(0, circlePad, touch, cStick, volume, gyro, accel); longjmp(exitJmp, 1); } gfxFlushBuffers(); gspWaitForVBlank(); gfxSwapBuffers(); } exit: GSPLCD_PowerOnAllBacklights(); socExit(); svcCloseHandle(fileHandle); fsExit(); gfxExit(); acExit(); return 0; }