[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8748 - gnuradio/branches/developers/jblum/gr-wxglgui/
From: |
jblum |
Subject: |
[Commit-gnuradio] r8748 - gnuradio/branches/developers/jblum/gr-wxglgui/src/python |
Date: |
Sun, 29 Jun 2008 00:34:18 -0600 (MDT) |
Author: jblum
Date: 2008-06-29 00:34:18 -0600 (Sun, 29 Jun 2008)
New Revision: 8748
Modified:
gnuradio/branches/developers/jblum/gr-wxglgui/src/python/common.py
gnuradio/branches/developers/jblum/gr-wxglgui/src/python/scopesink.py
Log:
proper time scaling, ac coupling, triggering
Modified: gnuradio/branches/developers/jblum/gr-wxglgui/src/python/common.py
===================================================================
--- gnuradio/branches/developers/jblum/gr-wxglgui/src/python/common.py
2008-06-29 03:25:15 UTC (rev 8747)
+++ gnuradio/branches/developers/jblum/gr-wxglgui/src/python/common.py
2008-06-29 06:34:18 UTC (rev 8748)
@@ -34,7 +34,6 @@
wx.StaticText.__init__(self, window, -1, label)
font = self.GetFont()
font.SetWeight(wx.FONTWEIGHT_BOLD)
- font.SetUnderlined(True)
self.SetFont(font)
class input_watcher(threading.Thread):
Modified: gnuradio/branches/developers/jblum/gr-wxglgui/src/python/scopesink.py
===================================================================
--- gnuradio/branches/developers/jblum/gr-wxglgui/src/python/scopesink.py
2008-06-29 03:25:15 UTC (rev 8747)
+++ gnuradio/branches/developers/jblum/gr-wxglgui/src/python/scopesink.py
2008-06-29 06:34:18 UTC (rev 8748)
@@ -41,9 +41,13 @@
)
TRIGGER_LEVELS = (
('Auto', None),
- ('Low', -0.5),
- ('Med', 0.0),
- ('High', 0.5),
+ ('+High', 0.75),
+ ('+Med', 0.5),
+ ('+Low', 0.25),
+ ('Zero', 0.0),
+ ('-Low', -0.25),
+ ('-Med', -0.5),
+ ('-High', -0.75),
)
CHANNEL_COLOR_SPECS = (
(0, 0, 1),
@@ -70,41 +74,38 @@
#begin control box
control_box.AddStretchSpacer()
- control_box.Add(common.LabelText(self, 'Select Channel'), 0,
wx.ALIGN_CENTER)
- #channel and trigger box
- channel_trigger_box = wx.BoxSizer(wx.HORIZONTAL)
- control_box.Add(channel_trigger_box, 0, wx.EXPAND)
+ control_box.Add(common.LabelText(self, 'Channel Menu'), 0,
wx.ALIGN_CENTER)
+ control_box.AddSpacer(2)
#channel chooser drop down
- self.channel_chooser = wx.Choice(self, -1, choices=map(lambda
ch: "Ch%d"%ch, range(1, parent.num_inputs+1)))
- self.channel_chooser.Bind(wx.EVT_CHOICE, self._on_chooser)
- channel_trigger_box.Add(self.channel_chooser, 0,
wx.ALIGN_CENTER)
- #trigger button
- self.trigger_button = wx.Button(self, -1, 'Trigger',
style=wx.BU_EXACTFIT)
- self.trigger_button.Bind(wx.EVT_BUTTON, self._on_set_trigger)
- channel_trigger_box.Add(self.trigger_button, 0, wx.ALIGN_CENTER)
+ self.channel_chooser = wx.Choice(self, -1, choices=map(lambda
ch: "Channel %d"%ch, range(1, parent.num_inputs+1)))
+ self.channel_chooser.Bind(wx.EVT_CHOICE, self._on_channel)
+ control_box.Add(self.channel_chooser, 0, wx.ALIGN_LEFT)
+ #trigger check box
+ self.trigger_check_box = wx.CheckBox(parent=self,
style=wx.CHK_2STATE, label="Trigger")
+ self.trigger_check_box.Bind(wx.EVT_CHECKBOX,
self._on_set_trigger)
+ control_box.Add(self.trigger_check_box, 0, wx.ALIGN_LEFT)
+ #ac couple check box
+ self.ac_couple_check_box = wx.CheckBox(parent=self,
style=wx.CHK_2STATE, label="AC Couple")
+ self.ac_couple_check_box.Bind(wx.EVT_CHECKBOX,
self._on_set_ac_couple)
+ control_box.Add(self.ac_couple_check_box, 0, wx.ALIGN_LEFT)
- #offset slider
- control_box.AddStretchSpacer()
- control_box.Add(common.LabelText(self, 'Channel Offset'), 0,
wx.ALIGN_CENTER)
- self.offset_slider = wx.Slider(self, -1, style=wx.SL_HORIZONTAL)
- control_box.Add(self.offset_slider, 0, wx.EXPAND)
-
#trigger menu
control_box.AddStretchSpacer()
control_box.Add(common.LabelText(self, 'Trigger Menu'), 0,
wx.ALIGN_CENTER)
+ control_box.AddSpacer(2)
#trigger mode
hbox = wx.BoxSizer(wx.HORIZONTAL)
control_box.Add(hbox, 1, wx.ALIGN_LEFT)
- hbox.Add(common.LabelText(self, ' Mode: '), 0,
wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
+ hbox.Add(wx.StaticText(self, -1, ' Mode '), 0,
wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
self.trigger_mode_chooser = wx.Choice(self, -1, choices=[tm[0]
for tm in TRIGGER_MODES])
- self.trigger_mode_chooser.Bind(wx.EVT_CHOICE, self._on_chooser)
+ self.trigger_mode_chooser.Bind(wx.EVT_CHOICE,
self._on_trigger_mode)
hbox.Add(self.trigger_mode_chooser, 0, wx.ALIGN_CENTER_VERTICAL
| wx.ALIGN_LEFT)
#trigger level
hbox = wx.BoxSizer(wx.HORIZONTAL)
control_box.Add(hbox, 1, wx.ALIGN_LEFT)
- hbox.Add(common.LabelText(self, ' Level: '), 0,
wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
+ hbox.Add(wx.StaticText(self, -1, ' Level '), 0,
wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
self.trigger_level_chooser = wx.Choice(self, -1, choices=[tl[0]
for tl in TRIGGER_LEVELS])
- self.trigger_level_chooser.Bind(wx.EVT_CHOICE, self._on_chooser)
+ self.trigger_level_chooser.Bind(wx.EVT_CHOICE,
self._on_trigger_level)
hbox.Add(self.trigger_level_chooser, 0,
wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
#setup axes menu
@@ -113,7 +114,7 @@
#x axis
hbox = wx.BoxSizer(wx.HORIZONTAL)
control_box.Add(hbox, 1, wx.ALIGN_LEFT)
- hbox.Add(common.LabelText(self, ' Time: '), 0,
wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
+ hbox.Add(wx.StaticText(self, -1, ' Secs/Div '), 0,
wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
self.x_plus_button = wx.Button(self, -1, '+',
style=wx.BU_EXACTFIT)
self.x_plus_button.Bind(wx.EVT_BUTTON, self._on_incr_x_axis)
hbox.Add(self.x_plus_button, 0, wx.ALIGN_CENTER_VERTICAL |
wx.ALIGN_LEFT)
@@ -123,7 +124,7 @@
#y axis
hbox = wx.BoxSizer(wx.HORIZONTAL)
control_box.Add(hbox, 1, wx.ALIGN_LEFT)
- hbox.Add(common.LabelText(self, ' Volts: '), 0,
wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
+ hbox.Add(wx.StaticText(self, -1, ' Units/Div '), 0,
wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
self.y_plus_button = wx.Button(self, -1, '+',
style=wx.BU_EXACTFIT)
self.y_plus_button.Bind(wx.EVT_BUTTON, self._on_incr_y_axis)
hbox.Add(self.y_plus_button, 0, wx.ALIGN_CENTER_VERTICAL |
wx.ALIGN_LEFT)
@@ -132,11 +133,11 @@
hbox.Add(self.y_minus_button, 0, wx.ALIGN_CENTER_VERTICAL |
wx.ALIGN_LEFT)
#Run button
+ control_box.AddStretchSpacer()
self.run_button = wx.Button(self, -1, '', style=wx.BU_EXACTFIT)
self.run_button.Bind(wx.EVT_BUTTON, self._on_run)
control_box.Add(self.run_button, 0, wx.ALIGN_CENTER)
- #TODO AC couple for each channel
#TODO autorange y axis
#end control box
@@ -152,27 +153,31 @@
"""
#update the channel chooser
self.channel_chooser.SetSelection(self.parent.input_index)
- #update the trigger button
- if self.parent.trigger_index == self.parent.input_index:
- self.trigger_button.Disable()
- else: self.trigger_button.Enable()
+ #update the trigger check box
+ checked = self.parent.input_index == self.parent.trigger_index
+ self.trigger_check_box.SetValue(checked)
+ if checked: self.trigger_check_box.Disable()
+ else: self.trigger_check_box.Enable()
+ #update the ac couple check box
+
self.ac_couple_check_box.SetValue(self.parent.ac_couple[self.parent.input_index])
+ #update trigger mode and level chooser
+
self.trigger_level_chooser.SetSelection(self.parent.trigger_level_index)
+
self.trigger_mode_chooser.SetSelection(self.parent.trigger_mode_index)
#update the run/stop button
if self.parent.running: self.run_button.SetLabel('Stop')
else: self.run_button.SetLabel('Run')
#update the slider
#TODO
- #update the trigger mode chooser
-
self.trigger_mode_chooser.SetSelection(self.parent.trigger_mode_index)
-
self.trigger_level_chooser.SetSelection(self.parent.trigger_level_index)
##################################################
# Event handlers
- ##################################################
- def _on_chooser(self, event):
- self.parent.set_input_index(self.channel_chooser.GetSelection())
-
self.parent.set_trigger_mode_index(self.trigger_mode_chooser.GetSelection())
-
self.parent.set_trigger_level_index(self.trigger_level_chooser.GetSelection())
- def _on_set_trigger(self, event):
self.parent.set_trigger_index(self.parent.input_index)
+ ##################################################
+ def _on_channel(self, event):
self.parent.set_input_index(self.channel_chooser.GetSelection())
+ def _on_set_ac_couple(self, event):
self.parent.set_ac_couple(self.parent.input_index, event.IsChecked())
+ def _on_trigger_mode(self, event):
self.parent.set_trigger_mode_index(self.trigger_mode_chooser.GetSelection())
+ def _on_trigger_level(self, event):
self.parent.set_trigger_level_index(self.trigger_level_chooser.GetSelection())
+ def _on_set_trigger(self, event):
+ if event.IsChecked():
self.parent.set_trigger_index(self.parent.input_index)
def _on_incr_x_axis(self, event):
self.parent.set_x_per_div(common.get_clean_incr(self.parent.x_per_div))
def _on_decr_x_axis(self, event):
self.parent.set_x_per_div(common.get_clean_decr(self.parent.x_per_div))
def _on_incr_y_axis(self, event):
self.parent.set_y_per_div(common.get_clean_incr(self.parent.y_per_div))
@@ -190,12 +195,17 @@
title,
scope,
num_inputs,
+ sample_rate,
x_per_div,
y_per_div,
):
+ #check num inputs
+ assert num_inputs <= len(CHANNEL_COLOR_SPECS)
#setup
self.running = True
self.num_inputs = num_inputs
+ self.sample_rate = sample_rate
+ self.ac_couple = [False]*num_inputs
self.input_index = 0
self.trigger_index = 0
self.trigger_mode_index = 0
@@ -204,6 +214,8 @@
self.x_per_div = x_per_div
self.y_divs = 8
self.y_per_div = y_per_div
+ self.scope = scope
+ self._init = False #HACK
#init panel and plot
wx.Panel.__init__(self, parent, -1)
self.plotter = plotter.grid_plotter(self)
@@ -219,28 +231,46 @@
self.update()
def update(self):
+ #update the trigger
+ if self._init: #HACK avoid segfaults, only set after a sample
has arrived
+ self.scope.set_trigger_channel(self.trigger_index)
+
self.scope.set_trigger_mode(TRIGGER_MODES[self.trigger_mode_index][1])
+ trigger_level =
TRIGGER_LEVELS[self.trigger_level_index][1]
+ if trigger_level is None:
self.scope.set_trigger_level_auto()
+ else:
self.scope.set_trigger_level(trigger_level*self.y_divs*self.y_per_div/2.0)
#update the x axis
- self.plotter.set_x_units('Time (s)')
- self.plotter.set_x_grid(0, self.x_per_div*self.x_divs,
self.x_per_div)
+ exp = common.get_exp(self.x_per_div)
+ if exp >= -0: x_units, scalar = 's', 1e0
+ elif exp >= -3: x_units, scalar = 'ms', 1e3
+ elif exp >= -6: x_units, scalar = 'us', 1e6
+ else: x_units, scalar = 'ns', 1e9
+ self.plotter.set_x_units('Time (%s)'%x_units)
+ self.plotter.set_x_grid(0, scalar*self.x_per_div*self.x_divs,
scalar*self.x_per_div)
#update the y axis
- self.plotter.set_y_units('Voltage (v)')
- self.plotter.set_y_grid(-1*self.y_per_div*self.y_divs/2,
self.y_per_div*self.y_divs/2, self.y_per_div)
+ self.plotter.set_y_units('Units')
+ self.plotter.set_y_grid(-1*self.y_per_div*self.y_divs/2.0,
self.y_per_div*self.y_divs/2.0, self.y_per_div)
#update control panel
self.control_panel.update()
#update the plotter
self.plotter.update()
def plot(self, sampleses):
+ if not self._init: #HACK
+ self._init = True
+ self.update()
if not self.running: return
for i, samples in enumerate(sampleses):
- #number of samples to scale to the screen
- num_samps =
int(len(samples)/(1250*self.x_per_div*self.x_divs))
+ #number of samples to scale to the screen
+ num_samps =
int(self.x_per_div*self.x_divs*self.sample_rate)
+ #ac coupling
+ if self.ac_couple[i]: offset = -1*numpy.average(samples)
+ else: offset = 0
#TODO handle num samps out of bounds
if num_samps > len(samples) or num_samps < 2: continue
self.plotter.set_waveform(
channel=i,
samples=samples[:num_samps],
- offset=0.0,
+ offset=offset,
color_spec=CHANNEL_COLOR_SPECS[i],
)
#update the plotter
@@ -270,6 +300,9 @@
def set_run(self, running):
self.running = running
self.update()
+ def set_ac_couple(self, channel_index, ac_couple):
+ self.ac_couple[channel_index] = ac_couple
+ self.update()
##################################################
# Scope sink block
@@ -311,6 +344,7 @@
title=title,
scope=scope,
num_inputs=num_inputs,
+ sample_rate=sample_rate,
x_per_div=t_scale,
y_per_div=v_scale,
)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8748 - gnuradio/branches/developers/jblum/gr-wxglgui/src/python,
jblum <=