klippy: Support FIRMWARE_RESTART command

Add initial support for micro-controller resets via the Arduino reset
mechanism.  Also, automatically attempt a firmware restart if the
printer CRC does not match.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-03-08 22:26:10 -05:00
parent b0329465ec
commit 64407dc5d2
5 changed files with 70 additions and 24 deletions

View file

@ -3,7 +3,7 @@
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging, threading
import logging, threading, time
import serial
import msgproto, chelper, util
@ -325,3 +325,16 @@ def stk500v2_leave(ser, reactor):
res = ser.read(4096)
logging.debug("Got %s from stk500v2" % (repr(res),))
ser.baudrate = origbaud
# Attempt an arduino style reset on a serial port
def arduino_reset(serialport, reactor):
# First try opening the port at 1200 baud
ser = serial.Serial(serialport, 1200, timeout=0)
ser.read(1)
time.sleep(0.100)
# Then try toggling DTR
ser.dtr = True
time.sleep(0.100)
ser.dtr = False
time.sleep(0.100)
ser.close()