Differences between version 6 and predecessor to the previous major change of HotPlugNotes.
Other diffs: Previous Revision, Previous Author, or view the Annotated Edit History
Newer page: | version 6 | Last edited on Thursday, September 8, 2005 6:38:35 pm | by MattBoyd | Revert |
Older page: | version 3 | Last edited on Tuesday, November 16, 2004 11:27:21 am | by JohnMcPherson | Revert |
@@ -1,5 +1,7 @@
This page has examples for using the HotPlug package.
+
+If you use [GNOME] 2.6 or later, you can install and run gnome-volume-manager, which can do things like run a program when a camera is plugged in, or mount a removable storage device when plugged in.
----
!!![USB]
!!"Usermap" files
@@ -10,16 +12,16 @@
The "fields_to_match" field is a bitfield - add 1 if you want to match against field1, add 2 if you also want to match against field2, add 4 to match against field3, etc. Only field1 and field2 are really necessary - they correspond to vendor_id and vendor_product_id respectively.
Here is my usb.usermap:
- --
+<verbatim>
# kodak dx3900 digital camera
usbcam 0x0003 0x040a 0x0170 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
# sony dsc p10 digital camera
usbcam 0x0003 0x054c 0x004e 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
# laser printer
brother_hl1440 0x0003 0x04f9 0x000d 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
- --
+</verbatim>
So, when a USB device with vendor ID of 40a and product ID of 170 is inserted, hotplug will run the script named "usbcam" in the /etc/hotplug/usb directory.
The 0x0003 tells hotplug to match this rule against only the vendor ID (1) + the product ID (2), ignoring all the other fields. These flags are defined in /etc/hotplug/usb.agent . You can determine the values for your device by looking at your system logs (eg run dmesg(8)) after inserting the [USB] device.
If you have the "usbutils" package installed, you could look in the file "/usr/share/misc/usb.ids" or run the "lsusb" command to get a description of connected USB devices.
@@ -27,21 +29,25 @@
See below for notes about the scripts.
! Notes about editing the usb.usermap file
In the version of hotplug in [Debian] [Woody], you should add your changes to /etc/hotplug/usb.usermap.local and then run
+<verbatim>
# update-usb.usermap
+</verbatim>
In more recent versions of hotplug, (such as Debian Testing/Unstable), create files named /etc/hotplug/usb/{foo}.usermap, for each script you have named foo.
!! USB scripts
Make sure these scripts are executable! Hotplug will set the following environment variables for use by the scripts:
+<verbatim>
ACTION {add, remove}
DEVICE {name of the usbdevfs device... for example /proc/bus/usb/001/003}
DEVFS
PRODUCT
INTERFACE
TYPE
+</verbatim>
See the /etc/hotplug/usb.agent script for more details.
Note that many of the script names in .../usb.distmap are actually module names.
@@ -50,24 +56,64 @@
''Note - you probably don't need to do this manually any more... most distributions probably do this for you. Eg Debian Sarge and Sid, and Ubuntu now (libgphoto2-2 ver 2.1.4-8, Nov 2004) have a script that lets people in the 'camera' group access the device'' -- JohnMcPherson
usb/usbcam:
- --
+<verbatim>
#!/bin/sh
# John - we need to make the usb device readable/writeable by normal
# users. Should be the same person as on console, but debian doesn't
# change /dev/console to the current user, so make it world +rw.
chmod a+rw "$DEVICE"
- --
+</verbatim>
I'm not entirely sure that this really needs to be done every time, but I have noticed that sometimes [CUPS] can't talk to the printer if it is powered on after boot. Also see [CUPSNotes] to see where this command line came from.
usb/brother_hl1440:
- --
+<verbatim>
#!/bin/sh
foomatic-configure -s cups -n Brother -c file:/dev/usb/lp0 -p Brother-HL-1440 \
- -d hl1250 -o !
PageSize=A4
- --
+ -d hl1250 -o PageSize=A4
+</verbatim>
+
+----
+! Disabling the touchpad when a USB mouse is added
+__1.__ I re-compiled the kernel so that PS/2 mouse support (psmouse.ko) is a module rather than compiled in.%%%
+__2.__ Get [UDev] to create a symlink for the PS/2 touchpad. Eg: Create /etc/udev/rules.d/mouse.rules:
+<verbatim>
+BUS="usb", KERNEL="mouse[-1]", NAME="input/%k" SYMLINK="input/usbmouse"
+# for psmouse (synaptic touchpad)
+KERNEL="mouse[-1]" NAME="input/%k" SYMLINK="input/touchpad"
+</verbatim>
+__3.__ get Xfree/Xorg to use /dev/input/mice as the core pointer, of type IMPS/2. All mice on the system send events via /dev/input/mice as well as each individual /dev/input/mouse<n> device. Add a secondary mouse that points to /dev/input/touchpad.%%%
+__4.__ Set up a hotplug script that disables the touchpad when a usb mouse is added. __Note!__ I had to comment out "usbmouse" from /etc/hotplug/blacklist otherwise hotplug ignores usb mouse events!
+/etc/hotplug/usb/usbmouse.usermap:
+<verbatim>
+# el cheapo optical usb scroll mouse:
+usbmouse 0x03 0x09da 0x0006 0 0 0 0 0 0 0 0
+</verbatim>
+
+/etc/hotplug/usb/usbmouse:
+<verbatim>
+#!/bin/sh
+
+# this removes the psmouse.ko kernel module for the touchpad when a
+# usb mouse is plugged in, and re-inserts the module when the usb mouse
+#is removed.
+
+if test "$ACTION" = "add" ; then
+ rmmod psmouse
+ if test -n "$REMOVER" ; then
+ # usb.agent sets this variable to point to an executable that
+ # will be run on remove, if it exists
+ ln -s "$" "$REMOVER"
+ fi
+elif test "$ACTION" = "remove" ; then
+ modprobe psmouse
+# else unknown action?
+fi
+
+</verbatim>
+I'm using kernel 2.6.12 and the module name is usbhid not usbmouse. I had the touchpad working already so all I needed to do was, comment out usbmouse from /etc/hotplug/blacklist and add the above script as /etc/hotplug/usb/usbhid then do a chmod +x /etc/hotplug/usb/usbhid.
!!![PCMCIA]/CardBus
By default, HotPlug in Debian (testing/unstable at least as of July 2004) won't automatically configure network interfaces.
@@ -76,12 +122,12 @@
default. This refers to which entries in /etc/network/interfaces should
be handled by hotplug.
My laptop's /etc/network/interfaces file includes the following lines:
- --
+<verbatim>
# use DHCP for the pccard network card
iface eth0 inet dhcp
# for the hotplug package
mapping hotplug
script echo
map eth0
- --
+</verbatim>