From: <sk...@us...> - 2011-03-09 16:54:37
|
Revision: 2406 http://linuxconsole.svn.sourceforge.net/linuxconsole/?rev=2406&view=rev Author: skitt Date: 2011-03-09 16:54:30 +0000 (Wed, 09 Mar 2011) Log Message: ----------- Add jscal-store/restore, and provide an installation target in the Makefile. Modified Paths: -------------- trunk/utils/Makefile Added Paths: ----------- trunk/utils/extract trunk/utils/filter trunk/utils/ident trunk/utils/jscal-restore.in trunk/utils/jscal-store.in Modified: trunk/utils/Makefile =================================================================== --- trunk/utils/Makefile 2011-03-06 21:07:05 UTC (rev 2405) +++ trunk/utils/Makefile 2011-03-09 16:54:30 UTC (rev 2406) @@ -33,8 +33,10 @@ CFLAGS = -g -O2 -Wall -I../linux/include PROGRAMS = evtest inputattach jstest jscal fftest ffmvforce ffset \ - ffcfstress # acceltest + ffcfstress jscal-restore jscal-store # acceltest +PREFIX ?= /usr/local + compile: $(PROGRAMS) clean: @@ -65,3 +67,16 @@ acceltest: acceltest.c $(CC) $(CFLAGS) $(CPPFLAGS) $^ -lm -o $@ + +jscal-restore: jscal-restore.in + sed "s^@@PREFIX@@^$(PREFIX)^g" < $^ > $@ + +jscal-store: jscal-store.in + sed "s^@@PREFIX@@^$(PREFIX)^g" < $^ > $@ + +install: compile + install $(PROGRAMS) $(DESTDIR)$(PREFIX)/bin + install -d $(DESTDIR)$(PREFIX)/share/joystick + install extract filter ident $(DESTDIR)$(PREFIX)/share/joystick + +.PHONY: compile clean install Added: trunk/utils/extract =================================================================== --- trunk/utils/extract (rev 0) +++ trunk/utils/extract 2011-03-09 16:54:30 UTC (rev 2406) @@ -0,0 +1,56 @@ +#!/usr/bin/awk -f + +# Extracts the settings for a given joystick from the joystick +# parameter file, matching the contents of the kernel, name, serial, +# vendor and product variables (typically specified on the command +# line), repectively kernel device, joystick name, joystick serial +# number, USB vendor code, USB product code. +# The exit code is 0 if a section was found, 1 otherwise. If multiple +# sections match, only the first is kept. + +BEGIN { + FS = "\""; + seckernel = ""; + secname = ""; + secserial = ""; + secvendor = ""; + secproduct = ""; +} + +/^DEVICE=/ { + seckernel = $2; +} + +/^NAME=/ { + secname = $2; +} + +/^SERIAL=/ { + secserial = $2; +} + +/^VENDOR=/ { + secvendor = $2; +} + +/^PRODUCT/ { + secproduct = $2; +} + +/(^js)|(^$)/ { + # Command or empty line, ends the match criteria for a given + # section + if ((kernel == "" || seckernel == kernel) && + (name == "" || secname == name) && + (serial == "" || secserial == serial) && + (vendor == "" || secvendor == vendor) && + (product == "" || secproduct == product)) { + # The section matches, output the command or exit if we've + # reached the end of the section + if ($0 ~ /^js/) { + print $0; + } else { + exit 0; + } + } +} Property changes on: trunk/utils/extract ___________________________________________________________________ Added: svn:executable + * Added: trunk/utils/filter =================================================================== --- trunk/utils/filter (rev 0) +++ trunk/utils/filter 2011-03-09 16:54:30 UTC (rev 2406) @@ -0,0 +1,79 @@ +#!/usr/bin/awk -f + +# Filters the joystick parameter file, keeping everything but sections +# matching the contents of the kernel, name, serial, vendor and +# product variables (typically specified on the command line), +# repectively kernel device, joystick name, joystick serial number, +# USB vendor code, USB product code. + +BEGIN { + FS = "\""; + seckernel = ""; + secname = ""; + secserial = ""; + secvendor = ""; + secproduct = ""; + secoutput = 0; +} + +/^DEVICE=/ { + seckernel = $2; +} + +/^NAME=/ { + secname = $2; +} + +/^SERIAL=/ { + secserial = $2; +} + +/^VENDOR=/ { + secvendor = $2; +} + +/^PRODUCT/ { + secproduct = $2; +} + +/(^js)|(^$)/ { + # Command or empty line, ends the match criteria for a given + # section + if ((kernel == "" || seckernel == kernel) && + (name == "" || secname == name) && + (serial == "" || secserial == serial) && + (vendor == "" || secvendor == vendor) && + (product == "" || secproduct == product)) { + # The section matches, skip it + } else { + # The section doesn't match, output it + if (secoutput == 0) { + if (seckernel != "") { + print "DEVICE=\"" seckernel "\""; + } + if (secname != "") { + print "NAME=\"" secname "\""; + } + if (secserial != "") { + print "SERIAL=\"" secserial "\""; + } + if (secvendor != "") { + print "VENDOR=\"" secvendor "\""; + } + if (secproduct != "") { + print "PRODUCT=\"" secproduct "\""; + } + secoutput = 1; + } + print $0; + if ($0 ~ /$^/) { + # New section, clear the section information + secoutput = 0; + seckernel = ""; + secname = ""; + secserial = ""; + secvendor = ""; + secproduct = ""; + } + } +} Property changes on: trunk/utils/filter ___________________________________________________________________ Added: svn:executable + * Added: trunk/utils/ident =================================================================== --- trunk/utils/ident (rev 0) +++ trunk/utils/ident 2011-03-09 16:54:30 UTC (rev 2406) @@ -0,0 +1,70 @@ +#!/usr/bin/awk -f + +BEGIN { + FS = "\""; + kernel = ""; + name = ""; + serial = ""; + vendor = ""; + product = ""; + seckernel = ""; + secname = ""; + secserial = ""; + secvendor = ""; + secproduct = ""; +} + +/KERNEL==/ { + kernel = $2; +} + +/KERNELS==/ { + seckernel = $2; +} + +/ATTRS{name}/ { + secname = $2; +} + +/ATTRS{serial}/ { + secserial = $2; +} + +/ATTRS{idVendor}/ { + secvendor = $2; +} + +/ATTRS{idProduct}/ { + secproduct = $2; +} + +/$^/ { + # New section, check the values remembered from the previous + # If the section defined a name, and we don't have one, and the + # section described an input device, store the name and serial + if (match(seckernel, "input") != 0 && secname != "" && name == "") { + name = secname; + serial = secserial; + } + # If the section defined a vendor (for USB devices), and we don't + # have one, store the vendor and product + if (secvendor != "" && vendor == "") { + vendor = secvendor; + product = secproduct; + } + + # Clear all section values before processing next section + seckernel = ""; + secname = ""; + secserial = ""; + secvendor = ""; + secproduct = ""; +} + +END { + print "DEVICE=\"" kernel "\""; + print "NAME=\"" name "\""; + print "SERIAL=\"" serial "\""; + print "VENDOR=\"" vendor "\""; + print "PRODUCT=\"" product "\""; +} Property changes on: trunk/utils/ident ___________________________________________________________________ Added: svn:executable + * Added: trunk/utils/jscal-restore.in =================================================================== --- trunk/utils/jscal-restore.in (rev 0) +++ trunk/utils/jscal-restore.in 2011-03-09 16:54:30 UTC (rev 2406) @@ -0,0 +1,33 @@ +#!/bin/sh + +if [ ! -x /sbin/udevadm ]; then + echo Restoring joystick configuration requires udev! >&2 +fi + +ident=$(mktemp) +/sbin/udevadm info -a -n $1 | @@PREFIX@@/share/joystick/ident > $ident +. $ident +rm -f $ident + +STORE=/var/lib/joystick/joystick.state + +# Retrieve the applicable commands +commands=$(mktemp) +if [ -f $STORE ]; then + if [ -z "$NAME" ] && [ -z "$VENDOR" ]; then + # Use the device name only + @@PREFIX@@/share/joystick/extract kernel="$DEVICE" < $STORE > $commands + else + @@PREFIX@@/share/joystick/extract name="$NAME" serial="$SERIAL" vendor="$VENDOR" product="$PRODUCT" < $STORE > $commands + fi +fi + +# Run the commands if any +if [ -f $commands ] && [ ! -z "$(cat $commands)" ]; then + while read command; do + $command $1 + done < $commands +fi + +# Delete the generated file +rm -f $commands Property changes on: trunk/utils/jscal-restore.in ___________________________________________________________________ Added: svn:executable + * Added: trunk/utils/jscal-store.in =================================================================== --- trunk/utils/jscal-store.in (rev 0) +++ trunk/utils/jscal-store.in 2011-03-09 16:54:30 UTC (rev 2406) @@ -0,0 +1,63 @@ +#!/bin/sh + +# Stores the current calibration settings for the given joystick +# (materialized by its device). The calibration settings are stored +# using the joystick's name and serial number if available, and its +# vendor and product codes if it's a USB device. If none of these can +# be determined, the settings are stored against the device name. + +if [ -z "$1" ]; then + echo "Usage: $0 {device}" + echo "Stores the device's calibration for future use." + exit 1 +fi + +if [ ! -x /sbin/udevadm ]; then + echo Storing joystick configuration requires udev! >&2 +fi + +ident=$(mktemp) +/sbin/udevadm info -a -n $1 | @@PREFIX@@/share/joystick/ident > $ident +. $ident +rm $ident + +STORE=/var/lib/joystick/joystick.state + +# Filter the existing file +if [ -f $STORE ]; then + if [ -z "$NAME" ] && [ -z "$VENDOR" ]; then + echo "No product name or vendor available, calibration will be stored for the" + echo "given device name ($DEVICE) only!" + @@PREFIX@@/share/joystick/filter kernel="$DEVICE" < $STORE > $STORE.new + else + @@PREFIX@@/share/joystick/filter name="$NAME" serial="$SERIAL" vendor="$VENDOR" product="$PRODUCT" < $STORE > $STORE.new + fi +fi + +# Append the new calibration information +if [ -f $STORE.new ] && [ ! -z "$(cat $STORE.new)" ]; then + echo >> $STORE.new +fi +if [ -z "$NAME" ] && [ -z "$VENDOR" ]; then + echo "DEVICE=\"$DEVICE\"" >> $STORE.new +fi +if [ ! -z "$NAME" ]; then + echo "NAME=\"$NAME\"" >> $STORE.new +fi +if [ ! -z "$SERIAL" ]; then + echo "SERIAL=\"$SERIAL\"" >> $STORE.new +fi +if [ ! -z "$VENDOR" ]; then + echo "VENDOR=\"$VENDOR\"" >> $STORE.new +fi +if [ ! -z "$PRODUCT" ]; then + echo "PRODUCT=\"$PRODUCT\"" >> $STORE.new +fi +jscal -p $1 | cut -d' ' -f-3 >> $STORE.new +jscal -q $1 | cut -d' ' -f-3 >> $STORE.new + +if [ -f $STORE ]; then + mv $STORE $STORE.old +fi +mv $STORE.new $STORE +rm -f $STORE.old Property changes on: trunk/utils/jscal-store.in ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |