1

I am using xboxdrv for my MAME controls, however I also want to use my arcade controls via the GPIO also. To do this, on boot up if a xbox controller is detected, I want to load the xboxdrv program, but if it is not, I want to load my program that interfaces my Arcade controls to the GPIO.

How do I detect if the xbox controler is plugged in? I can see the controller in /var/log/messages

Mar 29 11:17:17 raspberrypi kernel: [    6.134223] input: Microsoft X-Box 360 pad as /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2:1.0/input/input0

I would be doing this with a bash script like so:

#! /bin/bash
STR=$(lsusb | grep "Xbox360 Controller")

if [[ $STR == *Xbox360* ]]; then
 echo "x-box driver found"
else
  echo "load custom arcade controls"
fi

Is there a better way?

Thanks for the help.

4
  • 1
    Try looking into udev. With udev you can run command on events, like add and remove, of a usb device. – Gerben Mar 29 '14 at 13:00
  • 1
    Plugging in the Xbox controller should result in the creation of a /dev/input/eventX device. You can use udev to have be static, then just check for the existence of the device file. – Fred Mar 29 '14 at 18:48
  • Have any examples? – PhillyNJ Mar 29 '14 at 23:55
  • since your comments on creating a udev rule are a bit off topic for my original question, I asked that question in the unix/linux SE unix.stackexchange.com/questions/122246/… – PhillyNJ Mar 30 '14 at 13:37
1

Plug and play functionality in Linux is handled via udev rules, which look like this:

ACTION=="add", ATTRS{name}=="Xbox*", SUBSYSTEM=="input", RUN+="/path/to/script.sh"

Essentially, instead of checking for the device presence, you get your script executed the moment the device is plugged in ("added").

There are already several Github projects (1, 2) which you can study to understand how such rules and scripts are written.

0

This worked for me

The device is a GPSdongle which I gave the device name 'ttyUSBGMOUSE' using the 'USB port names rules' procedure

import os import subprocess rv4 = subprocess.call("sudo ls /dev | grep 'ttyUSBGMOUSE'", shell=True) print(rv4)

0 if it is attached, 1 if not

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.