Changes in uspace/app/mkbd/main.c [f9a627a:79ae36dd] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/mkbd/main.c
rf9a627a r79ae36dd 45 45 #include <devmap.h> 46 46 #include <usb/dev/hub.h> 47 //#include <usb/host.h>48 //#include <usb/driver.h>49 47 #include <usb/hid/iface.h> 50 48 #include <usb/dev/pipes.h> … … 58 56 #define NAME "mkbd" 59 57 60 static int dev_phone = -1;61 62 static int initialize_report_parser( int dev_phone, usb_hid_report_t **report)63 { 64 *report = (usb_hid_report_t *)malloc(sizeof(usb_hid_report_t)); 65 if (*report == NULL) {66 return ENOMEM;67 }58 static async_sess_t *dev_sess = NULL; 59 60 static int initialize_report_parser(async_sess_t *dev_sess, 61 usb_hid_report_t **report) 62 { 63 *report = (usb_hid_report_t *) malloc(sizeof(usb_hid_report_t)); 64 if (*report == NULL) 65 return ENOMEM; 68 66 69 67 int rc = usb_hid_report_init(*report); … … 71 69 usb_hid_free_report(*report); 72 70 *report = NULL; 73 printf("usb_hid_report_init() failed.\n"); 74 return rc; 75 } 76 77 // get the report descriptor length from the device 71 return rc; 72 } 73 74 /* Get the report descriptor length from the device */ 78 75 size_t report_desc_size; 79 rc = usbhid_dev_get_report_descriptor_length( 80 dev_phone, &report_desc_size); 81 if (rc != EOK) { 82 usb_hid_free_report(*report); 83 *report = NULL; 84 printf("usbhid_dev_get_report_descriptor_length() failed.\n"); 76 rc = usbhid_dev_get_report_descriptor_length(dev_sess, 77 &report_desc_size); 78 if (rc != EOK) { 79 usb_hid_free_report(*report); 80 *report = NULL; 85 81 return rc; 86 82 } … … 89 85 usb_hid_free_report(*report); 90 86 *report = NULL; 91 printf("usbhid_dev_get_report_descriptor_length() returned 0.\n");92 return EINVAL; // TODO: other error code?93 } 94 95 uint8_t *desc = (uint8_t *) malloc(report_desc_size);87 // TODO: other error code? 88 return EINVAL; 89 } 90 91 uint8_t *desc = (uint8_t *) malloc(report_desc_size); 96 92 if (desc == NULL) { 97 93 usb_hid_free_report(*report); … … 100 96 } 101 97 102 / / get the report descriptor from the device98 /* Get the report descriptor from the device */ 103 99 size_t actual_size; 104 rc = usbhid_dev_get_report_descriptor(dev_ phone, desc, report_desc_size,100 rc = usbhid_dev_get_report_descriptor(dev_sess, desc, report_desc_size, 105 101 &actual_size); 106 102 if (rc != EOK) { … … 108 104 *report = NULL; 109 105 free(desc); 110 printf("usbhid_dev_get_report_descriptor() failed.\n");111 106 return rc; 112 107 } … … 116 111 *report = NULL; 117 112 free(desc); 118 printf("usbhid_dev_get_report_descriptor() returned wrong size:" 119 " %zu, expected: %zu.\n", actual_size, report_desc_size); 120 return EINVAL; // TODO: other error code? 121 } 122 123 // initialize the report parser 113 // TODO: other error code? 114 return EINVAL; 115 } 116 117 /* Initialize the report parser */ 124 118 125 119 rc = usb_hid_parse_report_descriptor(*report, desc, report_desc_size); … … 128 122 if (rc != EOK) { 129 123 free(desc); 130 printf("usb_hid_parse_report_descriptor() failed.\n");131 124 return rc; 132 125 } … … 140 133 assert(report != NULL); 141 134 142 // printf("Calling usb_hid_parse_report() with size %zu and "143 // "buffer: \n", size);144 // for (size_t i = 0; i < size; ++i) {145 // printf(" %X ", buffer[i]);146 // }147 // printf("\n");148 149 135 uint8_t report_id; 150 136 int rc = usb_hid_parse_report(report, buffer, size, &report_id); 151 if (rc != EOK) { 152 // printf("Error parsing report: %s\n", str_error(rc)); 137 if (rc != EOK) 153 138 return; 154 }155 139 156 140 usb_hid_report_path_t *path = usb_hid_report_path(); … … 164 148 165 149 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 166 report, NULL, path, USB_HID_PATH_COMPARE_END 167 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 150 report, NULL, path, USB_HID_PATH_COMPARE_END 151 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 168 152 USB_HID_REPORT_TYPE_INPUT); 169 153 170 // printf("Field: %p\n", field);171 172 154 while (field != NULL) { 173 // printf("Field usage: %u, field value: %d\n", field->usage,174 // field->value);175 155 if (field->value != 0) { 176 156 const char *key_str = … … 183 163 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 184 164 USB_HID_REPORT_TYPE_INPUT); 185 // printf("Next field: %p\n", field);186 165 } 187 166 … … 194 173 { 195 174 #define _INDENT " " 196 197 printf(NAME ": Print out what multimedia keys were pressed.\n\n"); 198 printf("Usage: %s device\n", app_name); 199 printf(_INDENT "The device is a devman path to the device.\n"); 200 175 printf(NAME ": Print out what multimedia keys were pressed.\n\n"); 176 printf("Usage: %s device\n", app_name); 177 printf(_INDENT "The device is a devman path to the device.\n"); 201 178 #undef _OPTION 202 179 #undef _INDENT … … 223 200 } 224 201 225 rc = devman_device_connect(dev_handle, 0); 226 if (rc < 0) { 202 async_sess_t *sess = devman_device_connect(EXCHANGE_SERIALIZE, 203 dev_handle, 0); 204 if (!sess) { 227 205 printf(NAME ": failed to connect to the device (handle %" 228 PRIun "): %s.\n", dev_handle, str_error(rc)); 229 return rc; 230 } 231 232 dev_phone = rc; 233 // printf("Got phone to the device: %d\n", dev_phone); 206 PRIun "): %s.\n", dev_handle, str_error(errno)); 207 return errno; 208 } 209 210 dev_sess = sess; 234 211 235 212 char path[MAX_PATH_LENGTH]; … … 243 220 244 221 usb_hid_report_t *report = NULL; 245 rc = initialize_report_parser(dev_ phone, &report);222 rc = initialize_report_parser(dev_sess, &report); 246 223 if (rc != EOK) { 247 224 printf("Failed to initialize report parser: %s\n", … … 253 230 254 231 size_t size; 255 rc = usbhid_dev_get_event_length(dev_ phone, &size);232 rc = usbhid_dev_get_event_length(dev_sess, &size); 256 233 if (rc != EOK) { 257 234 printf("Failed to get event length: %s.\n", str_error(rc)); … … 259 236 } 260 237 261 // printf("Event length: %zu\n", size);262 238 uint8_t *event = (uint8_t *)malloc(size); 263 239 if (event == NULL) { 264 // hangup phone? 265 return ENOMEM; 266 } 267 268 // printf("Event length: %zu\n", size); 240 // TODO: hangup phone? 241 return ENOMEM; 242 } 269 243 270 244 size_t actual_size; 271 245 int event_nr; 272 246 273 while (1) { 274 // get event from the driver 275 // printf("Getting event from the driver.\n"); 276 247 while (true) { 277 248 /** @todo Try blocking call. */ 278 rc = usbhid_dev_get_event(dev_ phone, event, size, &actual_size,249 rc = usbhid_dev_get_event(dev_sess, event, size, &actual_size, 279 250 &event_nr, 0); 280 251 if (rc != EOK) { 281 // hangup phone?252 // TODO: hangup phone? 282 253 printf("Error in getting event from the HID driver:" 283 254 "%s.\n", str_error(rc)); … … 285 256 } 286 257 287 // printf("Got buffer: %p, size: %zu, max size: %zu\n", event,288 // actual_size, size);289 290 // printf("Event number: %d, my actual event: %d\n", event_nr,291 // act_event);292 258 if (event_nr > act_event) { 293 259 print_key(event, size, report); … … 301 267 } 302 268 303 304 269 /** @} 305 270 */
Note:
See TracChangeset
for help on using the changeset viewer.