slitaz-arm view rpi/cgi-adm/plugins/rpi_cam/rpi_cam.cgi @ rev 136

rpi: add Camera support in CG admin interface :-)
author Christophe Lincoln <pankso@slitaz.org>
date Sat Apr 26 10:43:15 2014 +0200 (2014-04-26)
parents
children e785c2b0ea5a
line source
1 #!/bin/sh
2 #
3 # TazBerry CGI Plugin - Raspberry Pi Camera tools web interface
4 #
6 case " $(GET) " in
8 *\ rpi_cam\ *)
9 html_header "PiCam"
10 export PATH="/opt/vc/bin:/bin:/usr/bin"
11 export LD_LIBRARY_PATH="/opt/vc/lib"
12 camdir="/var/www/adm/cam"
13 mkdir -p ${camdir}
15 # CSS --> style.css
16 cat << EOT
17 <style type="text/css">
18 img { margin: 10px 0; }
19 </style>
20 EOT
21 # Wen need VC Tools
22 if [ ! -x "/opt/vc/bin/raspivid" ]; then
23 echo "<p>VideoCore tools are missing. Please use tazberry \
24 to setup the PiCam/NoIR</p>" && exit 0
25 fi
27 # raspivid + raspistill
28 case " $(GET rpi_cam) " in
29 *\ shot\ *)
30 notify "Executing raspistill..."
31 echo "$(GET options)" > ${camdir}/shot.opts
32 raspistill $(GET options) -o ${camdir}/shot.jpg
33 notify hide ;;
34 *\ rm_shot\ *)
35 rm -f ${camdir}/shot.jpg ;;
36 esac
38 # Get last used options
39 if [ -f "${camdir}/shot.opts" ]; then
40 shot_opts="$(cat ${camdir}/shot.opts)"
41 else
42 shot_opts="--width 480 --height 320"
43 fi
45 cat << EOT
46 <h1>Raspberry Pi Camera</h1>
48 <div id="actions">
49 <form method="get" action="$script">
50 <input type="hidden" name="rpi_cam" value="shot" />
51 <input type="submit" name="raspistill" value="Take a picture" />
52 <input type="text" name="options" value="$shot_opts" />
53 </form>
54 </div>
56 EOT
57 # Display last shot
58 if [ -f "${camdir}/shot.jpg" ]; then
59 cat << EOT
60 <h2>Latest shot</h2>
61 <div class='center'>
62 <a href="/adm/cam/shot.jpg"><img src='/adm/cam/shot.jpg' /></a>
63 <p><a href="$script?rpi_cam=rm_shot">Remove</a></p>
64 </div>
66 EOT
67 fi
68 html_footer && exit 0 ;;
69 esac