mouse.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011 Vojtech Horky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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                         /* FIXME: guessed for QEMU */
00083                         async_req_2_0(mouse->console_phone,
00084                             MEVENT_MOVE,
00085                             - shift_x / 10,  - shift_y / 10);
00086                 }
00087                 if (butt) {
00088                         /* FIXME: proper button clicking. */
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         /* Guess. */
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 

Generated on Thu Jun 2 07:45:44 2011 for HelenOS/USB by  doxygen 1.4.7