Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset a3a2fdb in mainline


Ignore:
Timestamp:
2011-06-18T16:25:40Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master
Children:
58c0917
Parents:
ae5f77d5
Message:

USB HID - mouse subdriver refactoring

File:
1 edited

Legend:

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

    rae5f77d5 ra3a2fdb  
    5252#include "mousedev.h"
    5353#include "../usbhid.h"
     54
     55/** Number of simulated arrow-key presses for singel wheel step. */
     56#define ARROWS_PER_SINGLE_WHEEL 3
    5457
    5558// FIXME: remove this header
     
    201204static void usb_mouse_send_wheel(const usb_mouse_t *mouse_dev, int wheel)
    202205{
    203         kbd_event_t ev;
    204        
    205         ev.type = KEY_PRESS;
    206         ev.key = (wheel > 0) ? KC_UP : (wheel < 0) ? KC_DOWN : 0;
    207         ev.mods = 0;
    208         ev.c = 0;
     206        unsigned int key = (wheel > 0) ? KC_UP : KC_DOWN;
    209207
    210208        if (mouse_dev->wheel_phone < 0) {
     
    214212        }
    215213       
    216         int count = (wheel < 0) ? -wheel : wheel;
     214        int count = ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL;
    217215        int i;
    218216       
    219         for (i = 0; i < count * 3; ++i) {
    220                 usb_log_debug2("Sending key %d to the console\n", ev.key);
    221                 async_obsolete_msg_4(mouse_dev->wheel_phone, KBDEV_EVENT, ev.type,
    222                     ev.key, ev.mods, ev.c);
    223                 // send key release right away
    224                 async_obsolete_msg_4(mouse_dev->wheel_phone, KBDEV_EVENT, KEY_RELEASE,
    225                     ev.key, ev.mods, ev.c);
    226         }
    227 }
    228 
    229 /*----------------------------------------------------------------------------*/
     217        for (i = 0; i < count; i++) {
     218                /* Send arrow press and release. */
     219                usb_log_debug2("Sending key %d to the console\n", key);
     220                async_obsolete_msg_4(mouse_dev->wheel_phone, KBDEV_EVENT,
     221                    KEY_PRESS, key, 0, 0);
     222                async_obsolete_msg_4(mouse_dev->wheel_phone, KBDEV_EVENT,
     223                    KEY_RELEASE, key, 0, 0);
     224        }
     225}
     226
     227/*----------------------------------------------------------------------------*/
     228
     229static int get_mouse_axis_move_value(uint8_t rid, usb_hid_report_t *report,
     230    int32_t usage)
     231{
     232        int result = 0;
     233
     234        usb_hid_report_path_t *path = usb_hid_report_path();
     235        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
     236            usage);
     237
     238        usb_hid_report_path_set_report_id(path, rid);
     239
     240        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
     241            report, NULL, path, USB_HID_PATH_COMPARE_END,
     242            USB_HID_REPORT_TYPE_INPUT);
     243
     244        if (field != NULL) {
     245                result = field->value;
     246        }
     247
     248        usb_hid_report_path_free(path);
     249
     250        return result;
     251}
    230252
    231253static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev,
     
    239261        }
    240262
    241         /*
    242          * X
    243          */
    244         int shift_x = 0;
    245        
    246         usb_hid_report_path_t *path = usb_hid_report_path();
    247         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
    248             USB_HIDUT_USAGE_GENERIC_DESKTOP_X);
    249 
    250         usb_hid_report_path_set_report_id(path, hid_dev->report_id);
    251 
    252         usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    253             hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END,
    254             USB_HID_REPORT_TYPE_INPUT);
    255 
    256         if (field != NULL) {
    257                 usb_log_debug2(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    258                     field->usage);
    259                 shift_x = field->value;
    260         }
    261 
    262         usb_hid_report_path_free(path);
    263        
    264         /*
    265          * Y
    266          */
    267         int shift_y = 0;
    268        
    269         path = usb_hid_report_path();
    270         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
    271             USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);
    272 
    273         usb_hid_report_path_set_report_id(path, hid_dev->report_id);
    274 
    275         field = usb_hid_report_get_sibling(
    276             hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END,
    277             USB_HID_REPORT_TYPE_INPUT);
    278 
    279         if (field != NULL) {
    280                 usb_log_debug2(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    281                     field->usage);
    282                 shift_y = field->value;
    283         }
    284 
    285         usb_hid_report_path_free(path);
    286        
     263        int shift_x = get_mouse_axis_move_value(hid_dev->report_id,
     264            hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_X);
     265        int shift_y = get_mouse_axis_move_value(hid_dev->report_id,
     266            hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);
     267        int wheel = get_mouse_axis_move_value(hid_dev->report_id,
     268            hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
     269
    287270        if ((shift_x != 0) || (shift_y != 0)) {
    288271                async_obsolete_req_2_0(mouse_dev->mouse_phone,
    289272                    MEVENT_MOVE, shift_x, shift_y);
    290273        }
    291        
    292         /*
    293          * Wheel
    294          */
    295         int wheel = 0;
    296        
    297         path = usb_hid_report_path();
    298         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
    299             USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
    300 
    301         usb_hid_report_path_set_report_id(path, hid_dev->report_id);
    302        
    303         field = usb_hid_report_get_sibling(
    304             hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END,
    305             USB_HID_REPORT_TYPE_INPUT);
    306 
    307         if (field != NULL) {
    308                 usb_log_debug2(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    309                     field->usage);
    310                 wheel = field->value;
    311         }
    312 
    313         usb_hid_report_path_free(path);
    314        
    315         // send arrow up for positive direction and arrow down for negative
    316         // direction; three arrows for difference of 1
    317         usb_mouse_send_wheel(mouse_dev, wheel);
    318        
     274
     275        if (wheel != 0) {
     276                usb_mouse_send_wheel(mouse_dev, wheel);
     277        }
    319278       
    320279        /*
    321280         * Buttons
    322281         */
    323         path = usb_hid_report_path();
     282        usb_hid_report_path_t *path = usb_hid_report_path();
    324283        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0);
    325284        usb_hid_report_path_set_report_id(path, hid_dev->report_id);
    326285       
    327         field = usb_hid_report_get_sibling(
     286        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    328287            hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
    329288            | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
Note: See TracChangeset for help on using the changeset viewer.