commandline/usb-servo.c

Go to the documentation of this file.
00001 
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <string.h>
00013 #include <usb.h>                /* this is libusb, see
00014                                    http://libusb.sourceforge.net/ */
00015 
00016 #include "usbdrv.h"
00017 
00023 void usage(char *name) {
00024     fprintf(stderr, "usage:\n");
00025     fprintf(stderr, "  %s status\n", name);
00026     fprintf(stderr, "  %s set <angle>\n", name);
00027     fprintf(stderr, "  %s test\n\n", name);
00028     fprintf(stderr, "parameters:\n");
00029     fprintf(stderr, "  angle: Required angle for the servo.\n");
00030 }
00031 
00039 int main(int argc, char **argv) {
00040     usb_dev_handle *handle = NULL;
00041 
00042     if (argc < 2) {
00043         usage(argv[0]);
00044         exit(1);
00045     }
00046     usb_init();
00047     if (usbOpenDevice(&handle, USBDEV_SHARED_VENDOR, "www.schatenseite.de",
00048          USBDEV_SHARED_PRODUCT, "USB-Servo") != 0) {
00049         fprintf(stderr,
00050                 "Could not find USB device \"USB-Servo\" with vid=0x%x pid=0x%x\n",
00051                 USBDEV_SHARED_VENDOR, USBDEV_SHARED_PRODUCT);
00052         exit(1);
00053     }
00054     /* We have searched all devices on all busses for our USB device
00055        above. Now try to open it and perform the vendor specific control
00056        operations for the function requested by the user. */
00057     if (strcmp(argv[1], "test") == 0) {
00058         if (dev_test(handle, argc, argv) != 0) {
00059             usage(argv[1]);
00060         }
00061     } else if (strcmp(argv[1], "set") == 0) {
00062         if (dev_set(handle, argc, argv) != 0) {
00063             usage(argv[1]);
00064         }
00065     } else if (strcmp(argv[1], "status") == 0) {
00066         if (dev_status(handle, argc, argv) != 0) {
00067             usage(argv[1]);
00068         }
00069     } else {
00070         usage(argv[0]);
00071         exit(1);
00072     }
00073     usb_close(handle);
00074     return 0;
00075 }

Generated on Sat Oct 28 14:48:23 2006 for USB-Servo by  doxygen 1.4.7