Ignore:
File:
1 edited

Legend:

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

    ra1732929 rd4a829e  
    118118
    119119        if (mouse_dev == NULL) {
    120                 usb_log_debug("%s: Missing parameters.", __FUNCTION__);
     120                usb_log_debug("%s: Missing parameters.\n", __FUNCTION__);
    121121                async_answer_0(icallid, EINVAL);
    122122                return;
    123123        }
    124124
    125         usb_log_debug("%s: fun->name: %s", __FUNCTION__, ddf_fun_get_name(fun));
    126         usb_log_debug("%s: mouse_sess: %p",
     125        usb_log_debug("%s: fun->name: %s\n", __FUNCTION__, ddf_fun_get_name(fun));
     126        usb_log_debug("%s: mouse_sess: %p\n",
    127127            __FUNCTION__, mouse_dev->mouse_sess);
    128128
     
    132132                if (mouse_dev->mouse_sess == NULL) {
    133133                        mouse_dev->mouse_sess = sess;
    134                         usb_log_debug("Console session to %s set ok (%p).",
     134                        usb_log_debug("Console session to %s set ok (%p).\n",
    135135                            ddf_fun_get_name(fun), sess);
    136136                        async_answer_0(icallid, EOK);
    137137                } else {
    138                         usb_log_error("Console session to %s already set.",
     138                        usb_log_error("Console session to %s already set.\n",
    139139                            ddf_fun_get_name(fun));
    140140                        async_answer_0(icallid, ELIMIT);
     
    142142                }
    143143        } else {
    144                 usb_log_debug("%s: Invalid function.", __FUNCTION__);
     144                usb_log_debug("%s: Invalid function.\n", __FUNCTION__);
    145145                async_answer_0(icallid, EINVAL);
    146146        }
    147147}
    148148
    149 static const usb_hid_report_field_t *get_mouse_axis_move_field(uint8_t rid, usb_hid_report_t *report,
     149static int get_mouse_axis_move_value(uint8_t rid, usb_hid_report_t *report,
    150150    int32_t usage)
    151151{
     152        int result = 0;
     153
    152154        usb_hid_report_path_t *path = usb_hid_report_path();
    153155        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
     
    156158        usb_hid_report_path_set_report_id(path, rid);
    157159
    158         const usb_hid_report_field_t *field = usb_hid_report_get_sibling(
     160        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    159161            report, NULL, path, USB_HID_PATH_COMPARE_END,
    160162            USB_HID_REPORT_TYPE_INPUT);
    161163
     164        if (field != NULL) {
     165                result = field->value;
     166        }
     167
    162168        usb_hid_report_path_free(path);
    163169
    164         return field;
    165 }
    166 
    167 static void usb_mouse_process_report(usb_hid_dev_t *hid_dev,
     170        return result;
     171}
     172
     173static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev,
    168174    usb_mouse_t *mouse_dev)
    169175{
     
    171177
    172178        if (mouse_dev->mouse_sess == NULL) {
    173                 usb_log_warning(NAME " No console session.");
    174                 return;
    175         }
    176 
    177         const usb_hid_report_field_t *move_x = get_mouse_axis_move_field(
    178             hid_dev->report_id, &hid_dev->report,
    179             USB_HIDUT_USAGE_GENERIC_DESKTOP_X);
    180         const usb_hid_report_field_t *move_y = get_mouse_axis_move_field(
    181             hid_dev->report_id, &hid_dev->report,
    182             USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);
    183         const usb_hid_report_field_t *wheel= get_mouse_axis_move_field(
    184             hid_dev->report_id, &hid_dev->report,
    185             USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
    186 
    187         bool absolute_x = move_x && !USB_HID_ITEM_FLAG_RELATIVE(move_x->item_flags);
    188         bool absolute_y = move_y && !USB_HID_ITEM_FLAG_RELATIVE(move_y->item_flags);
    189 
    190         /* Tablet shall always report both X and Y */
    191         if (absolute_x != absolute_y) {
    192                 usb_log_error(NAME " cannot handle mix of absolute and relative mouse move.");
    193                 return;
    194         }
    195 
    196         int shift_x = move_x ? move_x->value : 0;
    197         int shift_y = move_y ? move_y->value : 0;
    198         int shift_z =  wheel ?  wheel->value : 0;
    199 
    200         if (absolute_x && absolute_y) {
    201                 async_exch_t *exch =
    202                     async_exchange_begin(mouse_dev->mouse_sess);
    203                 if (exch != NULL) {
    204                         async_msg_4(exch, MOUSEEV_ABS_MOVE_EVENT,
    205                             shift_x, shift_y, move_x->logical_maximum, move_y->logical_maximum);
    206                         async_exchange_end(exch);
    207                 }
    208 
    209                 // Even if we move the mouse absolutely, we need to resolve wheel
    210                 shift_x = shift_y = 0;
    211         }
    212 
    213 
    214         if (shift_x || shift_y || shift_z) {
     179                usb_log_warning(NAME " No console session.\n");
     180                return true;
     181        }
     182
     183        const int shift_x = get_mouse_axis_move_value(hid_dev->report_id,
     184            &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_X);
     185        const int shift_y = get_mouse_axis_move_value(hid_dev->report_id,
     186            &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);
     187        const int wheel = get_mouse_axis_move_value(hid_dev->report_id,
     188            &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
     189
     190        if (shift_x || shift_y || wheel) {
    215191                async_exch_t *exch =
    216192                    async_exchange_begin(mouse_dev->mouse_sess);
    217193                if (exch != NULL) {
    218194                        async_msg_3(exch, MOUSEEV_MOVE_EVENT,
    219                             shift_x, shift_y, shift_z);
     195                            shift_x, shift_y, wheel);
    220196                        async_exchange_end(exch);
    221197                }
     
    225201        usb_hid_report_path_t *path = usb_hid_report_path();
    226202        if (path == NULL) {
    227                 usb_log_warning("Failed to create USB HID report path.");
    228                 return;
     203                usb_log_warning("Failed to create USB HID report path.\n");
     204                return true;
    229205        }
    230206        int ret =
     
    232208        if (ret != EOK) {
    233209                usb_hid_report_path_free(path);
    234                 usb_log_warning("Failed to add buttons to report path.");
    235                 return;
     210                usb_log_warning("Failed to add buttons to report path.\n");
     211                return true;
    236212        }
    237213        usb_hid_report_path_set_report_id(path, hid_dev->report_id);
     
    242218
    243219        while (field != NULL) {
    244                 usb_log_debug2(NAME " VALUE(%X) USAGE(%X)", field->value,
     220                usb_log_debug2(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    245221                    field->usage);
    246222                assert(field->usage > field->usage_minimum);
     
    266242
    267243        usb_hid_report_path_free(path);
     244
     245        return true;
    268246}
    269247
     
    331309
    332310        if (mouse_dev->buttons == NULL) {
    333                 usb_log_error(NAME ": out of memory, giving up on device!");
     311                usb_log_error(NAME ": out of memory, giving up on device!\n");
    334312                free(mouse_dev);
    335313                return ENOMEM;
     
    344322int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data)
    345323{
    346         usb_log_debug("Initializing HID/Mouse structure...");
     324        usb_log_debug("Initializing HID/Mouse structure...\n");
    347325
    348326        if (hid_dev == NULL) {
     
    353331
    354332        /* Create the exposed function. */
    355         usb_log_debug("Creating DDF function %s...", HID_MOUSE_FUN_NAME);
     333        usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);
    356334        ddf_fun_t *fun = usb_device_ddf_fun_create(hid_dev->usb_dev,
    357335            fun_exposed, HID_MOUSE_FUN_NAME);
    358336        if (fun == NULL) {
    359                 usb_log_error("Could not create DDF function node `%s'.",
     337                usb_log_error("Could not create DDF function node `%s'.\n",
    360338                    HID_MOUSE_FUN_NAME);
    361339                return ENOMEM;
     
    364342        usb_mouse_t *mouse_dev = ddf_fun_data_alloc(fun, sizeof(usb_mouse_t));
    365343        if (mouse_dev == NULL) {
    366                 usb_log_error("Failed to alloc HID mouse device structure.");
     344                usb_log_error("Failed to alloc HID mouse device structure.\n");
    367345                ddf_fun_destroy(fun);
    368346                return ENOMEM;
     
    371349        int ret = mouse_dev_init(mouse_dev, hid_dev);
    372350        if (ret != EOK) {
    373                 usb_log_error("Failed to init HID mouse device structure.");
     351                usb_log_error("Failed to init HID mouse device structure.\n");
    374352                return ret;
    375353        }
     
    379357        ret = ddf_fun_bind(fun);
    380358        if (ret != EOK) {
    381                 usb_log_error("Could not bind DDF function `%s': %s.",
     359                usb_log_error("Could not bind DDF function `%s': %s.\n",
    382360                    ddf_fun_get_name(fun), str_error(ret));
    383361                ddf_fun_destroy(fun);
     
    385363        }
    386364
    387         usb_log_debug("Adding DDF function `%s' to category %s...",
     365        usb_log_debug("Adding DDF function `%s' to category %s...\n",
    388366            ddf_fun_get_name(fun), HID_MOUSE_CATEGORY);
    389367        ret = ddf_fun_add_to_category(fun, HID_MOUSE_CATEGORY);
     
    412390
    413391        usb_mouse_t *mouse_dev = data;
    414         usb_mouse_process_report(hid_dev, mouse_dev);
    415 
    416         /* Continue polling until the device is about to be removed. */
    417         return true;
     392
     393        return usb_mouse_process_report(hid_dev, mouse_dev);
    418394}
    419395
     
    444420
    445421        if (rc != EOK) {
    446                 usb_log_error("Failed to parse boot report descriptor: %s",
     422                usb_log_error("Failed to parse boot report descriptor: %s\n",
    447423                    str_error(rc));
    448424                return rc;
Note: See TracChangeset for help on using the changeset viewer.