Changeset 72af8da in mainline for uspace/drv/usbmouse/mouse.c


Ignore:
Timestamp:
2011-03-16T18:50:17Z (15 years ago)
Author:
Matus Dekanek <smekideki@…>
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.
Message:

merge from usb/development

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbmouse/mouse.c

    r3e7b7cd r72af8da  
    3737#include <usb/debug.h>
    3838#include <errno.h>
     39#include <str_error.h>
    3940#include <ipc/mouse.h>
    4041
    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 */
     50bool usb_mouse_polling_callback(usb_device_t *dev,
     51    uint8_t *buffer, size_t buffer_size, void *arg)
    4252{
    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;
    4654
    47         assert(mouse);
     55        usb_log_debug2("got buffer: %s.\n",
     56            usb_debug_str_buffer(buffer, buffer_size, 0));
    4857
    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        };
    5065
    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;
    5478        }
    5579
    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                }
    6094        }
    6195
    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);
    6498
    65                 size_t actual_size;
     99        /* Guess. */
     100        async_usleep(1000);
    66101
    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;
    118103}
    119104
     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 */
     112void 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}
    120120
    121121/**
Note: See TracChangeset for help on using the changeset viewer.