source: mainline/uspace/drv/usbmouse/mouse.c@ 4a4c8bcf

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4a4c8bcf was 4a4c8bcf, checked in by Martin Decky <martin@…>, 14 years ago

usbmouse: remove obsolete async framework stuff
cstyle

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Copyright (c) 2011 Vojtech Horky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup drvusbmouse
30 * @{
31 */
32/**
33 * @file
34 * Actual handling of USB mouse protocol.
35 */
36
37#include <usb/debug.h>
38#include <errno.h>
39#include <str_error.h>
40#include <ipc/mouse.h>
41#include <async.h>
42#include "mouse.h"
43
44/** Mouse polling callback.
45 *
46 * @param dev Device that is being polled.
47 * @param buffer Data buffer.
48 * @param size Buffer size in bytes.
49 * @param arg Pointer to usb_mouse_t.
50 *
51 * @return Always true.
52 *
53 */
54bool usb_mouse_polling_callback(usb_device_t *dev, uint8_t *buffer,
55 size_t size, void *arg)
56{
57 usb_mouse_t *mouse = (usb_mouse_t *) arg;
58
59 usb_log_debug2("got buffer: %s.\n",
60 usb_debug_str_buffer(buffer, size, 0));
61
62 uint8_t butt = buffer[0];
63 char str_buttons[4] = {
64 butt & 1 ? '#' : '.',
65 butt & 2 ? '#' : '.',
66 butt & 4 ? '#' : '.',
67 0
68 };
69
70 int shift_x = ((int) buffer[1]) - 127;
71 int shift_y = ((int) buffer[2]) - 127;
72 int wheel = ((int) buffer[3]) - 127;
73
74 if (buffer[1] == 0)
75 shift_x = 0;
76
77 if (buffer[2] == 0)
78 shift_y = 0;
79
80 if (buffer[3] == 0)
81 wheel = 0;
82
83 if (mouse->console_sess) {
84 if ((shift_x != 0) || (shift_y != 0)) {
85 // FIXME: guessed for QEMU
86
87 async_exch_t *exch = async_exchange_begin(mouse->console_sess);
88 async_req_2_0(exch, MEVENT_MOVE, -shift_x / 10, -shift_y / 10);
89 async_exchange_end(exch);
90 }
91 if (butt) {
92 // FIXME: proper button clicking
93
94 async_exch_t *exch = async_exchange_begin(mouse->console_sess);
95 async_req_2_0(exch, MEVENT_BUTTON, 1, 1);
96 async_req_2_0(exch, MEVENT_BUTTON, 1, 0);
97 async_exchange_end(exch);
98 }
99 }
100
101 usb_log_debug("buttons=%s dX=%+3d dY=%+3d wheel=%+3d\n",
102 str_buttons, shift_x, shift_y, wheel);
103
104 /* Guess. */
105 async_usleep(1000);
106
107 return true;
108}
109
110/** Callback when polling is terminated.
111 *
112 * @param dev Device where the polling terminated.
113 * @param recurring_errors Whether the polling was terminated due to
114 * recurring errors.
115 * @param arg Pointer to usb_mouse_t.
116 *
117 */
118void usb_mouse_polling_ended_callback(usb_device_t *dev, bool recurring_errors,
119 void *arg)
120{
121 usb_mouse_t *mouse = (usb_mouse_t *) arg;
122
123 async_hangup(mouse->console_sess);
124 mouse->console_sess = NULL;
125
126 usb_device_destroy(dev);
127}
128
129/**
130 * @}
131 */
Note: See TracBrowser for help on using the repository browser.