Changes in uspace/drv/bus/usb/usbhid/mouse/mousedev.c [5cc9eba:e3c78efc] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/mouse/mousedev.c
r5cc9eba re3c78efc 52 52 #include "../usbhid.h" 53 53 54 /** Number of simulated arrow-key presses for singel wheel step. */ 55 #define ARROWS_PER_SINGLE_WHEEL 3 56 54 57 #define NAME "mouse" 55 58 … … 66 69 67 70 const char *HID_MOUSE_FUN_NAME = "mouse"; 71 const char *HID_MOUSE_WHEEL_FUN_NAME = "mouse-wheel"; 68 72 const char *HID_MOUSE_CATEGORY = "mouse"; 73 const char *HID_MOUSE_WHEEL_CATEGORY = "keyboard"; 69 74 70 75 /** Default idle rate for mouses. */ … … 121 126 122 127 usb_log_debug("%s: fun->name: %s\n", __FUNCTION__, fun->name); 123 usb_log_debug("%s: mouse_sess: %p\n", 124 __FUNCTION__, mouse_dev->mouse_sess); 128 usb_log_debug("%s: mouse_sess: %p, wheel_sess: %p\n", 129 __FUNCTION__, mouse_dev->mouse_sess, mouse_dev->wheel_sess); 130 131 async_sess_t **sess_ptr = (fun == mouse_dev->mouse_fun) ? 132 &mouse_dev->mouse_sess : &mouse_dev->wheel_sess; 125 133 126 134 async_sess_t *sess = 127 135 async_callback_receive_start(EXCHANGE_SERIALIZE, icall); 128 136 if (sess != NULL) { 129 if ( mouse_dev->mouse_sess== NULL) {130 mouse_dev->mouse_sess= sess;137 if (*sess_ptr == NULL) { 138 *sess_ptr = sess; 131 139 usb_log_debug("Console session to %s set ok (%p).\n", 132 140 fun->name, sess); … … 136 144 fun->name); 137 145 async_answer_0(icallid, ELIMIT); 138 async_hangup(sess);139 146 } 140 147 } else { … … 143 150 } 144 151 } 145 /*----------------------------------------------------------------------------*/ 152 153 /*----------------------------------------------------------------------------*/ 154 155 static void usb_mouse_send_wheel(const usb_mouse_t *mouse_dev, int wheel) 156 { 157 unsigned int key = (wheel > 0) ? KC_UP : KC_DOWN; 158 159 if (mouse_dev->wheel_sess == NULL) { 160 usb_log_warning( 161 "Connection to console not ready, wheel roll discarded.\n"); 162 return; 163 } 164 165 const unsigned count = 166 ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL; 167 for (unsigned i = 0; i < count; i++) { 168 /* Send arrow press and release. */ 169 usb_log_debug2("Sending key %d to the console\n", key); 170 171 async_exch_t *exch = async_exchange_begin(mouse_dev->wheel_sess); 172 173 async_msg_4(exch, KBDEV_EVENT, KEY_PRESS, key, 0, 0); 174 async_msg_4(exch, KBDEV_EVENT, KEY_RELEASE, key, 0, 0); 175 176 async_exchange_end(exch); 177 } 178 } 179 180 /*----------------------------------------------------------------------------*/ 181 146 182 static int get_mouse_axis_move_value(uint8_t rid, usb_hid_report_t *report, 147 183 int32_t usage) … … 185 221 &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL); 186 222 187 if ( shift_x || shift_y || wheel) {223 if ((shift_x != 0) || (shift_y != 0)) { 188 224 async_exch_t *exch = 189 225 async_exchange_begin(mouse_dev->mouse_sess); 190 226 if (exch != NULL) { 191 async_msg_3(exch, MOUSEEV_MOVE_EVENT, 192 shift_x, shift_y, wheel); 227 async_req_2_0(exch, MOUSEEV_MOVE_EVENT, shift_x, shift_y); 193 228 async_exchange_end(exch); 194 229 } 195 230 } 231 232 if (wheel != 0) 233 usb_mouse_send_wheel(mouse_dev, wheel); 196 234 197 235 /* Buttons */ … … 303 341 mouse->mouse_fun = fun; 304 342 343 /* 344 * Special function for acting as keyboard (wheel) 345 */ 346 usb_log_debug("Creating DDF function %s...\n", 347 HID_MOUSE_WHEEL_FUN_NAME); 348 fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, 349 HID_MOUSE_WHEEL_FUN_NAME); 350 if (fun == NULL) { 351 usb_log_error("Could not create DDF function node `%s'.\n", 352 HID_MOUSE_WHEEL_FUN_NAME); 353 FUN_UNBIND_DESTROY(mouse->mouse_fun); 354 mouse->mouse_fun = NULL; 355 return ENOMEM; 356 } 357 358 /* 359 * Store the initialized HID device and HID ops 360 * to the DDF function. 361 */ 362 fun->ops = &mouse->ops; 363 fun->driver_data = mouse; 364 365 rc = ddf_fun_bind(fun); 366 if (rc != EOK) { 367 usb_log_error("Could not bind DDF function `%s': %s.\n", 368 fun->name, str_error(rc)); 369 FUN_UNBIND_DESTROY(mouse->mouse_fun); 370 mouse->mouse_fun = NULL; 371 372 fun->driver_data = NULL; 373 ddf_fun_destroy(fun); 374 return rc; 375 } 376 377 usb_log_debug("Adding DDF function to category %s...\n", 378 HID_MOUSE_WHEEL_CATEGORY); 379 rc = ddf_fun_add_to_category(fun, HID_MOUSE_WHEEL_CATEGORY); 380 if (rc != EOK) { 381 usb_log_error( 382 "Could not add DDF function to category %s: %s.\n", 383 HID_MOUSE_WHEEL_CATEGORY, str_error(rc)); 384 385 FUN_UNBIND_DESTROY(mouse->mouse_fun); 386 mouse->mouse_fun = NULL; 387 FUN_UNBIND_DESTROY(fun); 388 return rc; 389 } 390 mouse->wheel_fun = fun; 391 305 392 return EOK; 306 393 } 394 395 /*----------------------------------------------------------------------------*/ 307 396 308 397 /** Get highest index of a button mentioned in given report. … … 427 516 } 428 517 518 if (mouse_dev->wheel_sess != NULL) { 519 const int ret = async_hangup(mouse_dev->wheel_sess); 520 if (ret != EOK) 521 usb_log_warning("Failed to hang up wheel session: " 522 "%p, %s.\n", mouse_dev->wheel_sess, str_error(ret)); 523 } 524 429 525 FUN_UNBIND_DESTROY(mouse_dev->mouse_fun); 526 FUN_UNBIND_DESTROY(mouse_dev->wheel_fun); 430 527 431 528 free(mouse_dev->buttons);
Note:
See TracChangeset
for help on using the changeset viewer.