Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop multiple instances 3 #37

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down
31 changes: 19 additions & 12 deletions src/etc/default/xboxdrv
Original file line number Diff line number Diff line change
@@ -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=
62 changes: 62 additions & 0 deletions src/etc/init/ubuntu-xboxdrv.conf
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions src/etc/init/xboxdrv-helper.conf
Original file line number Diff line number Diff line change
@@ -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
56 changes: 29 additions & 27 deletions src/etc/init/xboxdrv.conf
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/etc/pm/sleep.d/xboxdrv
Original file line number Diff line number Diff line change
Expand Up @@ -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