void JOYSTICKGetNumButtons(int nlhs, mxArray *plhs[], int nrhs, CONSTmxArray *prhs[])
{

	ProjectTable *joystickTable=GetProjectTable();
	int  numSticks;
	CONSTmxArray *numArg;
	double stickNum;
	SDL_Joystick *pStick;

	prhs;
	if(joystickTable->giveHelp){GiveHelp(useGetNumButtons,synopsisGetNumButtons);return;}
	numArg = joystickTable->joystickNumberArgument; 
	if(numArg == NULL || nlhs > 1 || nrhs > 0 || !mxIsDouble(numArg) || (mxGetM(numArg) * mxGetN(numArg) != 1))
		GiveUsageExit(useGetNumButtons);
	numSticks = SDL_NumJoysticks();
	stickNum = mxGetPr(numArg)[0];
	if(stickNum > numSticks)
		PrintfExit("The joystick number %d passed to JOYSTICK 'GetNumButtons' exceeds the number of joysticks, %d",stickNum,numSticks);
	if(stickNum < 1)
		PrintfExit("The joystick number passed to JOYSTICK 'GetNumButtons' must be greater than 0");
	pStick = GetJoystickObjFromNum((int)stickNum-1);
	if(pStick == NULL)
		PrintfExit("JOYSTICK 'GetNumButtons' can not open joystick number %d",stickNum);
	plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);	
	mxGetPr(plhs[0])[0] = SDL_JoystickNumButtons(pStick);
		
}
Example #2
0
void JOYSTICKGetAxis(int nlhs, mxArray *plhs[], int nrhs, CONSTmxArray *prhs[])
{

	ProjectTable *joystickTable=GetProjectTable();
	int  numSticks, numAxes, fetchedAxis;
	CONSTmxArray *numArg;
	double stickNum;
	SDL_Joystick *pStick;


	if(joystickTable->giveHelp){GiveHelp(useGetAxis,synopsisGetAxis);return;}
	numArg = joystickTable->joystickNumberArgument; 
	if(numArg == NULL || nlhs > 1 || nrhs > 1 || nrhs < 1 || !mxIsDouble(numArg) || (mxGetM(numArg) * mxGetN(numArg) != 1 ||
		!mxIsDouble(prhs[0]) || mxGetM(prhs[0]) * mxGetN(prhs[0]) != 1)){
		GiveUsageExit(useGetAxis);
	}
	numSticks = SDL_NumJoysticks();
	stickNum = mxGetPr(numArg)[0];
	if(stickNum > numSticks)
		PrintfExit("The joystick number %d passed to JOYSTICK 'GetAxis' exceeds the number of joysticks, %d",stickNum,numSticks);
	if(stickNum < 1)
		PrintfExit("The joystick number passed to JOYSTICK 'GetButton' must be greater than 0");
	pStick = GetJoystickObjFromNum((int)stickNum-1);
	if(pStick == NULL)
		PrintfExit("JOYSTICK 'GetAxis' can not open joystick number %d",stickNum);
	numAxes = SDL_JoystickNumAxes(pStick);
	fetchedAxis = (int)mxGetPr(prhs[0])[0];
	if(fetchedAxis > numAxes || fetchedAxis < 0)
		PrintfExit("The axis number %d passed to JOYSTICK 'GetAxis' is oustide the allowable range",fetchedAxis);
	plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);	
	SDL_JoystickUpdate();
	mxGetPr(plhs[0])[0] = SDL_JoystickGetAxis(pStick, fetchedAxis-1);
	
}
void JOYSTICKGetNumJoysticks(int nlhs, mxArray *plhs[], int nrhs, CONSTmxArray *prhs[])
{

	ProjectTable *joystickTable=GetProjectTable();
	int numJoysticks;

	plhs; prhs;
	if(joystickTable->giveHelp){GiveHelp(useGetNumJoysticks,synopsisGetNumJoysticks);return;}
	if (joystickTable->joystickNumberArgument != NULL || nlhs > 1 || nrhs > 0)
		GiveUsageExit(useGetNumJoysticks);
	plhs[0]=mxCreateDoubleMatrix(1,1,mxREAL);
	numJoysticks = SDL_NumJoysticks();
	mxGetPr(plhs[0])[0]=(double)numJoysticks;

}
Example #4
0
void JOYSTICKGetHat(int nlhs, mxArray *plhs[], int nrhs, CONSTmxArray *prhs[])
{

	ProjectTable *joystickTable=GetProjectTable();
	int  numSticks, numHats, fetchedHat;
	CONSTmxArray *numArg;
	double stickNum;
	SDL_Joystick *pStick;
	Uint8 hatVal; 


	if(joystickTable->giveHelp){GiveHelp(useGetHat,synopsisGetHat);return;}
	numArg = joystickTable->joystickNumberArgument; 
	if(numArg == NULL || nlhs > 1 || nrhs > 1 || nrhs < 1 || !mxIsDouble(numArg) || (mxGetM(numArg) * mxGetN(numArg) != 1 ||
		!mxIsDouble(prhs[0]) || (mxGetM(prhs[0]) * mxGetN(prhs[0])) != 1)){
		GiveUsageExit(useGetHat);
	}
	numSticks = SDL_NumJoysticks();
	stickNum = mxGetPr(numArg)[0];
	if(stickNum > numSticks)
		PrintfExit("The joystick number %d passed to JOYSTICK 'GetHat' exceeds the number of joysticks, %d",stickNum,numSticks);
	if(stickNum < 1)
		PrintfExit("The joystick number passed to JOYSTICK 'GetHat' must be greater than 0");
	pStick = GetJoystickObjFromNum((int)stickNum-1);
	if(pStick == NULL)
		PrintfExit("JOYSTICK 'GetHat' can not open joystick number %d",stickNum);
	numHats = SDL_JoystickNumHats(pStick);
	fetchedHat = (int)mxGetPr(prhs[0])[0];
	if(fetchedHat > numHats || fetchedHat < 0)
		PrintfExit("The axis number %d passed to JOYSTICK 'GetHat' is oustide the allowable range",fetchedHat);
	SDL_JoystickUpdate();
	hatVal = SDL_JoystickGetHat(pStick, fetchedHat-1);
	plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);	
	switch(hatVal){
		case SDL_HAT_CENTERED:	mxGetPr(plhs[0])[0] = 0; break; 
		case SDL_HAT_UP:		mxGetPr(plhs[0])[0] = 1; break; 
		case SDL_HAT_RIGHT:		mxGetPr(plhs[0])[0] = 2; break; 
		case SDL_HAT_DOWN:		mxGetPr(plhs[0])[0] = 3; break;
		case SDL_HAT_LEFT:		mxGetPr(plhs[0])[0] = 4; break; 
		case SDL_HAT_RIGHTUP:	mxGetPr(plhs[0])[0] = 5; break; 
		case SDL_HAT_RIGHTDOWN: mxGetPr(plhs[0])[0] = 6; break; 
		case SDL_HAT_LEFTUP:	mxGetPr(plhs[0])[0] = 7; break; 
		case SDL_HAT_LEFTDOWN:	mxGetPr(plhs[0])[0] = 8; break; 
	}
	
}