xref: /netbsd-src/usr.bin/usbhidaction/usbhidaction.1 (revision 4d342c046e3288fb5a1edcd33cfec48c41c80664)
1.\" $NetBSD: usbhidaction.1,v 1.16 2018/05/15 01:41:29 jmcneill 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 May 14, 2018
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.Fl c Ar config-file
39.Op Fl d
40.Op Fl i
41.Fl f Ar device
42.Op Fl p Ar pidfile
43.Op Fl t Ar table
44.Op Fl v
45.Op Ar arg ...
46.Sh DESCRIPTION
47.Nm
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 Ds
56.It Fl c Ar config-file
57Specify a path name for the config file.
58When running as a daemon this needs to be an absolute path for the HUP
59signal to work.
60.It Fl d
61Toggle the daemon flag.
62.It Fl i
63Ignore HID items in the config file that do not exist in the device.
64.It Fl f Ar device
65Specify a path name for the device to operate on.
66If
67.Ar device
68is numeric, it is taken to be the USB HID device number.
69If it is a relative
70path, it is taken to be the name of the device under
71.Pa /dev .
72An absolute path is taken to be the literal device pathname.
73.It Fl p Ar pidfile
74Writes a file containing the process ID of the program.
75The file name has the form
76.Pa /var/run/usbhidaction.pid .
77If the option is not given,
78.Ar pidfile
79defaults to
80.Pa usbhidaction .
81.It Fl t Ar table
82Specify a path name for the HID usage table file.
83.It Fl v
84Be verbose, and do not become a daemon.
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 three parts: a name of a USB HID item, a value for that item,
96and 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(use the
103.Fl v
104flag to
105.Xr usbhidctl 1
106to see the page name).
107Replace spaces in the item name by underscores.
108.Pp
109The value is simply a numeric value.
110When the item reports this value
111the action will be performed.
112If the value is `*' it will match any value.
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.Pa /usr/share/misc/usb_hid_usages
124The HID usage table.
125.Sh EXAMPLES
126The following configuration file can be used to control a pair
127of Philips USB speakers with the HID controls on the speakers.
128.Bd -literal -offset indent
129# Configuration for various Philips USB speakers
130Consumer:Consumer_Control.Consumer:Volume_Up			   1
131	mixerctl -f $1 -n -w outputs.master++
132Consumer:Consumer_Control.Consumer:Volume_Down			   1
133	mixerctl -f $1 -n -w outputs.master--
134Consumer:Consumer_Control.Consumer:Mute				   1
135	mixerctl -f $1 -n -w outputs.mute++
136Consumer:Consumer_Control.Consumer:Channel_Top.Microsoft:Base_Up   1
137	mixerctl -f $1 -n -w outputs.bass++
138Consumer:Consumer_Control.Consumer:Channel_Top.Microsoft:Base_Down 1
139	mixerctl -f $1 -n -w outputs.bass--
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
147This configuration file can be used for various keyboards with extra keys:
148.Bd -literal -offset indent
149# Configuration for extra keyboard keys
150Consumer:Consumer_Control.Consumer:Volume_Up			1
151	mixerctl -n -w outputs.master++
152Consumer:Consumer_Control.Consumer:Volume_Down			1
153	mixerctl -n -w outputs.master--
154Consumer:Consumer_Control.Consumer:Mute				1
155	mixerctl -n -w outputs.mute++
156Consumer:Consumer_Control.Consumer:Pause/Play			1
157	xmms -p
158Consumer:Consumer_Control.Consumer:Stop				1
159	xmms -s
160Consumer:Consumer_Control.Consumer:Scan_Previous_Track		1
161	xmms -r
162Consumer:Consumer_Control.Consumer:Scan_Next_Track		1
163	xmms -f
164.Ed
165.Pp
166And this configuration can be used with, e.g.,
167.Bd -literal -offset indent
168usbhidaction -f /dev/uhid0 -c conf -i
169.Ed
170.Sh SEE ALSO
171.Xr usbhidctl 1 ,
172.Xr usbhid 3 ,
173.Xr uhid 4 ,
174.Xr usb 4
175.Sh HISTORY
176The
177.Nm
178command first appeared in
179.Nx 1.6 .
180