r4655 - developers/werner/ahrt/host/tmc/lib
werner at docs.openmoko.org
werner at docs.openmoko.org
Thu Sep 18 07:22:51 CEST 2008
Author: werner
Date: 2008-09-18 07:22:49 +0200 (Thu, 18 Sep 2008)
New Revision: 4655
Modified:
developers/werner/ahrt/host/tmc/lib/decode.py
developers/werner/ahrt/host/tmc/lib/dxplore.py
developers/werner/ahrt/host/tmc/lib/scope.py
Log:
Highlights:
- finally realized that the troubles with the Rigol's horizontal system are
caused by rounding errors in the scope's firmware
- added dxplore status display with window size, sample stop, and zoom factor
Details:
- lib/scope.py (horizontal.__init__): the Rigol DS1000C rounds :TIM:SCAL 0.0005
up and thus sets the time base to 1ms instead of 500us. We therefore set the
time base to 99% of the desired value.
- lib/dxplore.py: added status display with window size, sample step, and zoom
factor
Modified: developers/werner/ahrt/host/tmc/lib/decode.py
===================================================================
--- developers/werner/ahrt/host/tmc/lib/decode.py 2008-09-18 03:58:22 UTC (rev 4654)
+++ developers/werner/ahrt/host/tmc/lib/decode.py 2008-09-18 05:22:49 UTC (rev 4655)
@@ -11,7 +11,18 @@
# (at your option) any later version.
#
+#
+# New-style decoders:
+#
+# - return a list of tuples
+# - each tuple: (#bits, short, fmt, long)
+# - #bits: number of bits this tuple decodes
+# - short: short description
+# - fmt: printf-style format string for text-only display
+# - long: long description, e.g., for tooltips
+#
+
import tmc.crc
Modified: developers/werner/ahrt/host/tmc/lib/dxplore.py
===================================================================
--- developers/werner/ahrt/host/tmc/lib/dxplore.py 2008-09-18 03:58:22 UTC (rev 4654)
+++ developers/werner/ahrt/host/tmc/lib/dxplore.py 2008-09-18 05:22:49 UTC (rev 4655)
@@ -25,6 +25,7 @@
from Tkinter import *
from tmc.decode import *
from math import ceil, floor
+from string import maketrans
class channel:
@@ -133,43 +134,11 @@
self.main.w.delete("d_bg_"+self.tag)
-class measurement:
+# Base class to have access to the pretty-printing methods.
- background_color = "black"
- color = "white"
- font = "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*"
- # sigh, where's a mono-spaced font with a sans-serif "1" when you need
- # one ...
- font = "-*-fixed-medium-r-normal-*-14-*-*-*-*-*-iso8859-*"
+class measurement_base:
- def __init__(self, master, t0, dt, prefix = ""):
- self.fn = (
- ( self.show_samples, "Sa" ),
- ( self.show_time, "s " ),
- ( self.show_frequency, "Hz" ))
-
- self.t0 = t0
- self.dt = dt
- self.prefix = prefix
- self.last_prefix = None
- self.var = StringVar()
- self.button = Button(master, textvariable = self.var, width = 14,
- relief = FLAT, borderwidth = 0, font = self.font,
- fg = self.color, bg = self.background_color,
- activeforeground = self.color,
- activebackground = self.background_color,
- command = self.button)
- self.button.pack(side = LEFT)
- self.index = 0
- self.last = None
- self.hide()
-
- def button(self):
- self.index += 1
- self.index %= len(self.fn)
- self.__show(self.last)
-
- def pretty_float(self, f):
+ def pretty_float_common(self, f):
if f < 0:
sign = True
f = -f
@@ -203,14 +172,25 @@
print f
raise hell
+ return sign, f, unit
+
+ def pretty_float(self, f):
+ sign, f, unit = self.pretty_float_common(f)
return "%s%7.3f%s" % ((" ", "-")[sign], f, unit)
- # Comment out the line above to remove trailing zeroes, e.g.,
- # 5.100 becomes 5.1. While this looks like a nice idea, I found the
- # constantly changing format somewhat irritating. It's also inaccurate
- # in the sense that these numbers represent physical units well above
- # quantum level and therefore cannot be exact.
+ #
+ # pretty_float_trim is like pretty_float but it removes trailing zeroes,
+ # e.g., 5.100 becomes 5.1. While this looks like a nice idea, I found the
+ # constantly changing format somewhat irritating, so I don't use it for the
+ # continuously updated measurements.
+ #
+ # It's also inaccurate in the sense that these numbers represent physical
+ # units well above quantum level and therefore cannot be exact.
+ #
+ def pretty_float_trim(self, f):
+ sign, f, unit = self.pretty_float_common(f)
+
if round(f*1000) == round(f)*1000:
dec = 0
elif round(f*1000) == round(f*10)*100:
@@ -228,6 +208,43 @@
4-fract, "",
unit)
+
+class measurement(measurement_base):
+
+ background_color = "black"
+ color = "white"
+ font = "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*"
+ # sigh, where's a mono-spaced font with a sans-serif "1" when you need
+ # one ...
+ font = "-*-fixed-medium-r-normal-*-14-*-*-*-*-*-iso8859-*"
+
+ def __init__(self, master, t0, dt, prefix = ""):
+ self.fn = (
+ ( self.show_samples, "Sa" ),
+ ( self.show_time, "s " ),
+ ( self.show_frequency, "Hz" ))
+
+ self.t0 = t0
+ self.dt = dt
+ self.prefix = prefix
+ self.last_prefix = None
+ self.var = StringVar()
+ self.button = Button(master, textvariable = self.var, width = 14,
+ relief = FLAT, borderwidth = 0, font = self.font,
+ fg = self.color, bg = self.background_color,
+ activeforeground = self.color,
+ activebackground = self.background_color,
+ command = self.button)
+ self.button.pack(side = LEFT)
+ self.index = 0
+ self.last = None
+ self.hide()
+
+ def button(self):
+ self.index += 1
+ self.index %= len(self.fn)
+ self.__show(self.last)
+
def show_samples(self, samples):
self.var.set(self.prefix+"%8d Sa" % samples)
@@ -311,6 +328,7 @@
def __init__(self, master, d, t0, sample_step):
channels = len(d)
self.samples = len(d[0])
+ self.sample_step = sample_step
self.xres = self.samples
self.yres = channels*50
self.zres = channels*6+2
@@ -319,7 +337,7 @@
self.wz = self.zoom_window(master)
self.w = self.main_window(master)
self.wt = self.tick_window(master)
- self.wd = self.meas_window(master, t0, sample_step)
+ self.wd = self.meas_window(master, t0)
self.setup_events(master)
self.decode_from = None
self.user_pos = None
@@ -352,16 +370,25 @@
fill = self.background_color, width = 0)
return w
- def meas_window(self, master, t0, sample_step):
+ def meas_window(self, master, t0):
w = Frame(master, width = self.xres, height = 20,
bg = self.background_color)
w.pack(expand = 1, fill = "x")
- self.meas_start = measurement(w, 0, sample_step, "SEL ")
- self.meas_pos = measurement(w, t0, sample_step, "CUR ")
- self.meas_user = measurement(w, 0, sample_step, "USR ")
- self.meas_width = measurement(w, 0, sample_step)
+ self.meas_start = measurement(w, 0, self.sample_step, "SEL ")
+ self.meas_pos = measurement(w, t0, self.sample_step, "CUR ")
+ self.meas_user = measurement(w, 0, self.sample_step, "USR ")
+ self.meas_width = measurement(w, 0, self.sample_step)
+ self.meas_status = measurement_base()
+ self.status_var = StringVar()
+ self.status = Label(w, textvariable = self.status_var,
+ relief = FLAT, borderwidth = 0, font = measurement.font,
+ fg = measurement.color, bg = measurement.background_color,
+ activeforeground = measurement.color,
+ activebackground = measurement.background_color)
+ self.status.pack(side = RIGHT, fill = "x")
+
def tick_window(self, master):
w = Canvas(master, width = self.xres, height = 20,
bg = self.background_color)
@@ -533,6 +560,21 @@
int(float(self.pos0)/self.samples*self.xres), 0,
int(ceil((self.pos0+self.xres/self.mag)/self.samples*self.xres)),
self.zres)
+ shown = min(self.samples, self.xres/self.mag)
+ if self.pos0 < 0:
+ shown = min(shown, self.xres/self.mag+self.pos0)
+ if self.pos0 > 0:
+ shown = min(shown, self.samples-self.pos0)
+ self.status_var.set(
+ "%d/%d Sa, %ss/%ss, step %ss, %s%d" % (shown, self.samples,
+ self.meas_status.pretty_float_trim(shown*self.sample_step).
+ translate(maketrans("", ""), " "),
+ self.meas_status.pretty_float_trim(self.samples*self.sample_step).
+ translate(maketrans("", ""), " "),
+ self.meas_status.pretty_float_trim(self.sample_step).
+ translate(maketrans("", ""), " "),
+ ("/", "x")[self.mag > 0.9],
+ (1.0/self.mag, self.mag)[self.mag > 0.9]))
def button(self, event):
if self.decode_from is None:
Modified: developers/werner/ahrt/host/tmc/lib/scope.py
===================================================================
--- developers/werner/ahrt/host/tmc/lib/scope.py 2008-09-18 03:58:22 UTC (rev 4654)
+++ developers/werner/ahrt/host/tmc/lib/scope.py 2008-09-18 05:22:49 UTC (rev 4655)
@@ -164,11 +164,11 @@
def __init__(self, scope):
self.scope = scope
self.pos = setting(scope, ":TIM:OFFS",
- lambda x: float(x),
- lambda x: "%.9f" % x)
+ lambda x: float(x))
self.scale = setting(scope, ":TIM:SCAL",
lambda x: float(x),
- lambda x: "%.9f" % x)
+ lambda x: x*0.99)
+ # Rigol special: 0.0005 becomes 1ms, so we have to round down :-(
self.sweep = horizontal_trigger_setting(scope,
trigger.set_sweep, trigger.get_sweep)
self.lock_attr()
More information about the commitlog
mailing list