Ignore:
Timestamp:
2011-07-13T22:39:18Z (13 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e6910c8
Parents:
5974661 (diff), 8ecef91 (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:

Merge libposix.

File:
1 moved

Legend:

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

    r5974661 re4f8c77  
    4444#include <async_obsolete.h>
    4545#include <str_error.h>
    46 #include <ipc/mouse.h>
     46#include <ipc/mouseev.h>
    4747#include <io/console.h>
    4848
    49 #include <ipc/kbd.h>
     49#include <ipc/kbdev.h>
    5050#include <io/keycode.h>
    5151
    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) {
    211209                usb_log_warning(
    212                     "Connection to console not ready, key discarded.\n");
     210                    "Connection to console not ready, wheel roll discarded.\n");
    213211                return;
    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, KBD_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, KBD_EVENT, KEY_RELEASE,
    225                     ev.key, ev.mods, ev.c);
    226         }
    227 }
    228 
    229 /*----------------------------------------------------------------------------*/
    230 
    231 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev,
    232                                      usb_mouse_t *mouse_dev, uint8_t *buffer,
    233                                      size_t buffer_size)
     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}
     252
     253static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev,
     254    usb_mouse_t *mouse_dev)
    234255{
    235256        assert(mouse_dev != NULL);
    236        
    237         usb_log_debug2("got buffer: %s.\n",
    238             usb_debug_str_buffer(buffer, buffer_size, 0));
    239257       
    240258        if (mouse_dev->mouse_phone < 0) {
     
    243261        }
    244262
    245         /*
    246          * parse the input report
    247          */
    248        
    249         usb_log_debug(NAME " Calling usb_hid_parse_report() with "
    250             "buffer %s\n", usb_debug_str_buffer(buffer, buffer_size, 0));
    251        
    252         uint8_t report_id;
    253        
    254         int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size,
    255             &report_id);
    256        
    257         if (rc != EOK) {
    258                 usb_log_warning(NAME "Error in usb_hid_parse_report(): %s\n",
    259                     str_error(rc));
    260                 return true;
    261         }
    262        
    263         /*
    264          * X
    265          */
    266         int shift_x = 0;
    267        
    268         usb_hid_report_path_t *path = usb_hid_report_path();
    269         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
    270             USB_HIDUT_USAGE_GENERIC_DESKTOP_X);
    271 
    272         usb_hid_report_path_set_report_id(path, report_id);
    273 
    274         usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    275             hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END,
    276             USB_HID_REPORT_TYPE_INPUT);
    277 
    278         if (field != NULL) {
    279                 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    280                     field->usage);
    281                 shift_x = field->value;
    282         }
    283 
    284         usb_hid_report_path_free(path);
    285        
    286         /*
    287          * Y
    288          */
    289         int shift_y = 0;
    290        
    291         path = usb_hid_report_path();
    292         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
    293             USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);
    294 
    295         usb_hid_report_path_set_report_id(path, report_id);
    296 
    297         field = usb_hid_report_get_sibling(
    298             hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END,
    299             USB_HID_REPORT_TYPE_INPUT);
    300 
    301         if (field != NULL) {
    302                 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    303                     field->usage);
    304                 shift_y = field->value;
    305         }
    306 
    307         usb_hid_report_path_free(path);
    308        
     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
    309270        if ((shift_x != 0) || (shift_y != 0)) {
    310271                async_obsolete_req_2_0(mouse_dev->mouse_phone,
    311                     MEVENT_MOVE, shift_x, shift_y);
    312         }
    313        
    314         /*
    315          * Wheel
    316          */
    317         int wheel = 0;
    318        
    319         path = usb_hid_report_path();
    320         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_GENERIC_DESKTOP,
    321             USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
    322 
    323         usb_hid_report_path_set_report_id(path, report_id);
    324        
    325         field = usb_hid_report_get_sibling(
    326             hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END,
    327             USB_HID_REPORT_TYPE_INPUT);
    328 
    329         if (field != NULL) {
    330                 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    331                     field->usage);
    332                 wheel = field->value;
    333         }
    334 
    335         usb_hid_report_path_free(path);
    336        
    337         // send arrow up for positive direction and arrow down for negative
    338         // direction; three arrows for difference of 1
    339         usb_mouse_send_wheel(mouse_dev, wheel);
    340        
     272                    MOUSEEV_MOVE_EVENT, shift_x, shift_y);
     273        }
     274
     275        if (wheel != 0) {
     276                usb_mouse_send_wheel(mouse_dev, wheel);
     277        }
    341278       
    342279        /*
    343280         * Buttons
    344281         */
    345         path = usb_hid_report_path();
     282        usb_hid_report_path_t *path = usb_hid_report_path();
    346283        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0);
    347         usb_hid_report_path_set_report_id(path, report_id);
    348        
    349         field = usb_hid_report_get_sibling(
     284        usb_hid_report_path_set_report_id(path, hid_dev->report_id);
     285       
     286        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    350287            hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
    351288            | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     
    353290
    354291        while (field != NULL) {
    355                 usb_log_debug(NAME " VALUE(%X) USAGE(%X)\n", field->value,
     292                usb_log_debug2(NAME " VALUE(%X) USAGE(%X)\n", field->value,
    356293                    field->usage);
    357294               
     
    359296                    && field->value != 0) {
    360297                        async_obsolete_req_2_0(mouse_dev->mouse_phone,
    361                             MEVENT_BUTTON, field->usage, 1);
     298                            MOUSEEV_BUTTON_EVENT, field->usage, 1);
    362299                        mouse_dev->buttons[field->usage - field->usage_minimum]
    363300                            = field->value;
    364                 } else if (
    365                     mouse_dev->buttons[field->usage - field->usage_minimum] != 0
     301                } else if (mouse_dev->buttons[field->usage - field->usage_minimum] != 0
    366302                    && field->value == 0) {
    367                        async_obsolete_req_2_0(mouse_dev->mouse_phone,
    368                            MEVENT_BUTTON, field->usage, 0);
    369                        mouse_dev->buttons[field->usage - field->usage_minimum]
    370                            = field->value;
    371                }
     303                        async_obsolete_req_2_0(mouse_dev->mouse_phone,
     304                           MOUSEEV_BUTTON_EVENT, field->usage, 0);
     305                        mouse_dev->buttons[field->usage - field->usage_minimum] =
     306                           field->value;
     307                }
    372308               
    373309                field = usb_hid_report_get_sibling(
     
    510446/*----------------------------------------------------------------------------*/
    511447
    512 bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, void *data,
    513      uint8_t *buffer, size_t buffer_size)
    514 {
    515         usb_log_debug("usb_mouse_polling_callback()\n");
    516         usb_debug_str_buffer(buffer, buffer_size, 0);
    517        
     448bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, void *data)
     449{
    518450        if (hid_dev == NULL || data == NULL) {
    519451                usb_log_error("Missing argument to the mouse polling callback."
     
    524456        usb_mouse_t *mouse_dev = (usb_mouse_t *)data;
    525457               
    526         return usb_mouse_process_report(hid_dev, mouse_dev, buffer,
    527                                         buffer_size);
     458        return usb_mouse_process_report(hid_dev, mouse_dev);
    528459}
    529460
Note: See TracChangeset for help on using the changeset viewer.