Changeset 56a07e0 in mainline
- Timestamp:
- 2012-12-22T20:34:09Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b591cab
- Parents:
- 38b4a25
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/vuhid/main.c
r38b4a25 r56a07e0 40 40 #include <errno.h> 41 41 #include <str_error.h> 42 #include <getopt.h> 42 43 43 44 #include <usb/usb.h> … … 51 52 #include "ifaces.h" 52 53 #include "stdreq.h" 54 55 #define DEFAULT_CONTROLLER "/virt/usbhc/ctl" 53 56 54 57 static usbvirt_control_request_handler_t endpoint_zero_handlers[] = { … … 151 154 152 155 156 static struct option long_options[] = { 157 {"help", optional_argument, NULL, 'h'}, 158 {"controller", required_argument, NULL, 'c' }, 159 {"list", no_argument, NULL, 'l' }, 160 {0, 0, NULL, 0} 161 }; 162 static const char *short_options = "hc:l"; 163 164 static void print_help(const char* name, const char* module) 165 { 166 if (module == NULL) { 167 /* Default help */ 168 printf("Usage: %s [options] device.\n", name); 169 printf("\t-h, --help [device]\n"); 170 printf("\t\to With no argument print this help and exit.\n"); 171 printf("\t\to With argument print device specific help and exit.\n"); 172 printf("\t-l, --list \n\t\tPrint list of available devices.\n"); 173 printf("\t-c, --controller \n\t\t" 174 "Use provided virtual hc instead of default (%s)\n", 175 DEFAULT_CONTROLLER); 176 return; 177 } 178 printf("HELP for module %s\n", module); 179 } 180 181 static void print_list(void) 182 { 183 printf("Available devices:\n"); 184 for (vuhid_interface_t **i = available_hid_interfaces; *i != NULL; ++i) 185 { 186 printf("\t`%s'\t%s\n", (*i)->id, (*i)->name); 187 } 188 189 } 190 191 static const char *controller = DEFAULT_CONTROLLER; 192 153 193 int main(int argc, char * argv[]) 154 194 { 155 int rc; 195 196 if (argc == 1) { 197 print_help(*argv, NULL); 198 return 0; 199 } 200 201 int opt = 0; 202 while ((opt = getopt_long(argc, argv, short_options, long_options, NULL)) > 0) { 203 switch (opt) 204 { 205 case 'h': 206 print_help(*argv, optarg); 207 return 0; 208 case 'c': 209 controller = optarg; 210 break; 211 case 'l': 212 print_list(); 213 return 0; 214 case -1: 215 default: 216 break; 217 } 218 } 219 156 220 157 221 log_init("vuhid"); … … 161 225 162 226 /* 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], 227 for (int i = optind; i < argc; i++) { 228 int rc = add_interface_by_id(available_hid_interfaces, argv[i], 166 229 &hid_dev); 167 230 if (rc != EOK) { … … 173 236 } 174 237 175 for (i = 0; i < (int) hid_dev.descriptors->configuration->extra_count; i++) {238 for (int i = 0; i < (int) hid_dev.descriptors->configuration->extra_count; i++) { 176 239 usb_log_debug("Found extra descriptor: %s.\n", 177 240 usb_debug_str_buffer( … … 181 244 } 182 245 183 rc = usbvirt_device_plug(&hid_dev, "/virt/usbhc/ctl");246 const int rc = usbvirt_device_plug(&hid_dev, controller); 184 247 if (rc != EOK) { 185 printf("Unable to start communication with VHCD : %s.\n",186 str_error(rc));248 printf("Unable to start communication with VHCD `%s': %s.\n", 249 controller, str_error(rc)); 187 250 return rc; 188 251 } 189 252 190 printf("Connected to VHCD ...\n");253 printf("Connected to VHCD `%s'...\n", controller); 191 254 192 255 wait_for_interfaces_death(&hid_dev);
Note:
See TracChangeset
for help on using the changeset viewer.