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