[20100202]
|
Turn your ALIX into KITT (Updated)
Drop the following script into /etc/rc.d/alixkitt,
put "alixkitt=yes" into /etc/rc.conf and enjoy:
#!/bin/sh
# Turn ALIX2c front LEDs into running LED
# http://www.gifninja.com/Workspace/59f3f22e-5f40-4937-936c-1dc0d6fbe690/output.gif
#
# Copyright (c) 2010 Hubert Feyrer <hubertf@NetBSD.org>
# PROVIDE: alixkitt
$_rc_subr_loaded . /etc/rc.subr
name="alixkitt"
start_cmd="alixkitt_start"
stop_cmd="alixkitt_stop"
pidfile="/var/run/${name}.pid"
alixkitt_sleeptime=1.0 # 0.5
alixkitt_setled()
{
gpioctl -q -d /dev/gpio 6 $1
gpioctl -q -d /dev/gpio 25 $2
gpioctl -q -d /dev/gpio 27 $3
sleep $alixkitt_sleeptime
}
alixkitt_start()
{
touch $pidfile
(
alixkitt_setled 0 0 0
while [ -f $pidfile ] ; do
alixkitt_setled 0 1 1
alixkitt_setled 1 0 1
alixkitt_setled 1 1 0
alixkitt_setled 1 0 1
done
) &;
echo $! >$pidfile
echo Started pid $!
}
alixkitt_stop()
{
if [ -f /var/run/alixkitt.pid ]; then
read pid <$pidfile
echo Stopped pid $pid
kill $pid
rm $pidfile
alixkitt_setled 1 1 1
fi
exit 0
}
load_rc_config $name
run_rc_command "$1"
P.S.: There's still a bug left in that stopping immediately
re-starts the process. Got a patch?
Update:
Axel Scheepers suggested doing the while-loop only
as long as the PID-file exists. Changed above.
[Tags: alix, gpio, kitt]
|