r4845 - in developers/werner/ahrt/host/tmc: demo lib

werner at docs.openmoko.org werner at docs.openmoko.org
Thu Dec 4 12:45:49 CET 2008


Author: werner
Date: 2008-12-04 12:45:48 +0100 (Thu, 04 Dec 2008)
New Revision: 4845

Modified:
   developers/werner/ahrt/host/tmc/demo/dxplore.py
   developers/werner/ahrt/host/tmc/lib/dxplore.py
   developers/werner/ahrt/host/tmc/lib/scope.py
   developers/werner/ahrt/host/tmc/lib/wave.py
Log:
Highlights:

- waves can now be labeled (labels are stored when saving and can be displayed
  in dxplore)
- a user-defined origin in dxplore is now marked with a red triangle

Details:

- lib/wave.py: waves now have an attribute "label" containing their name
- lib/wave.py (wave.save, wave.load, waves.save, waves.load): save/load label
  to/from files
- lib/wave.py (wave.unary, wave.binary, analog.digitize): propagate label to
  resulting wave
- lib/dxplore.py: display channel labels and moved some literal geometry
  constants to global variables
- lib/dxplore.py (channel.redraw_zoom): deleting zoom waveform in window "w"
  instead of "wz" produced overlapped waveforms when redrawing the zoom
- lib/dxplore.py: add red marker when setting user-defined origin
- demo/dxplore.py: commit long-pending update to "new-style" data format
- demo/dxplore.py: propagate labels



Modified: developers/werner/ahrt/host/tmc/demo/dxplore.py
===================================================================
--- developers/werner/ahrt/host/tmc/demo/dxplore.py	2008-12-03 15:33:52 UTC (rev 4844)
+++ developers/werner/ahrt/host/tmc/demo/dxplore.py	2008-12-04 11:45:48 UTC (rev 4845)
@@ -27,9 +27,14 @@
 w.load(argv[1])
 
 dig = []
-for wv in w[1:]:
+
+# old-style format
+if len(w) == 7:
+    w.pop(0)
+
+for wv in w:
     dig.append(wv.digitize(0.5))
-#    dig[-1].debounce(100e-9)
+    dig[-1].debounce(900e-9)
 
 min = dig[0].sample_step()
 for d in dig[1:]:
@@ -37,12 +42,19 @@
     if step is not None and step < min:
 	min = step
 
+if min is None:
+    min = 1
+
 da = []
 for d in dig:
     a = d.sample(min)
 #    print len(a)
-    if len(a) >= 1500:
-	da.append(a)
+    da.append(a)
 
+lbl = []
+for wv in w:
+    lbl.append(wv.label)
+
 da.reverse()
-dxplore(da, dig[0].start(), min, argv[1])
+lbl.reverse()
+dxplore(da, dig[0].start(), min, argv[1], labels = lbl)

Modified: developers/werner/ahrt/host/tmc/lib/dxplore.py
===================================================================
--- developers/werner/ahrt/host/tmc/lib/dxplore.py	2008-12-03 15:33:52 UTC (rev 4844)
+++ developers/werner/ahrt/host/tmc/lib/dxplore.py	2008-12-04 11:45:48 UTC (rev 4845)
@@ -29,6 +29,11 @@
 from string import maketrans
 
 
+channel_y_step = 55
+channel_y_offset = 15
+channel_y_height = 20
+
+
 class channel:
 
     color_normal = "green"
@@ -38,13 +43,16 @@
     decode_color = "white"
     decode_bg_color = "#4040ff"
     decode_font = "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*"
+    label_color = "white"
+    label_font = "-*-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*"
 
-    def __init__(self, main, number, data):
+    def __init__(self, main, number, data, label):
 	self.main = main
 	self.number = number
 	self.tag = "d_%d" % number
 	self.zoom_tag = "d_z_%d" % number
 	self.d = data
+	self.label = label 
 	self.edits = []
 	self.draw()
 
@@ -52,6 +60,11 @@
 	if self.main.pos0 > len(self.d):
 	    return
 
+	if self.label:
+	    self.main.w.create_text(2, self.y(1)-1, anchor = "sw",
+	    text = self.label,
+	    fill = self.label_color, font = self.label_font,
+	    tags = "d_lbl_"+self.tag)
 	for pos in self.edits:
 	    if pos < self.main.pos0:
 		break
@@ -94,19 +107,21 @@
 	  fill = self.color_normal, tags = self.zoom_tag, *line)
 
     def redraw_zoom(self):
