2 * Copyright (c) 2001 Brian Somers <brian@Awfulhak.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/digiio.h>
36 #include <sys/ioctl.h>
39 enum aflag { NO_AFLAG, ALTPIN_DISABLE, ALTPIN_ENABLE, ALTPIN_QUERY };
42 usage(const char *prog)
44 fprintf(stderr, "usage: %s -a disable|enable|query device\n", prog);
45 fprintf(stderr, " %s [-d debug] [-ir] ctrl-device...\n", prog);
50 main(int argc, char **argv)
52 char namedata[256], *name = namedata;
54 enum digi_model model;
55 int altpin, ch, debug, fd, i, res;
56 int dflag, iflag, rflag;
59 if ((prog = strrchr(argv[0], '/')) == NULL)
65 dflag = iflag = rflag = 0;
66 while ((ch = getopt(argc, argv, "a:d:ir")) != -1)
69 if (strcasecmp(optarg, "disable") == 0)
70 aflag = ALTPIN_DISABLE;
71 else if (strcasecmp(optarg, "enable") == 0)
72 aflag = ALTPIN_ENABLE;
73 else if (strcasecmp(optarg, "query") == 0)
96 if ((dflag || iflag || rflag) && aflag != NO_AFLAG)
100 return (usage(prog));
102 altpin = (aflag == ALTPIN_ENABLE);
105 for (i = optind; i < argc; i++) {
106 if ((fd = open(argv[i], O_RDONLY)) == -1) {
107 fprintf(stderr, "%s: %s: open: %s\n", prog, argv[i],
119 if (ioctl(fd, DIGIIO_SETALTPIN, &altpin) != 0) {
120 fprintf(stderr, "%s: %s: set altpin: %s\n",
121 prog, argv[i], strerror(errno));
127 if (ioctl(fd, DIGIIO_GETALTPIN, &altpin) != 0) {
128 fprintf(stderr, "%s: %s: get altpin: %s\n",
129 prog, argv[i], strerror(errno));
132 if (argc > optind + 1)
133 printf("%s: ", argv[i]);
134 puts(altpin ? "enabled" : "disabled");
139 if (dflag && ioctl(fd, DIGIIO_DEBUG, &debug) != 0) {
140 fprintf(stderr, "%s: %s: debug: %s\n",
141 prog, argv[i], strerror(errno));
146 if (ioctl(fd, DIGIIO_MODEL, &model) != 0) {
147 fprintf(stderr, "%s: %s: model: %s\n",
148 prog, argv[i], strerror(errno));
150 } else if (ioctl(fd, DIGIIO_IDENT, &name) != 0) {
151 fprintf(stderr, "%s: %s: ident: %s\n",
152 prog, argv[i], strerror(errno));
155 if (argc > optind + 1)
156 printf("%s: ", argv[i]);
157 printf("%s (type %d)\n", name, (int)model);
161 if (rflag && ioctl(fd, DIGIIO_REINIT) != 0) {
162 fprintf(stderr, "%s: %s: reinit: %s\n",
163 prog, argv[i], strerror(errno));