added grbl version comparison and check to see if required version is detected.

If the right grbl version is not detected, the arduino is flashed with the right
hex file.
This commit is contained in:
make-ing 2015-08-25 16:46:32 +02:00
parent ed82f46f57
commit 4e76574bb9
3 changed files with 91 additions and 33 deletions

1
.gitignore vendored
View file

@ -24,3 +24,4 @@ OctoPrint.egg-info
*.codekit
/nbproject/
.directory
.project

View file

@ -820,6 +820,54 @@ 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._log("flashing grbl version: " + self._requiredGrblVer)
self._serial.close()
self._changeState(self.STATE_CLOSED)
import subprocess
params = ["avrdude", "-patmega328p", "-carduino", "-b" + str(self._baudrate), "-P" + str(self._port), "-D", "-Uflash:w:grbl.junior.hex"]
#params = ['pwd']
if subprocess.call(params) is 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 = []
@ -951,6 +999,14 @@ 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)

View file

@ -0,0 +1 @@
{dirty: true, git: b35ae73, grbl: 0.9g, lastConnect: null, minor: ''}