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
RevLine 
[c081780]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 */
[79ae36dd]36
[c081780]37#include <usb/debug.h>
38#include <errno.h>
[3faf416c]39#include <str_error.h>
[21bb58d]40#include <ipc/mouse.h>
[79ae36dd]41#include <async.h>
42#include "mouse.h"
[c081780]43
[adfe5ec]44/** Mouse polling callback.
[a6add7a]45 *
[4a4c8bcf]46 * @param dev Device that is being polled.
[adfe5ec]47 * @param buffer Data buffer.
[4a4c8bcf]48 * @param size Buffer size in bytes.
49 * @param arg Pointer to usb_mouse_t.
50 *
[adfe5ec]51 * @return Always true.
[4a4c8bcf]52 *
[a6add7a]53 */
[4a4c8bcf]54bool usb_mouse_polling_callback(usb_device_t *dev, uint8_t *buffer,
55 size_t size, void *arg)
[c081780]56{
[adfe5ec]57 usb_mouse_t *mouse = (usb_mouse_t *) arg;
[4a4c8bcf]58
[adfe5ec]59 usb_log_debug2("got buffer: %s.\n",
[4a4c8bcf]60 usb_debug_str_buffer(buffer, size, 0));
61
[adfe5ec]62 uint8_t butt = buffer[0];
63 char str_buttons[4] = {
64 butt & 1 ? '#' : '.',
65 butt & 2 ? '#' : '.',
66 butt & 4 ? '#' : '.',
67 0
68 };
[4a4c8bcf]69
[adfe5ec]70 int shift_x = ((int) buffer[1]) - 127;
71 int shift_y = ((int) buffer[2]) - 127;
72 int wheel = ((int) buffer[3]) - 127;
[4a4c8bcf]73
74 if (buffer[1] == 0)
[adfe5ec]75 shift_x = 0;
[4a4c8bcf]76
77 if (buffer[2] == 0)
[adfe5ec]78 shift_y = 0;
[4a4c8bcf]79
80 if (buffer[3] == 0)
[adfe5ec]81 wheel = 0;
[4a4c8bcf]82
83 if (mouse->console_sess) {
[adfe5ec]84 if ((shift_x != 0) || (shift_y != 0)) {
[4a4c8bcf]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);
[3faf416c]90 }
[adfe5ec]91 if (butt) {
[4a4c8bcf]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);
[3faf416c]98 }
[adfe5ec]99 }
[4a4c8bcf]100
[adfe5ec]101 usb_log_debug("buttons=%s dX=%+3d dY=%+3d wheel=%+3d\n",
102 str_buttons, shift_x, shift_y, wheel);
[4a4c8bcf]103
[adfe5ec]104 /* Guess. */
105 async_usleep(1000);
[4a4c8bcf]106
[adfe5ec]107 return true;
108}
[21bb58d]109
[adfe5ec]110/** Callback when polling is terminated.
111 *
[4a4c8bcf]112 * @param dev Device where the polling terminated.
[adfe5ec]113 * @param recurring_errors Whether the polling was terminated due to
[4a4c8bcf]114 * recurring errors.
115 * @param arg Pointer to usb_mouse_t.
116 *
[adfe5ec]117 */
[4a4c8bcf]118void usb_mouse_polling_ended_callback(usb_device_t *dev, bool recurring_errors,
119 void *arg)
[adfe5ec]120{
121 usb_mouse_t *mouse = (usb_mouse_t *) arg;
[4a4c8bcf]122
123 async_hangup(mouse->console_sess);
124 mouse->console_sess = NULL;
125
[3ef91c88]126 usb_device_destroy(dev);
[c081780]127}
128
129/**
130 * @}
131 */
Note: See TracBrowser for help on using the repository browser.