Polish up framework to auto-detect Mustang

This commit is contained in:
hirsch 2016-07-31 19:17:30 -04:00
parent 32b6bdde02
commit 45feec3d78
4 changed files with 53 additions and 48 deletions

View file

@ -1,7 +1,4 @@
# Mustang III (original)
ACTION=="add|change", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="1ed8", ATTRS{idProduct}=="0005", GROUP="plugdev", RUN+="/bin/bash -c '/bin/echo /usr/local/bin/mustang_bridge_start | /usr/bin/at now'"
ACTION=="remove", ENV{ID_VENDOR_ID}=="1ed8", ENV{ID_MODEL_ID}=="0005", ENV{DEVTYPE}=="usb_device", RUN+="/usr/local/bin/mustang_bridge_stop"
# Cover all known Mustang models
ACTION=="add|change", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="1ed8", ATTRS{idProduct}=="0004|0005|000a|0010|0012|0014|0016", GROUP="plugdev", RUN+="/bin/bash -c '/bin/echo /usr/local/bin/mustang_bridge_start | /usr/bin/at now'"
ACTION=="remove", ENV{ID_VENDOR_ID}=="1ed8", ENV{ID_MODEL_ID}=="0004|0005|000a|0010|0012|0014|0016", ENV{DEVTYPE}=="usb_device", RUN+="/usr/local/bin/mustang_bridge_stop"
# Mustang III v2
ACTION=="add|change", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="1ed8", ATTRS{idProduct}=="0016", GROUP="plugdev", RUN+="/bin/bash -c '/bin/echo /usr/local/bin/mustang_bridge_start | /usr/bin/at now'"
ACTION=="remove", ENV{ID_VENDOR_ID}=="1ed8", ENV{ID_MODEL_ID}=="0016", ENV{DEVTYPE}=="usb_device", RUN+="/usr/local/bin/mustang_bridge_stop"

View file

@ -1,2 +1,3 @@
# Must customize vendor and product id for your controller
ACTION=="add|change", SUBSYSTEM=="usb", ATTRS{idVendor}=="0763", ATTRS{idProduct}=="0160", RUN+="/bin/bash -c '/bin/echo /usr/local/bin/mustang_bridge_start | /usr/bin/at now'"
ACTION=="remove", ENV{ID_VENDOR_ID}=="0763", ENV{ID_MODEL_ID}=="0160", ENV{DEVTYPE}=="usb_device", RUN+="/usr/local/bin/mustang_bridge_stop"

View file

@ -9,9 +9,10 @@ if [ ! -f "mustang_midi" ]; then
exit 1
fi
if ! `grep -q mustang-user /etc/passwd`; then
echo "Create non-privileged user for MIDI bridge"
useradd -M -s /bin/false mustang-user
fi
echo "Copy program and support scripts to $BINDIR"

View file

@ -11,7 +11,7 @@ from string import split
import usb.core
####### Start User Edits #########
rundir = "/var/run/mustang/"
# Controller USB parms
control_vid = 0x0763
@ -19,12 +19,9 @@ control_pid = 0x0160
# Mustang USB parms
mustang_vid = 0x1ed8
mustang_pids = ( 0x0004, 0x0005, 0x000a, 0x0010, 0x0012, 0x0014, 0x0016 )
# Mustang III (original)
# mustang_pid = 0x0005
# Mustang III v2
mustang_pid = 0x0016
####### Start User Edits #########
# Controller MIDI device
midi_device = 1
@ -34,21 +31,32 @@ midi_channel = 1
######## End User Edits ##########
rundir = "/var/run/mustang/"
# Look for devices
controller = usb.core.find( idVendor = control_vid, idProduct = control_pid )
mustang = usb.core.find( idVendor=mustang_vid, idProduct=mustang_pid )
if ( not controller ):
sys.exit( 0 )
mustang = False
for pid in mustang_pids:
device = usb.core.find( idVendor = mustang_vid, idProduct = pid )
if ( device ):
mustang = True
break
if ( not mustang ):
sys.exit( 0 )
pid = os.getpid()
# syslog.syslog( "%d: Starting" % pid )
# was it found?
if controller and mustang:
# Look for atomic pid file
os.chdir( rundir )
filelist = glob.glob( 'mustang_*' )
if len( filelist ) != 1:
syslog.syslog( "%d: /var/run/mustang is not properly setup" % pid )
sys.exit( 0 )
if len( filelist ) == 1:
# Found file. Parse out the PID of the process that created it.
lockfile = filelist[0]
oldpid = split( lockfile, '_' )[1]
@ -73,5 +81,3 @@ if controller and mustang:
os.setuid( pwObj.pw_uid )
os.execl( "/usr/local/bin/mustang_midi", "mustang_midi", "%s" % midi_device, "%s" % midi_channel )
else:
syslog.syslog( "%d: /var/run/mustang is not properly setup" % pid )