Exemple #1
0
static int lua_cstickpad(lua_State *L)
{
	int argc = lua_gettop(L);
	#ifndef SKIP_ERROR_HANDLING
       if (argc != 0) return luaL_error(L, "wrong number of arguments.");
	#endif
	circlePosition cpos;
	hidCstickRead(&cpos);
	lua_pushnumber(L, cpos.dx);
	lua_pushnumber(L, cpos.dy);
    return 2;
}
Exemple #2
0
int hidCollectData(struct hidInfo *info)
{
    info->keys.up   = hidKeysUp();
    info->keys.down = hidKeysDown();
    info->keys.held = hidKeysHeld();

    hidTouchRead(&info->touchscreen);
    hidCircleRead(&info->circlepad);
    hidGyroRead(&info->gyro);
    hidCstickRead(&info->cstick);

    return 0;
}
Exemple #3
0
void IN_Move (usercmd_t *cmd)
{
  if(hidKeysHeld() & KEY_TOUCH){
    hidTouchRead(&touch);
    touch.px =  (touch.px + oldtouch.px) / 2;
    touch.py =  (touch.py + oldtouch.py) / 2;
    cl.viewangles[YAW] -= (touch.px - oldtouch.px) * sensitivity.value/2;
    if(in_mlook.state & 1)
      cl.viewangles[PITCH] += (touch.py - oldtouch.py) * sensitivity.value/2;
    oldtouch = touch;
  }

  hidCircleRead(&circlepad);
  //CirclePad deadzone to fix ghost movements
  if(abs(circlepad.dy) > 15){
    cmd->forwardmove += m_forward.value * circlepad.dy * 2;
  }
  if(abs(circlepad.dx) > 15){
    if((in_strafe.state & 1) || (lookstrafe.value))
      cmd->sidemove += m_side.value * circlepad.dx * 2;
    else
      cl.viewangles[YAW] -= m_side.value * circlepad.dx * 0.03;
  }

  //cStick is only available on N3DS... Until libctru implements support for circlePad Pro
  if(isN3DS){

    hidCstickRead(&cstick);

    if(m_pitch.value < 0)
      cstick.dy = -cstick.dy;

    cstick.dx = abs(cstick.dx) < 10 ? 0 : cstick.dx * csensitivity.value * 0.01;
    cstick.dy = abs(cstick.dy) < 10 ? 0 : cstick.dy * csensitivity.value * 0.01;

    cl.viewangles[YAW] -= cstick.dx;
    cl.viewangles[PITCH] -= cstick.dy;
  }

  V_StopPitchDrift ();

}
Exemple #4
0
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;
}
Exemple #5
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;
}
Exemple #6
0
//return true when we're ready to boot something
//(TEMP ?)
bool updateMenu(menu_s* m)
{
	if(!m)return false;
	if(!m->numEntries)return false;

	//controls
	s8 move=0;
	circlePosition cstick;
	touchPosition touch;
	hidCstickRead(&cstick);
	hidTouchRead(&touch);
	
	cstick.dy=(abs(cstick.dy)<5)?0:cstick.dy;

	if(hidKeysDown()&KEY_DOWN)move++;
	if(hidKeysDown()&KEY_UP)move--;
	if(hidKeysDown()&KEY_RIGHT)move+=4;
	if(hidKeysDown()&KEY_LEFT)move-=4;

	u16 oldEntry=m->selectedEntry;

	if(hidKeysDown()&KEY_TOUCH)
	{
		m->touchTimer=0;
		m->firstTouch=touch;
	}else if((hidKeysUp()&KEY_TOUCH) && m->touchTimer<30 && abs(m->firstTouch.px-m->previousTouch.px)+abs(m->firstTouch.py-m->previousTouch.py)<12){
		menuEntry_s* me=m->entries;
		int i=0;
		int p=0;
		while(me)
		{
			int h=(i==m->selectedEntry)?ENTRY_WIDTH_SELECTED:ENTRY_WIDTH;
			if((240-m->previousTouch.py)>=getEntryLocationPx(m,p)-h && (240-m->previousTouch.py)<getEntryLocationPx(m,p))break;
			p+=h;
			me=me->next;
			i++;
		}
		if(m->selectedEntry==i)return true;
		else m->selectedEntry=i;
	}else if(hidKeysHeld()&KEY_TOUCH){
		//condition to make sure previousTouch is valid
		cstick.dy+=(touch.py-m->previousTouch.py)*16;
		m->touchTimer++;
	}
	if(move+m->selectedEntry<0)m->selectedEntry=0;
	else if(move+m->selectedEntry>=m->numEntries)m->selectedEntry=m->numEntries-1;
	else m->selectedEntry+=move;

	if(m->selectedEntry!=oldEntry)m->atEquilibrium=false;

	if(hidKeysDown()&KEY_A)return true;

	m->previousTouch=touch;

	//scrolling code
	const int maxScroll=240-(m->numEntries)*ENTRY_WIDTH; //cf getEntryLocation

	if(!m->atEquilibrium)
	{
		m->scrollTarget=intToFpt(getEntryLocation(m, m->selectedEntry));
		if(m->scrollTarget>intToFpt(240-ENTRY_WIDTH) || (m->selectedEntry==0 && m->numEntries>3))
			m->scrollVelocity+=(intToFpt(240-ENTRY_WIDTH)-m->scrollTarget)/SCROLLING_SPEED;
		if(m->scrollTarget<0 || (m->selectedEntry==m->numEntries-1 && m->numEntries>3))
			m->scrollVelocity+=(intToFpt(0)-m->scrollTarget)/SCROLLING_SPEED;
	}else if(m->numEntries>3){
		s32 val=-cstick.dy*16; // TODO : make it inversely proportional to numEntries ?
		if(m->scrollLocation>intToFpt(-maxScroll))
		{
			m->scrollVelocity+=(intToFpt(-maxScroll)-m->scrollLocation)/SCROLLING_SPEED;
			if(val<0)m->scrollVelocity+=val;
		}else if(m->scrollLocation<intToFpt(0)){
			m->scrollVelocity-=m->scrollLocation/SCROLLING_SPEED;
			if(val>0)m->scrollVelocity+=val;
		}else m->scrollVelocity+=val;
	}

	m->scrollLocation+=m->scrollVelocity;
	m->scrollVelocity=(m->scrollVelocity*3)/4;

	m->scrollBarSize=40; //TEMP : make it adaptive to number of menu entries ?
	m->scrollBarPos=-fptToInt(m->scrollLocation*(200-m->scrollBarSize))/maxScroll;
	if(m->scrollBarPos<0)
	{
		m->currentScrollBarSize=m->scrollBarSize+m->scrollBarPos;
		if(m->currentScrollBarSize<10)m->currentScrollBarSize=10;
		m->scrollBarPos=m->currentScrollBarSize-m->scrollBarSize;
	}else if(m->scrollBarPos>=200-m->scrollBarSize)
	{
		m->currentScrollBarSize=-(m->scrollBarPos-200);
		if(m->currentScrollBarSize<10)m->currentScrollBarSize=10;
		debugValues[3]=m->scrollBarPos-200;
		m->scrollBarPos=200-m->scrollBarSize;
	}else m->currentScrollBarSize=m->scrollBarSize;

	if(!m->scrollVelocity)m->atEquilibrium=true;

	// debugValues[0]=m->scrollLocation;
	// debugValues[1]=m->scrollTarget;
	// debugValues[1]=fptToInt(m->scrollLocation);
	// debugValues[2]=intToFpt(maxScroll);
	// debugValues[3]=maxScroll;

	return false;
}