-	self.main.w.delete(self.zoom_tag)
+	self.main.wz.delete(self.zoom_tag)
 	self.draw_zoom()
 	
     def redraw(self):
 	self.main.w.delete(self.tag)
 	self.main.w.delete("d_ed_"+self.tag)
+	self.main.w.delete("d_lbl_"+self.tag)
 	self.draw()
 
     def x(self, sample):
 	return int(round(self.main.x0+(sample-self.main.pos0)*self.main.mag))
 
     def y(self, value):
-	return self.number*50-value*20+25
+	return self.number*channel_y_step+channel_y_offset+channel_y_height- \
+	  value*20
 
     def zoom_y(self, value):
 	return self.number*6-value*2+5
@@ -347,6 +362,7 @@
     selection_color = "#808080"
     data_color = "white"
     zoom_color = "#808080"
+    user_marker_color = "red"
 
     tick_font = "-*-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*",
     tick_color = "#c0c0c0"
@@ -354,13 +370,13 @@
 
     si = ("p", "n", "u", "m", "", "k", "M", "G", "T")
 
-    def __init__(self, master, d, t0, sample_step):
+    def __init__(self, master, d, t0, sample_step, labels):
 	channels = len(d)
 	self.samples = len(d[0])
 	self.t0 = t0
 	self.sample_step = sample_step
 	self.xres = self.samples
-	self.yres = channels*50
+	self.yres = channels*channel_y_step+channel_y_offset-5
 	self.zres = channels*6+2
 	self.geometry()
 	self.w3 = self.control_window(master)
@@ -374,7 +390,11 @@
 	self.ch = []
 	self.cur = cursor(self)
 	for ch in range(0, channels):
-	    self.ch.append(channel(self, ch, d[ch]))
+	    if labels is None:
+		label = None
+	    else:
+		label = labels[ch]
+	    self.ch.append(channel(self, ch, d[ch], label))
 	    self.decoder_menu(self.w3, self.ch[-1], ch)
 	self.selected = None
 	self.update_zoom()
@@ -457,7 +477,7 @@
     def decoder_menu(self, master, ch, n):
 	mb = Menubutton(master, direction = RIGHT, text = decoders[0][0],
 	  relief = FLAT, width = 16)
-	mb.place(x = 3, y = 50*n+3+self.zres+2)
+	mb.place(x = 3, y = channel_y_step*n+channel_y_offset-3+self.zres+2)
 	mb.menu = Menu(mb, tearoff = 0)
 	mb["menu"] = mb.menu
 
@@ -482,7 +502,7 @@
 	self.measure_width()
 
     def move_y(self, y):
-	ny = y/50
+	ny = y/channel_y_step
 	if ny >= len(self.ch):
 	    return
 	if self.selected is not None:
@@ -549,13 +569,23 @@
 	self.center(event)
 
     def user_coord(self, event):
+	self.w.delete("user")
 	if self.user_pos is None:
 	    self.user_pos = self.cur.pos
 	    self.meas_user.show(0)
+	    self.w.create_polygon(0, 0, 0, 0,
+	      fill = self.user_marker_color, outline = "", tags = "user")
+	    self.move_user()
 	else:
 	    self.user_pos = None
 	    self.meas_user.hide()
 
+    def move_user(self):
+	if self.user_pos is not None:
+	    x = self.ch[0].x(self.user_pos)
+	    self.w.coords("user",
+	      x-7, self.yres+1, x, self.yres-7, x+7, self.yres+1)
+
     def reset(self):
 	end = (self.samples-self.pos0)*self.mag
 	# Entire waveform is on screen
@@ -588,6 +618,7 @@
 	    ch.redraw()
 	self.cur.move(self.cur.x)
 	self.update_zoom()
