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