Changeset 948911d in mainline for uspace/drv/bus/usb/usbhid/mouse/mousedev.c
- Timestamp:
- 2012-01-24T02:27:43Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 230385c
- Parents:
- 8afeb04 (diff), 2df6f6fe (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/mouse/mousedev.c
r8afeb04 r948911d 52 52 #include "../usbhid.h" 53 53 54 /** Number of simulated arrow-key presses for singel wheel step. */55 #define ARROWS_PER_SINGLE_WHEEL 356 57 54 #define NAME "mouse" 58 55 … … 72 69 73 70 const char *HID_MOUSE_FUN_NAME = "mouse"; 74 const char *HID_MOUSE_WHEEL_FUN_NAME = "mouse-wheel";75 71 const char *HID_MOUSE_CATEGORY = "mouse"; 76 const char *HID_MOUSE_WHEEL_CATEGORY = "keyboard";77 72 78 73 /** Default idle rate for mouses. */ … … 129 124 130 125 usb_log_debug("%s: fun->name: %s\n", __FUNCTION__, fun->name); 131 usb_log_debug("%s: mouse_sess: %p, wheel_sess: %p\n", 132 __FUNCTION__, mouse_dev->mouse_sess, mouse_dev->wheel_sess); 133 134 async_sess_t **sess_ptr = (fun == mouse_dev->mouse_fun) ? 135 &mouse_dev->mouse_sess : &mouse_dev->wheel_sess; 126 usb_log_debug("%s: mouse_sess: %p\n", 127 __FUNCTION__, mouse_dev->mouse_sess); 136 128 137 129 async_sess_t *sess = 138 130 async_callback_receive_start(EXCHANGE_SERIALIZE, icall); 139 131 if (sess != NULL) { 140 if ( *sess_ptr== NULL) {141 *sess_ptr= sess;132 if (mouse_dev->mouse_sess == NULL) { 133 mouse_dev->mouse_sess = sess; 142 134 usb_log_debug("Console session to %s set ok (%p).\n", 143 135 fun->name, sess); … … 147 139 fun->name); 148 140 async_answer_0(icallid, ELIMIT); 141 async_hangup(sess); 149 142 } 150 143 } else { … … 153 146 } 154 147 } 155 156 /*----------------------------------------------------------------------------*/ 157 158 static void usb_mouse_send_wheel(const usb_mouse_t *mouse_dev, int wheel) 159 { 160 unsigned int key = (wheel > 0) ? KC_UP : KC_DOWN; 161 162 if (mouse_dev->wheel_sess == NULL) { 163 usb_log_warning( 164 "Connection to console not ready, wheel roll discarded.\n"); 165 return; 166 } 167 168 const unsigned count = 169 ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL; 170 for (unsigned i = 0; i < count; i++) { 171 /* Send arrow press and release. */ 172 usb_log_debug2("Sending key %d to the console\n", key); 173 174 async_exch_t *exch = async_exchange_begin(mouse_dev->wheel_sess); 175 176 async_msg_4(exch, KBDEV_EVENT, KEY_PRESS, key, 0, 0); 177 async_msg_4(exch, KBDEV_EVENT, KEY_RELEASE, key, 0, 0); 178 179 async_exchange_end(exch); 180 } 181 } 182 183 /*----------------------------------------------------------------------------*/ 184 148 /*----------------------------------------------------------------------------*/ 185 149 static int get_mouse_axis_move_value(uint8_t rid, usb_hid_report_t *report, 186 150 int32_t usage) … … 206 170 return result; 207 171 } 208 172 /*----------------------------------------------------------------------------*/ 209 173 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, 210 174 usb_mouse_t *mouse_dev) … … 224 188 &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL); 225 189 226 if ( (shift_x != 0) || (shift_y != 0)) {190 if (shift_x || shift_y || wheel) { 227 191 async_exch_t *exch = 228 192 async_exchange_begin(mouse_dev->mouse_sess); 229 193 if (exch != NULL) { 230 async_req_2_0(exch, MOUSEEV_MOVE_EVENT, shift_x, shift_y); 194 async_msg_3(exch, MOUSEEV_MOVE_EVENT, 195 shift_x, shift_y, wheel); 231 196 async_exchange_end(exch); 232 197 } 233 198 } 234 235 if (wheel != 0)236 usb_mouse_send_wheel(mouse_dev, wheel);237 199 238 200 /* Buttons */ … … 333 295 } 334 296 mouse->mouse_fun = fun; 335 336 /*337 * Special function for acting as keyboard (wheel)338 */339 usb_log_debug("Creating DDF function %s...\n",340 HID_MOUSE_WHEEL_FUN_NAME);341 fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,342 HID_MOUSE_WHEEL_FUN_NAME);343 if (fun == NULL) {344 usb_log_error("Could not create DDF function node `%s'.\n",345 HID_MOUSE_WHEEL_FUN_NAME);346 FUN_UNBIND_DESTROY(mouse->mouse_fun);347 mouse->mouse_fun = NULL;348 return ENOMEM;349 }350 351 /*352 * Store the initialized HID device and HID ops353 * to the DDF function.354 */355 fun->ops = &ops;356 fun->driver_data = mouse;357 358 rc = ddf_fun_bind(fun);359 if (rc != EOK) {360 usb_log_error("Could not bind DDF function `%s': %s.\n",361 fun->name, str_error(rc));362 FUN_UNBIND_DESTROY(mouse->mouse_fun);363 mouse->mouse_fun = NULL;364 365 fun->driver_data = NULL;366 ddf_fun_destroy(fun);367 return rc;368 }369 370 usb_log_debug("Adding DDF function to category %s...\n",371 HID_MOUSE_WHEEL_CATEGORY);372 rc = ddf_fun_add_to_category(fun, HID_MOUSE_WHEEL_CATEGORY);373 if (rc != EOK) {374 usb_log_error(375 "Could not add DDF function to category %s: %s.\n",376 HID_MOUSE_WHEEL_CATEGORY, str_error(rc));377 378 FUN_UNBIND_DESTROY(mouse->mouse_fun);379 mouse->mouse_fun = NULL;380 FUN_UNBIND_DESTROY(fun);381 return rc;382 }383 mouse->wheel_fun = fun;384 385 297 return EOK; 386 298 } 387 388 /*----------------------------------------------------------------------------*/ 389 299 /*----------------------------------------------------------------------------*/ 390 300 /** Get highest index of a button mentioned in given report. 391 301 * … … 506 416 } 507 417 508 if (mouse_dev->wheel_sess != NULL) {509 const int ret = async_hangup(mouse_dev->wheel_sess);510 if (ret != EOK)511 usb_log_warning("Failed to hang up wheel session: "512 "%p, %s.\n", mouse_dev->wheel_sess, str_error(ret));513 }514 515 418 FUN_UNBIND_DESTROY(mouse_dev->mouse_fun); 516 FUN_UNBIND_DESTROY(mouse_dev->wheel_fun);517 419 518 420 free(mouse_dev->buttons);
Note:
See TracChangeset
for help on using the changeset viewer.