diff --git a/README.md b/README.md index 3100335..b183e7a 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ This package adds additional configurations over xboxdrv: - Start with support for 4 joysticks; - Add a "Joysticks" entry into System Settings panel; - Easy ForceFeeback activation. +- Manages a specific xboxdrv process per controller ## Install @@ -33,7 +34,7 @@ sudo apt-get install ubuntu-xboxdrv The `xboxdrv` job is already started when the package is installed. But, if for some reason, you need to restart it, run in terminal: ```term -sudo service xboxdrv restart +sudo service ubuntu-xboxdrv restart ``` ## Force Feedback @@ -47,11 +48,18 @@ Then, restart the service: `sudo service xboxdrv restart`. By default, triggers are not enabled as z-axis, but as buttons. To change, edit `/etc/defaults/xboxdrv` and change `TRIGGERS_AS_BUTTONS` to `false`. -## Additional Configurations Options +## Configuring -You can edit `/etc/default/xboxdrv` and add more configurations to `xboxdrv`. +Ubuntu-Xboxdrv is designed to be interacted with once. However this means that you must edit `/etc/default/xboxdrv`to have at least one controller setup. To to this, edit the following fields in the default file: +- `CONTROLLER1_OPTIONS` +This field is for the arguements for `xboxdrv` that you would usually use with a specific controller. +- `CONTROLLER1` +This field is for your controllers USB vendor:product keys. These values are easily found with an internet search for your device. -To see a list of available configurations, please, check `xboxdrv` [options page](http://pingus.seul.org/~grumbel/xboxdrv/xboxdrv.html). +In addition to having arguements added based on the controller, there is also a field to add arguements that are used with all controllers. + +To see a list of available arguements to use, please, check `xboxdrv` [options page](http://pingus.seul.org/~grumbel/xboxdrv/xboxdrv.html). +**One important note**: due to implimentation restrictions, it is recommended to avoid using controller slots, as this may cause issues. ## PS3 dualshock diff --git a/src/etc/default/xboxdrv b/src/etc/default/xboxdrv index 1c10a75..7db1c4f 100644 --- a/src/etc/default/xboxdrv +++ b/src/etc/default/xboxdrv @@ -1,21 +1,28 @@ +########################################################################## # Defaults for xboxdrv service - +# -Applied to all instances # If enabled, can present problems on wine games FORCE_FEEDBACK=false -# Make triggers work like buttons instead of zaxis -TRIGGER_AS_BUTTON=true - # Mimic xpad buttons -MIMIC_XPAD=true +MIMIC_XPAD=false # Additional options that are passed to xboxdrv (see xboxdrv man pages). -# These are appended once during start +# These are appended first during start XBOXDRV_OPTIONS="" - +########################################################################## # Edit each block to give each controller slot its own options. -# These are appended last for their respective slots -CONTROLLER0_OPTIONS="" -CONTROLLER1_OPTIONS="" -CONTROLLER2_OPTIONS="" -CONTROLLER3_OPTIONS="" +# These are appended last to their respective instance of xboxdrv. +# Config slots are okay, however use of controller slots in these fields +# -may cause undesired behavior. NOTE: need to be enclosed in double quotes +CONTROLLER1_OPTIONS= +CONTROLLER2_OPTIONS= +CONTROLLER3_OPTIONS= +CONTROLLER4_OPTIONS= + +########################################################################## +# Enter the device product:vendor keys of your controllers (ex 045e:028e) +CONTROLLER1= +CONTROLLER2= +CONTROLLER3= +CONTROLLER4= diff --git a/src/etc/init/ubuntu-xboxdrv.conf b/src/etc/init/ubuntu-xboxdrv.conf new file mode 100644 index 0000000..2992b5b --- /dev/null +++ b/src/etc/init/ubuntu-xboxdrv.conf @@ -0,0 +1,62 @@ +start on (filesystem and RUNLEVEL [2345]) or starting xboxdrv-helper +env RUNPATH="/var/run/xboxdrv" +env DEFAULT="/etc/default/xboxdrv" +pre-start script + # create working directory + mkdir -p $RUNPATH + mkdir ${RUNPATH}/profile + # load user options + if [ -f $DEFAULT ] ; then + . $DEFAULT + fi + # remove potentially problematic js files on start + rm -f /dev/input/js* + # initialize loop variables + SLOTID=1 + EXISTS=true + # this loop creates files named the value of CONTROLLER[x] from the default file + # - Inside the files are the options in CONTROLLER[x]_OPTIONS + while [ "$EXISTS" = true ]; do + # sets controller usbid container to the variable format of the default file + CONTROLLER="CONTROLLER${SLOTID}" + # replace CONTROLLER[x] with its value from the default file + eval CONTROLLER="\$$CONTROLLER" + # test for length of a vendor:product pair + if [ "${#CONTROLLER}" = "9" ]; then + # set option container to the respective options variable + OPTIONS="CONTROLLER${SLOTID}_OPTIONS" + # populate container with options + eval OPTIONS="\$$OPTIONS" + # export options into a file named after the appropriate controller + echo $OPTIONS > "${RUNPATH}/profile/${CONTROLLER}" + # incriment slot for next iteration + SLOTID=$(( SLOTID + 1 )) + # when the last controller profile file is built, exit loop + else + EXISTS=false + fi + done +end script + +post-start script + # if a controller being added triggered the start of this service, do + # - not start any other controllers, just exit + if [ "$JOB" = "xboxdrv-checker" ]; then + exit 0 + else + # loop to try to start one job per profile + ID="0" + for PROFILE in `ls $RUNPATH/profile/`; do + ID=$((ID + 1)) + # seperate vendor and product from profile + VENDOR=${PROFILE%:*} + PRODUCT=${PROFILE#*:} + start xboxdrv ID="$ID" VENDOR="$VENDOR" PRODUCT="$PRODUCT" + done + fi +end script + +post-stop script + # cleanup runpath on exit + rm -rf $RUNPATH +end script diff --git a/src/etc/init/xboxdrv-helper.conf b/src/etc/init/xboxdrv-helper.conf new file mode 100644 index 0000000..c473f2a --- /dev/null +++ b/src/etc/init/xboxdrv-helper.conf @@ -0,0 +1,23 @@ +start on usb-device-added +task +env RUNPATH="/var/run/xboxdrv" +script + # If ubuntu xboxdrv is set to react to this device, aka a profile for this device exists + if [ -e "${RUNPATH}/profile/${ID_VENDOR_ID}:${ID_MODEL_ID}" ]; then + # Initialize id tracking variable + ID="1" + # test for running controllers + for pidfile in ${RUNPATH}/*.pid; do + # if a controller with this id is running + if [ -e ${RUNPATH}/${ID}* ] ; then + # then increment + ID="$((ID + 1))" + fi + done + # Once the id is verified, start the controller job + start xboxdrv ID="${ID}" VENDOR="${ID_VENDOR_ID}" PRODUCT="${ID_MODEL_ID}" + else + # If an optfile for the usb device doesnt exist, exit + exit 0 + fi +end script diff --git a/src/etc/init/xboxdrv.conf b/src/etc/init/xboxdrv.conf index 8446452..470b6e5 100644 --- a/src/etc/init/xboxdrv.conf +++ b/src/etc/init/xboxdrv.conf @@ -1,38 +1,40 @@ -# xboxdrv.conf -# Please, DO NOT EDIT THIS FILE. Edit /etc/defaults/xboxdrv -start on filesystem -pre-start script - rm -f /dev/input/js* -end script +# Xboxdrv Controller +stop on stopping ubuntu-xboxdrv or usb-device-removed ID_VENDOR_ID="$VENDOR" ID_MODEL_ID="$PRODUCT" +# This is the job name, which will be the controller id and vendor:product id of the controller +instance ${ID}'|'${VENDOR}':'${PRODUCT} + +env DEFAULT="/etc/default/xboxdrv" +env RUNPATH="/var/run/xboxdrv" script - # Edit /etc/default/xboxdrv to change these options - FORCE_FEEDBACK=false - MIMIC_XPAD=true - TRIGGER_AS_BUTTON=true - XBOXDRV_OPTIONS="" - CONTROLLER0_OPTIONS="" - CONTROLLER1_OPTIONS="" - CONTROLLER2_OPTIONS="" - CONTROLLER3_OPTIONS="" # Read configuration variable file if it is present - if [ -f /etc/default/xboxdrv ] ; then - . /etc/default/xboxdrv + if [ -f $DEFAULT ] ; then + . $DEFAULT fi - # This will store all pad options from /etc/default/xboxdrv - PAD_OPTIONS="" - # Checking if user has enabled forcefeedback + # this will store all system pad options from /etc/default/xboxdrv + PAD_OPTIONS="--silent --daemon --dbus disabled --pid-file ${RUNPATH}/${UPSTART_INSTANCE}.pid" + + # checking if user has enabled forcefeedback if [ "$FORCE_FEEDBACK" = true ] ; then PAD_OPTIONS="$PAD_OPTIONS --force-feedback" fi - # Checking if user has enabled mimic_xpad + + # checking if user has enabled mimic_xpad if [ "$MIMIC_XPAD" = true ] ; then PAD_OPTIONS="$PAD_OPTIONS --mimic-xpad --mimic-xpad-wireless" fi - # Checking if user is using trigger as buttons instead of zaxis - if [ "$TRIGGER_AS_BUTTON" = true ] ; then - PAD_OPTIONS="$PAD_OPTIONS --trigger-as-button" - fi - # Adding --detache-kernel-driver + # adding --detache-kernel-driver PAD_OPTIONS="$PAD_OPTIONS --detach-kernel-driver" - xboxdrv --daemon --silent --dbus disabled $XBOXDRV_OPTIONS $PAD_OPTIONS $CONTROLLER0_OPTIONS --next-controller $PAD_OPTIONS $CONTROLLER1_OPTIONS --next-controller $PAD_OPTIONS $CONTROLLER2_OPTIONS--next-controller $PAD_OPTIONS $CONTROLLER3_OPTIONS + # Get controller options from respective optfile + CONTROLLER_OPTIONS="$(cat ${RUNPATH}/profile/${VENDOR}:${PRODUCT} )" + # add xboxdrv options to make this newly connected controller's process unique + ID_ARGS="--id $((ID - 1)) --wid $((ID - 1)) --led $((ID + 1)) --match usbid=${VENDOR}:${PRODUCT}" + # store all xboxdrv arguements + ARGS="$XBOXDRV_OPTIONS $PAD_OPTIONS $ID_ARGS $CONTROLLER_OPTIONS" + # start xboxdrv with appropriate arguements + exec xboxdrv $ARGS +end script + +pre-stop script + # remove controllers pid file when job exits + rm -f ${RUNPATH}/${UPSTART_INSTANCE}.pid end script diff --git a/src/etc/pm/sleep.d/xboxdrv b/src/etc/pm/sleep.d/xboxdrv index 321b06f..effb5d7 100755 --- a/src/etc/pm/sleep.d/xboxdrv +++ b/src/etc/pm/sleep.d/xboxdrv @@ -4,9 +4,9 @@ case $1 in suspend|suspend_hybrid|hibernate) - stop -q xboxdrv || : + stop -q ubuntu-xboxdrv || : ;; resume|thaw) - start -q xboxdrv || : + start -q ubuntu-xboxdrv || : ;; esac