Changeset a3a2fdb in mainline
- Timestamp:
- 2011-06-18T16:25:40Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 58c0917
- Parents:
- ae5f77d5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/mouse/mousedev.c
rae5f77d5 ra3a2fdb 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) { … … 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, KBDEV_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, KBDEV_EVENT, KEY_RELEASE, 225 ev.key, ev.mods, ev.c); 226 } 227 } 228 229 /*----------------------------------------------------------------------------*/ 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 } 230 252 231 253 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, … … 239 261 } 240 262 241 /* 242 * X 243 */ 244 int shift_x = 0; 245 246 usb_hid_report_path_t *path = usb_hid_report_path(); 247 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP, 248 USB_HIDUT_USAGE_GENERIC_DESKTOP_X); 249 250 usb_hid_report_path_set_report_id(path, hid_dev->report_id); 251 252 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 253 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END, 254 USB_HID_REPORT_TYPE_INPUT); 255 256 if (field != NULL) { 257 usb_log_debug2(NAME " VALUE(%X) USAGE(%X)\n", field->value, 258 field->usage); 259 shift_x = field->value; 260 } 261 262 usb_hid_report_path_free(path); 263 264 /* 265 * Y 266 */ 267 int shift_y = 0; 268 269 path = usb_hid_report_path(); 270 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP, 271 USB_HIDUT_USAGE_GENERIC_DESKTOP_Y); 272 273 usb_hid_report_path_set_report_id(path, hid_dev->report_id); 274 275 field = usb_hid_report_get_sibling( 276 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END, 277 USB_HID_REPORT_TYPE_INPUT); 278 279 if (field != NULL) { 280 usb_log_debug2(NAME " VALUE(%X) USAGE(%X)\n", field->value, 281 field->usage); 282 shift_y = field->value; 283 } 284 285 usb_hid_report_path_free(path); 286 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 287 270 if ((shift_x != 0) || (shift_y != 0)) { 288 271 async_obsolete_req_2_0(mouse_dev->mouse_phone, 289 272 MEVENT_MOVE, shift_x, shift_y); 290 273 } 291 292 /* 293 * Wheel 294 */ 295 int wheel = 0; 296 297 path = usb_hid_report_path(); 298 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP, 299 USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL); 300 301 usb_hid_report_path_set_report_id(path, hid_dev->report_id); 302 303 field = usb_hid_report_get_sibling( 304 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END, 305 USB_HID_REPORT_TYPE_INPUT); 306 307 if (field != NULL) { 308 usb_log_debug2(NAME " VALUE(%X) USAGE(%X)\n", field->value, 309 field->usage); 310 wheel = field->value; 311 } 312 313 usb_hid_report_path_free(path); 314 315 // send arrow up for positive direction and arrow down for negative 316 // direction; three arrows for difference of 1 317 usb_mouse_send_wheel(mouse_dev, wheel); 318 274 275 if (wheel != 0) { 276 usb_mouse_send_wheel(mouse_dev, wheel); 277 } 319 278 320 279 /* 321 280 * Buttons 322 281 */ 323 path = usb_hid_report_path();282 usb_hid_report_path_t *path = usb_hid_report_path(); 324 283 usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0); 325 284 usb_hid_report_path_set_report_id(path, hid_dev->report_id); 326 285 327 field = usb_hid_report_get_sibling(286 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 328 287 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END 329 288 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
Note:
See TracChangeset
for help on using the changeset viewer.