PCB lives now in its own git repo https://git.la10cy.net/DeltaLima/CanGrow-12V-PCB
167 lines
5.7 KiB
Bash
Executable file
167 lines
5.7 KiB
Bash
Executable file
#!/bin/bash
|
|
#
|
|
|
|
test -z $TTY && TTY="/dev/ttyUSB0"
|
|
test -z $IP && IP="192.168.4.20"
|
|
test -z $VER && VER="$(grep "define CANGROW_VER" include/CanGrow.h | cut -d \" -f2 |sed -e 's/\"//g')" #VER="0.2-dev"
|
|
test -z $BOARD && BOARD="esp8266:esp8266:d1_mini_clone"
|
|
#test -z $BOARD && BOARD="esp32:esp32:d1_mini32"
|
|
|
|
BUILD="$(git rev-parse --short HEAD)-$(echo $BOARD | cut -d : -f1)_$(echo $BOARD | cut -d : -f3)-$(date '+%Y%m%d%H%M%S')"
|
|
|
|
# arduino-cli path and version
|
|
ACLI="$HOME/.local/bin/arduino-cli"
|
|
ACLI_VER="1.2.0"
|
|
ACLI_CMD="$ACLI --config-file arduino-cli.yml"
|
|
test -z $BUILDDIR && BUILDDIR="build"
|
|
|
|
|
|
function help() {
|
|
echo "$0 [setup|build|upload|webupload|monitor]"
|
|
echo "setup: setup build environment, download arduino-cli, install all dependencies for arduino ide"
|
|
echo "build: build firmware binary. will be saved into ${BUILDDIR}/"
|
|
echo "upload: upload firmware by serial connection $TTY"
|
|
echo "webupload: upload firmware with webupload to $IP"
|
|
echo "monitor: serial monitor $TTY"
|
|
exit 1
|
|
}
|
|
|
|
function check_acli() {
|
|
if [ ! -x $ACLI ]
|
|
then
|
|
echo "$ACLI does not exist nor is executable. Please run '$0 setup' first"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
test -z $1 && help
|
|
|
|
case $1 in
|
|
s|setup)
|
|
ACLI_DIR="$(dirname $ACLI)"
|
|
ALIB_DIR="${HOME}/Arduino/libraries/"
|
|
declare -a CORES=(
|
|
"esp8266:esp8266@3.1.2"
|
|
"esp32:esp32@3.0.7"
|
|
)
|
|
declare -a LIBS=(
|
|
"Adafruit SSD1306@2.5.12"
|
|
"Adafruit BME280 Library@2.2.4"
|
|
"ArduinoJson@7.3.0"
|
|
"NTPClient@3.2.1"
|
|
"Time@1.6.1"
|
|
"ESP Async WebServer@3.6.0"
|
|
"Async TCP@3.3.2"
|
|
"Nusabot Simple Timer@1.0.0"
|
|
"ArduinoLog@1.1.1"
|
|
"RTClib@2.1.4"
|
|
"Adafruit BME680 Library@2.0.5"
|
|
"Adafruit ADS1X15@2.5.0"
|
|
"Adafruit SHT31 Library@2.2.2"
|
|
"Adafruit MCP4725@2.0.2"
|
|
"Adafruit TCS34725@1.4.4"
|
|
"Adafruit MLX90614 Library@2.1.5"
|
|
"I2CSoilMoistureSensor@1.1.4"
|
|
"DFRobot_GP8XXX@1.0.1"
|
|
"Adafruit CCS811 Library@1.1.3"
|
|
)
|
|
|
|
echo ":: Setting up build environment for CanGrow Firmware."
|
|
echo " This will download the binary for arduino-cli and install"
|
|
echo " the packages for the arduino ide from the debian repository."
|
|
echo " !! This script is meant to be executed on a Debian stable (bookworm) system !!"
|
|
echo ""
|
|
echo ":: Press Enter to continue"
|
|
read
|
|
echo ""
|
|
echo ":: Installing Arduino IDE packages with apt, please enter sudo password:"
|
|
sudo apt update || exit 1
|
|
sudo apt install arduino python3 python3-serial wget curl xxd || exit 1
|
|
echo ":: Ensure directory ${ACLI_DIR} is present"
|
|
test -d ${ACLI_DIR} || mkdir -p ${ACLI_DIR}
|
|
echo ":: Please ensure ${ACLI_DIR} is in your \$PATH, I wont do it."
|
|
echo ""
|
|
echo ":: Downloading arduino-cli ${ACLI_VER} into ${ACLI_DIR}/"
|
|
wget -O - "https://github.com/arduino/arduino-cli/releases/download/v${ACLI_VER}/arduino-cli_${ACLI_VER}_Linux_64bit.tar.gz" | tar -C ${ACLI_DIR} -zxvf - arduino-cli
|
|
chmod +x ${ACLI}
|
|
echo ""
|
|
echo ":: Installing ESP8266 and ESP32 cores for Arduino"
|
|
for core in ${!CORES[@]}
|
|
do
|
|
${ACLI_CMD} core install ${CORES[$core]}
|
|
done
|
|
echo ":: Installing Arduino libraries"
|
|
${ACLI_CMD} lib update-index || exit 1
|
|
for lib in ${!LIBS[@]}
|
|
do
|
|
echo " - ${LIBS[$lib]}"
|
|
done
|
|
|
|
for lib in ${!LIBS[@]}
|
|
do
|
|
${ACLI_CMD} lib install "${LIBS[$lib]}" || exit 1
|
|
done
|
|
echo ""
|
|
|
|
echo ":: fetching ESPAsyncTCP-esphome from GIT"
|
|
wget -q https://github.com/mathieucarbou/esphome-ESPAsyncTCP/archive/refs/tags/v2.0.0.tar.gz -O - | tar -xzf - -C $ALIB_DIR
|
|
mv $ALIB_DIR/esphome-ESPAsyncTCP-2.0.0 $ALIB_DIR/ESPAsyncTCP-esphome
|
|
echo ":: Patching ArduinoLog (https://github.com/thijse/Arduino-Log/pull/28/commits/57d350a25428376935b793a2138210320cf3801c)"
|
|
sed -i -e 's/register//g' $ALIB_DIR/ArduinoLog/ArduinoLog.cpp
|
|
|
|
echo ":: Setup build environment done! You can now build the firmware"
|
|
echo " with: $0 build"
|
|
|
|
;;
|
|
b|build)
|
|
check_acli
|
|
ACLI_CMD="${ACLI_CMD} --output-dir ${BUILDDIR}"
|
|
echo ":: Building firmware $VER $BUILD, target dir: ${BUILDDIR}/"
|
|
|
|
test -d ${BUILDDIR} || mkdir ${BUILDDIR}
|
|
|
|
|
|
# esp8266 and esp32 compiler have to use different compile flags for VER and BUILD
|
|
if [ "$(echo $BOARD | cut -d : -f1)" == "esp8266" ]
|
|
then
|
|
${ACLI_CMD} --no-color compile -b ${BOARD} --build-property "build.extra_flags=-DCANGROW_VER=\"${VER}\" -DCANGROW_BUILD=\"${BUILD}\"" "CanGrow.ino" || exit 1
|
|
elif [ "$(echo $BOARD | cut -d : -f1)" == "esp32" ]
|
|
then
|
|
${ACLI_CMD} --no-color compile -b ${BOARD} --build-property "build.defines=-DCANGROW_VER=\"${VER}\" -DCANGROW_BUILD=\"${BUILD}\"" "CanGrow.ino" || exit 1
|
|
fi
|
|
|
|
cp ${BUILDDIR}/CanGrow.ino.bin ${BUILDDIR}/CanGrow_v${VER}_${BUILD}.bin
|
|
;;
|
|
u|upload)
|
|
check_acli
|
|
echo ":: Build and upload firmware $VER $BUILD to $TTY"
|
|
|
|
test -d build || mkdir build
|
|
|
|
# esp8266 and esp32 compiler have to use different compile flags for VER and BUILD
|
|
if [ "$(echo $BOARD | cut -d : -f1)" == "esp8266" ]
|
|
then
|
|
${ACLI_CMD} --no-color compile -b ${BOARD} --build-property "build.extra_flags=-DCANGROW_VER=\"${VER}\" -DCANGROW_BUILD=\"${BUILD}\"" ${ACLI_BUILD_OPTS} -u -p $TTY "CanGrow.ino"
|
|
elif [ "$(echo $BOARD | cut -d : -f1)" == "esp32" ]
|
|
then
|
|
${ACLI_CMD} --no-color compile -b ${BOARD} --build-property "build.defines=-DCANGROW_VER=\"${VER}\" -DCANGROW_BUILD=\"${BUILD}\"" ${ACLI_BUILD_OPTS} -u -p $TTY "CanGrow.ino"
|
|
fi
|
|
|
|
;;
|
|
w|webupload)
|
|
test -z "$2" && UPLOAD_FILE="${BUILDDIR}/CanGrow.ino.bin"
|
|
test -n "$2" && UPLOAD_FILE="$2"
|
|
|
|
echo ":: Uploading $UPLOAD_FILE to $IP"
|
|
curl -v http://$IP/system/update -X POST -H 'Content-Type: multipart/form-data' -F "firmware=@${UPLOAD_FILE}"
|
|
echo
|
|
;;
|
|
m|mon|monitor)
|
|
check_acli
|
|
echo ":: Open serial monitor $TTY"
|
|
${ACLI_CMD} monitor -c baudrate=115200 -b ${BOARD} -p $TTY
|
|
;;
|
|
*)
|
|
help
|
|
;;
|
|
esac
|