Added check to prevent printing when firmware is being updated

This commit is contained in:
Jaime van Kessel 2015-04-14 10:32:06 +02:00
parent f5e8e7df80
commit 6e9a07d73c
2 changed files with 44 additions and 4 deletions

View file

@ -77,6 +77,8 @@ class PrinterConnection(SignalEmitter):
# This index is the extruder we requested data from the last time.
self._temperature_requested_extruder_index = 0
self._updating_firmware = False
#TODO: Might need to add check that extruders can not be changed when it started printing or loading these settings from settings object
def setNumExtuders(self, num):
self._extruder_count = num
@ -111,10 +113,9 @@ class PrinterConnection(SignalEmitter):
## Try to connect the serial. This simply starts the thread, which runs _connect.
def connect(self):
if not self._connect_thread.isAlive():
if not self._updating_firmware and not self._connect_thread.isAlive():
self._connect_thread.start()
def updateFirmware(self, file_name):
if self._is_connecting or self._is_connected:
return False
@ -124,15 +125,19 @@ class PrinterConnection(SignalEmitter):
Logger.log('e', "Unable to read provided hex file. Could not update firmware")
return False
programmer = stk500v2.Stk500v2()
programmer.progressCallback = self.setProgress
programmer.connect(self._serial_port)
time.sleep(1) #Give programmer some time to connect
if not programmer.isConnected():
Logger.log('e', "Unable to connect with serial. Could not update firmware")
return False
self._updating_firmware = True
try:
programmer.programChip(hex_file)
self._updating_firmware = False
except Exception as e:
Logger.log("e", "Exception while trying to update firmware" , e)
self._updating_firmware = False
return False
programmer.close()
return True
@ -383,7 +388,7 @@ class PrinterConnection(SignalEmitter):
progressChanged = Signal()
def setProgress(self, progress):
def setProgress(self, progress,max_progress = 100):
self._progress = progress
self.progressChanged.emit(self._progress, self._serial_port)

View file

@ -9,6 +9,7 @@ import platform
import glob
import time
import os
import sys
from PyQt5.QtQuick import QQuickView
from PyQt5.QtCore import QUrl, QObject,pyqtSlot , pyqtProperty,pyqtSignal
@ -29,6 +30,7 @@ class USBPrinterManager(QObject, SignalEmitter,PluginObject):
self._extruder_temp = 0
self._bed_temp = 0
self._error_message = ""
#time.sleep(1)
#self.connectAllConnections()
#time.sleep(5)
@ -103,6 +105,39 @@ class USBPrinterManager(QObject, SignalEmitter,PluginObject):
pass
def updateFirmwareBySerial(self, serial_port):
printer_connection = self.getConnectionByPort(serial_port)
if printer_connection is not None:
printer_connection.updateFirmware(Resources.getPath(Resources.FirmwareLocation, self._getDefaultFirmwareName()))
def _getDefaultFirmwareName(self):
machine_type = Application.getInstance().getActiveMachine().getTypeID()
firmware_name = ""
baudrate = 250000
if sys.platform.startswith('linux'):
baudrate = 115200
if machine_type == "ultimaker_original":
firmware_name = 'MarlinUltimaker'
firmware_name += '-%d' % (baudrate)
elif machine_type == "ultimaker_original_plus":
firmware_name = 'MarlinUltimaker-UMOP-%d' % (baudrate)
elif machine_type == "Witbox":
return "MarlinWitbox.hex"
elif machine_type == "ultimaker2go":
return "MarlinUltimaker2go.hex"
elif machine_type == "ultimaker2extended":
return "MarlinUltimaker2extended.hex"
elif machine_type == "ultimaker2":
return "MarlinUltimaker2.hex"
##TODO: Add check for multiple extruders
if firmware_name != "":
firmware_name += ".hex"
return firmware_name
def onBedTemperature(self, serial_port,temperature):
self._bed_temperature = temperature
self.pyqtBedTemperature.emit(temperature)