comparison src/joystick/bsd/SDL_sysjoystick.c @ 544:2d7373ffd131

Fixed bsd joystick detection ... again (thanks Wilbern)
author Sam Lantinga <slouken@libsdl.org>
date Sun, 17 Nov 2002 19:03:05 +0000
parents 2ee72e47ca08
children 639d58d32471
comparison
equal deleted inserted replaced
543:522e5202014d 544:2d7373ffd131
134 134
135 memset(joynames, NULL, sizeof(joynames)); 135 memset(joynames, NULL, sizeof(joynames));
136 memset(joydevnames, NULL, sizeof(joydevnames)); 136 memset(joydevnames, NULL, sizeof(joydevnames));
137 137
138 for (i = 0; i < MAX_UHID_JOYS; i++) { 138 for (i = 0; i < MAX_UHID_JOYS; i++) {
139 SDL_Joystick nj;
140
139 sprintf(s, "/dev/uhid%d", i); 141 sprintf(s, "/dev/uhid%d", i);
140 fd = open(s, O_RDWR); 142
141 if (fd > 0) { 143 nj.index = SDL_numjoysticks;
142 joynames[SDL_numjoysticks++] = strdup(s); 144 joynames[nj.index] = strdup(s);
143 close(fd); 145
146 if (SDL_SYS_JoystickOpen(&nj) == 0) {
147 SDL_SYS_JoystickClose(&nj);
148 SDL_numjoysticks++;
149 } else {
150 free(joynames[nj.index]);
144 } 151 }
145 } 152 }
146 for (i = 0; i < MAX_JOY_JOYS; i++) { 153 for (i = 0; i < MAX_JOY_JOYS; i++) {
147 sprintf(s, "/dev/joy%d", i); 154 sprintf(s, "/dev/joy%d", i);
148 fd = open(s, O_RDWR); 155 fd = open(s, O_RDONLY);
149 if (fd > 0) { 156 if (fd != -1) {
150 joynames[SDL_numjoysticks++] = strdup(s); 157 joynames[SDL_numjoysticks++] = strdup(s);
151 close(fd); 158 close(fd);
152 } 159 }
153 } 160 }
154 161
176 struct hid_data *hdata; 183 struct hid_data *hdata;
177 struct report *rep; 184 struct report *rep;
178 int fd; 185 int fd;
179 186
180 fd = open(path, O_RDWR); 187 fd = open(path, O_RDWR);
181 if (fd < 0) { 188 if (fd == -1) {
182 SDL_SetError("%s: %s", path, strerror(errno)); 189 SDL_SetError("%s: %s", path, strerror(errno));
183 return (-1); 190 return (-1);
184 } 191 }
185 192
186 hw = (struct joystick_hwdata *)malloc(sizeof(struct joystick_hwdata)); 193 hw = (struct joystick_hwdata *)malloc(sizeof(struct joystick_hwdata));
398 report_alloc(struct report *r, struct report_desc *rd, int repind) 405 report_alloc(struct report *r, struct report_desc *rd, int repind)
399 { 406 {
400 int len; 407 int len;
401 408
402 #ifdef USBHID_NEW 409 #ifdef USBHID_NEW
410 len = hid_report_size(rd, repinfo[repind].kind, r->rid);
411 #else
403 len = hid_report_size(rd, repinfo[repind].kind, &r->rid); 412 len = hid_report_size(rd, repinfo[repind].kind, &r->rid);
404 #else
405 len = hid_report_size(rd, repinfo[repind].kind, r->rid);
406 #endif 413 #endif
407 if (len < 0) { 414 if (len < 0) {
408 SDL_SetError("Negative HID report size"); 415 SDL_SetError("Negative HID report size");
409 return (-1); 416 return (-1);
410 } 417 }