Ticket #7429: usbjoy_v2.patch
File usbjoy_v2.patch, 14.0 KB (added by , 12 years ago) |
---|
-
src/add-ons/kernel/drivers/joystick/usb_joy/driver.h
77 77 void *buffer; 78 78 bool buffer_valid; 79 79 80 const usb_device *dev;80 usb_device dev; 81 81 int number; 82 82 83 83 bool active; … … 107 107 /* devmgmt.c */ 108 108 109 109 my_device_info * 110 create_device ( const usb_device *dev, const usb_interface_info *ii);110 create_device (usb_device dev, const usb_interface_info *ii); 111 111 112 112 void 113 113 remove_device (my_device_info *my_dev); -
src/add-ons/kernel/drivers/joystick/usb_joy/devmgmt.c
12 12 static int device_number = 0; 13 13 14 14 my_device_info *create_device ( 15 const usb_device *dev,15 usb_device dev, 16 16 const usb_interface_info *ii) 17 17 { 18 18 my_device_info *my_dev = NULL; … … 21 21 sem_id sem; 22 22 char area_name [32]; 23 23 24 assert (usb != NULL && dev != NULL);24 assert (usb != NULL); 25 25 26 26 number = device_number++; 27 27 -
src/add-ons/kernel/drivers/joystick/usb_joy/driver.c
36 36 _EXPORT int32 api_version = B_CUR_DRIVER_API_VERSION; 37 37 38 38 const char *my_driver_name = "usb_joy"; 39 const char *my_base_name = "joystick/usb /";39 const char *my_base_name = "joystick/usb_haiku/"; 40 40 41 41 usb_module_info *usb; 42 42 … … 154 154 155 155 static void usb_callback ( 156 156 void *cookie, 157 uint32status,157 status_t status, 158 158 void *data, 159 159 uint32 actual_len) 160 160 { … … 215 215 */ 216 216 217 217 static status_t my_device_added ( 218 const usb_device *dev,218 usb_device dev, 219 219 void **cookie) 220 220 { 221 221 my_device_info *my_dev; … … 225 225 status_t st; 226 226 usb_hid_descriptor *hid_desc; 227 227 uint8 *rep_desc = NULL; 228 report_insn *reallocated_insns = NULL; 228 229 size_t desc_len, actual; 229 230 decomp_item *items; 230 231 size_t num_items; 231 232 int i, ifno, fd, report_id; 232 233 233 assert ( dev != NULL &&cookie != NULL);234 assert (cookie != NULL); 234 235 DPRINTF_INFO ((MY_ID "device_added()\n")); 235 236 236 237 dev_desc = usb->get_device_descriptor (dev); … … 353 354 parse_report_descriptor (items, num_items, my_dev->insns, 354 355 &my_dev->num_insns, &my_dev->total_report_size, &report_id); 355 356 free (items); 356 realloc (my_dev->insns, sizeof (report_insn) * my_dev->num_insns); 357 reallocated_insns = realloc (my_dev->insns, sizeof (report_insn) * my_dev->num_insns); 358 my_dev->insns = reallocated_insns; 357 359 DPRINTF_INFO ((MY_ID "%d items, %d insns, %d bytes\n", 358 360 (int)num_items, (int)my_dev->num_insns, (int)my_dev->total_report_size)); 359 361 … … 661 663 my_dev->insns, my_dev->num_insns, 662 664 my_dev->prod_info, my_dev->flags, &joy_data); 663 665 } 664 665 if (cookie->enhanced && *num_bytes >= sizeof (extended_joystick)) 666 667 // always work in enhanced mode, the joystick caller will handle legacy mode 668 if (*num_bytes >= sizeof (extended_joystick)) 666 669 { 667 670 /* enhanced mode */ 668 671 joy_data.timestamp = my_dev->timestamp; … … 671 674 err = B_OK; 672 675 } 673 676 674 if (!cookie->enhanced && *num_bytes >= sizeof (joystick))675 {676 /* standard mode */677 joystick std_joy_data;678 679 std_joy_data.timestamp = my_dev->timestamp;680 std_joy_data.horizontal = joy_data.axes [0];681 std_joy_data.vertical = joy_data.axes [1];682 /* false if pressed */683 std_joy_data.button1 = (joy_data.buttons & 1) ? false : true;684 std_joy_data.button2 = (joy_data.buttons & 2) ? false : true;685 memcpy (buf, &std_joy_data, sizeof (joystick));686 *num_bytes = sizeof (joystick);687 err = B_OK;688 }689 690 677 return err; 691 678 } 692 679 … … 735 722 the joystick product may be connected 736 723 */ 737 724 assert (arg != NULL); 738 if (!cookie->enhanced &&739 strstr (((joystick_module_info*)arg)->device_name, "USB") != NULL) /* XXX */725 if (!cookie->enhanced)// && 726 //strstr (((joystick_module_info*)arg)->device_name, "USB") != NULL) /* XXX */ 740 727 { 741 728 cookie->joy_mod_info = *(joystick_module_info *)arg; 742 729 … … 744 731 745 732 /* set actual # of controls detected */ 746 733 /* this will be returned in B_JOYSTICK_GET_DEVICE_MODULE */ 734 cookie->joy_mod_info.num_sticks = 1; 747 735 cookie->joy_mod_info.num_axes = my_dev->num_axes; 748 736 cookie->joy_mod_info.num_hats = my_dev->num_hats; 749 737 cookie->joy_mod_info.num_buttons = my_dev->num_buttons; -
src/kits/device/Joystick.cpp
4 4 * Distributed under the terms of the MIT License. 5 5 */ 6 6 7 #include <JoystickTweaker.h> 7 8 8 9 #include <List.h> 9 #include "Joystick.h"10 #include <Joystick.h> 10 11 11 12 #include <errno.h> 12 13 #include <fcntl.h> … … 19 20 #include <String.h> 20 21 #include <Debug.h> 21 22 23 #define JOYSTICK_READ 'jrea' 22 24 23 25 #if DEBUG 24 26 static FILE *sLogFile = NULL; … … 43 45 44 46 #define CALLED() LOG("%s\n", __PRETTY_FUNCTION__) 45 47 46 #include "JoystickTweaker.h"47 48 49 48 BJoystick::BJoystick() 50 49 : 50 horizontal(0), 51 vertical(0), 52 button1(0), 53 button2(0), 51 54 fBeBoxMode(false), 52 55 ffd(-1), 53 fDevices(new BList), 54 fJoystickInfo(new _joystick_info()) 56 fDevices(NULL), 57 fJoystickInfo(new _joystick_info()), 58 fDevName(0) 55 59 { 56 60 #if DEBUG 57 61 sLogFile = fopen("/var/log/libdevice.log", "a"); 58 62 #endif 59 //ScanDevices(); 63 64 memset(&fJoystickInfo->module_info, 0, 65 sizeof(_joystick_module_info)); 66 memset(&fJoystickInfo->sticks, 0, 67 sizeof(fJoystickInfo->sticks)); 60 68 } 61 69 62 70 … … 65 73 if (ffd >= 0) 66 74 close(ffd); 67 75 68 for (int32 count = fDevices->CountItems() - 1; count >= 0; count--) { 69 free(fDevices->RemoveItem(count)); 76 if(fDevices) 77 { 78 for (int32 count = fDevices->CountItems() - 1; count >= 0; count--) 79 free(fDevices->RemoveItem(count)); 70 80 } 71 81 82 free(fDevName); 72 83 delete fDevices; 73 84 delete fJoystickInfo; 74 85 } … … 98 109 snprintf(buf, 64, DEVICEPATH"/%s", portName); 99 110 else 100 111 snprintf(buf, 64, "%s", portName); 101 112 102 113 if (ffd >= 0) 103 114 close(ffd); 104 115 … … 118 129 _BJoystickTweaker jt(*this); 119 130 jt.GetInfo(fJoystickInfo, portName); 120 131 121 LOG("ioctl - %d\n", fJoystickInfo->num_buttons); 122 ioctl(ffd, B_JOYSTICK_SET_DEVICE_MODULE, fJoystickInfo); 123 ioctl(ffd, B_JOYSTICK_GET_DEVICE_MODULE, fJoystickInfo); 124 LOG("ioctl - %d\n", fJoystickInfo->num_buttons); 132 int result = ioctl(ffd, B_JOYSTICK_SET_DEVICE_MODULE, &fJoystickInfo->module_info); 133 LOG("ioctl B_JOYSTICK_SET_DEVICE_MODULE: %d\n", result); 134 result = ioctl(ffd, B_JOYSTICK_GET_DEVICE_MODULE, &fJoystickInfo->module_info); 135 LOG("ioctl B_JOYSTICK_GET_DEVICE_MODULE: %d\n", result); 136 LOG("NumberOfButtons - %d\n", fJoystickInfo->module_info.num_buttons); 125 137 126 138 return ffd; 127 139 } else … … 144 156 BJoystick::ScanDevices(bool useDisabled) 145 157 { 146 158 CALLED(); 159 if(!fDevices) fDevices = new BList(); 160 147 161 if (useDisabled) { 148 162 _BJoystickTweaker temp(*this); 149 163 temp.scan_including_disabled(); … … 157 171 CALLED(); 158 172 159 173 // Refresh devices list 160 ScanDevices(true);174 if(!fDevices) ScanDevices(true); 161 175 162 176 int32 count = 0; 163 177 if (fDevices != NULL) … … 173 187 { 174 188 CALLED(); 175 189 BString *temp = NULL; 190 191 if(!fDevices) ScanDevices(true); 192 176 193 if (fDevices != NULL && fDevices->CountItems() > n) 177 194 temp = static_cast<BString*>(fDevices->ItemAt(n)); 178 195 else … … 203 220 BJoystick::CountSticks() 204 221 { 205 222 CALLED(); 206 return fJoystickInfo-> num_sticks;223 return fJoystickInfo->module_info.num_sticks; 207 224 } 208 225 209 226 … … 211 228 BJoystick::CountAxes() 212 229 { 213 230 CALLED(); 214 return fJoystickInfo-> num_axes;231 return fJoystickInfo->module_info.num_axes; 215 232 } 216 233 217 234 … … 219 236 BJoystick::CountHats() 220 237 { 221 238 CALLED(); 222 return fJoystickInfo-> num_hats;239 return fJoystickInfo->module_info.num_hats; 223 240 } 224 241 225 242 … … 227 244 BJoystick::CountButtons() 228 245 { 229 246 CALLED(); 230 return fJoystickInfo-> num_buttons;247 return fJoystickInfo->module_info.num_buttons; 231 248 } 232 249 233 250 … … 236 253 { 237 254 CALLED(); 238 255 if (fJoystickInfo != NULL && ffd >= 0) { 239 out_name->SetTo(fJoystickInfo->module_name); 256 out_name->SetTo(fJoystickInfo->module_info.module_name); 257 //out_name->SetTo("Module"); 240 258 return B_OK; 241 259 } else 242 260 return B_ERROR; … … 249 267 { 250 268 CALLED(); 251 269 if (fJoystickInfo != NULL && ffd >= 0) { 252 out_name->SetTo(fJoystickInfo->controller_name); 270 //out_name->SetTo("Joystick"); 271 out_name->SetTo(fJoystickInfo->module_info.device_name); 253 272 return B_OK; 254 273 } else 255 274 return B_ERROR; … … 280 299 BJoystick::SetMaxLatency(bigtime_t max_latency) 281 300 { 282 301 CALLED(); 283 fJoystickInfo->max_latency = max_latency; 284 //else B_ERROR (when?) 285 return B_OK; 302 if(ffd >= 0) { 303 return ioctl(ffd, B_JOYSTICK_SET_MAX_LATENCY, 304 &max_latency, sizeof(bigtime_t)); 305 } 306 return B_ERROR; 286 307 } 287 308 288 309 //--------- not done ------------------- … … 291 312 BJoystick::GetAxisNameAt(int32 index, BString *out_name) 292 313 { 293 314 CALLED(); 294 return B_BAD_INDEX; 315 BString axisName = "Axis "; 316 axisName << index + 1; 317 out_name->SetTo(axisName); 318 return B_OK; 295 319 } 296 320 297 321 … … 299 323 BJoystick::GetHatNameAt(int32 index, BString *out_name) 300 324 { 301 325 CALLED(); 302 return B_BAD_INDEX; 326 BString hatName = "Hat "; 327 hatName << index + 1; 328 out_name->SetTo(hatName); 329 return B_OK; 303 330 } 304 331 305 332 … … 307 334 BJoystick::GetButtonNameAt(int32 index, BString *out_name) 308 335 { 309 336 CALLED(); 310 return B_BAD_INDEX; 337 BString buttonName = "Button "; 338 buttonName << index + 1; 339 out_name->SetTo(buttonName); 340 return B_OK; 311 341 } 312 342 313 343 … … 315 345 BJoystick::GetAxisValues(int16 *out_values, int32 for_stick) 316 346 { 317 347 CALLED(); 318 return B_BAD_VALUE; 348 if(for_stick < 0 || for_stick >= fJoystickInfo->module_info.num_sticks) 349 return B_BAD_VALUE; 350 351 memcpy(out_values, fJoystickInfo->sticks[0].axes, 352 fJoystickInfo->module_info.num_axes * sizeof(int16)); 353 return B_OK; 319 354 } 320 355 321 356 … … 323 358 BJoystick::GetHatValues(uint8 *out_hats, int32 for_stick) 324 359 { 325 360 CALLED(); 326 return B_BAD_VALUE; 361 if(for_stick < 0 || for_stick >= fJoystickInfo->module_info.num_sticks) 362 return B_BAD_VALUE; 363 364 memcpy(out_hats, fJoystickInfo->sticks[0].hats, 365 fJoystickInfo->module_info.num_hats); 366 return B_OK; 327 367 } 328 368 329 369 … … 331 371 BJoystick::ButtonValues(int32 for_stick) 332 372 { 333 373 CALLED(); 334 return 0; 374 if(for_stick < 0 || for_stick >= fJoystickInfo->module_info.num_sticks) 375 return B_BAD_VALUE; 376 377 return fJoystickInfo->sticks[0].buttons; 335 378 } 336 379 337 380 … … 340 383 { 341 384 CALLED(); 342 385 if (ffd >= 0) { 386 // Always read in enhanced mode, then assign legacy axes and buttons their values 387 extended_joystick joystick; 388 memset(&joystick, 0, sizeof(joystick)); 389 390 status_t length = read(ffd, &joystick, sizeof(extended_joystick)); 391 if(length == sizeof(joystick)) fJoystickInfo->sticks[0] = joystick; 392 393 // legacy mode buttons are true when 0 394 horizontal = fJoystickInfo->sticks[0].axes[0]; 395 vertical = fJoystickInfo->sticks[0].axes[1]; 396 button1 = !(fJoystickInfo->sticks[0].buttons & 1); 397 button2 = !(fJoystickInfo->sticks[0].buttons & 2); 398 //printf("hor: %d ver:%d buttons: %d\n", horizontal, vertical, fJoystickInfo->sticks[0].buttons); 343 399 return B_OK; 344 400 } else 345 401 return B_ERROR; -
src/kits/device/JoystickTweaker.cpp
125 125 } 126 126 127 127 128 status_t 128 _joystick_info * 129 129 _BJoystickTweaker::get_info() 130 130 { 131 131 CALLED(); 132 return B_ERROR;132 return fJoystick->fJoystickInfo; 133 133 } 134 134 135 135 … … 141 141 status_t err = B_ERROR; 142 142 BString str(JOYSTICKPATH); 143 143 str.Append(ref); 144 145 144 FILE *file = fopen(str.String(), "r"); 146 145 if (file != NULL) { 147 146 char line [STRINGLENGTHCPY]; … … 167 166 168 167 if (str.IFindFirst("module") != -1) { 169 168 str.RemoveFirst("module = "); 170 strlcpy(info->module_ name, str.String(), STRINGLENGTHCPY);169 strlcpy(info->module_info.module_name, str.String(), STRINGLENGTHCPY); 171 170 } else if (str.IFindFirst("gadget") != -1) { 172 171 str.RemoveFirst("gadget = "); 173 strlcpy(info-> controller_name, str.String(), STRINGLENGTHCPY);172 strlcpy(info->module_info.device_name, str.String(), STRINGLENGTHCPY); 174 173 } else if (str.IFindFirst("num_axes") != -1) { 175 174 str.RemoveFirst("num_axes = "); 176 info-> num_axes = atoi(str.String());175 info->module_info.num_axes = atoi(str.String()); 177 176 } else if (str.IFindFirst("num_hats") != -1) { 178 177 str.RemoveFirst("num_hats = "); 179 info-> num_hats = atoi(str.String());178 info->module_info.num_hats = atoi(str.String()); 180 179 } else if (str.IFindFirst("num_buttons") != -1) { 181 180 str.RemoveFirst("num_buttons = "); 182 info-> num_buttons = atoi(str.String());181 info->module_info.num_buttons = atoi(str.String()); 183 182 } else if (str.IFindFirst("num_sticks") != -1) { 184 183 str.RemoveFirst("num_sticks = "); 185 info-> num_sticks = atoi(str.String());184 info->module_info.num_sticks = atoi(str.String()); 186 185 } else { 187 186 LOG("Path = %s\n", str.String()); 188 187 } -
headers/private/device/JoystickTweaker.h
21 21 class BJoystick; 22 22 23 23 typedef struct _joystick_info { 24 _joystick_module_info module_info; 25 _extended_joystick sticks[4]; 26 BList name_axis; 27 BList name_hat; 28 BList name_button; 29 bool calibration_enable; 30 } joystick_info; 31 32 #if 0 33 typedef struct _joystick_info { 24 34 char module_name[64]; 25 35 char controller_name[64]; 26 36 int16 num_axes; … … 34 44 BList name_button; 35 45 // BList name_ 36 46 } joystick_info; 47 #endif 37 48 38 49 class _BJoystickTweaker { 39 50 … … 47 58 // BeOS R5's joystick pref need these 48 59 status_t save_config(const entry_ref * ref = NULL); 49 60 void scan_including_disabled(); 50 status_tget_info();61 _joystick_info * get_info(); 51 62 52 63 private: 53 64 void _BuildFromJoystickDesc(char *string, _joystick_info* info);