Fix and updated error messages for issue 20

This commit is contained in:
endolf 2003-10-04 12:48:51 +00:00
parent 46e48bb00e
commit e749b96a4a
5 changed files with 30 additions and 8 deletions

View file

@ -40,9 +40,11 @@ EventDevice::EventDevice(char *deviceFileName) {
fd = open(deviceFileName, O_RDWR | O_NONBLOCK);
if(fd<0) {
char errorMessage[512];
/*char errorMessage[512];
sprintf(errorMessage, "Error opening device %s\n", deviceFileName);
perror(errorMessage);
perror(errorMessage);*/
inited = 0;
return;
}
if(ioctl(fd, EVIOCGNAME(sizeof(tempName)), tempName) < 0) {
@ -191,6 +193,10 @@ EventDevice::EventDevice(char *deviceFileName) {
inited = 1;
}
int EventDevice::isValidDevice() {
return inited;
}
int EventDevice::getNumberRelAxes(){
if(inited!=1) return -1;
return numRelAxes;

View file

@ -79,6 +79,7 @@ class EventDevice : public Device {
int getAbsAxisMinimum(int axisNumber);
int getAbsAxisMaximum(int axisNumber);
int getAbsAxisFuzz(int axisNumber);
int isValidDevice();
};

View file

@ -95,16 +95,24 @@ int evInit() {
evNumDevices = 0;
for(i=0;i<numDeviceFiles;i++) {
tempDeviceList[i] = new EventDevice(deviceFileNames[i]);
if(tempDeviceList[i]->getBusType()!=-1) {
EventDevice *tempDevice = new EventDevice(deviceFileNames[i]);
if(tempDevice->isValidDevice()==1) {
tempDeviceList[i] = tempDevice;
evNumDevices++;
}
}
int highDeviceCountNumber = i;
int evTempDeviceCount = 0;
// Now we know for certain which devices are open, we can take notes
evDeviceList = (Device **)malloc(evNumDevices * sizeof(Device *));
for(i=0;i<evNumDevices;i++) {
evDeviceList[i] = tempDeviceList[i];
while(tempDeviceList[evTempDeviceCount] == NULL) {
evTempDeviceCount++;
}
evDeviceList[i] = tempDeviceList[evTempDeviceCount];
//printf("Copied device %d to %d\n", evTempDeviceCount, i);
evTempDeviceCount++;
}
evInited=1;

View file

@ -52,11 +52,11 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEnvironmentPlugin_init
(JNIEnv *, jobject) {
if(evInit()!=0) {
fprintf(stderr, "Failed to init native jinput\n");
fprintf(stderr, "Failed to init native event interface\n");
return -1;
}
if(jsInit()!=0) {
fprintf(stderr, "Failed to init native jinput\n");
fprintf(stderr, "Failed to init native joystick interface\n");
return -1;
}

View file

@ -102,10 +102,17 @@ int jsInit() {
}
}
int highDeviceCountNumber = i;
int jsTempDeviceCount = 0;
// Now we know for certain which devices are open, we can take notes
jsDeviceList = (Device **)malloc(jsNumDevices * sizeof(Device *));
for(i=0;i<jsNumDevices;i++) {
jsDeviceList[i] = tempDeviceList[i];
while(tempDeviceList[jsTempDeviceCount] == NULL) {
jsTempDeviceCount++;
}
jsDeviceList[i] = tempDeviceList[jsTempDeviceCount];
//printf("Copied joystick %d to %d\n", jsTempDeviceCount, i);
jsTempDeviceCount++;
}
jsInited=1;