Reply to comment

USB Panic Button on Linux

I found this USB "big red button" recently, and decided that I'd love to have a play with it, using it to run dangerous scripts. At just £5, it was worth the risk of lack of Linux support.

When it arrived, I was initially relieved, as it was detected at least by my system:

$lsusb
...SNIP...
Bus 001 Device 007: ID 1130:0202 Tenx Technology, Inc.
...SNIP...

However, even going down to looking at the scancodes, I couldn't detect any status changes in the switch when pressed. I initially thought I was going to have to hack a driver out of a generic USB mouse driver, which as I don't know C would have been hard.

Fortunately, Google threw up links to this page, which is a perl module to interface with the button. Obviously, this means that somewhere that I was missing, the kernel was detecting the button presses. Rather than re-inventing the wheel, it was obvious that I should use this module to do my work.

On my Ubuntu 8.10 (Intrepid Ibex) machine, I first had to install libinline-perl (and libyaml-perl to stop some CPAN warnings), and then the module in CPAN.

$ sudo aptitude install libinline-perl libyaml-perl
$ sudo cpan
### If this is your first use of CPAN, you'll need to let it run it's configuration process.
### Accepting defaults for this should be fine.
install Device::USB::PanicButton

Now we're ready to use our button via the perl script on the PanicButton.pm pagelinked to earlier.

    use Device::USB::PanicButton;

    my $pbutton = Device::USB::PanicButton->new();

    if(!$pbutton || $pbutton->error()) {
        printf(STDERR "FATAL: ". $pbutton->error() ."\n");
        exit(-1);
    }

    while(1) {
        my $result = $pbutton->pressed();

        if($result == 1) {
###            printf("PANIC ;)\n");
               system( "/home/lunarlamp/myscript.sh" );

        } elsif($result < 0) {
            printf(STDERR "WARN: ". $pbutton->error() ."\n");
        }       

        sleep(1);
    }

As you can see, I changed the script to run the bash script that I had already written as I did not want to have to rewrite it in Perl.

I hope this helps anyone else to quickly work out how to use this fun little device under Linux.

Reply

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
  _____           ___    ____    ___   _   
|___ | ___ ( _ ) | _ \ |_ _| | |_
/ / / __| / _ \ | |_) | | | | __|
/ / | (__ | (_) | | _ < | | | |_
/_/ \___| \___/ |_| \_\ |___| \__|
Enter the code depicted in ASCII art style.

Copyright

Creative Commons License

This work is licenced under a Creative Commons Licence.

User login