Changeset f2962621 in mainline for uspace/app/virtusbkbd/virtusbkbd.c


Ignore:
Timestamp:
2010-12-17T10:14:01Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6e5dc07
Parents:
9223dc5c (diff), 11658b64 (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 with usb/development

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/virtusbkbd/virtusbkbd.c

    r9223dc5c rf2962621  
    5555#include "stdreq.h"
    5656
    57 #define LOOPS 5
     57/** Pause between individual key-presses in seconds. */
     58#define KEY_PRESS_DELAY 2
    5859#define NAME "virt-usb-kbd"
    5960
     
    7576}
    7677
    77 static int on_class_request(struct usbvirt_device *dev,
    78     usb_device_request_setup_packet_t *request, uint8_t *data)
    79 {       
    80         printf("%s: class request (%d)\n", NAME, (int) request->request);
    81        
    82         return EOK;
     78
     79/** Compares current and last status of pressed keys.
     80 *
     81 * @warning Has side-efect - changes status_last field.
     82 *
     83 * @param status_now Status now.
     84 * @param status_last Last status.
     85 * @param len Size of status.
     86 * @return Whether they are the same.
     87 */
     88static bool keypress_check_with_last_request(uint8_t *status_now,
     89    uint8_t *status_last, size_t len)
     90{
     91        bool same = true;
     92        size_t i;
     93        for (i = 0; i < len; i++) {
     94                if (status_now[i] != status_last[i]) {
     95                        status_last[i] = status_now[i];
     96                        same = false;
     97                }
     98        }
     99        return same;
    83100}
    84101
     
    86103    usb_endpoint_t endpoint, void *buffer, size_t size, size_t *actual_size)
    87104{
     105        static uint8_t last_data[2 + KB_MAX_KEYS_AT_ONCE];
     106
    88107        if (size < 2 + KB_MAX_KEYS_AT_ONCE) {
    89108                return EINVAL;
     
    101120        }
    102121       
     122        if (keypress_check_with_last_request(data, last_data,
     123            2 + KB_MAX_KEYS_AT_ONCE)) {
     124                *actual_size = 0;
     125                return EOK;
     126        }
     127
    103128        memcpy(buffer, &data, *actual_size);
    104129       
     
    106131}
    107132
     133static usbvirt_control_transfer_handler_t endpoint_zero_handlers[] = {
     134        {
     135                .request_type = USBVIRT_MAKE_CONTROL_REQUEST_TYPE(
     136                    USB_DIRECTION_IN,
     137                    USBVIRT_REQUEST_TYPE_STANDARD,
     138                    USBVIRT_REQUEST_RECIPIENT_DEVICE),
     139                .request = USB_DEVREQ_GET_DESCRIPTOR,
     140                .name = "GetDescriptor",
     141                .callback = stdreq_on_get_descriptor
     142        },
     143        {
     144                .request_type = USBVIRT_MAKE_CONTROL_REQUEST_TYPE(
     145                    USB_DIRECTION_IN,
     146                    USBVIRT_REQUEST_TYPE_CLASS,
     147                    USBVIRT_REQUEST_RECIPIENT_DEVICE),
     148                .request = USB_DEVREQ_GET_DESCRIPTOR,
     149                .name = "GetDescriptor",
     150                .callback = stdreq_on_get_descriptor
     151        },
     152        USBVIRT_CONTROL_TRANSFER_HANDLER_LAST
     153};
    108154
    109155/** Keyboard callbacks.
     
    111157 */
    112158static usbvirt_device_ops_t keyboard_ops = {
    113         .standard_request_ops = &standard_request_ops,
    114         .on_class_device_request = on_class_request,
     159        .control_transfer_handlers = endpoint_zero_handlers,
    115160        .on_data = on_incoming_data,
    116161        .on_data_request = on_request_for_data
     
    152197        .ops = &keyboard_ops,
    153198        .descriptors = &descriptors,
     199        .lib_debug_level = 3,
     200        .lib_debug_enabled_tags = USBVIRT_DEBUGTAG_ALL,
    154201        .name = "keyboard"
    155202};
     
    177224        printf("\n");
    178225       
    179         fibril_sleep(1);
     226        fibril_sleep(KEY_PRESS_DELAY);
    180227}
    181228
     
    223270       
    224271        printf("%s: Simulating keyboard events...\n", NAME);
    225         while(1){
     272        fibril_sleep(10);
     273        while (1) {
    226274                kb_process_events(&status, keyboard_events, keyboard_events_count,
    227275                        on_keyboard_change);
Note: See TracChangeset for help on using the changeset viewer.