[BRLTTY] Contrib: Brltty and usb-serial hotplugging
Rudolf Weeber
rudolf at faveve.uni-stuttgart.de
Wed Jul 13 05:41:52 EDT 2005
Hi,
I figured out, how to set up hotplug to automatically load and kill
brltty with a brailledisplay, that is attached via a usb-serial adapter.
May be, that would be something for the util-section of the next
Brltty distribution...
Attached to this mail is a shell script, that creates the config files
(you don't need any software apart from hotplug),
and documentation, that describes, how the hotplugging works, and what
the script does.
I appreciate any comments!
Greetings,
Rudolf
--
Quantum mechanics - The dreams stuff is made of.
Rudolf Weeber
Mühlrain 9
70180 Stuttgart
Tel: 0711 62009381
Mobil: 0172 7136893
-------------- next part --------------
Using Brltty with an usb-serial adapter and hotplug
Introduction
------------
Many notebooks don't have serial ports anymore, so you have to attach your braille terminal with a usb-serial-adapter.
The hotplug-daemon has the task of loading and unloading drivers for usb devices, when they are plugged in or removed.
Hotplug can also be persuaded to load and kill brltty automatically.
This document describes, how to do that.
Quick start
-----------
If you aren't interested in the technical details, you can do this:
* Plug in your usb-serial adapter
* become root
* lsmod|grep usbserial
In the right-most column you can see, what modules are using the usbserial module. This is the module, your usb-serial adapter uses.
Example:
usbserial 33392 3 pl2303
so the module is pl2303
Now, that you now the module, you can run the install script
./install-brltty-usbserial <MODULENAME>
This script generates the two required config files in /etc/hotplug/usb
If all goes well, brltty is loaed, when the usb-serial-adapter is plugged in, and killed, when it is removed.
Detailed description
--------------------
When a usb device is plugged in, hotplug looks in /etc/hotplug/usb/*.usermap
to see, if there is a script for this device. (Each usb-device has a vendor and product number by which it can be identified).
The format of this file is the same as that of /lib/modules/<KERNELVERSION>/modules.usbmap, except, that the first column contains the name of a script to be run instead of the module name. (The good thing is, you don't need to know details!)
We call the script like the module, so we can just grep through the modules.usbmap to get the lines for the hotplug .usermap file.
Example for the module pl2303:
grep pl2303 /lib/modules/2.6.12/modules.usbmap >/etc/hotplug/usb/pl2303.usermap
Thats exactly what the intall script does first.
Now we have to create the script, that is run, when the deivce is plugged in
/etc/hotplug/usb/<MODULENAME>
#!/bin/bash
if [ "$ACTION" = "add" ]
then
killall brltty # in case, one is running
sleep .3 # Give it enough time to close everything
brltty
# Create the script, that will kill brltty, when interface is removed
echo killall brltty > $REMOVER
chmod +x $REMOVER
fi
The $ACTION and $REMOVER variable are provided by hotplug. REMOVER is a script, that is called, when the device is removed, and before hotplug unloads the module. On my system, the remover goes to /var/run/usb. But you don't have to care about it. Hotplug does that for you.
Don't forget to make the /etc/hotplug/usb/pl2303 executable.
That's it.
Have fun!
rudolf.weeber at gmx.de 2005-07-13
-------------- next part --------------
#!/bin/bash
if [ "$1" = "" ]
then
echo Please give the module name of your usb-serial-interface as argument!
exit 1
fi
if [ -d /etc/hotplug/usb ]
then
echo Found directory /etc/hotplug/usb
else
echo /etc/hotplug/usb does not exist
fi
echo Creating /etc/hotplug/usb/$1.usermap. This file contains the Device-Ids
echo of your adapter.
grep $1 /lib/modules/`uname -r`/modules.usbmap > /etc/hotplug/usb/$1.usermap|| exit 1
echo Creating the setup script /etc/hotplug/usb/$1
cat >/etc/hotplug/usb/$1 <<END
#!/bin/bash
if [ "\$ACTION" = "add" ]
then
killall brltty # in case, one is running
sleep .3 # Give it enough time to close everything
brltty
# Create the script, that will kill brltty, when interface is removed
echo killall brltty > \$REMOVER
chmod +x \$REMOVER
fi
END
chmod +x /etc/hotplug/usb/$1
echo If you are lucky, everything works now
More information about the BRLTTY
mailing list