Changeset 7943c43 in mainline for uspace/drv/bus/usb/usbhid/mouse/mousedev.c
- Timestamp:
- 2012-01-16T22:45:38Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 32817cc, 3fe58d3c
- Parents:
- 9117ef9b (diff), 3ea725e (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
r9117ef9b r7943c43 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 … … 69 66 70 67 const char *HID_MOUSE_FUN_NAME = "mouse"; 71 const char *HID_MOUSE_WHEEL_FUN_NAME = "mouse-wheel";72 68 const char *HID_MOUSE_CATEGORY = "mouse"; 73 const char *HID_MOUSE_WHEEL_CATEGORY = "keyboard";74 69 75 70 /** Default idle rate for mouses. */ … … 126 121 127 122 usb_log_debug("%s: fun->name: %s\n", __FUNCTION__, fun->name); 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; 123 usb_log_debug("%s: mouse_sess: %p\n", 124 __FUNCTION__, mouse_dev->mouse_sess); 133 125 134 126 async_sess_t *sess = 135 127 async_callback_receive_start(EXCHANGE_SERIALIZE, icall); 136 128 if (sess != NULL) { 137 if ( *sess_ptr== NULL) {138 *sess_ptr= sess;129 if (mouse_dev->mouse_sess == NULL) { 130 mouse_dev->mouse_sess = sess; 139 131 usb_log_debug("Console session to %s set ok (%p).\n", 140 132 fun->name, sess); … … 144 136 fun->name); 145 137 async_answer_0(icallid, ELIMIT); 138 async_hangup(sess); 146 139 } 147 140 } else { … … 150 143 } 151 144 } 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 145 /*----------------------------------------------------------------------------*/ 182 146 static int get_mouse_axis_move_value(uint8_t rid, usb_hid_report_t *report, 183 147 int32_t usage) … … 203 167 return result; 204 168 } 205 169 /*----------------------------------------------------------------------------*/ 206 170 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, 207 171 usb_mouse_t *mouse_dev) … … 221 185 &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL); 222 186 223 if ( (shift_x != 0) || (shift_y != 0)) {187 if (shift_x || shift_y || wheel) { 224 188 async_exch_t *exch = 225 189 async_exchange_begin(mouse_dev->mouse_sess); 226 190 if (exch != NULL) { 227 async_req_2_0(exch, MOUSEEV_MOVE_EVENT, shift_x, shift_y); 191 async_msg_3(exch, MOUSEEV_MOVE_EVENT, 192 shift_x, shift_y, wheel); 228 193 async_exchange_end(exch); 229 194 } 230 195 } 231 232 if (wheel != 0)233 usb_mouse_send_wheel(mouse_dev, wheel);234 196 235 197 /* Buttons */ … … 341 303 mouse->mouse_fun = fun; 342 304 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 ops360 * 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 392 305 return EOK; 393 306 } 394 395 /*----------------------------------------------------------------------------*/ 396 307 /*----------------------------------------------------------------------------*/ 397 308 /** Get highest index of a button mentioned in given report. 398 309 * … … 516 427 } 517 428 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 525 429 FUN_UNBIND_DESTROY(mouse_dev->mouse_fun); 526 FUN_UNBIND_DESTROY(mouse_dev->wheel_fun);527 430 528 431 free(mouse_dev->buttons);
Note:
See TracChangeset
for help on using the changeset viewer.