Ignore:
File:
1 edited

Legend:

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

    re3c78efc r70172dc4  
    5252#include "../usbhid.h"
    5353
    54 /** Number of simulated arrow-key presses for singel wheel step. */
    55 #define ARROWS_PER_SINGLE_WHEEL 3
    56 
    5754#define NAME "mouse"
    5855
     
    6966
    7067const char *HID_MOUSE_FUN_NAME = "mouse";
    71 const char *HID_MOUSE_WHEEL_FUN_NAME = "mouse-wheel";
    7268const char *HID_MOUSE_CATEGORY = "mouse";
    73 const char *HID_MOUSE_WHEEL_CATEGORY = "keyboard";
    7469
    7570/** Default idle rate for mouses. */
     
    126121
    127122        usb_log_debug("%s: fun->name: %s\n", __FUNCTION__, fun->name);
    128         usb_log_debug("%s: mouse_sess: %p, wheel_sess: %p\n",
    129             __FUNCTION__, mouse_dev->mouse_sess, mouse_dev->wheel_sess);
    130 
    131         async_sess_t **sess_ptr = (fun == mouse_dev->mouse_fun) ?
    132             &mouse_dev->mouse_sess : &mouse_dev->wheel_sess;
     123        usb_log_debug("%s: mouse_sess: %p\n",
     124            __FUNCTION__, mouse_dev->mouse_sess);
    133125
    134126        async_sess_t *sess =
    135127            async_callback_receive_start(EXCHANGE_SERIALIZE, icall);
    136128        if (sess != NULL) {
    137                 if (*sess_ptr == NULL) {
    138                         *sess_ptr = sess;
     129                if (mouse_dev->mouse_sess == NULL) {
     130                        mouse_dev->mouse_sess = sess;
    139131                        usb_log_debug("Console session to %s set ok (%p).\n",
    140132                            fun->name, sess);
     
    144136                            fun->name);
    145137                        async_answer_0(icallid, ELIMIT);
     138                        async_hangup(sess);
    146139                }
    147140        } else {
     
    150143        }
    151144}
    152 
    153 /*----------------------------------------------------------------------------*/
    154 
    155 static void usb_mouse_send_wheel(const usb_mouse_t *mouse_dev, int wheel)
    156 {
    157         unsigned int key = (wheel > 0) ? KC_UP : KC_DOWN;
    158 
    159         if (mouse_dev->wheel_sess == NULL) {
    160                 usb_log_warning(
    161                     "Connection to console not ready, wheel roll discarded.\n");
    162                 return;
    163         }
    164 
    165         const unsigned count =
    166             ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL;
    167         for (unsigned i = 0; i < count; i++) {
    168                 /* Send arrow press and release. */
    169                 usb_log_debug2("Sending key %d to the console\n", key);
    170                
    171                 async_exch_t *exch = async_exchange_begin(mouse_dev->wheel_sess);
    172                
    173                 async_msg_4(exch, KBDEV_EVENT, KEY_PRESS, key, 0, 0);
    174                 async_msg_4(exch, KBDEV_EVENT, KEY_RELEASE, key, 0, 0);
    175                
    176                 async_exchange_end(exch);
    177         }
    178 }
    179 
    180 /*----------------------------------------------------------------------------*/
    181 
     145/*----------------------------------------------------------------------------*/
    182146static int get_mouse_axis_move_value(uint8_t rid, usb_hid_report_t *report,
    183147    int32_t usage)
     
    203167        return result;
    204168}
    205 
     169/*----------------------------------------------------------------------------*/
    206170static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev,
    207171    usb_mouse_t *mouse_dev)
     
    221185            &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
    222186
    223         if ((shift_x != 0) || (shift_y != 0)) {
     187        if (shift_x || shift_y || wheel) {
    224188                async_exch_t *exch =
    225189                    async_exchange_begin(mouse_dev->mouse_sess);
    226190                if (exch != NULL) {
    227                         async_req_2_0(exch, MOUSEEV_MOVE_EVENT, shift_x, shift_y);
     191                        async_msg_3(exch, MOUSEEV_MOVE_EVENT,
     192                            shift_x, shift_y, wheel);
    228193                        async_exchange_end(exch);
    229194                }
    230195        }
    231 
    232         if (wheel != 0)
    233                 usb_mouse_send_wheel(mouse_dev, wheel);
    234196
    235197        /* Buttons */
     
    341303        mouse->mouse_fun = fun;
    342304
    343         /*
    344          * Special function for acting as keyboard (wheel)
    345          */
    346         usb_log_debug("Creating DDF function %s...\n",
    347                       HID_MOUSE_WHEEL_FUN_NAME);
    348         fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
    349             HID_MOUSE_WHEEL_FUN_NAME);
    350         if (fun == NULL) {
    351                 usb_log_error("Could not create DDF function node `%s'.\n",
    352                     HID_MOUSE_WHEEL_FUN_NAME);
    353                 FUN_UNBIND_DESTROY(mouse->mouse_fun);
    354                 mouse->mouse_fun = NULL;
    355                 return ENOMEM;
    356         }
    357 
    358         /*
    359          * Store the initialized HID device and HID ops
    360          * to the DDF function.
    361          */
    362         fun->ops = &mouse->ops;
    363         fun->driver_data = mouse;
    364 
    365         rc = ddf_fun_bind(fun);
    366         if (rc != EOK) {
    367                 usb_log_error("Could not bind DDF function `%s': %s.\n",
    368                     fun->name, str_error(rc));
    369                 FUN_UNBIND_DESTROY(mouse->mouse_fun);
    370                 mouse->mouse_fun = NULL;
    371 
    372                 fun->driver_data = NULL;
    373                 ddf_fun_destroy(fun);
    374                 return rc;
    375         }
    376 
    377         usb_log_debug("Adding DDF function to category %s...\n",
    378             HID_MOUSE_WHEEL_CATEGORY);
    379         rc = ddf_fun_add_to_category(fun, HID_MOUSE_WHEEL_CATEGORY);
    380         if (rc != EOK) {
    381                 usb_log_error(
    382                     "Could not add DDF function to category %s: %s.\n",
    383                     HID_MOUSE_WHEEL_CATEGORY, str_error(rc));
    384 
    385                 FUN_UNBIND_DESTROY(mouse->mouse_fun);
    386                 mouse->mouse_fun = NULL;
    387                 FUN_UNBIND_DESTROY(fun);
    388                 return rc;
    389         }
    390         mouse->wheel_fun = fun;
    391 
    392305        return EOK;
    393306}
    394 
    395 /*----------------------------------------------------------------------------*/
    396 
     307/*----------------------------------------------------------------------------*/
    397308/** Get highest index of a button mentioned in given report.
    398309 *
     
    516427        }
    517428
    518         if (mouse_dev->wheel_sess != NULL) {
    519                 const int ret = async_hangup(mouse_dev->wheel_sess);
    520                 if (ret != EOK)
    521                         usb_log_warning("Failed to hang up wheel session: "
    522                             "%p, %s.\n", mouse_dev->wheel_sess, str_error(ret));
    523         }
    524 
    525429        FUN_UNBIND_DESTROY(mouse_dev->mouse_fun);
    526         FUN_UNBIND_DESTROY(mouse_dev->wheel_fun);
    527430
    528431        free(mouse_dev->buttons);
Note: See TracChangeset for help on using the changeset viewer.