Changeset 72af8da in mainline for uspace/drv/usbmouse/mouse.c
- Timestamp:
- 2011-03-16T18:50:17Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 42a3a57
- Parents:
- 3e7b7cd (diff), fcf07e6 (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
-
uspace/drv/usbmouse/mouse.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbmouse/mouse.c
r3e7b7cd r72af8da 37 37 #include <usb/debug.h> 38 38 #include <errno.h> 39 #include <str_error.h> 39 40 #include <ipc/mouse.h> 40 41 41 int usb_mouse_polling_fibril(void *arg) 42 /** Mouse polling callback. 43 * 44 * @param dev Device that is being polled. 45 * @param buffer Data buffer. 46 * @param buffer_size Buffer size in bytes. 47 * @param arg Custom argument - points to usb_mouse_t. 48 * @return Always true. 49 */ 50 bool usb_mouse_polling_callback(usb_device_t *dev, 51 uint8_t *buffer, size_t buffer_size, void *arg) 42 52 { 43 assert(arg != NULL); 44 ddf_dev_t *dev = (ddf_dev_t *) arg; 45 usb_mouse_t *mouse = (usb_mouse_t *) dev->driver_data; 53 usb_mouse_t *mouse = (usb_mouse_t *) arg; 46 54 47 assert(mouse); 55 usb_log_debug2("got buffer: %s.\n", 56 usb_debug_str_buffer(buffer, buffer_size, 0)); 48 57 49 size_t buffer_size = mouse->poll_pipe.max_packet_size; 58 uint8_t butt = buffer[0]; 59 char str_buttons[4] = { 60 butt & 1 ? '#' : '.', 61 butt & 2 ? '#' : '.', 62 butt & 4 ? '#' : '.', 63 0 64 }; 50 65 51 if (buffer_size < 4) { 52 usb_log_error("Weird mouse, results will be skewed.\n"); 53 buffer_size = 4; 66 int shift_x = ((int) buffer[1]) - 127; 67 int shift_y = ((int) buffer[2]) - 127; 68 int wheel = ((int) buffer[3]) - 127; 69 70 if (buffer[1] == 0) { 71 shift_x = 0; 72 } 73 if (buffer[2] == 0) { 74 shift_y = 0; 75 } 76 if (buffer[3] == 0) { 77 wheel = 0; 54 78 } 55 79 56 uint8_t *buffer = malloc(buffer_size); 57 if (buffer == NULL) { 58 usb_log_error("Out of memory, poll fibril aborted.\n"); 59 return ENOMEM; 80 if (mouse->console_phone >= 0) { 81 if ((shift_x != 0) || (shift_y != 0)) { 82 /* FIXME: guessed for QEMU */ 83 async_req_2_0(mouse->console_phone, 84 MEVENT_MOVE, 85 - shift_x / 10, - shift_y / 10); 86 } 87 if (butt) { 88 /* FIXME: proper button clicking. */ 89 async_req_2_0(mouse->console_phone, 90 MEVENT_BUTTON, 1, 1); 91 async_req_2_0(mouse->console_phone, 92 MEVENT_BUTTON, 1, 0); 93 } 60 94 } 61 95 62 while (true) {63 async_usleep(mouse->poll_interval_us);96 usb_log_debug("buttons=%s dX=%+3d dY=%+3d wheel=%+3d\n", 97 str_buttons, shift_x, shift_y, wheel); 64 98 65 size_t actual_size; 99 /* Guess. */ 100 async_usleep(1000); 66 101 67 /* FIXME: check for errors. */ 68 usb_endpoint_pipe_start_session(&mouse->poll_pipe); 69 70 usb_endpoint_pipe_read(&mouse->poll_pipe, 71 buffer, buffer_size, &actual_size); 72 73 usb_endpoint_pipe_end_session(&mouse->poll_pipe); 74 75 uint8_t butt = buffer[0]; 76 char str_buttons[4] = { 77 butt & 1 ? '#' : '.', 78 butt & 2 ? '#' : '.', 79 butt & 4 ? '#' : '.', 80 0 81 }; 82 83 int shift_x = ((int) buffer[1]) - 127; 84 int shift_y = ((int) buffer[2]) - 127; 85 int wheel = ((int) buffer[3]) - 127; 86 87 if (buffer[1] == 0) { 88 shift_x = 0; 89 } 90 if (buffer[2] == 0) { 91 shift_y = 0; 92 } 93 if (buffer[3] == 0) { 94 wheel = 0; 95 } 96 97 if (mouse->console_phone >= 0) { 98 if ((shift_x != 0) || (shift_y != 0)) { 99 /* FIXME: guessed for QEMU */ 100 async_req_2_0(mouse->console_phone, 101 MEVENT_MOVE, 102 - shift_x / 10, - shift_y / 10); 103 } 104 if (butt) { 105 /* FIXME: proper button clicking. */ 106 async_req_2_0(mouse->console_phone, 107 MEVENT_BUTTON, 1, 1); 108 async_req_2_0(mouse->console_phone, 109 MEVENT_BUTTON, 1, 0); 110 } 111 } 112 113 usb_log_debug("buttons=%s dX=%+3d dY=%+3d wheel=%+3d\n", 114 str_buttons, shift_x, shift_y, wheel); 115 } 116 117 return EOK; 102 return true; 118 103 } 119 104 105 /** Callback when polling is terminated. 106 * 107 * @param dev Device where the polling terminated. 108 * @param recurring_errors Whether the polling was terminated due to 109 * recurring errors. 110 * @param arg Custom argument - points to usb_mouse_t. 111 */ 112 void usb_mouse_polling_ended_callback(usb_device_t *dev, 113 bool recurring_errors, void *arg) 114 { 115 usb_mouse_t *mouse = (usb_mouse_t *) arg; 116 117 async_hangup(mouse->console_phone); 118 mouse->console_phone = -1; 119 } 120 120 121 121 /**
Note:
See TracChangeset
for help on using the changeset viewer.
