1 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
9 from Cura.avr_isp import stk500v2
10 from Cura.avr_isp import ispBase
11 from Cura.avr_isp import intelHex
13 from Cura.util import machineCom
14 from Cura.util import profile
15 from Cura.util import resources
17 def getDefaultFirmware(machineIndex = None):
18 if profile.getMachineSetting('machine_type', machineIndex) == 'ultimaker':
19 name = 'MarlinUltimaker'
20 if profile.getMachineSettingFloat('extruder_amount', machineIndex) > 2:
22 if profile.getMachineSetting('has_heated_bed', machineIndex) == 'True':
24 if sys.platform.startswith('linux'):
28 if profile.getMachineSettingFloat('extruder_amount', machineIndex) > 1:
30 return resources.getPathForFirmware(name + '.hex')
32 if profile.getMachineSetting('machine_type', machineIndex) == 'ultimaker_plus':
33 name = 'MarlinUltimaker-UMOP'
34 if profile.getMachineSettingFloat('extruder_amount', machineIndex) > 2:
36 if sys.platform.startswith('linux'):
40 if profile.getMachineSettingFloat('extruder_amount', machineIndex) > 1:
42 return resources.getPathForFirmware(name + '.hex')
44 if profile.getMachineSetting('machine_type', machineIndex) == 'ultimaker2':
45 return resources.getPathForFirmware("MarlinUltimaker2.hex")
46 if profile.getMachineSetting('machine_type', machineIndex) == 'lulzbot_mini':
47 return resources.getPathForFirmware("marlin_mini_2014Q4.hex")
48 if profile.getMachineSetting('machine_type', machineIndex) == 'Witbox':
49 return resources.getPathForFirmware("MarlinWitbox.hex")
52 class InstallFirmware(wx.Dialog):
53 def __init__(self, filename = None, port = None, machineIndex = None):
54 super(InstallFirmware, self).__init__(parent=None, title="Firmware install for %s" % (profile.getMachineSetting('machine_name', machineIndex).title()), size=(250, 100))
56 port = profile.getMachineSetting('serial_port')
58 filename = getDefaultFirmware(machineIndex)
60 wx.MessageBox(_("I am sorry, but Cura does not ship with a default firmware for your machine configuration."), _("Firmware update"), wx.OK | wx.ICON_ERROR)
63 self._machine_type = profile.getMachineSetting('machine_type', machineIndex)
64 if self._machine_type == 'reprap':
65 wx.MessageBox(_("Cura only supports firmware updates for ATMega2560 based hardware.\nSo updating your RepRap with Cura might or might not work."), _("Firmware update"), wx.OK | wx.ICON_INFORMATION)
67 sizer = wx.BoxSizer(wx.VERTICAL)
69 self.progressLabel = wx.StaticText(self, -1, 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nX\nX')
70 sizer.Add(self.progressLabel, 0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
71 self.progressGauge = wx.Gauge(self, -1)
72 sizer.Add(self.progressGauge, 0, flag=wx.EXPAND)
73 self.okButton = wx.Button(self, -1, _("OK"))
74 self.okButton.Disable()
75 self.okButton.Bind(wx.EVT_BUTTON, self.OnOk)
76 sizer.Add(self.okButton, 0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
79 self.filename = filename
85 self.thread = threading.Thread(target=self.OnRun)
86 self.thread.daemon = True
94 wx.CallAfter(self.updateLabel, _("Reading firmware..."))
95 hexFile = intelHex.readHex(self.filename)
96 wx.CallAfter(self.updateLabel, _("Connecting to machine..."))
97 programmer = stk500v2.Stk500v2()
98 programmer.progressCallback = self.OnProgress
99 if self.port == 'AUTO':
100 wx.CallAfter(self.updateLabel, _("Please connect the printer to\nyour computer with the USB cable."))
101 while not programmer.isConnected():
102 for self.port in machineCom.serialList(True):
104 programmer.connect(self.port)
106 except ispBase.IspError:
114 programmer.connect(self.port)
115 except ispBase.IspError:
118 if not programmer.isConnected():
119 wx.MessageBox(_("Failed to find machine for firmware upgrade\nIs your machine connected to the PC?"),
120 _("Firmware update"), wx.OK | wx.ICON_ERROR)
121 wx.CallAfter(self.Close)
124 if self._machine_type == 'ultimaker':
125 if programmer.hasChecksumFunction():
126 wx.CallAfter(self.updateLabel, _("Failed to install firmware:\nThis firmware is not compatible with this machine.\nTrying to install UMO firmware on an UM2 or UMO+?"))
128 wx.CallAfter(self.okButton.Enable)
130 if self._machine_type == 'ultimaker_plus' or self._machine_type == 'ultimaker2':
131 if not programmer.hasChecksumFunction():
132 wx.CallAfter(self.updateLabel, _("Failed to install firmware:\nThis firmware is not compatible with this machine.\nTrying to install UM2 or UMO+ firmware on an UMO?"))
134 wx.CallAfter(self.okButton.Enable)
137 wx.CallAfter(self.updateLabel, _("Uploading firmware..."))
139 programmer.programChip(hexFile)
140 wx.CallAfter(self.updateLabel, _("Done!\nInstalled firmware: %s") % (os.path.basename(self.filename)))
141 except ispBase.IspError as e:
142 wx.CallAfter(self.updateLabel, _("Failed to write firmware.\n") + str(e))
145 wx.CallAfter(self.okButton.Enable)
147 def updateLabel(self, text):
148 self.progressLabel.SetLabel(text)
151 def OnProgress(self, value, max):
152 wx.CallAfter(self.progressGauge.SetRange, max)
153 wx.CallAfter(self.progressGauge.SetValue, value)
158 def OnClose(self, e):