Changes in uspace/app/virtusbkbd/virtusbkbd.c [ad79d80:d5e7668] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/virtusbkbd/virtusbkbd.c
rad79d80 rd5e7668 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 … … 75 76 } 76 77 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 */ 88 static 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; 83 100 } 84 101 … … 86 103 usb_endpoint_t endpoint, void *buffer, size_t size, size_t *actual_size) 87 104 { 105 static uint8_t last_data[2 + KB_MAX_KEYS_AT_ONCE]; 106 88 107 if (size < 2 + KB_MAX_KEYS_AT_ONCE) { 89 108 return EINVAL; … … 101 120 } 102 121 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 103 128 memcpy(buffer, &data, *actual_size); 104 129 … … 106 131 } 107 132 133 static 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 }; 108 154 109 155 /** Keyboard callbacks. … … 111 157 */ 112 158 static 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, 115 160 .on_data = on_incoming_data, 116 161 .on_data_request = on_request_for_data … … 152 197 .ops = &keyboard_ops, 153 198 .descriptors = &descriptors, 199 .lib_debug_level = 3, 200 .lib_debug_enabled_tags = USBVIRT_DEBUGTAG_ALL, 154 201 .name = "keyboard" 155 202 }; … … 177 224 printf("\n"); 178 225 179 fibril_sleep( 1);226 fibril_sleep(KEY_PRESS_DELAY); 180 227 } 181 228 … … 223 270 224 271 printf("%s: Simulating keyboard events...\n", NAME); 225 kb_process_events(&status, keyboard_events, keyboard_events_count, 226 on_keyboard_change); 272 fibril_sleep(10); 273 while (1) { 274 kb_process_events(&status, keyboard_events, keyboard_events_count, 275 on_keyboard_change); 276 } 227 277 228 278 printf("%s: Terminating...\n", NAME);
Note:
See TracChangeset
for help on using the changeset viewer.