Changeset cf99c4c in mainline


Ignore:
Timestamp:
2011-11-06T13:14:58Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update
Children:
50f2095
Parents:
e04182d
Message:

usbhid: multimedia: Remove useless check, add more useful checks.

File:
1 edited

Legend:

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

    re04182d rcf99c4c  
    127127 *       sends also these keys to application (otherwise it cannot use those
    128128 *       keys at all).
    129  * 
    130  * @param hid_dev 
    131  * @param lgtch_dev
    132  * @param type Type of the event (press / release). Recognized values: 
     129 *
     130 * @param hid_dev
     131 * @param multim_dev
     132 * @param type Type of the event (press / release). Recognized values:
    133133 *             KEY_PRESS, KEY_RELEASE
    134134 * @param key Key code of the key according to HID Usage Tables.
    135135 */
    136 static void usb_multimedia_push_ev(usb_hid_dev_t *hid_dev, 
     136static void usb_multimedia_push_ev(usb_hid_dev_t *hid_dev,
    137137    usb_multimedia_t *multim_dev, int type, unsigned int key)
    138138{
    139         assert(hid_dev != NULL);
    140139        assert(multim_dev != NULL);
    141140
    142         kbd_event_t ev;
    143 
    144         ev.type = type;
    145         ev.key = key;
    146         ev.mods = 0;
    147         ev.c = 0;
     141        const kbd_event_t ev = {
     142                .type = type,
     143                .key = key,
     144                .mods = 0,
     145                .c = 0,
     146        };
    148147
    149148        usb_log_debug2(NAME " Sending key %d to the console\n", ev.key);
     
    164163{
    165164        if (hid_dev == NULL || hid_dev->usb_dev == NULL) {
    166                 return EINVAL; /*! @todo Other return code? */
     165                return EINVAL;
    167166        }
    168167
     
    199198        }
    200199
    201         usb_log_debug("%s function created (handle: %" PRIun ").\n",
    202             NAME, fun->handle);
     200        usb_log_debug(NAME " function created (handle: %" PRIun ").\n",
     201            fun->handle);
    203202
    204203        rc = ddf_fun_add_to_category(fun, "keyboard");
     
    222221void usb_multimedia_deinit(struct usb_hid_dev *hid_dev, void *data)
    223222{
    224         if (hid_dev == NULL) {
    225                 return;
    226         }
    227 
    228223        if (data != NULL) {
    229                 usb_multimedia_t *multim_dev = (usb_multimedia_t *)data;
    230                 // hangup session to the console
    231                 async_hangup(multim_dev->console_sess);
     224                usb_multimedia_t *multim_dev = data;
     225                /* Hangup session to the console */
     226                if (multim_dev->console_sess)
     227                        async_hangup(multim_dev->console_sess);
    232228                const int ret = ddf_fun_unbind(multim_dev->fun);
    233229                if (ret != EOK) {
    234                         usb_log_error("Failed to unbind multim function.\n");
     230                        usb_log_error("Failed to unbind %s function.\n",
     231                            multim_dev->fun->name);
    235232                } else {
    236233                        usb_log_debug2("%s unbound.\n", multim_dev->fun->name);
     234                        /* This frees multim_dev too as it was stored in
     235                         * fun->data */
    237236                        ddf_fun_destroy(multim_dev->fun);
    238237                }
     
    249248        }
    250249
    251         usb_multimedia_t *multim_dev = (usb_multimedia_t *)data;
     250        usb_multimedia_t *multim_dev = data;
    252251
    253252        usb_hid_report_path_t *path = usb_hid_report_path();
    254         usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0);
     253        int ret =
     254            usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0);
     255        if (ret != EOK)
     256                return true; /* This might be a temporary failure. */
    255257
    256258        usb_hid_report_path_set_report_id(path, hid_dev->report_id);
     
    268270                        usb_log_debug(NAME " KEY VALUE(%X) USAGE(%X)\n",
    269271                            field->value, field->usage);
    270                         unsigned int key =
     272                        const unsigned key =
    271273                            usb_multimedia_map_usage(field->usage);
    272                         const char *key_str = 
     274                        const char *key_str =
    273275                            usbhid_multimedia_usage_to_str(field->usage);
    274276                        usb_log_info("Pressed key: %s\n", key_str);
    275                         usb_multimedia_push_ev(hid_dev, multim_dev, KEY_PRESS, 
     277                        usb_multimedia_push_ev(hid_dev, multim_dev, KEY_PRESS,
    276278                                               key);
    277279                }
     
    279281                field = usb_hid_report_get_sibling(
    280282                    &hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
    281                     | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 
     283                    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    282284                    USB_HID_REPORT_TYPE_INPUT);
    283285        }
Note: See TracChangeset for help on using the changeset viewer.