00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00036 #include "mouse.h"
00037 #include <usb/debug.h>
00038 #include <errno.h>
00039 #include <str_error.h>
00040 #include <ipc/mouse.h>
00041
00050 bool usb_mouse_polling_callback(usb_device_t *dev,
00051 uint8_t *buffer, size_t buffer_size, void *arg)
00052 {
00053 usb_mouse_t *mouse = (usb_mouse_t *) arg;
00054
00055 usb_log_debug2("got buffer: %s.\n",
00056 usb_debug_str_buffer(buffer, buffer_size, 0));
00057
00058 uint8_t butt = buffer[0];
00059 char str_buttons[4] = {
00060 butt & 1 ? '#' : '.',
00061 butt & 2 ? '#' : '.',
00062 butt & 4 ? '#' : '.',
00063 0
00064 };
00065
00066 int shift_x = ((int) buffer[1]) - 127;
00067 int shift_y = ((int) buffer[2]) - 127;
00068 int wheel = ((int) buffer[3]) - 127;
00069
00070 if (buffer[1] == 0) {
00071 shift_x = 0;
00072 }
00073 if (buffer[2] == 0) {
00074 shift_y = 0;
00075 }
00076 if (buffer[3] == 0) {
00077 wheel = 0;
00078 }
00079
00080 if (mouse->console_phone >= 0) {
00081 if ((shift_x != 0) || (shift_y != 0)) {
00082
00083 async_req_2_0(mouse->console_phone,
00084 MEVENT_MOVE,
00085 - shift_x / 10, - shift_y / 10);
00086 }
00087 if (butt) {
00088
00089 async_req_2_0(mouse->console_phone,
00090 MEVENT_BUTTON, 1, 1);
00091 async_req_2_0(mouse->console_phone,
00092 MEVENT_BUTTON, 1, 0);
00093 }
00094 }
00095
00096 usb_log_debug("buttons=%s dX=%+3d dY=%+3d wheel=%+3d\n",
00097 str_buttons, shift_x, shift_y, wheel);
00098
00099
00100 async_usleep(1000);
00101
00102 return true;
00103 }
00104
00112 void usb_mouse_polling_ended_callback(usb_device_t *dev,
00113 bool recurring_errors, void *arg)
00114 {
00115 usb_mouse_t *mouse = (usb_mouse_t *) arg;
00116
00117 async_hangup(mouse->console_phone);
00118 mouse->console_phone = -1;
00119
00120 usb_device_destroy(dev);
00121 }
00122