source: mainline/uspace/drv/usbhid/kbdrepeat.c@ 8a02ff3

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8a02ff3 was dfe53af, checked in by Lubos Slovak <lubos.slovak@…>, 15 years ago

Auto-repeat of keys.

  • Added structure usbhid_kbd_repeat_t.
  • Added functions for:
    • checking repeat status in a loop
    • starting to repeat a key
    • stopping to repeat a key
  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Copyright (c) 2011 Lubos Slovak
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup drvusbhid
30 * @{
31 */
32/**
33 * @file
34 * USB HID keyboard autorepeat facilities
35 */
36
37#include <fibril_synch.h>
38#include <io/keycode.h>
39#include <io/console.h>
40#include <errno.h>
41
42#include <usb/debug.h>
43
44#include "kbdrepeat.h"
45#include "kbddev.h"
46
47static unsigned int CHECK_DELAY = 1000;
48
49/*----------------------------------------------------------------------------*/
50
51static void usbhid_kbd_repeat_loop(usbhid_kbd_t *kbd)
52{
53 unsigned int delay = 0;
54
55 usb_log_debug("Starting autorepeat loop.\n");
56
57 while (true) {
58 fibril_mutex_lock(kbd->repeat_mtx);
59
60 if (kbd->repeat.key_new > 0) {
61 if (kbd->repeat.key_new == kbd->repeat.key_repeated) {
62 usb_log_debug2("Repeating key: %u.\n",
63 kbd->repeat.key_repeated);
64 usbhid_kbd_push_ev(kbd, KEY_PRESS,
65 kbd->repeat.key_repeated);
66 delay = kbd->repeat.delay_between;
67 } else {
68 usb_log_debug("New key to repeat: %u.\n",
69 kbd->repeat.key_new);
70 kbd->repeat.key_repeated = kbd->repeat.key_new;
71 delay = kbd->repeat.delay_before;
72 }
73 } else {
74 if (kbd->repeat.key_repeated > 0) {
75 usb_log_debug("Stopping to repeat key: %u.\n",
76 kbd->repeat.key_repeated);
77 kbd->repeat.key_repeated = 0;
78 }
79 delay = CHECK_DELAY;
80 }
81 fibril_mutex_unlock(kbd->repeat_mtx);
82
83 async_usleep(delay);
84 }
85}
86
87/*----------------------------------------------------------------------------*/
88
89int usbhid_kbd_repeat_fibril(void *arg)
90{
91 usb_log_debug("Autorepeat fibril spawned.\n");
92
93 if (arg == NULL) {
94 usb_log_error("No device!\n");
95 return EINVAL;
96 }
97
98 usbhid_kbd_t *kbd = (usbhid_kbd_t *)arg;
99
100 usbhid_kbd_repeat_loop(kbd);
101
102 return EOK;
103}
104
105/*----------------------------------------------------------------------------*/
106
107void usbhid_kbd_repeat_start(usbhid_kbd_t *kbd, unsigned int key)
108{
109 fibril_mutex_lock(kbd->repeat_mtx);
110 kbd->repeat.key_new = key;
111 fibril_mutex_unlock(kbd->repeat_mtx);
112}
113
114/*----------------------------------------------------------------------------*/
115
116void usbhid_kbd_repeat_stop(usbhid_kbd_t *kbd, unsigned int key)
117{
118 fibril_mutex_lock(kbd->repeat_mtx);
119 if (key == kbd->repeat.key_new) {
120 kbd->repeat.key_new = 0;
121 }
122 fibril_mutex_unlock(kbd->repeat_mtx);
123}
124
125/**
126 * @}
127 */
Note: See TracBrowser for help on using the repository browser.