Changes in uspace/app/vuhid/main.c [920d0fc:2a6e2358] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/vuhid/main.c
r920d0fc r2a6e2358 40 40 #include <errno.h> 41 41 #include <str_error.h> 42 #include <getopt.h> 42 43 43 44 #include <usb/usb.h> … … 52 53 #include "stdreq.h" 53 54 55 #define DEFAULT_CONTROLLER "/virt/usbhc/ctl" 56 54 57 static usbvirt_control_request_handler_t endpoint_zero_handlers[] = { 55 58 { 56 .req_direction = USB_DIRECTION_IN, 57 .req_type = USB_REQUEST_TYPE_STANDARD, 58 .req_recipient = USB_REQUEST_RECIPIENT_INTERFACE, 59 .request = USB_DEVREQ_GET_DESCRIPTOR, 59 STD_REQ_IN(USB_REQUEST_RECIPIENT_INTERFACE, USB_DEVREQ_GET_DESCRIPTOR), 60 60 .name = "Get_Descriptor", 61 61 .callback = req_get_descriptor 62 62 }, 63 63 { 64 .req_direction = USB_DIRECTION_OUT, 65 .req_recipient = USB_REQUEST_RECIPIENT_INTERFACE, 66 .req_type = USB_REQUEST_TYPE_CLASS, 67 .request = USB_HIDREQ_SET_PROTOCOL, 64 CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_INTERFACE, USB_HIDREQ_SET_PROTOCOL), 68 65 .name = "Set_Protocol", 69 66 .callback = req_set_protocol 70 67 }, 71 68 { 72 .req_direction = USB_DIRECTION_OUT, 73 .req_recipient = USB_REQUEST_RECIPIENT_INTERFACE, 74 .req_type = USB_REQUEST_TYPE_CLASS, 75 .request = USB_HIDREQ_SET_REPORT, 69 CLASS_REQ_OUT(USB_REQUEST_RECIPIENT_INTERFACE, USB_HIDREQ_SET_REPORT), 76 70 .name = "Set_Report", 77 71 .callback = req_set_report … … 151 145 152 146 147 static struct option long_options[] = { 148 {"help", optional_argument, NULL, 'h'}, 149 {"controller", required_argument, NULL, 'c' }, 150 {"list", no_argument, NULL, 'l' }, 151 {0, 0, NULL, 0} 152 }; 153 static const char *short_options = "hc:l"; 154 155 static void print_help(const char* name, const char* module) 156 { 157 if (module == NULL) { 158 /* Default help */ 159 printf("Usage: %s [options] device.\n", name); 160 printf("\t-h, --help [device]\n"); 161 printf("\t\to With no argument print this help and exit.\n"); 162 printf("\t\to With argument print device specific help and exit.\n"); 163 printf("\t-l, --list \n\t\tPrint list of available devices.\n"); 164 printf("\t-c, --controller \n\t\t" 165 "Use provided virtual hc instead of default (%s)\n", 166 DEFAULT_CONTROLLER); 167 return; 168 } 169 printf("HELP for module %s\n", module); 170 } 171 172 static void print_list(void) 173 { 174 printf("Available devices:\n"); 175 for (vuhid_interface_t **i = available_hid_interfaces; *i != NULL; ++i) 176 { 177 printf("\t`%s'\t%s\n", (*i)->id, (*i)->name); 178 } 179 180 } 181 182 static const char *controller = DEFAULT_CONTROLLER; 183 153 184 int main(int argc, char * argv[]) 154 185 { 155 int rc; 186 187 if (argc == 1) { 188 print_help(*argv, NULL); 189 return 0; 190 } 191 192 int opt = 0; 193 while ((opt = getopt_long(argc, argv, short_options, long_options, NULL)) > 0) { 194 switch (opt) 195 { 196 case 'h': 197 print_help(*argv, optarg); 198 return 0; 199 case 'c': 200 controller = optarg; 201 break; 202 case 'l': 203 print_list(); 204 return 0; 205 case -1: 206 default: 207 break; 208 } 209 } 210 156 211 157 212 log_init("vuhid"); … … 161 216 162 217 /* Determine which interfaces to initialize. */ 163 int i; 164 for (i = 1; i < argc; i++) { 165 rc = add_interface_by_id(available_hid_interfaces, argv[i], 218 for (int i = optind; i < argc; i++) { 219 int rc = add_interface_by_id(available_hid_interfaces, argv[i], 166 220 &hid_dev); 167 221 if (rc != EOK) { … … 173 227 } 174 228 175 for (i = 0; i < (int) hid_dev.descriptors->configuration->extra_count; i++) {229 for (int i = 0; i < (int) hid_dev.descriptors->configuration->extra_count; i++) { 176 230 usb_log_debug("Found extra descriptor: %s.\n", 177 231 usb_debug_str_buffer( … … 181 235 } 182 236 183 rc = usbvirt_device_plug(&hid_dev, "/virt/usbhc/hc");237 const int rc = usbvirt_device_plug(&hid_dev, controller); 184 238 if (rc != EOK) { 185 printf("Unable to start communication with VHCD : %s.\n",186 str_error(rc));239 printf("Unable to start communication with VHCD `%s': %s.\n", 240 controller, str_error(rc)); 187 241 return rc; 188 242 } 189 243 190 printf("Connected to VHCD ...\n");244 printf("Connected to VHCD `%s'...\n", controller); 191 245 192 246 wait_for_interfaces_death(&hid_dev);
Note:
See TracChangeset
for help on using the changeset viewer.