Ignore:
Timestamp:
2017-11-21T18:15:12Z (6 years ago)
Author:
Aearsis <Hlavaty.Ondrej@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a0e09ef
Parents:
6283cefb
Message:

usbhid mouse: support absolute coordinates

File:
1 edited

Legend:

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

    r6283cefb rae303ad  
    147147}
    148148
    149 static int get_mouse_axis_move_value(uint8_t rid, usb_hid_report_t *report,
     149static const usb_hid_report_field_t *get_mouse_axis_move_field(uint8_t rid, usb_hid_report_t *report,
    150150    int32_t usage)
    151151{
    152         int result = 0;
    153 
    154152        usb_hid_report_path_t *path = usb_hid_report_path();
    155153        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
     
    158156        usb_hid_report_path_set_report_id(path, rid);
    159157
    160         usb_hid_report_field_t *field = usb_hid_report_get_sibling(
     158        const usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    161159            report, NULL, path, USB_HID_PATH_COMPARE_END,
    162160            USB_HID_REPORT_TYPE_INPUT);
    163161
    164         if (field != NULL) {
    165                 result = field->value;
    166         }
    167 
    168162        usb_hid_report_path_free(path);
    169163
    170         return result;
     164        return field;
    171165}
    172166
     
    181175        }
    182176
    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) {
     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 true;
     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) {
    191215                async_exch_t *exch =
    192216                    async_exchange_begin(mouse_dev->mouse_sess);
    193217                if (exch != NULL) {
    194218                        async_msg_3(exch, MOUSEEV_MOVE_EVENT,
    195                             shift_x, shift_y, wheel);
     219                            shift_x, shift_y, shift_z);
    196220                        async_exchange_end(exch);
    197221                }
Note: See TracChangeset for help on using the changeset viewer.