forked from kliment/Printrun
/
firmwareInstall.py
109 lines (90 loc) · 3.3 KB
/
firmwareInstall.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from __future__ import absolute_import
import os, wx, threading, sys
from avr_isp import stk500v2
from avr_isp import ispBase
from avr_isp import intelHex
from util import machineCom
from util import profile
from util import resources
def getDefaultFirmware():
if profile.getPreference('machine_type') == 'ultimaker':
if profile.getPreferenceFloat('extruder_amount') > 1:
return None
if profile.getPreference('has_heated_bed') == 'True':
return None
if sys.platform.startswith('linux'):
return resources.getPathForFirmware("ultimaker_115200.hex")
else:
return resources.getPathForFirmware("ultimaker_250000.hex")
return None
class InstallFirmware(wx.Dialog):
def __init__(self, filename = None, port = None):
#super(InstallFirmware, self).__init__(parent=None, title="Firmware install", size=(250, 100))
if port is None:
port = profile.getPreference('serial_port')
if filename is None:
filename = getDefaultFirmware()
if filename is None:
wx.MessageBox('I am sorry, but Coordia does not ship with a default firmware for your machine configuration.', 'Firmware update', wx.OK | wx.ICON_ERROR)
self.Destroy()
return
#sizer = wx.BoxSizer(wx.VERTICAL)
#self.progressLabel = wx.StaticText(self, -1, 'Reading firmware...')
#sizer.Add(self.progressLabel, 0, flag=wx.ALIGN_CENTER)
#self.progressGauge = wx.Gauge(self, -1)
#sizer.Add(self.progressGauge, 0, flag=wx.EXPAND)
#self.okButton = wx.Button(self, -1, 'Ok')
#self.okButton.Disable()
#self.okButton.Bind(wx.EVT_BUTTON, self.OnOk)
#sizer.Add(self.okButton, 0, flag=wx.ALIGN_CENTER)
#self.SetSizer(sizer)
self.filename = filename
self.port = port
threading.Thread(target=self.OnRun).start()
#self.ShowModal()
#self.Destroy()
return
def OnRun(self):
hexFile = intelHex.readHex(self.filename)
print "Connecting to machine."
#wx.CallAfter(self.updateLabel, "Connecting to machine...")
programmer = stk500v2.Stk500v2()
#programmer.progressCallback = self.OnProgress
if self.port == 'AUTO':
for self.port in machineCom.serialList():
try:
programmer.connect(self.port)
break
except ispBase.IspError:
pass
else:
try:
programmer.connect(self.port)
except ispBase.IspError:
pass
if programmer.isConnected():
#wx.CallAfter(self.updateLabel, "Uploading firmware...")
try:
programmer.programChip(hexFile)
print "Firmware successfully installed!"
#wx.CallAfter(self.updateLabel, "Done!\nInstalled firmware: %s" % (os.path.basename(self.filename)))
except ispBase.IspError as e:
print "Failed to upload firmware."
#wx.CallAfter(self.updateLabel, "Failed to write firmware.\n" + str(e))
programmer.close()
#wx.CallAfter(self.Close)
#wx.CallAfter(self.okButton.Enable)
return
#wx.MessageBox('Failed to find machine for firmware upgrade\nIs your machine connected to the PC?', 'Firmware update', wx.OK | wx.ICON_ERROR)
print "Failed to find machine. Ensure your machine is connected to your computer via USB."
#wx.CallAfter(self.Close)
def updateLabel(self, text):
self.progressLabel.SetLabel(text)
self.Layout()
def OnProgress(self, value, max):
wx.CallAfter(self.progressGauge.SetRange, max)
wx.CallAfter(self.progressGauge.SetValue, value)
def OnOk(self, e):
self.Close()
def OnClose(self, e):
self.Destroy()