+	self.move_user()
 
     def update_zoom(self):
 	self.wz.coords(self.zoom_area,
@@ -708,14 +739,20 @@
 	self.cur.move(self.cur.x)
 	
 
+#
+# @@@ The interface is a little ugly with waves containing data and labels,
+# but dxplore separating the two. Perhaps the future common wrapper will make
+# this more palatable.
+#
+
 class dxplore:
 
-    def __init__(self, channels, t0, sample_step, title = None):
+    def __init__(self, channels, t0, sample_step, title = None, labels = None):
 	self.master = Tk()
 	if title is not None:
 	    self.master.title(title)
 	self.master.resizable(1, 0)
-	self.main = main_window(self.master, channels, t0, sample_step)
+	self.main = main_window(self.master, channels, t0, sample_step, labels)
 	self.master.bind("q", self.quit)
 	mainloop()
 

Modified: developers/werner/ahrt/host/tmc/lib/scope.py
===================================================================
--- developers/werner/ahrt/host/tmc/lib/scope.py	2008-12-03 15:33:52 UTC (rev 4844)
+++ developers/werner/ahrt/host/tmc/lib/scope.py	2008-12-04 11:45:48 UTC (rev 4845)
@@ -388,10 +388,12 @@
 	for ch in channels:
 	    if isinstance(ch, channel):
 		res.append(self.download_wave(ch, start, end, step))
+		res[-1].label = ch.name
 	    else:
 		if la is None:
 		    la = self.download_la(start, end, step)
 		res.append(la[ch])
+		res[-1].label = "D"+str(ch)
 	return res
 
     # WORK IN PROGRESS. INTERFACE WILL CHANGE !

Modified: developers/werner/ahrt/host/tmc/lib/wave.py
===================================================================
--- developers/werner/ahrt/host/tmc/lib/wave.py	2008-12-03 15:33:52 UTC (rev 4844)
+++ developers/werner/ahrt/host/tmc/lib/wave.py	2008-12-04 11:45:48 UTC (rev 4845)
@@ -60,6 +60,8 @@
 	f = open(name, ("w", "a")[append])
 	if append:
 	    print >>f
+	if self.label is not None:
+	    print >>f, "# TMC-Label:", self.label
 	for xy in self:
 	    print >>f, xy[0], xy[1]
 	f.close()
@@ -67,6 +69,8 @@
     def load(self, name, step = None):
 	self.__init__()
 	empty = re.compile("^\s*(#.*)$")
+	# note: an empty label counts as no label
+	label = re.compile("^#\s*TMC-Label:\s+(\S+)\s*$")
 	if step is None:
 	    numbers = re.compile("^\s*(\S+)\s*(\S+)\s*")
 	else:
@@ -78,6 +82,9 @@
 	    if line == "":
 		break
 	    if empty.match(line):
+		m = label.match(line)
+		if m is not None:
+		    self.label = m.group(1)
 		continue
 	    m = numbers.match(line)
 	    if m is None:
@@ -100,12 +107,20 @@
 
     def unary(self, op):
 	res = analog()
+	res.label = self.label
 	for p in self:
 	    res.append(float(p[0]), float(op(p[1])))
 	return res
 
     def binary(self, other, op):
 	res = analog()
+	s = self.label
+	if not s:
+	    s = ""
+	if other.label:
+	    if s:
+		s += "_"
+	    s += other.label
 	if isinstance(self, wave):
 	    if isinstance(other, wave):
 		for v in waves(self, other).iterate():
@@ -238,25 +253,41 @@
 	f = open(name, ("w", "a")[append])
 	if append:
 	    print >>f
+
+	s = ""
+	for w in self:
+	    if s:
+		s += ", "
+	    if w.label is not None:
+		s += w.label
+	if s:
+	    print >>f, "# TMC-Label:", s
+
 	for v in self.iterate():
 	    for i in range(0, len(v)-1):
 		print >>f, v[i],
 	    print >>f, v[-1]
+
 	f.close()
 
     def load(self, name, step = None):
 	list.__init__(self)
 	empty = re.compile("^\s*(#.*)$")
+	label = re.compile("^#\s*TMC-Label:\s+((\S*\s*,\s*)*\S*)?\s*$")
 	space = re.compile("\s+")
 	first = True
 	skip = step is None
 	t = 0
+	labels = None
 	f = open(name, "r")
 	while True:
 	    line = f.readline()
 	    if line == "":
 		break
 	    if empty.match(line):
+		m = label.match(line);
+		if m is not None:
+		    labels = m.group(1).split(",")
 		continue
 	    m = space.split(line.lstrip().rstrip())
 	    if first:
@@ -274,6 +305,13 @@
 		    self[i].append(t, float(m[i]))
 		t += step
 	f.close()
+	if labels is None:
+	    return
+	one_label = re.compile("\s*(\S+)\s*")
+	for i in range(0, len(labels)):
+	    m = one_label.match(labels[i])
+	    if m is not None:
+		self[i].label = m.group(1)
 
 
 # === Analog waves ============================================================
@@ -319,6 +357,7 @@
 
     def __init__(self):
 	self.data = []
+	self.label = None
 
     def start(self):
 	if len(self.data) == 0:
@@ -364,6 +403,7 @@
 	if high < low:
 	    raise hell
 	res = digital()
+	res.label = self.label
 	for p in self.data:
 	    if p[1] >= high:
 		res.append(p[0], 1)
@@ -403,6 +443,7 @@
 	self.initial = None
 	self.data = []
 	self.t_end = None
+	self.label = None
 
     def start(self):
 	if self.initial is None:




More information about the commitlog mailing list