Changeset 37f7cfe in mainline for uspace/app/virtusbkbd/virtusbkbd.c


Ignore:
Timestamp:
2010-12-13T01:11:27Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
75732da, a9b6bec
Parents:
682b697 (diff), f9a0cef (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 vojtechhorky/ - hub driver and VHC fixes

The hub driver shall be working by now. At least a bit.

File:
1 edited

Legend:

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

    r682b697 r37f7cfe  
    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
     
    8384}
    8485
     86/** Compares current and last status of pressed keys.
     87 *
     88 * @warning Has side-efect - changes status_last field.
     89 *
     90 * @param status_now Status now.
     91 * @param status_last Last status.
     92 * @param len Size of status.
     93 * @return Whether they are the same.
     94 */
     95static bool keypress_check_with_last_request(uint8_t *status_now,
     96    uint8_t *status_last, size_t len)
     97{
     98        bool same = true;
     99        size_t i;
     100        for (i = 0; i < len; i++) {
     101                if (status_now[i] != status_last[i]) {
     102                        status_last[i] = status_now[i];
     103                        same = false;
     104                }
     105        }
     106        return same;
     107}
     108
    85109static int on_request_for_data(struct usbvirt_device *dev,
    86110    usb_endpoint_t endpoint, void *buffer, size_t size, size_t *actual_size)
    87111{
     112        static uint8_t last_data[2 + KB_MAX_KEYS_AT_ONCE];
     113
    88114        if (size < 2 + KB_MAX_KEYS_AT_ONCE) {
    89115                return EINVAL;
     
    101127        }
    102128       
     129        if (keypress_check_with_last_request(data, last_data,
     130            2 + KB_MAX_KEYS_AT_ONCE)) {
     131                *actual_size = 0;
     132                return EOK;
     133        }
     134
    103135        memcpy(buffer, &data, *actual_size);
    104136       
     
    152184        .ops = &keyboard_ops,
    153185        .descriptors = &descriptors,
     186        .lib_debug_level = 3,
     187        .lib_debug_enabled_tags = USBVIRT_DEBUGTAG_ALL,
    154188        .name = "keyboard"
    155189};
     
    177211        printf("\n");
    178212       
    179         fibril_sleep(1);
     213        fibril_sleep(KEY_PRESS_DELAY);
    180214}
    181215
     
    223257       
    224258        printf("%s: Simulating keyboard events...\n", NAME);
    225         while(1){
     259        while (1) {
    226260                kb_process_events(&status, keyboard_events, keyboard_events_count,
    227261                        on_keyboard_change);
Note: See TracChangeset for help on using the changeset viewer.