xref: /freebsd/usr.bin/usbhidaction/usbhidaction.1 (revision 77b7cdf1999ee965ad494fddd184b18f532ac91a)
1.\" $FreeBSD$
2.\" $NetBSD: usbhidaction.1,v 1.8 2003/02/25 10:35:59 wiz Exp $
3.\"
4.\" Copyright (c) 2000 The NetBSD Foundation, Inc.
5.\" All rights reserved.
6.\"
7.\" This code is derived from software contributed to The NetBSD Foundation
8.\" by Lennart Augustsson (lennart@augustsson.net).
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. All advertising materials mentioning features or use of this software
19.\"    must display the following acknowledgement:
20.\"        This product includes software developed by the NetBSD
21.\"        Foundation, Inc. and its contributors.
22.\" 4. Neither the name of The NetBSD Foundation nor the names of its
23.\"    contributors may be used to endorse or promote products derived
24.\"    from this software without specific prior written permission.
25.\"
26.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36.\" POSSIBILITY OF SUCH DAMAGE.
37.\"
38.Dd April 9, 2003
39.Dt USBHIDACTION 1
40.Os
41.Sh NAME
42.Nm usbhidaction
43.Nd perform actions according to USB HID controls
44.Sh SYNOPSIS
45.Nm
46.Op Fl diev
47.Fl c Ar config-file
48.Fl f Ar device
49.Op Fl p Ar pidfile
50.Ar arg ...
51.Sh DESCRIPTION
52.Nm
53can be used to execute commands when certain values appear on HID controls.
54The normal operation for this program is to read the configuration file
55and then become a daemon and execute commands as the HID items specify.
56If a read from the HID device fails the program dies; this will make it
57die when the USB device is unplugged.
58.Pp
59The options are as follows:
60.Bl -tag -width Ds
61.It Fl d
62Toggle the daemon flag.
63.It Fl e
64Instruct
65.Nm
66to die early.  Useful when specified with multiple
67verbose options to see how files are parsed.
68.It Fl i
69Ignore HID items in the config file that does not exist in the device.
70.It Fl v
71Be verbose, and do not become a daemon.
72.It Fl c Ar config-file
73Specify a path name for the config file.
74.It Fl f Ar device
75Specify a path name for the device to operate on.
76If
77.Ar device
78is numeric, it is taken to be the USB HID device number.
79If it is a relative
80path, it is taken to be the name of the device under
81.Pa /dev .
82An absolute path is taken to be the literal device pathname.
83.It Fl p Ar pidfile
84Specify an alternate file in which to store the process ID.
85.El
86.Pp
87The config file will be re-read if the process gets a HUP signal.
88.Sh CONFIGURATION
89The configuration file has a very simple format.
90Each line describes an
91action; if a line begins with a whitespace it is considered a continuation
92of the previous line.
93Lines beginning with `#' are considered as comments.
94.Pp
95Each line has four parts: a name of a USB HID item, a value for that item,
96a debounce value, and an action.
97There must be whitespace between the parts.
98.Pp
99The item names are similar to those used by
100.Xr usbhidctl 1 ,
101but each part must be prefixed by its page name.
102.Pp
103The value is simply a numeric value.
104When the item reports this value
105the action will be performed.
106If the value is `*' it will match any value.
107.Pp
108The debouce value is an integer not less than 0.  The value of 0
109indicates that no debouncing should occur. A value of 1 will only
110execute the action when the state changes. Values greater than one
111specify that an action should be performed only when the value
112changes by that amount.
113.Pp
114The action is a normal command that is executed with
115.Xr system 3 .
116Before it is executed some substitution will occur:
117`$n' will be replaced by the nth argument on the
118command line, `$V' will be replaced by the numeric value
119of the HID item, `$N' will be replaced by the name
120of the control, and `$H' will be replaced by the name
121of the HID device.
122.Sh FILES
123.Bl -tag -width indent
124.It Pa /usr/share/misc/usb_hid_usages
125The HID usage table.
126.It Pa /var/run/usbaction.pid
127The default location of the pid file.
128.El
129.Sh EXAMPLES
130The following configuration file can be used to control a pair
131of Philips USB speakers with the HID controls on the speakers.
132.Bd -literal -offset indent
133# Configuration for various Philips USB speakers
134Consumer:Volume_Up			 1 0 mixer -f $1 vol +1
135Consumer:Volume_Down			 1 0 mixer -f $1 vol -1
136# mute not supported
137#Consumer:Mute				 1 0 mixer -f $1 mute
138Consumer:Channel_Top.Microsoft:Base_Up	 1 0 mixer -f $1 bass +1
139Consumer:Channel_Top.Microsoft:Base_Down 1 0 mixer -f $1 bass -1
140.Ed
141.Pp
142A sample invocation using this configuration would be
143.Bd -literal -offset indent
144usbhidaction -f /dev/uhid1 -c conf /dev/mixer1
145.Ed
146.Pp
147The following example controls the mixer volume using a Logitech Wingman.
148Notice the debouce of 1 for buttons and 5 for the slider.
149.Bd -literal -offset indent
150Button:Button_1	  1 1	mixer vol +10
151Button:Button_2	  1 1	mixer vol -10
152Generic_Desktop:Z * 5	mixer vol `echo $V | awk '{print int($$1/255*100)}'`
153.Ed
154.Sh SEE ALSO
155.Xr usbhidctl 1 ,
156.Xr usbhid 3 ,
157.Xr uhid 4 ,
158.Xr usb 4
159.Sh HISTORY
160The
161.Nm
162command first appeared in
163.Nx 1.6 .
164The
165.Nm
166command appeard in
167.Fx 5.1 .
168