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.Op Fl t Ar tablefile 51.Ar arg ... 52.Sh DESCRIPTION 53The 54.Nm 55utility 56can be used to execute commands when certain values appear on HID controls. 57The normal operation for this program is to read the configuration file 58and then become a daemon and execute commands as the HID items specify. 59If a read from the HID device fails, the program dies; this will make it 60die when the USB device is unplugged. 61.Pp 62The options are as follows: 63.Bl -tag -width indent 64.It Fl d 65Toggle the daemon flag. 66.It Fl e 67Instruct 68.Nm 69to die early. 70Useful when specified with multiple verbose options to see how files are parsed. 71.It Fl i 72Ignore HID items in the configuration file that do not exist in the device. 73.It Fl v 74Be verbose, and do not become a daemon. 75.It Fl c Ar config-file 76Specify a path name for the configuration file. 77.It Fl t Ar tablefile 78Specify a path name for the HID usage table file. 79.It Fl f Ar device 80Specify a path name for the device to operate on. 81If 82.Ar device 83is numeric, it is taken to be the USB HID device number. 84If it is a relative 85path, it is taken to be the name of the device under 86.Pa /dev . 87An absolute path is taken to be the literal device pathname. 88.It Fl p Ar pidfile 89Specify an alternate file in which to store the process ID. 90.El 91.Pp 92The configuration file will be re-read if the process gets a 93.Dv SIGHUP 94signal. 95.Sh CONFIGURATION 96The configuration file has a very simple format. 97Each line describes an 98action; if a line begins with a whitespace, it is considered a continuation 99of the previous line. 100Lines beginning with 101.Ql # 102are considered as comments. 103.Pp 104Each line has four parts: a name of a USB HID item, a value for that item, 105a debounce value, and an action. 106There must be whitespace between the parts. 107.Pp 108The item names are similar to those used by 109.Xr usbhidctl 1 , 110but each part must be prefixed by its page name. 111.Pp 112The value is simply a numeric value. 113When the item reports this value, 114the action will be performed. 115If the value is 116.Ql * , 117it will match any value. 118.Pp 119The debounce value is an integer not less than 0. 120The value of 0 indicates that no debouncing should occur. 121A value of 1 will only execute the action when the state changes. 122Values greater than one specify that an action should be performed 123only when the value changes by that amount. 124.Pp 125The action is a normal command that is executed with 126.Xr system 3 . 127Before it is executed some substitution will occur: 128.Ql $n 129will be replaced by the 130.Ar n Ns th 131argument on the command line, 132.Ql $V 133will be replaced by the numeric value of the HID item, 134.Ql $N 135will be replaced by the name of the control, and 136.Ql $H 137will be replaced by the name of the HID device. 138.Sh FILES 139.Bl -tag -width ".Pa /usr/share/misc/usb_hid_usages" 140.It Pa /usr/share/misc/usb_hid_usages 141The HID usage table. 142.It Pa /var/run/usbaction.pid 143The default location of the PID file. 144.El 145.Sh EXAMPLES 146The following configuration file can be used to control a pair 147of Philips USB speakers with the HID controls on the speakers. 148.Bd -literal -offset indent 149# Configuration for various Philips USB speakers 150Consumer:Volume_Up 1 0 mixer -f $1 vol +1 151Consumer:Volume_Down 1 0 mixer -f $1 vol -1 152# mute not supported 153#Consumer:Mute 1 0 mixer -f $1 mute 154Consumer:Channel_Top.Microsoft:Base_Up 1 0 mixer -f $1 bass +1 155Consumer:Channel_Top.Microsoft:Base_Down 1 0 mixer -f $1 bass -1 156.Ed 157.Pp 158A sample invocation using this configuration would be 159.Pp 160.Dl "usbhidaction -f /dev/uhid1 -c conf /dev/mixer1" 161.Pp 162The following example controls the mixer volume using a Logitech Wingman. 163Notice the debounce of 1 for buttons and 5 for the slider. 164.Bd -literal -offset indent 165Button:Button_1 1 1 mixer vol +10 166Button:Button_2 1 1 mixer vol -10 167Generic_Desktop:Z * 5 mixer vol `echo $V | awk '{print int($$1/255*100)}'` 168.Ed 169.Sh SEE ALSO 170.Xr usbhidctl 1 , 171.Xr usbhid 3 , 172.Xr uhid 4 , 173.Xr usb 4 174.Sh HISTORY 175The 176.Nm 177command first appeared in 178.Nx 1.6 . 179The 180.Nm 181command appeared in 182.Fx 5.1 . 183