#!/bin/sh if [ $# -ne 2 ]; then echo 'usage: tlapse.g1 ' exit 0 fi function tidy_exit () { sync echo np=$(ls -1 tlapse.*.jpg | wc -l) pr=$[($a - $st + (($np - 1) / 2)) / ($np - 1)] sp=$(du -sc tlapse.*.jpg | grep -e total | tr '\t' ' ' | sed -e 's/ .*$//') ps=$[($sp + ($np / 2)) / $np] echo $np pictures taken, average $pr seconds apart and $ps Kbytes exit 0 } trap tidy_exit SIGINT trap tidy_exit SIGHUP brem=$(grep /proc/acpi/battery/BAT0/state -e remaining | sed -e 's/^.* \([0-9]\+\) .*$/\1/') cbs=$(gphoto2 --summary 2>&1 | grep -e 'Power status' | sed -e 's/^.*(//' | sed -e 's/)//') echo $(date), PC Battery = $brem, Camera $cbs i=1 n=$1 t=$2 b=$(date +%s) st=0 while [ $i -le $n ]; do gphoto2 --capture-preview > /tmp/gphoto.out 2>&1 if [ $? -ne 0 ]; then echo cat /tmp/gphoto.out break fi iz=000000$i il=$(expr length $iz) iz=$(expr substr $iz $[$il - 5] 6) mv canon_preview.jpg tlapse.$iz.jpg brem=$(grep /proc/acpi/battery/BAT0/state -e remaining | sed -e 's/^.* \([0-9]\+\) .*$/\1/') cbs=$(gphoto2 --summary 2>&1 | grep -e 'Power status' | sed -e 's/^.*(//' | sed -e 's/)//') a=$(date +%s) if [ $st -eq 0 ]; then st=$a oldbrem=$brem echo -e -n \\r$i - $(date), PC Battery = $brem, Camera $cbs else brate=$[($oldbrem - $brem) * 60 / ($a - $st)] if [ $brate -gt 0 ]; then ml=$[$brem / $brate] fi echo -e -n \\r$i - $(date), PC Battery = $brem "($brate/minute, $ml minutes left)", Camera $cbs fi i=$[$i + 1] if [ $t -gt $[$a - $b] -a $i -le $n ]; then echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor sleep $[$t - ($a - $b)] echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor fi b=$(date +%s) done tidy_exit