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