diff options
author | Marc Balmer <mbalmer@cvs.openbsd.org> | 2008-11-29 09:19:26 +0000 |
---|---|---|
committer | Marc Balmer <mbalmer@cvs.openbsd.org> | 2008-11-29 09:19:26 +0000 |
commit | 0940b0a72c8e7479bf568c506559775a26fd0870 (patch) | |
tree | db4253776a657e7d7652040bba4975a7883fe5eb | |
parent | 73d3c052344befa70b938d775d88a4efcc043df7 (diff) |
Allow the words "on", "off", or "toggle" to be used instead of the
numerical values when writing to a pin; fix an error message.
-rw-r--r-- | usr.sbin/gpioctl/gpioctl.8 | 15 | ||||
-rw-r--r-- | usr.sbin/gpioctl/gpioctl.c | 23 |
2 files changed, 29 insertions, 9 deletions
diff --git a/usr.sbin/gpioctl/gpioctl.8 b/usr.sbin/gpioctl/gpioctl.8 index f51a5c07c3e..7a33df90712 100644 --- a/usr.sbin/gpioctl/gpioctl.8 +++ b/usr.sbin/gpioctl/gpioctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: gpioctl.8,v 1.15 2008/11/26 14:56:10 mbalmer Exp $ +.\" $OpenBSD: gpioctl.8,v 1.16 2008/11/29 09:19:25 mbalmer Exp $ .\" .\" Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: November 26 2008 $ +.Dd $Mdocdate: November 29 2008 $ .Dt GPIOCTL 8 .Os .Sh NAME @@ -42,6 +42,11 @@ detach .Op Fl q .Ar device .Ar pin +.Op Ar on | off | toggle +.Nm gpioctl +.Op Fl q +.Ar device +.Ar pin set .Op Ar flags .Op Ar name @@ -87,6 +92,12 @@ Values can be either 0 or 1. A value of 2 has a special meaning: it .Dq toggles the pin, i.e. changes its state to the opposite. +Instead of the numerical values, the word +.Ar on , +.Ar off , +or +.Ar toggle +can be used. .Pp Only pins that have been configured at securelevel 0, typically during system startup, are accessible once the securelevel has been raised. diff --git a/usr.sbin/gpioctl/gpioctl.c b/usr.sbin/gpioctl/gpioctl.c index 84cf6709665..0868460989c 100644 --- a/usr.sbin/gpioctl/gpioctl.c +++ b/usr.sbin/gpioctl/gpioctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gpioctl.c,v 1.11 2008/11/26 15:02:43 mbalmer Exp $ */ +/* $OpenBSD: gpioctl.c,v 1.12 2008/11/29 09:19:25 mbalmer Exp $ */ /* * Copyright (c) 2008 Marc Balmer <mbalmer@openbsd.org> * Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org> @@ -161,8 +161,17 @@ main(int argc, char *argv[]) } else { value = strtonum(argv[2], INT_MIN, INT_MAX, &errstr); - if (errstr) - errx(1, "%s: invalid value", argv[2]); + if (errstr) { + if (!strcmp(argv[2], "on")) + value = 1; + else if (!strcmp(argv[2], "off")) + value = 0; + else if (!strcmp(argv[2], "toggle")) + value = 2; + else + errx(1, "%s: invalid value", + argv[2]); + } pinwrite(pin, nm, value); } } else @@ -226,7 +235,7 @@ pinwrite(int pin, char *gp_name, int value) op.gp_value = (value == 0 ? GPIO_PIN_LOW : GPIO_PIN_HIGH); if (value < 2) { if (ioctl(devfd, GPIOPINWRITE, &op) == -1) - err(1, "GPIOPINWR"); + err(1, "GPIOPINWRITE"); } else { if (ioctl(devfd, GPIOPINTOGGLE, &op) == -1) err(1, "GPIOPINTOGGLE"); @@ -328,12 +337,12 @@ usage(void) { extern char *__progname; - fprintf(stderr, "usage: %s [-q] device [pin] [0 | 1 | 2]\n", - __progname); + fprintf(stderr, "usage: %s [-q] device [pin] [0 | 1 | 2 | " + "on | off | toggle]\n", __progname); fprintf(stderr, " %s [-q] device pin set [flags] [name]\n", __progname); fprintf(stderr, " %s [-q] device pin unset\n", __progname); - fprintf(stderr, " %s [-q] device attach device offset mask\n", + fprintf(stderr, " %s [-q] device attach device offset mask\n", __progname); fprintf(stderr, " %s [-q] device detach device\n", __progname); |