slitaz-arm view rpi/pileds @ rev 193
tazbian: typo
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Nov 15 23:50:51 2014 +0100 (2014-11-15) |
parents | 030fa11a61f2 |
children |
line source
1 #!/bin/sh
2 #
3 # PiLeds - Let's play with leds as a kid :-)
4 # (C) 2014 SliTaz GNU/Linux - BSD License
5 #
6 . /lib/libtaz.sh
7 check_root
9 usage() {
10 cat << EOT
12 $(boldify "Usage:") $(basename $0) [command] [--option]
14 $(boldify "Commands:")
15 act $(gettext "Turn on/off the on board ACT green led")
16 7-clock $(gettext "Adafruit 7-segment LED Backpack clock example")
17 8x8 $(gettext "Adafruit 8x8 LED Matrix Backpack example")
18 ada-clean $(gettext "Clean: Adafruit 7-segment or 8x8 Matrix")
20 $(boldify "8x8 Options:")
21 --test $(gettext "Test the 8x8 LED Matrix")
22 --boat $(gettext "Draw a tiny boat")
23 --smile $(gettext "Draw a smiley :-)")
24 --ovni $(gettext "Draw an OVNI")
26 EOT
27 }
29 load_modules() {
30 modprobe i2c-bcm2708
31 modprobe i2c-dev
32 }
34 check_packages() {
35 db="/var/lib/tazpkg/installed"
36 for pkg in i2c-tools $@; do
37 [ -f "$db/$pkg/receipt" ] || spk-add ${pkg}
38 done
39 }
41 adafruit_clean() {
42 python /usr/lib/python2.7/Adafruit_LEDBackpack.py
43 }
45 case "$1" in
47 act)
48 brightness="/sys/class/leds/led0/brightness"
49 status="$(cat $brightness)"
50 [ "$quiet" ] || gettext "Current status:"; echo " '$status'"
51 if [ "$status" == 0 ]; then
52 echo "0" > ${brightness}; usleep 50000
53 echo "1" > ${brightness}
54 else
55 echo "0" > ${brightness}
56 fi ;;
58 7-clock)
59 scripts="/usr/share/adafruit/LEDBackpack"
60 load_modules
61 check_packages "python-rpi-adafruit"
62 if [ -f "${scripts}/ex_7segment_clock.py" ]; then
63 python ${scripts}/ex_7segment_clock.py
64 else
65 gettext "Missing:"; echo " ${scripts}/ex_7segment_clock.py"
66 fi ;;
68 8x8)
69 if [ "$2" == "--test" ]|| [ ! "$2" ]; then
70 script="/usr/share/adafruit/LEDBackpack/ex_8x8_pixels.py"
71 check_packages "python-rpi-adafruit"
72 else
73 script_name="${2#--}.py"
74 script="/usr/share/piclass/code/leds/8x8/$script_name"
75 check_packages "python-rpi-adafruit piclass-code-examples"
76 fi
77 load_modules
78 if [ -f "${script}" ]; then
79 python ${script}
80 else
81 gettext "Missing script:"; echo " ${script}"
82 fi ;;
84 ada-clean)
85 adafruit_clean ;;
87 *) usage ;;
89 esac && exit 0