31 lines
1.1 KiB
Bash
Executable File
31 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
|
|
echo "Building..."
|
|
SRC_DIR="$SCRIPT_DIR/src"
|
|
TMP_DIR=$(mktemp -d)
|
|
find "$SRC_DIR" -name '*.py' | while read -r FILE
|
|
do
|
|
REL_PATH="${FILE#"$SRC_DIR"/}"
|
|
OUT_DIR="$TMP_DIR/$(dirname "$REL_PATH")"
|
|
BASE_NAME=$(basename "$FILE")
|
|
mkdir -p "$OUT_DIR"
|
|
"$SCRIPT_DIR/mpy-cross" "$FILE" -o "$OUT_DIR/${BASE_NAME%.py}.mpy"
|
|
done
|
|
rm "$TMP_DIR/main.mpy"
|
|
cp "$SRC_DIR/main.py" "$TMP_DIR"
|
|
|
|
echo "Erasing files..."
|
|
"$SCRIPT_DIR"/venv/bin/ampy --port /dev/ttyUSB0 rmdir /lib
|
|
|
|
echo "Uploading..."
|
|
"$SCRIPT_DIR"/venv/bin/ampy --port /dev/ttyUSB0 put "$TMP_DIR" /
|
|
"$SCRIPT_DIR"/venv/bin/ampy --port /dev/ttyUSB0 rm /config.sample.mpy
|
|
rm -rf "$TMP_DIR"
|
|
|
|
echo "Resetting..."
|
|
"$SCRIPT_DIR"/venv/bin/ampy --port /dev/ttyUSB0 run --no-output "$SCRIPT_DIR/src/reset.py"
|
|
|
|
# Uploading can take a while so make a sound when it's done
|
|
# https://unix.stackexchange.com/questions/1974/how-do-i-make-my-pc-speaker-beep/163716#163716
|
|
( speaker-test -t sine -f 1000 > /dev/null )& pid=$! ; sleep 0.1s ; kill -9 $pid |