static int lua_readC(lua_State *L) { int argc = lua_gettop(L); #ifndef SKIP_ERROR_HANDLING if (argc != 0) return luaL_error(L, "wrong number of arguments."); #endif hidScanInput(); irrstScanInput(); lua_pushnumber(L, hidKeysHeld()); return 1; }
void hidScanInput(void) { u32 Id=0; kOld = kHeld; irrstScanInput(); kHeld = 0; memset(&cPos, 0, sizeof(circlePosition)); memset(&tPos, 0, sizeof(touchPosition)); memset(&aVec, 0, sizeof(accelVector)); memset(&gRate, 0, sizeof(angularRate)); Id = hidSharedMem[4];//PAD / circle-pad if(Id>7)Id=7; if(hidCheckSectionUpdateTime(hidSharedMem, Id)==0) { kHeld = hidSharedMem[10 + Id*4]; cPos = *(circlePosition*)&hidSharedMem[10 + Id*4 + 3]; } Id = hidSharedMem[42 + 4];//Touch-screen if(Id>7)Id=7; if(hidCheckSectionUpdateTime(&hidSharedMem[42], Id)==0) { tPos = *(touchPosition*)&hidSharedMem[42 + 8 + Id*2]; if (hidSharedMem[42 + 8 + Id*2 + 1]) kHeld |= KEY_TOUCH; } kHeld |= irrstKeysHeld(); kDown = (~kOld) & kHeld; kUp = kOld & (~kHeld); Id = hidSharedMem[66 + 4];//Accelerometer if(Id>7)Id=7; if(hidCheckSectionUpdateTime(&hidSharedMem[66], Id)==0) { aVec = ((accelVector*)&hidSharedMem[66 + 8])[Id]; } Id = hidSharedMem[86 + 4];//Gyroscope if(Id>31)Id=31; if(hidCheckSectionUpdateTime(&hidSharedMem[86], Id)==0) { gRate = ((angularRate*)&hidSharedMem[86 + 8])[Id]; } }
int main(void) { irmemloc = (u32*) memalign(0x1000, 0x1000); resultStartup = IRU_Initialize(irmemloc, 0x1000); resultSetBit = IRU_SetBitRate(0xB); recordedIR = (u32*) malloc(REC_SIZE * NUM_OF_BUTTONS); //Currently there are 11(NUM_OF_BUTTONS) recordable buttons. (start switches mode) recentIR = (u32*) calloc(REC_SIZE, 0x1); //Whatever was last viewed in memory resultGetStatus = irucmd_GetTransferState(&StatusIR); srvInit(); // services aptInit(); // applets hidInit(NULL); // input gfxInitDefault(); // gfx gfxSetDoubleBuffering(GFX_TOP, true); gfxSetDoubleBuffering(GFX_BOTTOM, true); bot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); if(setjmp(exitJmp)) goto exit; clearScreen(); gfxFlushBuffers(); gfxSwapBuffers(); bool startToggle = false; bool upToggle = false; bool downToggle = false; while(aptMainLoop()) { bot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); hidScanInput(); irrstScanInput(); u32 kHeld = hidKeysHeld(); circlePosition circlePad; circlePosition cStick; hidCstickRead(&cStick); hidCircleRead(&circlePad); touchPosition touch; touchRead(&touch); clearScreen(); char keys[30] = "ABXY URDL SEST LR ZLZR"; if(kHeld & KEY_A) { keys[0] = '*'; ir('A'); } if(kHeld & KEY_B) { keys[1] = '*'; ir('B'); } if(kHeld & KEY_X) { keys[2] = '*'; ir('X'); } if(kHeld & KEY_Y) { keys[3] = '*'; ir('Y'); } if(kHeld & KEY_DUP) { keys[5] = '*'; if(upToggle) { if(bitrate < 18) { bitrate++; resultSetBit = IRU_SetBitRate(bitrate); } upToggle = false; } } else { upToggle = true; } if(kHeld & KEY_DRIGHT) { keys[6] = '*'; ir('R'); } if(kHeld & KEY_DDOWN) { keys[7] = '*'; if(downToggle) { if(bitrate > 3) { bitrate--; resultSetBit = IRU_SetBitRate(bitrate); } downToggle = false; } } else { downToggle = true; } if(kHeld & KEY_DLEFT) { keys[8] = '*'; ir('L'); } if(kHeld & KEY_SELECT) { keys[10] = '*'; keys[11] = '*'; ir('S'); } if(kHeld & KEY_START) { keys[12] = '*'; keys[13] = '*'; if(startToggle) { rec = !rec; startToggle = false; } } else { startToggle = true; } if(kHeld & KEY_L) { keys[15] = '*'; ir('L'); } if(kHeld & KEY_R) { keys[16] = '*'; ir('R'); } if(kHeld & KEY_ZL) { keys[18] = '*'; keys[19] = '*'; ir('1'); } if(kHeld & KEY_ZR) { keys[20] = '*'; keys[21] = '*'; ir('2'); } drawString(top, 10, 10, keys); drawString(top, 10, 20, "Circle Pad x: %04+d, y: %04+d", circlePad.dx, circlePad.dy); drawString(top, 10, 30, "Touch x: %04d, y: %04d", touch.px, touch.py ); if(resultStartup == 0) { drawString(top, 10, 40, "IR started!"); } else { drawString(top, 10, 40, "IR Init |Error: %x", resultStartup); } if(resultSetBit == 0) { drawString(top, 10, 50, "IR bit rate works!"); } else { drawString(top, 10, 50, "IR bit rate |Error: %x", resultSetBit); } if(resultTransferIR == 0) { drawString(top, 10, 60, "IR transfer works!"); } else { drawString(top, 10, 60, "IR transfer |Error: %x", resultTransferIR); } irucmd_GetTransferState(&StatusIR); drawString(top, 10, 70, "IR mode: %x", StatusIR); drawString(top, 10, 80, "Got %d bytes", TransIR); drawString(top, 10, 90, "Bitrate: %d (see IRU:SetBitRate)", bitrate); printMemory(NULL,REC_SIZE,10, false); //might be dangerous? if(rec) { drawString(top, 10, 210, "Recording mode active."); }else{ drawString(top, 10, 210, "Sending mode active."); } drawString(top, 10, 220, "Start + Select to exit."); if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) longjmp(exitJmp, 1); gfxFlushBuffers(); gspWaitForVBlank(); gfxSwapBuffers(); } exit: //I should really be fixing these. free(recordedIR); //Crashes the program. Should free on release. free(irmemloc); //Crashes the program. Should free on release. free(recentIR); //Crashes the program. Should free on release. IRU_Shutdown(); //Crashes the program. Should free on release. gfxExit(); hidExit(); aptExit(); srvExit(); return 0; }
int main(void) { acInit(); gfxInitDefault(); gfxSetDoubleBuffering(GFX_TOP, false); gfxSetDoubleBuffering(GFX_BOTTOM, false); if(setjmp(exitJmp)) goto exit; preRenderKeyboard(); clearScreen(); drawString(10, 10, "Initing FS..."); gfxFlushBuffers(); gfxSwapBuffers(); fsInit(); clearScreen(); drawString(10, 10, "Initing SOC..."); gfxFlushBuffers(); gfxSwapBuffers(); SOC_Initialize((u32 *)memalign(0x1000, 0x100000), 0x100000); u32 wifiStatus = 0; ACU_GetWifiStatus(NULL, &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(); 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(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(); SOC_Shutdown(); svcCloseHandle(fileHandle); fsExit(); gfxExit(); acExit(); return 0; }