Ignore:
File:
1 edited

Legend:

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

    r2d1ba51 r5f6e25e  
    4545#include "kbddev.h"
    4646
     47
     48/** Delay between auto-repeat state checks when no key is being repeated. */
     49static unsigned int CHECK_DELAY = 10000;
     50
     51/*----------------------------------------------------------------------------*/
    4752/**
    4853 * Main loop handling the auto-repeat of keys.
     
    5560 * If the same key is still pressed, it uses the delay between repeats stored
    5661 * in the keyboard structure to wait until the key should be repeated.
    57  *
     62 * 
    5863 * If the currently repeated key is not pressed any more (
    59  * usb_kbd_repeat_stop() was called), it stops repeating it and starts
     64 * usb_kbd_repeat_stop() was called), it stops repeating it and starts 
    6065 * checking again.
    6166 *
    6267 * @note For accessing the keyboard device auto-repeat information a fibril
    6368 *       mutex (repeat_mtx) from the @a kbd structure is used.
    64  *
     69 * 
    6570 * @param kbd Keyboard device structure.
    6671 */
     
    6873{
    6974        unsigned int delay = 0;
    70 
     75       
    7176        usb_log_debug("Starting autorepeat loop.\n");
    7277
    7378        while (true) {
    74                 /* Check if the kbd structure is usable. */
     79                // check if the kbd structure is usable
    7580                if (!usb_kbd_is_initialized(kbd)) {
    76                         usb_log_warning("kbd not ready, exiting autorepeat.\n");
     81                        if (usb_kbd_is_ready_to_destroy(kbd)) {
     82                                usb_kbd_destroy(kbd);
     83                        }
    7784                        return;
    7885                }
    79 
    80                 fibril_mutex_lock(&kbd->repeat_mtx);
     86               
     87                fibril_mutex_lock(kbd->repeat_mtx);
    8188
    8289                if (kbd->repeat.key_new > 0) {
    8390                        if (kbd->repeat.key_new == kbd->repeat.key_repeated) {
    84                                 usb_log_debug2("Repeating key: %u.\n",
     91                                usb_log_debug2("Repeating key: %u.\n", 
    8592                                    kbd->repeat.key_repeated);
    86                                 usb_kbd_push_ev(kbd, KEY_PRESS,
     93                                // ugly hack with the NULL
     94                                usb_kbd_push_ev(NULL, kbd, KEY_PRESS,
    8795                                    kbd->repeat.key_repeated);
    8896                                delay = kbd->repeat.delay_between;
     
    101109                        delay = CHECK_DELAY;
    102110                }
    103                 fibril_mutex_unlock(&kbd->repeat_mtx);
     111                fibril_mutex_unlock(kbd->repeat_mtx);
     112               
    104113                async_usleep(delay);
    105114        }
    106115}
     116
    107117/*----------------------------------------------------------------------------*/
    108118/**
     
    110120 *
    111121 * Starts the loop for checking changes in auto-repeat.
    112  *
     122 * 
    113123 * @param arg User-specified argument. Expects pointer to the keyboard device
    114124 *            structure representing the keyboard.
     
    120130{
    121131        usb_log_debug("Autorepeat fibril spawned.\n");
    122 
     132       
    123133        if (arg == NULL) {
    124134                usb_log_error("No device!\n");
    125135                return EINVAL;
    126136        }
    127 
    128         usb_kbd_t *kbd = arg;
    129 
     137       
     138        usb_kbd_t *kbd = (usb_kbd_t *)arg;
     139       
    130140        usb_kbd_repeat_loop(kbd);
    131 
     141       
    132142        return EOK;
    133143}
     144
    134145/*----------------------------------------------------------------------------*/
    135146/**
     
    145156void usb_kbd_repeat_start(usb_kbd_t *kbd, unsigned int key)
    146157{
    147         fibril_mutex_lock(&kbd->repeat_mtx);
     158        fibril_mutex_lock(kbd->repeat_mtx);
    148159        kbd->repeat.key_new = key;
    149         fibril_mutex_unlock(&kbd->repeat_mtx);
     160        fibril_mutex_unlock(kbd->repeat_mtx);
    150161}
     162
    151163/*----------------------------------------------------------------------------*/
    152164/**
     
    154166 *
    155167 * @note Only one key is repeated at any time, but this function may be called
    156  *       even with key that is not currently repeated (in that case nothing
     168 *       even with key that is not currently repeated (in that case nothing 
    157169 *       happens).
    158170 *
     
    162174void usb_kbd_repeat_stop(usb_kbd_t *kbd, unsigned int key)
    163175{
    164         fibril_mutex_lock(&kbd->repeat_mtx);
     176        fibril_mutex_lock(kbd->repeat_mtx);
    165177        if (key == kbd->repeat.key_new) {
    166178                kbd->repeat.key_new = 0;
    167179        }
    168         fibril_mutex_unlock(&kbd->repeat_mtx);
     180        fibril_mutex_unlock(kbd->repeat_mtx);
    169181}
     182
    170183/**
    171184 * @}
Note: See TracChangeset for help on using the changeset viewer.