Merge branch 'grblautoupdate' into mrbeam
This commit is contained in:
commit
221c6de990
4 changed files with 1891 additions and 34 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -24,3 +24,4 @@ OctoPrint.egg-info
|
|||
*.codekit
|
||||
/nbproject/
|
||||
.directory
|
||||
.project
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ class MachineCom(object):
|
|||
STATE_TRANSFERING_FILE = 11
|
||||
STATE_LOCKED = 12
|
||||
STATE_HOMING = 13
|
||||
STATE_FLASHING = 14
|
||||
|
||||
|
||||
|
||||
|
|
@ -316,6 +317,8 @@ class MachineCom(object):
|
|||
return "Locked"
|
||||
if self._state == self.STATE_HOMING:
|
||||
return "Homing"
|
||||
if self._state == self.STATE_FLASHING:
|
||||
return "Flashing"
|
||||
return "?%d?" % (self._state)
|
||||
|
||||
def getErrorString(self):
|
||||
|
|
@ -332,9 +335,13 @@ class MachineCom(object):
|
|||
|
||||
def isLocked(self):
|
||||
return self._state == self.STATE_LOCKED
|
||||
|
||||
def isHoming(self):
|
||||
return self._state == self.STATE_HOMING
|
||||
|
||||
def isFlashing(self):
|
||||
return self._state == self.STATE_FLASHING
|
||||
|
||||
def isPrinting(self):
|
||||
return self._state == self.STATE_PRINTING
|
||||
|
||||
|
|
@ -820,6 +827,53 @@ class MachineCom(object):
|
|||
|
||||
##~~ Serial monitor processing received messages
|
||||
|
||||
@staticmethod
|
||||
def _writeGrblVersionToFile(versionDict):
|
||||
if versionDict['dirty'] == '-dirty':
|
||||
versionDict['dirty'] = True
|
||||
versionDict['lastConnect'] = time.time()
|
||||
import yaml
|
||||
versionFile = os.path.join(settings().getBaseFolder("logs"), 'grbl_Version.yml')
|
||||
with open(versionFile, 'w') as outfile:
|
||||
outfile.write(yaml.dump(versionDict, default_flow_style=True))
|
||||
|
||||
def _compareGrblVersion(self, versionDict):
|
||||
with open("src/octoprint/util/grblVersionRequirement.yml", 'r') as infile:
|
||||
import yaml
|
||||
grblReqDict = yaml.load(infile)
|
||||
requiredGrblVer = str(grblReqDict['grbl']) + '_' + str(grblReqDict['git'])
|
||||
if grblReqDict['dirty'] is not(None):
|
||||
requiredGrblVer += '-dirty'
|
||||
if grblReqDict['minor'] != '':
|
||||
requiredGrblVer += ':' + grblReqDict['minor']
|
||||
actualGrblVer = str(versionDict['grbl']) + '_' + str(versionDict['git'])
|
||||
if versionDict['dirty'] is not(None):
|
||||
actualGrblVer += '-dirty'
|
||||
if versionDict['minor'] != '':
|
||||
actualGrblVer += ':' + versionDict['minor']
|
||||
# compare actual and required grbl version
|
||||
self._requiredGrblVer = requiredGrblVer
|
||||
self._actualGrblVer = actualGrblVer
|
||||
if requiredGrblVer != actualGrblVer:
|
||||
self._log("unsupported grbl version detected...")
|
||||
self._log("required: " + requiredGrblVer)
|
||||
self._log("detected: " + actualGrblVer)
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def _flashGrbl(self):
|
||||
self._changeState(self.STATE_FLASHING)
|
||||
self._serial.close()
|
||||
import subprocess
|
||||
params = ["avrdude", "-patmega328p", "-carduino", "-b" + str(self._baudrate), "-P" + str(self._port), "-D", "-Uflash:w:grbl.hex"]
|
||||
returnCode = subprocess.call(params)
|
||||
if returnCode == False:
|
||||
self._log("successfully flashed new grbl version")
|
||||
else:
|
||||
self._log("error during flashing of new grbl version")
|
||||
self._openSerial()
|
||||
|
||||
def _monitor(self):
|
||||
feedback_controls, feedback_matcher = convert_feedback_controls(settings().get(["controls"]))
|
||||
feedback_errors = []
|
||||
|
|
@ -933,7 +987,6 @@ class MachineCom(object):
|
|||
self._openSerial()
|
||||
self._changeState(self.STATE_CONNECTING)
|
||||
|
||||
|
||||
if("Invalid gcode" in line and self._state == self.STATE_PRINTING):
|
||||
# TODO Pause machine instead of resetting it.
|
||||
errorMsg = line
|
||||
|
|
@ -951,10 +1004,17 @@ class MachineCom(object):
|
|||
self._changeState(self.STATE_LOCKED)
|
||||
eventManager().fire(Events.ERROR, {"error": self.getErrorString()})
|
||||
|
||||
if("Grbl" in line):
|
||||
versionMatch = re.search("Grbl (?P<grbl>.+)_(?P<git>[0-9a-f]{7})(?P<dirty>-dirty)?(?P<minor>.*) \[.+\]", line)
|
||||
if(versionMatch):
|
||||
versionDict = versionMatch.groupdict()
|
||||
self._writeGrblVersionToFile(versionDict)
|
||||
if self._compareGrblVersion(versionDict) is False:
|
||||
self._flashGrbl()
|
||||
|
||||
if("error:" in line):
|
||||
self.handle_grbl_error(line)
|
||||
|
||||
|
||||
##~~ SD file list
|
||||
# if we are currently receiving an sd file list, each line is just a filename, so just read it and abort processing
|
||||
if self._sdFileList and not "End file list" in line:
|
||||
|
|
|
|||
1
src/octoprint/util/grblVersionRequirement.yml
Normal file
1
src/octoprint/util/grblVersionRequirement.yml
Normal file
|
|
@ -0,0 +1 @@
|
|||
{dirty: true, git: b35ae73, grbl: 0.9g, lastConnect: null, minor: ''}
|
||||
Loading…
Reference in a new issue