]> oss.titaniummirror.com Git - cp210x.git/commitdiff
cptwiddle now accepts a device argument on its command line.
authorsmckown <smckown@986fd584-583e-0410-b54d-b9fe63dff8e5>
Mon, 2 Nov 2009 20:21:31 +0000 (20:21 +0000)
committersmckown <smckown@986fd584-583e-0410-b54d-b9fe63dff8e5>
Mon, 2 Nov 2009 20:21:31 +0000 (20:21 +0000)
src/examples/cptwiddle.c

index 068809eae917818631ba261d8d55f9a2eb538901..54171752fe318f3d5585e41512925a38f2a32d2b 100644 (file)
@@ -53,10 +53,10 @@ typedef struct {
     uint8_t enhancedFxn;
 } cp2103_port_config_t;
 
-int cpConnect()
+int cpConnect(char* device)
 {
     int ret, ioval;
-    int fd = open("/dev/usb/tts/0", O_RDWR);
+    int fd = open(device, O_RDWR);
     if (fd < 0) {
        fprintf(stderr, "cannot open tty\n");
        return -1;
@@ -71,7 +71,7 @@ void cpDisconnect(int fd)
        close(fd);
 }
 
-int main()
+int main(int argc, char* argv[])
 {
     int fd;
     cp2103_port_config_t config;
@@ -80,7 +80,13 @@ int main()
     int ret;
     int i;
 
-    if ((fd = cpConnect()) < 0)
+    if (argc != 2) {
+       fprintf(stderr, "usage: %s <tty>\n", argv[0]);
+       return 1;
+    }
+
+    /* open */
+    if ((fd = cpConnect(argv[1])) < 0)
        return 1;
 
     /* Read the current port configuration */
@@ -121,7 +127,7 @@ int main()
     printf("disconnected\n");
     for (i = 0; i < 10; i++) {
        sleep(1);
-       if ((fd = cpConnect()) >= 0)
+       if ((fd = cpConnect(argv[1])) >= 0)
            break;
     }
     if (i == 100) {