1 from __future__ import absolute_import
2 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
10 from Cura.avr_isp import stk500v2
11 from Cura.avr_isp import ispBase
12 from Cura.avr_isp import intelHex
14 from Cura.util import machineCom
15 from Cura.util import profile
16 from Cura.util import resources
18 def getDefaultFirmware():
19 if profile.getMachineSetting('machine_type') == 'ultimaker':
20 if profile.getMachineSetting('has_heated_bed') == 'True':
22 if profile.getMachineSettingFloat('extruder_amount') > 2:
24 if profile.getMachineSettingFloat('extruder_amount') > 1:
25 if sys.platform.startswith('linux'):
26 return resources.getPathForFirmware("MarlinUltimaker-115200-dual.hex")
28 return resources.getPathForFirmware("MarlinUltimaker-250000-dual.hex")
29 if sys.platform.startswith('linux'):
30 return resources.getPathForFirmware("MarlinUltimaker-115200.hex")
32 return resources.getPathForFirmware("MarlinUltimaker-250000.hex")
33 if profile.getMachineSetting('machine_type') == 'ultimaker2':
34 return resources.getPathForFirmware("MarlinUltimaker2.hex")
37 class InstallFirmware(wx.Dialog):
38 def __init__(self, filename = None, port = None):
39 super(InstallFirmware, self).__init__(parent=None, title="Firmware install for %s" % (profile.getMachineSetting('machine_name').title()), size=(250, 100))
41 port = profile.getMachineSetting('serial_port')
43 filename = getDefaultFirmware()
45 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)
48 if profile.getMachineSetting('machine_type') == 'reprap':
49 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)
51 sizer = wx.BoxSizer(wx.VERTICAL)
53 self.progressLabel = wx.StaticText(self, -1, 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nX')
54 sizer.Add(self.progressLabel, 0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
55 self.progressGauge = wx.Gauge(self, -1)
56 sizer.Add(self.progressGauge, 0, flag=wx.EXPAND)
57 self.okButton = wx.Button(self, -1, _("OK"))
58 self.okButton.Disable()
59 self.okButton.Bind(wx.EVT_BUTTON, self.OnOk)
60 sizer.Add(self.okButton, 0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
63 self.filename = filename
69 self.thread = threading.Thread(target=self.OnRun)
70 self.thread.daemon = True
78 wx.CallAfter(self.updateLabel, _("Reading firmware..."))
79 hexFile = intelHex.readHex(self.filename)
80 wx.CallAfter(self.updateLabel, _("Connecting to machine..."))
81 programmer = stk500v2.Stk500v2()
82 programmer.progressCallback = self.OnProgress
83 if self.port == 'AUTO':
84 wx.CallAfter(self.updateLabel, _("Please connect the printer to\nyour computer with the USB cable."))
85 while not programmer.isConnected():
86 for self.port in machineCom.serialList(True):
88 programmer.connect(self.port)
90 except ispBase.IspError:
98 programmer.connect(self.port)
99 except ispBase.IspError:
102 if not programmer.isConnected():
103 wx.MessageBox(_("Failed to find machine for firmware upgrade\nIs your machine connected to the PC?"),
104 _("Firmware update"), wx.OK | wx.ICON_ERROR)
105 wx.CallAfter(self.Close)
108 wx.CallAfter(self.updateLabel, _("Uploading firmware..."))
110 programmer.programChip(hexFile)
111 wx.CallAfter(self.updateLabel, _("Done!\nInstalled firmware: %s") % (os.path.basename(self.filename)))
112 except ispBase.IspError as e:
113 wx.CallAfter(self.updateLabel, _("Failed to write firmware.\n") + str(e))
116 wx.CallAfter(self.okButton.Enable)
118 def updateLabel(self, text):
119 self.progressLabel.SetLabel(text)
122 def OnProgress(self, value, max):
123 wx.CallAfter(self.progressGauge.SetRange, max)
124 wx.CallAfter(self.progressGauge.SetValue, value)
129 def OnClose(self, e):