Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/vuhid/main.c

    r920d0fc r2a6e2358  
    4040#include <errno.h>
    4141#include <str_error.h>
     42#include <getopt.h>
    4243
    4344#include <usb/usb.h>
     
    5253#include "stdreq.h"
    5354
     55#define DEFAULT_CONTROLLER   "/virt/usbhc/ctl"
     56
    5457static usbvirt_control_request_handler_t endpoint_zero_handlers[] = {
    5558        {
    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),
    6060                .name = "Get_Descriptor",
    6161                .callback = req_get_descriptor
    6262        },
    6363        {
    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),
    6865                .name = "Set_Protocol",
    6966                .callback = req_set_protocol
    7067        },
    7168        {
    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),
    7670                .name = "Set_Report",
    7771                .callback = req_set_report
     
    151145
    152146
     147static 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};
     153static const char *short_options = "hc:l";
     154
     155static 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
     172static 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
     182static const char *controller = DEFAULT_CONTROLLER;
     183
    153184int main(int argc, char * argv[])
    154185{
    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
    156211
    157212        log_init("vuhid");
     
    161216
    162217        /* 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],
    166220                    &hid_dev);
    167221                if (rc != EOK) {
     
    173227        }
    174228
    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++) {
    176230                usb_log_debug("Found extra descriptor: %s.\n",
    177231                    usb_debug_str_buffer(
     
    181235        }
    182236
    183         rc = usbvirt_device_plug(&hid_dev, "/virt/usbhc/hc");
     237        const int rc = usbvirt_device_plug(&hid_dev, controller);
    184238        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));
    187241                return rc;
    188242        }
    189243       
    190         printf("Connected to VHCD...\n");
     244        printf("Connected to VHCD `%s'...\n", controller);
    191245
    192246        wait_for_interfaces_death(&hid_dev);
Note: See TracChangeset for help on using the changeset viewer.