Changeset f1fae414 in mainline for uspace/drv/bus/usb/usbhid/mouse/mousedev.c
- Timestamp:
- 2011-06-22T01:34:53Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8d7e82c1, cac458f
- Parents:
- 72ec8cc (diff), bf172825 (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 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/mouse/mousedev.c
r72ec8cc rf1fae414 44 44 #include <async_obsolete.h> 45 45 #include <str_error.h> 46 #include <ipc/mouse .h>46 #include <ipc/mouseev.h> 47 47 #include <io/console.h> 48 48 49 #include <ipc/kbd .h>49 #include <ipc/kbdev.h> 50 50 #include <io/keycode.h> 51 51 52 52 #include "mousedev.h" 53 53 #include "../usbhid.h" 54 55 /** Number of simulated arrow-key presses for singel wheel step. */ 56 #define ARROWS_PER_SINGLE_WHEEL 3 54 57 55 58 // FIXME: remove this header … … 201 204 static void usb_mouse_send_wheel(const usb_mouse_t *mouse_dev, int wheel) 202 205 { 203 kbd_event_t ev; 204 205 ev.type = KEY_PRESS; 206 ev.key = (wheel > 0) ? KC_UP : (wheel < 0) ? KC_DOWN : 0; 207 ev.mods = 0; 208 ev.c = 0; 206 unsigned int key = (wheel > 0) ? KC_UP : KC_DOWN; 209 207 210 208 if (mouse_dev->wheel_phone < 0) { 211 209 usb_log_warning( 212 "Connection to console not ready, keydiscarded.\n");210 "Connection to console not ready, wheel roll discarded.\n"); 213 211 return; 214 212 } 215 213 216 int count = ( wheel < 0) ? -wheel : wheel;214 int count = ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL; 217 215 int i; 218 216 219 for (i = 0; i < count * 3; ++i) { 220 usb_log_debug2("Sending key %d to the console\n", ev.key); 221 async_obsolete_msg_4(mouse_dev->wheel_phone, KBD_EVENT, ev.type, 222 ev.key, ev.mods, ev.c); 223 // send key release right away 224 async_obsolete_msg_4(mouse_dev->wheel_phone, KBD_EVENT, KEY_RELEASE, 225 ev.key, ev.mods, ev.c); 226 } 227 } 228 229 /*----------------------------------------------------------------------------*/ 230 231 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, 232 usb_mouse_t *mouse_dev, uint8_t *buffer, 233 size_t buffer_size) 217 for (i = 0; i < count; i++) { 218 /* Send arrow press and release. */ 219 usb_log_debug2("Sending key %d to the console\n", key); 220 async_obsolete_msg_4(mouse_dev->wheel_phone, KBDEV_EVENT, 221 KEY_PRESS, key, 0, 0); 222 async_obsolete_msg_4(mouse_dev->wheel_phone, KBDEV_EVENT, 223 KEY_RELEASE, key, 0, 0); 224 } 225 } 226 227 /*----------------------------------------------------------------------------*/ 228 229 static int get_mouse_axis_move_value(uint8_t rid, usb_hid_report_t *report, 230 int32_t usage) 231 { 232 int result = 0; 233 234 usb_hid_report_path_t *path = usb_hid_report_path(); 235 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP, 236 usage); 237 238 usb_hid_report_path_set_report_id(path, rid); 239 240 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 241 report, NULL, path, USB_HID_PATH_COMPARE_END, 242 USB_HID_REPORT_TYPE_INPUT); 243 244 if (field != NULL) { 245 result = field->value; 246 } 247 248 usb_hid_report_path_free(path); 249 250 return result; 251 } 252 253 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, 254 usb_mouse_t *mouse_dev) 234 255 { 235 256 assert(mouse_dev != NULL); 236 237 usb_log_debug2("got buffer: %s.\n",238 usb_debug_str_buffer(buffer, buffer_size, 0));239 257 240 258 if (mouse_dev->mouse_phone < 0) { … … 243 261 } 244 262 245 /* 246 * parse the input report 247 */ 248 249 usb_log_debug(NAME " Calling usb_hid_parse_report() with " 250 "buffer %s\n", usb_debug_str_buffer(buffer, buffer_size, 0)); 251 252 uint8_t report_id; 253 254 int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size, 255 &report_id); 256 257 if (rc != EOK) { 258 usb_log_warning(NAME "Error in usb_hid_parse_report(): %s\n", 259 str_error(rc)); 260 return true; 261 } 262 263 /* 264 * X 265 */ 266 int shift_x = 0; 267 268 usb_hid_report_path_t *path = usb_hid_report_path(); 269 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP, 270 USB_HIDUT_USAGE_GENERIC_DESKTOP_X); 271 272 usb_hid_report_path_set_report_id(path, report_id); 273 274 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 275 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END, 276 USB_HID_REPORT_TYPE_INPUT); 277 278 if (field != NULL) { 279 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value, 280 field->usage); 281 shift_x = field->value; 282 } 283 284 usb_hid_report_path_free(path); 285 286 /* 287 * Y 288 */ 289 int shift_y = 0; 290 291 path = usb_hid_report_path(); 292 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP, 293 USB_HIDUT_USAGE_GENERIC_DESKTOP_Y); 294 295 usb_hid_report_path_set_report_id(path, report_id); 296 297 field = usb_hid_report_get_sibling( 298 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END, 299 USB_HID_REPORT_TYPE_INPUT); 300 301 if (field != NULL) { 302 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value, 303 field->usage); 304 shift_y = field->value; 305 } 306 307 usb_hid_report_path_free(path); 308 263 int shift_x = get_mouse_axis_move_value(hid_dev->report_id, 264 hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_X); 265 int shift_y = get_mouse_axis_move_value(hid_dev->report_id, 266 hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_Y); 267 int wheel = get_mouse_axis_move_value(hid_dev->report_id, 268 hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL); 269 309 270 if ((shift_x != 0) || (shift_y != 0)) { 310 271 async_obsolete_req_2_0(mouse_dev->mouse_phone, 311 MEVENT_MOVE, shift_x, shift_y); 312 } 313 314 /* 315 * Wheel 316 */ 317 int wheel = 0; 318 319 path = usb_hid_report_path(); 320 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP, 321 USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL); 322 323 usb_hid_report_path_set_report_id(path, report_id); 324 325 field = usb_hid_report_get_sibling( 326 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END, 327 USB_HID_REPORT_TYPE_INPUT); 328 329 if (field != NULL) { 330 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value, 331 field->usage); 332 wheel = field->value; 333 } 334 335 usb_hid_report_path_free(path); 336 337 // send arrow up for positive direction and arrow down for negative 338 // direction; three arrows for difference of 1 339 usb_mouse_send_wheel(mouse_dev, wheel); 340 272 MOUSEEV_MOVE_EVENT, shift_x, shift_y); 273 } 274 275 if (wheel != 0) { 276 usb_mouse_send_wheel(mouse_dev, wheel); 277 } 341 278 342 279 /* 343 280 * Buttons 344 281 */ 345 path = usb_hid_report_path();282 usb_hid_report_path_t *path = usb_hid_report_path(); 346 283 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0); 347 usb_hid_report_path_set_report_id(path, report_id);348 349 field = usb_hid_report_get_sibling(284 usb_hid_report_path_set_report_id(path, hid_dev->report_id); 285 286 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 350 287 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END 351 288 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, … … 353 290 354 291 while (field != NULL) { 355 usb_log_debug (NAME " VALUE(%X) USAGE(%X)\n", field->value,292 usb_log_debug2(NAME " VALUE(%X) USAGE(%X)\n", field->value, 356 293 field->usage); 357 294 … … 359 296 && field->value != 0) { 360 297 async_obsolete_req_2_0(mouse_dev->mouse_phone, 361 M EVENT_BUTTON, field->usage, 1);298 MOUSEEV_BUTTON_EVENT, field->usage, 1); 362 299 mouse_dev->buttons[field->usage - field->usage_minimum] 363 300 = field->value; 364 } else if ( 365 mouse_dev->buttons[field->usage - field->usage_minimum] != 0 301 } else if (mouse_dev->buttons[field->usage - field->usage_minimum] != 0 366 302 && field->value == 0) { 367 368 M EVENT_BUTTON, field->usage, 0);369 mouse_dev->buttons[field->usage - field->usage_minimum]370 =field->value;371 303 async_obsolete_req_2_0(mouse_dev->mouse_phone, 304 MOUSEEV_BUTTON_EVENT, field->usage, 0); 305 mouse_dev->buttons[field->usage - field->usage_minimum] = 306 field->value; 307 } 372 308 373 309 field = usb_hid_report_get_sibling( … … 510 446 /*----------------------------------------------------------------------------*/ 511 447 512 bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, void *data, 513 uint8_t *buffer, size_t buffer_size) 514 { 515 usb_log_debug("usb_mouse_polling_callback()\n"); 516 usb_debug_str_buffer(buffer, buffer_size, 0); 517 448 bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, void *data) 449 { 518 450 if (hid_dev == NULL || data == NULL) { 519 451 usb_log_error("Missing argument to the mouse polling callback." … … 524 456 usb_mouse_t *mouse_dev = (usb_mouse_t *)data; 525 457 526 return usb_mouse_process_report(hid_dev, mouse_dev, buffer, 527 buffer_size); 458 return usb_mouse_process_report(hid_dev, mouse_dev); 528 459 } 529 460
Note:
See TracChangeset
for help on using the changeset viewer.