Fix the speed rate modify in the printing interface.

master
Daid 2012-09-07 12:04:55 +02:00
parent 68f1353e60
commit 2e01bbbe79
3 changed files with 39 additions and 16 deletions

View File

@ -296,10 +296,14 @@ class printWindow(wx.Frame):
def UpdateButtonStates(self):
self.connectButton.Enable(self.machineCom == None or self.machineCom.isClosedOrError())
#self.loadButton.Enable(self.printIdx == None)
self.printButton.Enable(self.machineCom != None and self.machineCom.isOperational() and not (self.machineCom.isPrinting() or self.machineCome.isPaused()))
self.pauseButton.Enable(self.machineCom != None and (self.machineCom.isPrinting() or self.machineCome.isPaused()))
self.cancelButton.Enable(self.machineCom != None and (self.machineCom.isPrinting() or self.machineCome.isPaused()))
#self.loadButton.Enable(self.machineCom == None or not (self.machineCom.isPrinting() or self.machineCom.isPaused()))
self.printButton.Enable(self.machineCom != None and self.machineCom.isOperational() and not (self.machineCom.isPrinting() or self.machineCom.isPaused()))
self.pauseButton.Enable(self.machineCom != None and (self.machineCom.isPrinting() or self.machineCom.isPaused()))
if self.machineCom != None and self.machineCom.isPaused():
self.pauseButton.SetLabel('Resume')
else:
self.pauseButton.SetLabel('Pause')
self.cancelButton.Enable(self.machineCom != None and (self.machineCom.isPrinting() or self.machineCom.isPaused()))
self.temperatureSelect.Enable(self.machineCom != None and self.machineCom.isOperational())
self.bedTemperatureSelect.Enable(self.machineCom != None and self.machineCom.isOperational())
self.directControlPanel.Enable(self.machineCom != None and self.machineCom.isOperational())
@ -367,10 +371,8 @@ class printWindow(wx.Frame):
def OnPause(self, e):
if self.machineCom.isPaused():
self.machineCom.setPause(False)
self.pauseButton.SetLabel('Pause')
else:
self.machineCom.setPause(True)
self.pauseButton.SetLabel('Resume')
def OnClose(self, e):
global printWindowHandle
@ -386,10 +388,12 @@ class printWindow(wx.Frame):
self.machineCom.sendCommand("M140 S%d" % (self.bedTemperatureSelect.GetValue()))
def OnSpeedChange(self, e):
self.feedrateRatioOuterWall = self.outerWallSpeedSelect.GetValue() / 100.0
self.feedrateRatioInnerWall = self.innerWallSpeedSelect.GetValue() / 100.0
self.feedrateRatioFill = self.fillSpeedSelect.GetValue() / 100.0
self.feedrateRatioSupport = self.supportSpeedSelect.GetValue() / 100.0
if self.machineCom == None:
return
self.machineCom.setFeedrateModifier('WALL-OUTER', self.outerWallSpeedSelect.GetValue() / 100.0)
self.machineCom.setFeedrateModifier('WALL-INNER', self.innerWallSpeedSelect.GetValue() / 100.0)
self.machineCom.setFeedrateModifier('FILL', self.fillSpeedSelect.GetValue() / 100.0)
self.machineCom.setFeedrateModifier('SUPPORT', self.supportSpeedSelect.GetValue() / 100.0)
def AddTermLog(self, line):
self.termLog.AppendText(unicode(line, 'utf-8', 'replace'))
@ -422,9 +426,8 @@ class printWindow(wx.Frame):
if self.machineCom != None and self.machineCom.isPrinting():
return
#Send an initial M110 to reset the line counter to zero.
lineType = 'CUSTOM'
prevLineType = lineType = 'CUSTOM'
gcodeList = ["M110"]
typeList = [lineType]
for line in open(filename, 'r'):
if line.startswith(';TYPE:'):
lineType = line[6:].strip()
@ -432,15 +435,17 @@ class printWindow(wx.Frame):
line = line[0:line.find(';')]
line = line.strip()
if len(line) > 0:
gcodeList.append(line)
typeList.append(lineType)
if prevLineType != lineType:
gcodeList.append((line, lineType, ))
else:
gcodeList.append(line)
prevLineType = lineType
gcode = gcodeInterpreter.gcode()
gcode.loadList(gcodeList)
print "Loaded: %s (%d)" % (filename, len(gcodeList))
self.filename = filename
self.gcode = gcode
self.gcodeList = gcodeList
self.typeList = typeList
wx.CallAfter(self.progress.SetRange, len(gcodeList))
wx.CallAfter(self.UpdateButtonStates)

View File

@ -68,6 +68,8 @@ class gcode(object):
currentPath.list[0].e = totalExtrusion
currentLayer.append(currentPath)
for line in gcodeFile:
if type(line) is tuple:
line = line[0]
if self.progressCallback != None:
if filePos != gcodeFile.tell():
filePos = gcodeFile.tell()

View File

@ -134,6 +134,7 @@ class MachineCom(object):
self._gcodePos = 0
self._commandQueue = queue.Queue()
self._logQueue = queue.Queue(256)
self._feedRateModifier = {}
if port == 'AUTO':
programmer = stk500v2.Stk500v2()
@ -323,7 +324,7 @@ class MachineCom(object):
if ret == '':
#self._log("Recv: TIMEOUT")
return ''
self._log("Recv: %s" % (unicode(ret, 'ascii', 'replace').rstrip()))
self._log("Recv: %s" % (unicode(ret, 'ascii', 'replace').encode('ascii', 'replace').rstrip()))
return ret
def close(self, isError = False):
@ -355,6 +356,17 @@ class MachineCom(object):
self._changeState(self.STATE_OPERATIONAL)
return
line = self._gcodeList[self._gcodePos]
if type(line) is tuple:
self._printSection = line[1]
line = line[0]
try:
if line == 'M0' or line == 'M1':
self.setPause(True)
line = 'M105' #Don't send the M0 or M1 to the machine, as M0 and M1 are handled as an LCD menu pause.
if self._printSection in self._feedRateModifier:
line = re.sub('F([0-9]*)', lambda m: 'F' + str(int(int(m.group(1)) * self._feedRateModifier[self._printSection])), line)
except:
self._log("Unexpected error: %s" % (getExceptionString()))
checksum = reduce(lambda x,y:x^y, map(ord, "N%d%s" % (self._gcodePos, line)))
self._sendCommand("N%d%s*%d" % (self._gcodePos, line, checksum))
self._gcodePos += 1
@ -372,6 +384,7 @@ class MachineCom(object):
return
self._gcodeList = gcodeList
self._gcodePos = 0
self._printSection = 'CUSTOM'
self._changeState(self.STATE_PRINTING)
for i in xrange(0, 6):
self._sendNext()
@ -387,6 +400,9 @@ class MachineCom(object):
self._sendNext()
if pause and self.isPrinting():
self._changeState(self.STATE_PAUSED)
def setFeedrateModifier(self, type, value):
self._feedRateModifier[type] = value
def getExceptionString():
locationInfo = traceback.extract_tb(sys.exc_info()[2])[0]