-
Notifications
You must be signed in to change notification settings - Fork 1
/
cali_msp430.py
148 lines (120 loc) · 5.38 KB
/
cali_msp430.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import os
import gtk
import subprocess
import time
if os.name == 'posix' :
import pexpect
from threading import Thread
class ProcessLog(Thread):
def __init__(self, msp430_instance, cmds):
Thread.__init__(self)
self.msp430 = msp430_instance
jtagfile = './msp430-jtag.py'
if not os.path.isfile(jtagfile):
jtagfile = './msp430-jtag.pyc'
self.cmds = ['python', jtagfile, '--time', '-p']
if os.name == 'posix':
self.cmds.append('/dev/ttyACM0')
else:
self.cmds.append('TIUSB')
self.cmds += cmds
def run(self):
print "thread processlog starts.."
if os.name == 'posix':
command = ''
for cmd in self.cmds:
command += cmd
command += ' '
start_time = time.time()
child = pexpect.spawn(command)
while True:
try:
child.expect('\r')
gtk.threads_enter()
self.msp430.TextBufferOfMsp.insert_at_cursor(child.before)
gtk.threads_leave()
except:
gtk.threads_enter()
print child.after
self.msp430.TextBufferOfMsp.insert_at_cursor("\nTime: " + str(time.time() - start_time) + 's\n')
gtk.threads_leave()
break
time.sleep(0.1)
else:
proc = subprocess.Popen(self.cmds,
shell=False,
stderr=subprocess.PIPE)
gtk.threads_enter()
self.msp430.TextBufferOfMsp.insert_at_cursor(proc.communicate()[1])
gtk.threads_leave()
print "thread processlog stopped.."
class Msp430():
def on_WindowOfMsp430_destroy(self, widget, data=None):
if self.not_from_parent_gtk == 1:
print "msp gtk quit.."
gtk.main_quit()
def on_ButtonOfMspConnectByApi_clicked(self, widget, data=None):
print "todo"
def on_ButtonOfMspEraseByApi_clicked(self,widget, data=None):
cmds = ['-e']
ProcessLog(self, cmds).start()
def on_ButtonOfMspErase_clicked(self, widget, data=None):
cmds = ['-e']
ProcessLog(self, cmds).start()
def on_ButtonOfEraseCheck_clicked(self, widget, data=None):
cmds = ['-E']
ProcessLog(self, cmds).start()
def on_ButtonOfMspProgram_clicked(self, widget, data=None):
file = self.FileChooserButtonOfHex.get_filename()
if file != None:
filename, fileext = os.path.splitext(file)
if fileext == ".hex" or fileext == ".ihex":
cmds = ['-P', '-i', 'ihex', file]
ProcessLog(self, cmds).start()
def on_ButtonOfMspReset_clicked(self, widget, data=None):
cmds = ['-r']
ProcessLog(self, cmds).start()
def on_ButtonOfMspProgramAll_clicked(self, widget, data=None):
file = self.FileChooserButtonOfHex.get_filename()
if file != None:
filename, fileext = os.path.splitext(file)
if fileext == ".hex" or fileext == ".ihex":
cmds = ['-eE', '-PV', '-r', '-i', 'ihex', self.FileChooserButtonOfHex.get_filename()]
ProcessLog(self, cmds).start()
def on_TextViewOfMsp_size_allocate(self, widget, data=None):
adj = self.ScrolledWindowOfMsp.get_vadjustment()
adj.set_value(adj.upper - adj.page_size)
def run(self, parent_window):
self.window.set_transient_for(parent_window) # will make the child window located at center of main window. why??
self.window.show_all()
def __init__(self):
if os.name == 'posix' :
os.environ['LIBMSPGCC_PATH'] = '/usr/lib'
builder = gtk.Builder()
builder.add_from_file("./glades/msp430.glade")
builder.connect_signals(self)
self.window = builder.get_object("WindowOfMsp430")
self.TextBufferOfMsp= builder.get_object("textbuffer1")
self.ScrolledWindowOfMsp = builder.get_object("ScrolledWindowOfMsp")
self.FrameOfMspApi = builder.get_object("FrameOfMspApi")
self.FileFilterForView = builder.get_object("filefilter1")
self.FileFilterForView.add_pattern("*.hex")
self.FileFilterForView.add_pattern("*.ihex")
self.FileChooserButtonOfHex = builder.get_object("FileChooserButtonOfHex")
self.FileChooserButtonOfApiHex = builder.get_object("FileChooserButtonOfApiHex")
default_hex_file = './ihexfiles/lavida.hex'
if os.path.isfile(default_hex_file):
self.FileChooserButtonOfHex.set_filename(default_hex_file)
self.FileChooserButtonOfApiHex.set_filename(default_hex_file)
self.not_from_parent_gtk = 0 # was activated by cali_test main window
def main(self):
self.FrameOfMspApi.set_visible(True)
self.window.show_all()
self.not_from_parent_gtk = 1
gtk.threads_init()
gtk.threads_enter()
gtk.main()
gtk.threads_leave()
if __name__ == "__main__":
msp = Msp430()
msp.main()