Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hard-coded upload port #43 #44

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
60 changes: 37 additions & 23 deletions run_arduino.sh
Original file line number Diff line number Diff line change
@@ -1,45 +1,59 @@
#!/bin/bash

#TODO: script should have format ./run.sh build|upload] mcu_type arduino_folder
# with mcu_type and arduino_folder optional

# Check if ROS is running
ROS_RUNNING=$(ps aux | grep -c "[r]osmaster")

COMMAND=$1
PROJECT=$2
# Stop ROS when uploading new code
STOPPED_ROS=false
if [[ $1 == upload* ]] && [[ $ROS_RUNNING == "1" ]]; then # test for any upload... command
if [[ $COMMAND == upload* ]] && [[ $ROS_RUNNING == "1" ]]; then # test for any upload... command
echo "STOPPING ROS"
sudo service mirte-ros stop || /bin/true
STOPPED_ROS=true
fi

# Different build scripts
if test "$1" == "build"; then
arduino-cli -v compile --fqbn STM32:stm32:GenF1:pnum=BLUEPILL_F103C8,upload_method=dfu2Method,xserial=generic,usb=CDCgen,xusb=FS,opt=osstd,rtlib=nano /home/mirte/arduino_project/$2
if test "$COMMAND" == "build"; then
arduino-cli -v compile --fqbn STM32:stm32:GenF1:pnum=BLUEPILL_F103C8,upload_method=dfu2Method,xserial=generic,usb=CDCgen,xusb=FS,opt=osstd,rtlib=nano /home/mirte/arduino_project/$PROJECT
fi
if test "$1" == "build_nano"; then
arduino-cli -v compile --fqbn arduino:avr:nano:cpu=atmega328 /home/mirte/arduino_project/$2
if test "$COMMAND" == "build_nano"; then
arduino-cli -v compile --fqbn arduino:avr:nano:cpu=atmega328 /home/mirte/arduino_project/$PROJECT
fi
if test "$1" == "build_nano_old"; then
arduino-cli -v compile --fqbn arduino:avr:nano:cpu=atmega328old /home/mirte/arduino_project/$2
if test "$COMMAND" == "build_nano_old"; then
arduino-cli -v compile --fqbn arduino:avr:nano:cpu=atmega328old /home/mirte/arduino_project/$PROJECT
fi
if test "$1" == "build_uno"; then
arduino-cli -v compile --fqbn arduino:avr:uno /home/mirte/arduino_project/$2
if test "$COMMAND" == "build_uno"; then
arduino-cli -v compile --fqbn arduino:avr:uno /home/mirte/arduino_project/$PROJECT
fi
upload() {
PORT=$1
# Different upload scripts
if test "$COMMAND" == "upload" || test "$COMMAND" == "upload_stm32"; then
arduino-cli -v upload -p $PORT --fqbn STM32:stm32:GenF1:pnum=BLUEPILL_F103C8,upload_method=dfu2Method,xserial=generic,usb=CDCgen,xusb=FS,opt=osstd,rtlib=nano /home/mirte/arduino_project/$PROJECT
fi
if test "$COMMAND" == "upload_nano"; then
arduino-cli -v upload -p $PORT --fqbn arduino:avr:nano:cpu=atmega328 /home/mirte/arduino_project/$PROJECT
fi
if test "$COMMAND" == "upload_nano_old"; then
arduino-cli -v upload -p $PORT --fqbn arduino:avr:nano:cpu=atmega328old /home/mirte/arduino_project/$PROJECT
fi
if test "$COMMAND" == "upload_uno"; then
arduino-cli -v upload -p $PORT --fqbn arduino:avr:uno /home/mirte/arduino_project/$PROJECT
fi
}

# Different upload scripts
if test "$1" == "upload" || test "$1" == "upload_stm32"; then
arduino-cli -v upload -p /dev/ttyACM0 --fqbn STM32:stm32:GenF1:pnum=BLUEPILL_F103C8,upload_method=dfu2Method,xserial=generic,usb=CDCgen,xusb=FS,opt=osstd,rtlib=nano /home/mirte/arduino_project/$2
fi
if test "$1" == "upload_nano"; then
arduino-cli -v upload -p /dev/ttyUSB0 --fqbn arduino:avr:nano:cpu=atmega328 /home/mirte/arduino_project/$2
fi
if test "$1" == "upload_nano_old"; then
arduino-cli -v upload -p /dev/ttyUSB0 --fqbn arduino:avr:nano:cpu=atmega328old /home/mirte/arduino_project/$2
fi
if test "$1" == "upload_uno"; then
arduino-cli -v upload -p /dev/ttyACM0 --fqbn arduino:avr:uno /home/mirte/arduino_project/$2
if [[ $COMMAND == upload* ]] && test "$1" != "upload_pico"; then
shopt -s nullglob
for PORT in "/dev/ttyUSB"*; do
echo "Uploading to $PORT"
upload $PORT
done
for PORT in "/dev/ttyACM"*; do
echo "Uploading to $PORT"
upload $PORT
done
fi

if test "$1" == "upload_pico"; then
Expand Down
Loading