-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathrecording_trigger.sh
More file actions
executable file
·55 lines (44 loc) · 1.33 KB
/
recording_trigger.sh
File metadata and controls
executable file
·55 lines (44 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# This script reads the state of a hardcoded pin every set interval, and if the pin is read 'HIGH',
# a user-defined recording is launched. After the command is launched, the script exits.
# First the user lets us know whether to launch a preset or custom command
echo 'Please enter the recording command you wish to launch:'
echo 'If you instead want to read a preset command from a file, press key f and enter'
rec_cmd=
while [[ $rec_cmd = "" ]]; do
read rec_cmd
done
# Read command from a file if rec_cmd == f, otherwise store input as command
if [[ $rec_cmd = "f" ]]; then
rec_cmd=$(<preset_rec_cmd.txt)
echo "Running preset command upon triggering: "
echo $rec_cmd
else
echo "running this command upon triggering: "
echo $rec_cmd
fi
# Set desired input pin
echo "which pin would you like to read? (BCM numbering scheme) "
read input_pin
if [ ! -e /sys/class/gpio/gpio$input_pin ]; then
echo "$input_pin" > /sys/class/gpio/export
fi
echo "pin $input_pin is set as input pin"
#reading the input pin continuously, every interval
declare -i i
while [ 1 ]; do
status=$(< /sys/class/gpio/gpio$input_pin/value)
#echo $status
if [[ $status = "1" ]]; then
i+=1
fi
sleep 0.1 #seconds
if [[ $status != "1" && i>="1" ]]; then
i=0
fi
if [[ $i = "5" ]]; then
break
fi
done
#run commmand
$rec_cmd