File: GetJoystickNumbersFromName.cpp

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (43 lines) | stat: -rwxr-xr-x 1,586 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "StdAfx.h"


char useGetJoystickNumbersFromName[] = "joystickNumbers = JOYSTICK('GetJoystickNumbersFromName', joystickName)";
char synopsisGetJoystickNumbersFromName[] = "Given a joystick device name return the numbers of all currently "
  "connected joysticks with that name.   The name is the device name assigned by the manufacturer. "
   "Identical joysticks should report the same device name.";
	

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

	ProjectTable *joystickTable=GetProjectTable();
	int i, numSticks, *foundSticks, numFoundSticks=0, nameSize;
	char *joystickName;
	double *resultArray;
	
	
	plhs;
	if(joystickTable->giveHelp){GiveHelp(useGetJoystickNumbersFromName,synopsisGetJoystickNumbersFromName);return;}
	if (joystickTable->joystickNumberArgument != NULL || nlhs > 1 || nrhs > 1 || nrhs < 1 || !mxIsChar(prhs[0]))
		GiveUsageExit(useGetJoystickNumbersFromName);

	numSticks = SDL_NumJoysticks();
	foundSticks = (int *)malloc(numSticks * sizeof(int));
	nameSize = mxGetM(prhs[0]) * mxGetN(prhs[0]) * sizeof(mxChar) + 1;
	joystickName = (char *)malloc(nameSize);
	mxGetString(prhs[0],joystickName, nameSize);
	for(i=0;i<numSticks;i++){
		if(strcmp(joystickName, SDL_JoystickName(i)) == 0){
			foundSticks[numFoundSticks] = i+1;
			++numFoundSticks;
		}
	}
	plhs[0] = mxCreateDoubleMatrix(1,numFoundSticks,mxREAL);
	resultArray = mxGetPr(plhs[0]);
	for(i=0;i<numFoundSticks;i++)
		resultArray[i] = foundSticks[i];
	free(foundSticks);
	free(joystickName);
	

}