FreeBSD support for the Jam Panic Button

Yes, it is a large red button! Like so many others I saw one of these at my local electronics retailer (Jaycar Electronics) and just had to have one. Unfortunately the software supplied was extremely limitted - it is a "Boss Key" and only works under Windows. Boss keys - especially when driven by large red buttons - require an almost Dilbertian disconnection from reallity to be considered useful. So something a bit more flexible was needed.

Others have also noted the need for a more useful interface. A Linux program built for Python which also works with the Panic Button www.acid2000.co.uk/pypanic/pypanic.py is also distributed under a BSD licence. Although neither is a derivative work of the other I have included the code in this page as another example of the protocol.

A note of caution is required. During the development of this software I discovered that the hid driver in FreeBSD does not get on well with the Panic Button to the point that pressing the button and probing the hid facilities crashed my box.

ENSURE that the Panic Button is not connecting to the hid device driver.

The Jam Panic Button is based on a Tenx USB chip, probably a TMU3102. These chips are also used in missile launcher toys. The code presented will read a button press from the panic button provided the device is detected as a ugen device by the FreeBSD kernel.

To use the program issue the command

panicbutton BUTTON_NUMBER PROGNAME

where BUTTON_NUMBER is the number of the panic button to be used and PROGNAME is the program to execute when the panicbutton is depressed. The BUTTON_NUMBER is used to allow multiple panic buttons to be connected to the one computer. The panic buttons are numbered from 1 and are in the order they are detected by the usb driver in the operating system.

An example of the use of the program is to display a web site when the button is depressed:

panicbutton 1 "firefox www.castro.aus.net"

or more usefully reboot a machine which has lost video while changing a driver:

panicbutton 1 "sudo reboot"

Please note that there have been occasions when it has been necessary to disconnect the panic button from the USB host to reset the device and allow the button to be detected - although this has mostly been corrected through the use of a signal handler.

The program requires access to the device files /dev/usb and /dev/ugen[0-9]+ for the device which has the panic button attached. This is safely achieved by creating a setuid root program which drops priveleges to run as the user which started the program when it runs the program specified on the command line of the panicbutton program. To ensure that this security mechanism is enforced the program will not run if it is started by root directly.

The code does NOT use libusb (libusb.sourceforge.net) and hence can serve as a model for those wishing to implement their own native usb interfaces under FreeBSD.

Please note: The code is supplied "AS IS" under a BSD licence

Source code:

Archive of python source: