Changes in uspace/app/virtusbkbd/virtusbkbd.c [56b962d:2aee3e06] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/virtusbkbd/virtusbkbd.c
r56b962d r2aee3e06 55 55 #include "stdreq.h" 56 56 57 #define LOOPS 5 57 /** Pause between individual key-presses in seconds. */ 58 #define KEY_PRESS_DELAY 2 58 59 #define NAME "virt-usb-kbd" 59 60 … … 83 84 } 84 85 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 */ 95 static 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 85 109 static int on_request_for_data(struct usbvirt_device *dev, 86 110 usb_endpoint_t endpoint, void *buffer, size_t size, size_t *actual_size) 87 111 { 112 static uint8_t last_data[2 + KB_MAX_KEYS_AT_ONCE]; 113 88 114 if (size < 2 + KB_MAX_KEYS_AT_ONCE) { 89 115 return EINVAL; … … 101 127 } 102 128 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 103 135 memcpy(buffer, &data, *actual_size); 104 136 … … 111 143 */ 112 144 static usbvirt_device_ops_t keyboard_ops = { 113 .on_standard_request[USB_DEVREQ_GET_DESCRIPTOR] 114 = stdreq_on_get_descriptor, 145 .standard_request_ops = &standard_request_ops, 115 146 .on_class_device_request = on_class_request, 116 147 .on_data = on_incoming_data, … … 153 184 .ops = &keyboard_ops, 154 185 .descriptors = &descriptors, 186 .lib_debug_level = 3, 187 .lib_debug_enabled_tags = USBVIRT_DEBUGTAG_ALL, 155 188 .name = "keyboard" 156 189 }; … … 171 204 static void on_keyboard_change(kb_status_t *status) 172 205 { 173 printf("%s: Current keyboard status: %0 8hhb", NAME, status->modifiers);206 printf("%s: Current keyboard status: %02hhx", NAME, status->modifiers); 174 207 size_t i; 175 208 for (i = 0; i < KB_MAX_KEYS_AT_ONCE; i++) { … … 178 211 printf("\n"); 179 212 180 fibril_sleep( 1);213 fibril_sleep(KEY_PRESS_DELAY); 181 214 } 182 215 … … 203 236 int main(int argc, char * argv[]) 204 237 { 205 printf("Dump of report descriptor (% u bytes):\n", report_descriptor_size);238 printf("Dump of report descriptor (%zu bytes):\n", report_descriptor_size); 206 239 size_t i; 207 240 for (i = 0; i < report_descriptor_size; i++) { … … 224 257 225 258 printf("%s: Simulating keyboard events...\n", NAME); 226 kb_process_events(&status, keyboard_events, keyboard_events_count, 227 on_keyboard_change); 259 while (1) { 260 kb_process_events(&status, keyboard_events, keyboard_events_count, 261 on_keyboard_change); 262 } 228 263 229 264 printf("%s: Terminating...\n", NAME);
Note:
See TracChangeset
for help on using the changeset viewer.