Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ memory [total|used|free] [gb|mb] displays the total memory of the devic
storage [total|used|free] [gb|mb|kb] displays the total storage of the device, the storage used as well as the available free storage
temperature [celsius|fahrenheit|kelvin] displays raspberry pi's CPU temperature
speedtest tests internet download and upload speed
camera [on|off|detect|capture|record] enables and disables camera, detects camera module version, captures photo, records video
camera [on|off|detect|capture|record] enables and disables camera, detects camera
[convert] <in file> <out file> module version, captures photo, records video,
and converts video and audio files
picture [file|url] displays a picture in the terminal
cron [list|add|delete|deleteall] adds, deletes a custom cron job or deletes, lists all cron jobs
[0W|tor|timestamp] adds premade cron job (or removes it if already active)
Expand All @@ -154,7 +156,6 @@ log <0|1|2|3|4|show|max> gets/sets log level and shows log
blocker <0|1|2|3|4||max> website blocking levels using /etc/hosts
sdbench displays read and write speed of micro SD card
inspire [fact|joke|qotd|random] displays quote based on user input
convert <input file> <output file> converts video and audio files
gpio displays raspberry pi model and corresponding GPIO ports
changelog [view|compare] displays the most recent changes to treehouses
magazines downloads specific magazine issue as a pdf based on user input
Expand Down
3 changes: 2 additions & 1 deletion _treehouses
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ treehouses button bluetooth
treehouses button off
treehouses camera
treehouses camera capture
treehouses camera convert
treehouses camera detect
treehouses camera off
treehouses camera on
treehouses camera record
treehouses changelog
treehouses changelog compare
treehouses changelog view
Expand All @@ -57,7 +59,6 @@ treehouses container
treehouses container balena
treehouses container docker
treehouses container none
treehouses convert
treehouses coralenv demo-always-on
treehouses coralenv demo-off
treehouses coralenv demo-on
Expand Down
49 changes: 45 additions & 4 deletions modules/camera.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function camera {
local directory timestamp config configtemp savetype
checkrpi
checkargn $# 2
checkargn $# 4
directory="/home/pi/Pictures/"
viddir="/home/pi/Videos/"
timestamp=$(date +"%Y%m%d-%H%M%S")
Expand All @@ -13,6 +13,7 @@ function camera {

case "$1" in
"")
checkargn $# 2
if grep -q "start_x=1" ${config} ; then
echo "Config file has Camera settings which are currently enabled. Use \"$BASENAME help camera\" for more commands."
else
Expand All @@ -21,6 +22,7 @@ function camera {
;;

"on")
checkargn $# 2
if ! grep -q "start_x=1" ${config} ; then
raspi-config nonint do_camera 0
echo "Camera settings have been enabled. A reboot is needed in order to use the camera."
Expand All @@ -34,6 +36,7 @@ function camera {
;;

"off")
checkargn $# 2
if grep -q "start_x=1" ${config} ; then
raspi-config nonint do_camera 1
echo "Camera has been disabled. A reboot is needed in order to use the camera."
Expand All @@ -46,6 +49,7 @@ function camera {
;;

"capture")
checkargn $# 2
mkdir -p ${directory}
if ! grep -q "start_x=1" ${config} ; then
log_and_exit1 "Error: you need to enable AND reboot first in order to take pictures."
Expand All @@ -55,7 +59,36 @@ function camera {
fi
;;

"convert")
local frames percent status
inputFile="$1"
outputFile="$2"
if [ -e "$inputFile" ] && [[ "$outputFile" != "" ]]; then
frames=$(ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 $inputFile)
if ! [[ $frames =~ ^[0-9]+$ ]]; then
frames=""
fi
while read -r line || { status=$line && break; }; do
if [ -z $frames ]; then
echo -ne "conversion running"\\r
else
percent=$(bc <<< "scale=2; ($line / $frames) * 100")
echo -ne " [$percent%] completed"\\r
fi
done < <(ffmpeg -y -i $inputFile $outputFile -loglevel error -hide_banner -max_error_rate 0.0 -progress - -nostats | grep -oP --line-buffered '(?<=frame=)[0-9]+'; printf "${PIPESTATUS[0]}")
# be careful not to delete line-buffered
if [ "$status" = 0 ]; then
echo "$inputFile has been successfully converted to $outputFile"
else
echo "conversion unsuccessful"
fi
else
log_and_exit1 "Error: invalid arguments"
fi
;;

"record")
checkargn $# 2
mkdir -p ${viddir}
if ! grep -q "start_x=1" ${config} ; then
log_and_exit1 "Error: you need to enable AND reboot first in order to take pictures."
Expand Down Expand Up @@ -84,6 +117,7 @@ function camera {
;;

"detect")
checkargn $# 2
mkdir -p ${directory}
if ! grep -q "start_x=1" ${config} ; then
log_and_exit1 "Error: you need to enable AND reboot first in order to take pictures."
Expand All @@ -96,7 +130,7 @@ function camera {
echo "Camera Module v1 detected."
rm ${directory}$BASENAME-${timestamp}.png
elif file ${directory}$BASENAME-${timestamp}.png | grep -q "2582 x 1933" ; then
echo "Coral Camera Module detected."
echo "Coral Camera Module detected."
rm ${directory}$BASENAME-${timestamp}.png
elif file ${directory}$BASENAME-${timestamp}.png | grep -q "3280 x 2464" ; then
echo "Camera Module v2 detected."
Expand All @@ -106,14 +140,15 @@ function camera {
rm ${directory}$BASENAME-${timestamp}.png
else
echo "Unknown Camera detected. Something went wrong!"
file ${directory}$BASENAME-${timestamp}.png
file ${directory}$BASENAME-${timestamp}.png
rm ${directory}$BASENAME-${timestamp}.png
fi
fi
fi
;;

*)
checkargn $# 2
echo "Error: The only supported options are 'on', 'off', 'detect, 'capture', and 'record'."
camera_help
;;
Expand All @@ -122,7 +157,7 @@ function camera {

function camera_help {
echo
echo "Usage: $BASENAME camera [on|off|detect|capture|record]"
echo "Usage: $BASENAME camera [on|off|detect|capture|convert|record]"
echo
echo "Example:"
echo " $BASENAME camera"
Expand All @@ -142,6 +177,12 @@ function camera_help {
echo " $BASENAME camera capture"
echo " Camera is capturing and storing a time-stamped photo in ${directory}."
echo
echo " $BASENAME camera convert <input file> <output file>"
echo
echo " Example:"
echo " $BASENAME convert video.mp4 video.mp3"
echo " convert video mp4 file to mp3 format"
echo
echo " $BASENAME camera record"
echo " Camera is recording ${length} seconds of video and storing a time-stamped ${vidtype} video in ${viddir}."
echo
Expand Down
38 changes: 0 additions & 38 deletions modules/convert.sh

This file was deleted.

5 changes: 3 additions & 2 deletions modules/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ memory [total|used|free] [gb|mb] displays the total memory of the devic
storage [total|used|free] [gb|mb|kb] displays the total storage of the device, the storage used as well as the available free storage
temperature [celsius|fahrenheit|kelvin] displays raspberry pi's CPU temperature
speedtest tests internet download and upload speed
camera [on|off|detect|capture|record] enables and disables camera, detects camera module version, captures photo, records video
camera [on|off|detect|capture|record] enables and disables camera, detects camera
[convert] <in file> <out file> module version, captures photo, records video,
and converts video and audio files
picture [file|url] displays a picture in the terminal
cron [list|add|delete|deleteall] adds, deletes a custom cron job or deletes, lists all cron jobs
[0W|tor|timestamp] adds premade cron job (or removes it if already active)
Expand All @@ -130,7 +132,6 @@ log <0|1|2|3|4|show|max> gets/sets log level and shows log
blocker <0|1|2|3|4||max> website blocking levels using /etc/hosts
sdbench displays read and write speed of micro SD card
inspire [fact|joke|qotd|random] displays quote based on user input
convert <input file> <output file> converts video and audio files
gpio displays raspberry pi model and corresponding GPIO ports
changelog [view|compare] displays the most recent changes to treehouses
magazines downloads specific magazine issue as a pdf based on user input
Expand Down