Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/mouse/mousedev.c

    rf90c0d6 r310c4df  
    4343#include <str_error.h>
    4444#include <ipc/mouse.h>
    45 #include <io/console.h>
    46 
    47 #include <ipc/kbd.h>
    48 #include <io/keycode.h>
    4945
    5046#include "mousedev.h"
     
    6561
    6662const char *HID_MOUSE_FUN_NAME = "mouse";
    67 const char *HID_MOUSE_WHEEL_FUN_NAME = "mouse-wheel";
    6863const char *HID_MOUSE_CLASS_NAME = "mouse";
    69 const char *HID_MOUSE_WHEEL_CLASS_NAME = "keyboard";
    7064
    7165/** Default idle rate for mouses. */
     
    125119       
    126120        if (hid_dev == NULL || hid_dev->data == NULL) {
    127                 usb_log_debug("default_connection_handler: Missing "
    128                     "parameters.\n");
    129121                async_answer_0(icallid, EINVAL);
    130122                return;
     
    135127        usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data;
    136128       
    137         int *phone = (str_cmp(fun->name, HID_MOUSE_FUN_NAME) == 0)
    138                      ? &mouse_dev->mouse_phone : &mouse_dev->wheel_phone;
    139        
    140129        if (method == IPC_M_CONNECT_TO_ME) {
    141130                int callback = IPC_GET_ARG5(*icall);
    142131
    143                 if (*phone != -1) {
    144                         usb_log_debug("default_connection_handler: Console "
    145                             "phone to mouse already set.\n");
     132                if (mouse_dev->console_phone != -1) {
    146133                        async_answer_0(icallid, ELIMIT);
    147                         //async_answer_0(icallid, EOK);
    148134                        return;
    149135                }
    150136
    151                 *phone = callback;
     137                mouse_dev->console_phone = callback;
    152138                usb_log_debug("Console phone to mouse set ok (%d).\n", callback);
    153139                async_answer_0(icallid, EOK);
     
    155141        }
    156142
    157         usb_log_debug("default_connection_handler: Invalid function.\n");
    158143        async_answer_0(icallid, EINVAL);
    159144}
     
    167152                return NULL;
    168153        }
    169         mouse->mouse_phone = -1;
    170         mouse->wheel_phone = -1;
     154        mouse->console_phone = -1;
    171155       
    172156        return mouse;
     
    180164       
    181165        // hangup phone to the console
    182         if ((*mouse_dev)->mouse_phone >= 0) {
    183                 async_hangup((*mouse_dev)->mouse_phone);
    184         }
    185        
    186         if ((*mouse_dev)->wheel_phone >= 0) {
    187                 async_hangup((*mouse_dev)->wheel_phone);
     166        if ((*mouse_dev)->console_phone >= 0) {
     167                async_hangup((*mouse_dev)->console_phone);
    188168        }
    189169       
     
    194174/*----------------------------------------------------------------------------*/
    195175
    196 static void usb_mouse_send_wheel(const usb_mouse_t *mouse_dev, int wheel)
    197 {
    198         console_event_t ev;
    199        
    200         ev.type = KEY_PRESS;
    201         ev.key = (wheel > 0) ? KC_UP : (wheel < 0) ? KC_DOWN : 0;
    202         ev.mods = 0;
    203         ev.c = 0;
    204 
    205         if (mouse_dev->wheel_phone < 0) {
    206                 usb_log_warning(
    207                     "Connection to console not ready, key discarded.\n");
    208                 return;
    209         }
    210        
    211         int count = (wheel < 0) ? -wheel : wheel;
    212         int i;
    213        
    214         for (i = 0; i < count * 3; ++i) {
    215                 usb_log_debug2("Sending key %d to the console\n", ev.key);
    216                 async_msg_4(mouse_dev->wheel_phone, KBD_EVENT, ev.type,
    217                     ev.key, ev.mods, ev.c);
    218                 // send key release right away
    219                 async_msg_4(mouse_dev->wheel_phone, KBD_EVENT, KEY_RELEASE,
    220                     ev.key, ev.mods, ev.c);
    221         }
    222 }
    223 
    224 /*----------------------------------------------------------------------------*/
    225 
    226 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, uint8_t *buffer,
    227     size_t buffer_size)
     176static bool usb_mouse_process_boot_report(usb_hid_dev_t *hid_dev,
     177    uint8_t *buffer, size_t buffer_size)
    228178{
    229179        usb_mouse_t *mouse_dev = (usb_mouse_t *)hid_dev->data;
     
    232182            usb_debug_str_buffer(buffer, buffer_size, 0));
    233183       
    234         if (mouse_dev->mouse_phone < 0) {
     184        if (mouse_dev->console_phone < 0) {
    235185                usb_log_error(NAME " No console phone.\n");
    236186                return false;   // ??
     
    302252       
    303253        if ((shift_x != 0) || (shift_y != 0)) {
    304                 async_req_2_0(mouse_dev->mouse_phone,
     254                async_req_2_0(mouse_dev->console_phone,
    305255                    MEVENT_MOVE, shift_x, shift_y);
    306256        }
    307        
    308         /*
    309          * Wheel
    310          */
    311         int wheel = 0;
    312        
    313         path = usb_hid_report_path();
    314         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
    315             USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
    316 
    317         usb_hid_report_path_set_report_id(path, report_id);
    318        
    319         field = usb_hid_report_get_sibling(
    320             hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END,
    321             USB_HID_REPORT_TYPE_INPUT);
    322 
    323         if (field != NULL) {
    324                 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    325                     field->usage);
    326                 wheel = field->value;
    327         }
    328 
    329         usb_hid_report_path_free(path);
    330        
    331         // send arrow up for positive direction and arrow down for negative
    332         // direction; three arrows for difference of 1
    333         usb_mouse_send_wheel(mouse_dev, wheel);
    334        
    335257       
    336258        /*
     
    352274                if (mouse_dev->buttons[field->usage - field->usage_minimum] == 0
    353275                    && field->value != 0) {
    354                         async_req_2_0(mouse_dev->mouse_phone,
     276                        async_req_2_0(mouse_dev->console_phone,
    355277                            MEVENT_BUTTON, field->usage, 1);
    356278                        mouse_dev->buttons[field->usage - field->usage_minimum]
     
    359281                    mouse_dev->buttons[field->usage - field->usage_minimum] != 0
    360282                    && field->value == 0) {
    361                        async_req_2_0(mouse_dev->mouse_phone,
     283                       async_req_2_0(mouse_dev->console_phone,
    362284                           MEVENT_BUTTON, field->usage, 0);
    363285                       mouse_dev->buttons[field->usage - field->usage_minimum]
     
    415337        }
    416338       
    417         /*
    418          * Special function for acting as keyboard (wheel)
    419          */
    420         usb_log_debug("Creating DDF function %s...\n",
    421                       HID_MOUSE_WHEEL_FUN_NAME);
    422         fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
    423             HID_MOUSE_WHEEL_FUN_NAME);
    424         if (fun == NULL) {
    425                 usb_log_error("Could not create DDF function node.\n");
    426                 return ENOMEM;
    427         }
    428        
    429         /*
    430          * Store the initialized HID device and HID ops
    431          * to the DDF function.
    432          */
    433         fun->ops = &hid_dev->ops;
    434         fun->driver_data = hid_dev;   // TODO: maybe change to hid_dev->data
    435 
    436         rc = ddf_fun_bind(fun);
    437         if (rc != EOK) {
    438                 usb_log_error("Could not bind DDF function: %s.\n",
    439                     str_error(rc));
    440                 ddf_fun_destroy(fun);
    441                 return rc;
    442         }
    443        
    444         usb_log_debug("Adding DDF function to class %s...\n",
    445             HID_MOUSE_WHEEL_CLASS_NAME);
    446         rc = ddf_fun_add_to_class(fun, HID_MOUSE_WHEEL_CLASS_NAME);
    447         if (rc != EOK) {
    448                 usb_log_error(
    449                     "Could not add DDF function to class %s: %s.\n",
    450                     HID_MOUSE_WHEEL_CLASS_NAME, str_error(rc));
    451                 ddf_fun_destroy(fun);
    452                 return rc;
    453         }
    454        
    455339        return EOK;
    456340}
     
    523407        }
    524408       
    525         return usb_mouse_process_report(hid_dev, buffer, buffer_size);
     409        return usb_mouse_process_boot_report(hid_dev, buffer, buffer_size);
    526410}
    527411
Note: See TracChangeset for help on using the changeset viewer.