-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_pico_photometer.sh
69 lines (61 loc) · 2.47 KB
/
run_pico_photometer.sh
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# -*- coding: utf-8 -*-
# Copyright 2023 Julian Schwanbeck (schwan@umn.edu)
# ##Explanation
# This file starts the photometer.
# This file is part of pico_photometer. pico_photometer is free software: you can distribute it and/or modify
# it under the terms of the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version. pico_photometer is distributed in
# the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details. You should have received a copy of the GNU General Public License along with pico_photometer. If
# not, see <https://www.gnu.org/licenses/>.
# See:
# https://askubuntu.com/questions/519/how-do-i-write-a-shell-script-to-install-a-list-of-applications/956410#956410
set -eu -o pipefail
# Add time stamps if possible, print normally otherwise
if ! command -v ts &> /dev/null;
then
function ts {
cat < /dev/stdin
}
fi
# Set file path
if command -v realpath &> /dev/null;
then
# If possible, expand path
file_path=$(realpath $"$(dirname "$0")/pico_photometer.py")
else
# Hope that this works
file_path="./pico_photometer.py"
fi
# Test for mpremote installation
if ! command -v mpremote &> /dev/null;
then
echo "mpremote could not be found, please install it" | ts
echo "See: https://pypi.org/project/mpremote/" | ts
exit 1
fi
# Test if script is present
# echo "Checking Python script under $file_path" | ts
if ! test -f "$file_path";
then
echo "Python script not found: $file_path" | ts
echo "Downloading file now" | ts
wget -t -c --show-progress -O "$file_path" https://raw.githubusercontent.com/schwanbeck/pico_photometer/master/pico_photometer.py
echo "Check correct settings in script: " "$file_path" | ts
echo "Aborting." | ts
exit 1
fi
# Check if device can be connected
if ! mpremote disconnect | ts;
then
echo "Could not connect to a device, aborting." | ts
exit 1
fi
echo "Starting mpremote, disconnecting & connecting (auto: first available pico) to reset pico,
mounting local folder and running ./pico_photometer.py" | ts
# further arguments: setrtc - sets the clock, currently buggy (20230524)
# See: https://github.com/orgs/micropython/discussions/9096#discussioncomment-5785470
# mpremote disconnect auto reset rtc --set rtc | ts
exec mpremote disconnect connect auto setrtc mount . run "$file_path" | ts