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 if sys.platform.startswith('linux'):
20 name = 'MarlinUltimaker-115200'
22 name = 'MarlinUltimaker-250000'
23 if profile.getMachineSettingFloat('extruder_amount', machineIndex) > 2:
25 if profile.getMachineSetting('has_heated_bed', machineIndex) == 'True':
27 if profile.getMachineSettingFloat('extruder_amount', machineIndex) > 1:
31 if profile.getMachineSetting('machine_type', machineIndex) == 'ultimaker2':
32 return resources.getPathForFirmware("MarlinUltimaker2.hex")
35 class InstallFirmware(wx.Dialog):
36 def __init__(self, filename = None, port = None, machineIndex = None):
37 super(InstallFirmware, self).__init__(parent=None, title="Firmware install for %s" % (profile.getMachineSetting('machine_name', machineIndex).title()), size=(250, 100))
39 port = profile.getMachineSetting('serial_port')
41 filename = getDefaultFirmware(machineIndex)
43 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)
46 if profile.getMachineSetting('machine_type', machineIndex) == 'reprap':
47 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)
49 sizer = wx.BoxSizer(wx.VERTICAL)
51 self.progressLabel = wx.StaticText(self, -1, 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nX')
52 sizer.Add(self.progressLabel, 0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
53 self.progressGauge = wx.Gauge(self, -1)
54 sizer.Add(self.progressGauge, 0, flag=wx.EXPAND)
55 self.okButton = wx.Button(self, -1, _("OK"))
56 self.okButton.Disable()
57 self.okButton.Bind(wx.EVT_BUTTON, self.OnOk)
58 sizer.Add(self.okButton, 0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
61 self.filename = filename
67 self.thread = threading.Thread(target=self.OnRun)
68 self.thread.daemon = True
76 wx.CallAfter(self.updateLabel, _("Reading firmware..."))
77 hexFile = intelHex.readHex(self.filename)
78 wx.CallAfter(self.updateLabel, _("Connecting to machine..."))
79 programmer = stk500v2.Stk500v2()
80 programmer.progressCallback = self.OnProgress
81 if self.port == 'AUTO':
82 wx.CallAfter(self.updateLabel, _("Please connect the printer to\nyour computer with the USB cable."))
83 while not programmer.isConnected():
84 for self.port in machineCom.serialList(True):
86 programmer.connect(self.port)
88 except ispBase.IspError:
96 programmer.connect(self.port)
97 except ispBase.IspError:
100 if not programmer.isConnected():
101 wx.MessageBox(_("Failed to find machine for firmware upgrade\nIs your machine connected to the PC?"),
102 _("Firmware update"), wx.OK | wx.ICON_ERROR)
103 wx.CallAfter(self.Close)
106 wx.CallAfter(self.updateLabel, _("Uploading firmware..."))
108 programmer.programChip(hexFile)
109 wx.CallAfter(self.updateLabel, _("Done!\nInstalled firmware: %s") % (os.path.basename(self.filename)))
110 except ispBase.IspError as e:
111 wx.CallAfter(self.updateLabel, _("Failed to write firmware.\n") + str(e))
114 wx.CallAfter(self.okButton.Enable)
116 def updateLabel(self, text):
117 self.progressLabel.SetLabel(text)
120 def OnProgress(self, value, max):
121 wx.CallAfter(self.progressGauge.SetRange, max)
122 wx.CallAfter(self.progressGauge.SetValue, value)
127 def OnClose(self, e):