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 if profile.getMachineSetting('machine_type', machineIndex) == 'reprap':
64 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)
66 sizer = wx.BoxSizer(wx.VERTICAL)
68 self.progressLabel = wx.StaticText(self, -1, 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nX')
69 sizer.Add(self.progressLabel, 0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
70 self.progressGauge = wx.Gauge(self, -1)
71 sizer.Add(self.progressGauge, 0, flag=wx.EXPAND)
72 self.okButton = wx.Button(self, -1, _("OK"))
73 self.okButton.Disable()
74 self.okButton.Bind(wx.EVT_BUTTON, self.OnOk)
75 sizer.Add(self.okButton, 0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
78 self.filename = filename
84 self.thread = threading.Thread(target=self.OnRun)
85 self.thread.daemon = True
93 wx.CallAfter(self.updateLabel, _("Reading firmware..."))
94 hexFile = intelHex.readHex(self.filename)
95 wx.CallAfter(self.updateLabel, _("Connecting to machine..."))
96 programmer = stk500v2.Stk500v2()
97 programmer.progressCallback = self.OnProgress
98 if self.port == 'AUTO':
99 wx.CallAfter(self.updateLabel, _("Please connect the printer to\nyour computer with the USB cable."))
100 while not programmer.isConnected():
101 for self.port in machineCom.serialList(True):
103 programmer.connect(self.port)
105 except ispBase.IspError:
113 programmer.connect(self.port)
114 except ispBase.IspError:
117 if not programmer.isConnected():
118 wx.MessageBox(_("Failed to find machine for firmware upgrade\nIs your machine connected to the PC?"),
119 _("Firmware update"), wx.OK | wx.ICON_ERROR)
120 wx.CallAfter(self.Close)
123 wx.CallAfter(self.updateLabel, _("Uploading firmware..."))
125 programmer.programChip(hexFile)
126 wx.CallAfter(self.updateLabel, _("Done!\nInstalled firmware: %s") % (os.path.basename(self.filename)))
127 except ispBase.IspError as e:
128 wx.CallAfter(self.updateLabel, _("Failed to write firmware.\n") + str(e))
131 wx.CallAfter(self.okButton.Enable)
133 def updateLabel(self, text):
134 self.progressLabel.SetLabel(text)
137 def OnProgress(self, value, max):
138 wx.CallAfter(self.progressGauge.SetRange, max)
139 wx.CallAfter(self.progressGauge.SetValue, value)
144 def OnClose(self, e):