From f7c370bb62213bde2d52ec4816401fb3778773a5 Mon Sep 17 00:00:00 2001 From: smckown Date: Mon, 2 Nov 2009 20:21:31 +0000 Subject: [PATCH] cptwiddle now accepts a device argument on its command line. --- src/examples/cptwiddle.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/examples/cptwiddle.c b/src/examples/cptwiddle.c index 068809e..5417175 100644 --- a/src/examples/cptwiddle.c +++ b/src/examples/cptwiddle.c @@ -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 \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) { -- 2.39.2