Ignore:
Timestamp:
2012-01-24T02:27:43Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
230385c
Parents:
8afeb04 (diff), 2df6f6fe (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:

Mainline changes.

File:
1 edited

Legend:

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

    r8afeb04 r948911d  
    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
     
    7269
    7370const char *HID_MOUSE_FUN_NAME = "mouse";
    74 const char *HID_MOUSE_WHEEL_FUN_NAME = "mouse-wheel";
    7571const char *HID_MOUSE_CATEGORY = "mouse";
    76 const char *HID_MOUSE_WHEEL_CATEGORY = "keyboard";
    7772
    7873/** Default idle rate for mouses. */
     
    129124
    130125        usb_log_debug("%s: fun->name: %s\n", __FUNCTION__, fun->name);
    131         usb_log_debug("%s: mouse_sess: %p, wheel_sess: %p\n",
    132             __FUNCTION__, mouse_dev->mouse_sess, mouse_dev->wheel_sess);
    133 
    134         async_sess_t **sess_ptr = (fun == mouse_dev->mouse_fun) ?
    135             &mouse_dev->mouse_sess : &mouse_dev->wheel_sess;
     126        usb_log_debug("%s: mouse_sess: %p\n",
     127            __FUNCTION__, mouse_dev->mouse_sess);
    136128
    137129        async_sess_t *sess =
    138130            async_callback_receive_start(EXCHANGE_SERIALIZE, icall);
    139131        if (sess != NULL) {
    140                 if (*sess_ptr == NULL) {
    141                         *sess_ptr = sess;
     132                if (mouse_dev->mouse_sess == NULL) {
     133                        mouse_dev->mouse_sess = sess;
    142134                        usb_log_debug("Console session to %s set ok (%p).\n",
    143135                            fun->name, sess);
     
    147139                            fun->name);
    148140                        async_answer_0(icallid, ELIMIT);
     141                        async_hangup(sess);
    149142                }
    150143        } else {
     
    153146        }
    154147}
    155 
    156 /*----------------------------------------------------------------------------*/
    157 
    158 static void usb_mouse_send_wheel(const usb_mouse_t *mouse_dev, int wheel)
    159 {
    160         unsigned int key = (wheel > 0) ? KC_UP : KC_DOWN;
    161 
    162         if (mouse_dev->wheel_sess == NULL) {
    163                 usb_log_warning(
    164                     "Connection to console not ready, wheel roll discarded.\n");
    165                 return;
    166         }
    167 
    168         const unsigned count =
    169             ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL;
    170         for (unsigned i = 0; i < count; i++) {
    171                 /* Send arrow press and release. */
    172                 usb_log_debug2("Sending key %d to the console\n", key);
    173                
    174                 async_exch_t *exch = async_exchange_begin(mouse_dev->wheel_sess);
    175                
    176                 async_msg_4(exch, KBDEV_EVENT, KEY_PRESS, key, 0, 0);
    177                 async_msg_4(exch, KBDEV_EVENT, KEY_RELEASE, key, 0, 0);
    178                
    179                 async_exchange_end(exch);
    180         }
    181 }
    182 
    183 /*----------------------------------------------------------------------------*/
    184 
     148/*----------------------------------------------------------------------------*/
    185149static int get_mouse_axis_move_value(uint8_t rid, usb_hid_report_t *report,
    186150    int32_t usage)
     
    206170        return result;
    207171}
    208 
     172/*----------------------------------------------------------------------------*/
    209173static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev,
    210174    usb_mouse_t *mouse_dev)
     
    224188            &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
    225189
    226         if ((shift_x != 0) || (shift_y != 0)) {
     190        if (shift_x || shift_y || wheel) {
    227191                async_exch_t *exch =
    228192                    async_exchange_begin(mouse_dev->mouse_sess);
    229193                if (exch != NULL) {
    230                         async_req_2_0(exch, MOUSEEV_MOVE_EVENT, shift_x, shift_y);
     194                        async_msg_3(exch, MOUSEEV_MOVE_EVENT,
     195                            shift_x, shift_y, wheel);
    231196                        async_exchange_end(exch);
    232197                }
    233198        }
    234 
    235         if (wheel != 0)
    236                 usb_mouse_send_wheel(mouse_dev, wheel);
    237199
    238200        /* Buttons */
     
    333295        }
    334296        mouse->mouse_fun = fun;
    335 
    336         /*
    337          * Special function for acting as keyboard (wheel)
    338          */
    339         usb_log_debug("Creating DDF function %s...\n",
    340                       HID_MOUSE_WHEEL_FUN_NAME);
    341         fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
    342             HID_MOUSE_WHEEL_FUN_NAME);
    343         if (fun == NULL) {
    344                 usb_log_error("Could not create DDF function node `%s'.\n",
    345                     HID_MOUSE_WHEEL_FUN_NAME);
    346                 FUN_UNBIND_DESTROY(mouse->mouse_fun);
    347                 mouse->mouse_fun = NULL;
    348                 return ENOMEM;
    349         }
    350 
    351         /*
    352          * Store the initialized HID device and HID ops
    353          * to the DDF function.
    354          */
    355         fun->ops = &ops;
    356         fun->driver_data = mouse;
    357 
    358         rc = ddf_fun_bind(fun);
    359         if (rc != EOK) {
    360                 usb_log_error("Could not bind DDF function `%s': %s.\n",
    361                     fun->name, str_error(rc));
    362                 FUN_UNBIND_DESTROY(mouse->mouse_fun);
    363                 mouse->mouse_fun = NULL;
    364 
    365                 fun->driver_data = NULL;
    366                 ddf_fun_destroy(fun);
    367                 return rc;
    368         }
    369 
    370         usb_log_debug("Adding DDF function to category %s...\n",
    371             HID_MOUSE_WHEEL_CATEGORY);
    372         rc = ddf_fun_add_to_category(fun, HID_MOUSE_WHEEL_CATEGORY);
    373         if (rc != EOK) {
    374                 usb_log_error(
    375                     "Could not add DDF function to category %s: %s.\n",
    376                     HID_MOUSE_WHEEL_CATEGORY, str_error(rc));
    377 
    378                 FUN_UNBIND_DESTROY(mouse->mouse_fun);
    379                 mouse->mouse_fun = NULL;
    380                 FUN_UNBIND_DESTROY(fun);
    381                 return rc;
    382         }
    383         mouse->wheel_fun = fun;
    384 
    385297        return EOK;
    386298}
    387 
    388 /*----------------------------------------------------------------------------*/
    389 
     299/*----------------------------------------------------------------------------*/
    390300/** Get highest index of a button mentioned in given report.
    391301 *
     
    506416        }
    507417
    508         if (mouse_dev->wheel_sess != NULL) {
    509                 const int ret = async_hangup(mouse_dev->wheel_sess);
    510                 if (ret != EOK)
    511                         usb_log_warning("Failed to hang up wheel session: "
    512                             "%p, %s.\n", mouse_dev->wheel_sess, str_error(ret));
    513         }
    514 
    515418        FUN_UNBIND_DESTROY(mouse_dev->mouse_fun);
    516         FUN_UNBIND_DESTROY(mouse_dev->wheel_fun);
    517419
    518420        free(mouse_dev->buttons);
Note: See TracChangeset for help on using the changeset viewer.