Category: Linux
New Toy for the Defender
....okay it's a pretty ancient toy but new to me. After the screen on my omibook500 froze (and I mean FROZE in the non I.T sense) when it got wet in the truck during the winter I was left without a carpc to use.
Hadn't noticed before but ToughBook prices for old low spec models are really cheap. I think a ToughBook is just the ticket for life in harsh careless life the Landrover.
It's a ToughBook CF-27 MKII. PII 300Mhz processor. 256MB RAM and a 100Gb HDD (which I added myself after digging out the 6GB it came with). Unfortunately its not fitted with a touchscreen like some are.
I chemically stripped back the lid to bare magnesium alloy as that's the way I like it. I fitted a low profile thumbnail bluetooth dongle but had cut the rear cover to accommodate it. I will reseal this over with a moulded bump. The BT is for the Holux BT GPS I use. WIFI is via an old PCMCIA card. There is an internal GSM modem but haven't investigate that yet.
I reluctantly set the machine up with Windows XP (a barebones release) so that I could use the HAM radio software I have which are difficult to emulate under Linux on a low spec machine. MemoryMap OS5 is installed along with the entire UK's 50k and 25k maps. The only other stuff I need to store on there is the landrover workshop manuals.
Anyhows... will see how long it lasts.
Take photo with laptop webcam when lid is opened
Recent news reports of a school in the USA causing controversy with its pupil issued laptops being used to spy on them. Made me think that taking a snap image when laptop lid is opened could be a cool pseudo security feature to catch if a snooper uses a laptop without permission. Would at least be a use for an otherwise unused laptop camera. How to do it though?
Brief search of the web turned up a howto for making the computer play a different sound for opening and closing the lid, something easily adapted to my needs.
To take the photo I used a command-line application called fswebcam which can be installed through the Synaptic Package Manager. fswebcam is a neat and simple webcam application with several useful configuration options. Once installed you can take snapshots with the example command:
fswebcam --no-banner --delay 1 -save ~/Desktop/%Y%m%d%H%M%S.jpeg
The above example is configured to turn off the overlay banner in the photo, delays the camera by 1sec before taking a photo (to make sure light is adjusted etc) and saves the jpeg image file to the desktop with a time/date stamp. Using a time stamp like this allows multiply files to be saved instead of over writing the same file each time which would be useless.
Now that photos can be successively taken the next thing to do is set up the system (I'm using Ubuntu 9.10 64bit) to take a shot whenever the lid is opened. This is where the "Advanced Configuration and Power Interface" (ACPI) is employed.
ACPI has a file called lid.sh which is located in Ubuntu under /etc/acpi, this script is run whenever the lid of the laptop is opened or closed. Opening this script file (sudo gedit /etc/acpi/lid.sh) in a text editor will show what commands are run when lid is opened or closed.
I added the following commands near the top of the file.
test -f /usr/share/acpi-support/state-funcs || exit 0
# take camera shot when lid opens
grep -q closed /proc/acpi/button/lid/LID/state
if [ $? != 0 ]
then
fswebcam --delay 1 --no-banner -save /home/yourusername/Pictures/LID_OPEN_CAPTURES/%Y%m%d%H%M%S.jpeg
fi
The command that grabs information about the state of the lid is the line:
grep ?q closed /proc/acpi/button/lid/LID/state
This line is followed by an if statement. This statement is used to discover if the lid has been opened or closed. So if [ $? != 0 ] (if not zero) means the lid has been opened so then do the following command...
fswebcam --delay 1 --no-banner -save /home/yourusername/Pictures/LID_OPEN_CAPTURES/%Y%m%d%H%M%S.jpeg
Which is the one that tells fswebcam to take the photo. Note because this script is run by the system (root) we have to use the full path of where to store the photos instead of the ~/ home short cut. (least that is the way I got it to work with my limited linux understanding).
The rest of the lid.sh script is left as is. Once saved it should be ready to work. Close the lid, open lid and camera LED will briefly light and the photo should be stored in the specified folder. That's it!
fswebcam can be configured to run further commands so it could in theory be used to trigger for example an ftp script which uploads the photo to a webserver, send as an email or sms alert to a phone etc.





12/05/10 08:57:29 pm, 