diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index e384d8a..bcde2d7 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -531,10 +531,22 @@ endif # Reset # ifndef RESET_CMD -ifeq ($(BOARD_TAG),leonardo) -RESET_CMD = $(ARDMK_PATH)/ard-reset-leonardo $(ARD_RESET_OPTS) -else -RESET_CMD = $(ARDMK_PATH)/ard-reset-arduino $(ARD_RESET_OPTS) + ifeq ($(BOARD_TAG),leonardo) + RESET_CMD = $(ARDMK_PATH)/ard-reset-leonardo \ + $(ARD_RESET_OPTS) $(call get_arduino_port) + else + RESET_CMD = $(ARDMK_PATH)/ard-reset-arduino \ + $(ARD_RESET_OPTS) $(call get_arduino_port) + endif +endif + +ifndef WAIT_CONNECTION_CMD + ifeq ($(BOARD_TAG),leonardo) + WAIT_CONNECTION_CMD = \ + $(ARDMK_PATH)/wait-connection-leonardo $(call get_arduino_port) + else + WAIT_CONNECTION_CMD = + endif endif ######################################################################## @@ -964,13 +976,9 @@ raw_eeprom: reset $(TARGET_EEP) $(TARGET_HEX) # the last part is for leonardo. # wait until leonardo reboots and establish a new connection. reset: - $(ECHO) "Resetting Arduino..." - $(RESET_CMD) $(call get_arduino_port) - while [ ! -e $(ARD_PORT) ] ;\ - do \ - echo "Waiting for arduino at $(ARD_PORT)";\ - sleep 0.3 ;\ - done + $(call arduino_output,Resetting Arduino...) + $(RESET_CMD) + $(WAIT_CONNECTION_CMD) # stty on MacOS likes -F, but on Debian it likes -f redirecting # stdin/out appears to work but generates a spurious error on MacOS at diff --git a/bin/ard-reset-leonardo b/bin/ard-reset-leonardo index 044bc7d..dc05f06 100755 --- a/bin/ard-reset-leonardo +++ b/bin/ard-reset-leonardo @@ -4,8 +4,9 @@ import sys import serial ser = serial.Serial(sys.argv[1], 57600) -s.open() -s.close() -s.setBaudrate(1200) +ser.close() +ser.open() +ser.close() +ser.setBaudrate(1200) ser.open() ser.close() diff --git a/bin/wait-connection-leonardo b/bin/wait-connection-leonardo new file mode 100755 index 0000000..92d26f7 --- /dev/null +++ b/bin/wait-connection-leonardo @@ -0,0 +1,15 @@ +#! /bin/bash + +while [ ! -e $1 ] +do + echo Waiting connection at $1 + sleep 0.2 +done + +sleep 1 +# necessary for me... +# /dev/ttyACM0 used to disappear after the reset +# but no longer now. How can I tell whether the +# connection is ready? + +echo Connection Established