[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8753 - gnuradio/branches/developers/jblum/gr-wxglgui/
From: |
jblum |
Subject: |
[Commit-gnuradio] r8753 - gnuradio/branches/developers/jblum/gr-wxglgui/src/python |
Date: |
Mon, 30 Jun 2008 13:42:28 -0600 (MDT) |
Author: jblum
Date: 2008-06-30 13:42:28 -0600 (Mon, 30 Jun 2008)
New Revision: 8753
Modified:
gnuradio/branches/developers/jblum/gr-wxglgui/src/python/fftsink.py
gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py
gnuradio/branches/developers/jblum/gr-wxglgui/src/python/scopesink.py
Log:
removed offset param in plot, scopesink: ref lvl control and better autorange
and triggering
Modified: gnuradio/branches/developers/jblum/gr-wxglgui/src/python/fftsink.py
===================================================================
--- gnuradio/branches/developers/jblum/gr-wxglgui/src/python/fftsink.py
2008-06-30 19:24:49 UTC (rev 8752)
+++ gnuradio/branches/developers/jblum/gr-wxglgui/src/python/fftsink.py
2008-06-30 19:42:28 UTC (rev 8753)
@@ -183,15 +183,13 @@
#plot the fft
self.plotter.set_waveform(
channel=1,
- samples=samples,
- offset=0.0,
+ samples=samples,
color_spec=FFT_PLOT_COLOR_SPEC,
)
#plot the peak hold
self.plotter.set_waveform(
channel=2,
- samples=self.peak_vals,
- offset=0.0,
+ samples=self.peak_vals,
color_spec=PEAK_VALS_COLOR_SPEC,
)
#update the plotter
Modified: gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py
===================================================================
--- gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py
2008-06-30 19:24:49 UTC (rev 8752)
+++ gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py
2008-06-30 19:42:28 UTC (rev 8753)
@@ -194,7 +194,7 @@
# Draw Waveforms
##################################################
for channel in reversed(sorted(self.channels.keys())):
- samples, offset, color_spec = self.channels[channel]
+ samples, color_spec = self.channels[channel]
glColor3f(*color_spec)
glBegin(GL_LINE_STRIP)
num_samps = len(samples)
@@ -202,7 +202,7 @@
x_scalar =
(self.width-self.padding_left-self.padding_right)
x_arr = x_scalar*numpy.arange(0,
num_samps)/float(num_samps-1) + self.padding_left
y_scalar =
(self.height-self.padding_top-self.padding_bottom)
- y_arr = y_scalar*(1 - (numpy.array(samples) + offset -
self.y_min)/(self.y_max-self.y_min)) + self.padding_top
+ y_arr = y_scalar*(1 - (numpy.array(samples) -
self.y_min)/(self.y_max-self.y_min)) + self.padding_top
#draw the lines
for x, y in zip(x_arr, y_arr): glVertex3f(x, y, 0)
glEnd()
@@ -296,7 +296,7 @@
if self.legend:
for i, channel in
enumerate(sorted(self.channels.keys())):
x_off =
1.1*LEGEND_BOX_WIDTH*(len(self.channels) - i - 1) + LEGEND_BOX_WIDTH/2
- samples, offset, color_spec =
self.channels[channel]
+ samples, color_spec = self.channels[channel]
#draw colored rectangle
glColor3f(*color_spec)
self._draw_rect(
@@ -373,15 +373,14 @@
glVertex3f(x, y+height, 0)
glEnd()
- def set_waveform(self, channel, samples, offset, color_spec):
+ def set_waveform(self, channel, samples, color_spec):
"""!
Set the waveform for a given channel.
@param channel the channel number
@param samples the waveform samples
- @param offset the offset to add to each sample
@param color_spec the 3-tuple for line color
"""
- self.channels[channel] = samples, offset, color_spec
+ self.channels[channel] = samples, color_spec
if __name__ == '__main__':
app = wx.PySimpleApp()
Modified: gnuradio/branches/developers/jblum/gr-wxglgui/src/python/scopesink.py
===================================================================
--- gnuradio/branches/developers/jblum/gr-wxglgui/src/python/scopesink.py
2008-06-30 19:24:49 UTC (rev 8752)
+++ gnuradio/branches/developers/jblum/gr-wxglgui/src/python/scopesink.py
2008-06-30 19:42:28 UTC (rev 8753)
@@ -29,6 +29,7 @@
import math
import numpy
import time
+import mutex
##################################################
# Constants
@@ -78,11 +79,18 @@
#begin control box
control_box.AddSpacer(2)
control_box.Add(common.LabelText(self, 'Channel Menu'), 0,
wx.ALIGN_CENTER)
- control_box.AddSpacer(2)
+ control_box.AddSpacer(2)
+ hbox = wx.BoxSizer(wx.HORIZONTAL)
+ control_box.Add(hbox, 1, wx.EXPAND)
#channel chooser drop down
- self.channel_chooser = wx.Choice(self, -1, choices=map(lambda
ch: "Channel %d"%ch, range(1, parent.num_inputs+1)))
+ 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_channel)
- control_box.Add(self.channel_chooser, 0, wx.ALIGN_LEFT)
+ hbox.Add(self.channel_chooser, 0, wx.EXPAND)
+ #Run button
+ control_box.AddSpacer(2)
+ self.run_button = wx.Button(self, -1, '', style=wx.BU_EXACTFIT)
+ self.run_button.Bind(wx.EVT_BUTTON, self._on_run)
+ hbox.Add(self.run_button, 0, wx.EXPAND)
#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)
@@ -118,33 +126,37 @@
#setup axes menu
control_box.AddSpacer(2)
control_box.Add(common.LabelText(self, 'Axes Menu'), 0,
wx.ALIGN_CENTER)
- #x axis
+ #x axis divs
hbox = wx.BoxSizer(wx.HORIZONTAL)
control_box.Add(hbox, 1, 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)
+ self.x_plus_button.Bind(wx.EVT_BUTTON, self._on_incr_x_divs)
hbox.Add(self.x_plus_button, 0, wx.ALIGN_CENTER_VERTICAL |
wx.ALIGN_LEFT)
self.x_minus_button = wx.Button(self, -1, ' - ',
style=wx.BU_EXACTFIT)
- self.x_minus_button.Bind(wx.EVT_BUTTON, self._on_decr_x_axis)
+ self.x_minus_button.Bind(wx.EVT_BUTTON, self._on_decr_x_divs)
hbox.Add(self.x_minus_button, 0, wx.ALIGN_CENTER_VERTICAL |
wx.ALIGN_LEFT)
- #y axis
+ #y axis divs
hbox = wx.BoxSizer(wx.HORIZONTAL)
control_box.Add(hbox, 1, 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)
+ self.y_plus_button.Bind(wx.EVT_BUTTON, self._on_incr_y_divs)
hbox.Add(self.y_plus_button, 0, wx.ALIGN_CENTER_VERTICAL |
wx.ALIGN_LEFT)
self.y_minus_button = wx.Button(self, -1, ' - ',
style=wx.BU_EXACTFIT)
- self.y_minus_button.Bind(wx.EVT_BUTTON, self._on_decr_y_axis)
+ self.y_minus_button.Bind(wx.EVT_BUTTON, self._on_decr_y_divs)
hbox.Add(self.y_minus_button, 0, wx.ALIGN_CENTER_VERTICAL |
wx.ALIGN_LEFT)
+ #y axis ref lvl
+ hbox = wx.BoxSizer(wx.HORIZONTAL)
+ control_box.Add(hbox, 1, wx.ALIGN_LEFT)
+ hbox.Add(wx.StaticText(self, -1, ' Ref Level '), 0,
wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
+ self.ref_lvl_plus_button = wx.Button(self, -1, '+',
style=wx.BU_EXACTFIT)
+ self.ref_lvl_plus_button.Bind(wx.EVT_BUTTON,
self._on_incr_ref_lvl)
+ hbox.Add(self.ref_lvl_plus_button, 0, wx.ALIGN_CENTER_VERTICAL
| wx.ALIGN_LEFT)
+ self.ref_lvl_minus_button = wx.Button(self, -1, ' - ',
style=wx.BU_EXACTFIT)
+ self.ref_lvl_minus_button.Bind(wx.EVT_BUTTON,
self._on_decr_ref_lvl)
+ hbox.Add(self.ref_lvl_minus_button, 0, wx.ALIGN_CENTER_VERTICAL
| wx.ALIGN_LEFT)
- #Run button
- control_box.AddSpacer(2)
- 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)
-
#end control box
control_box.AddSpacer(2)
#set sizer
@@ -177,9 +189,13 @@
if self.parent.autorange_index is None:
self.y_plus_button.Enable()
self.y_minus_button.Enable()
+ self.ref_lvl_plus_button.Enable()
+ self.ref_lvl_minus_button.Enable()
else:
self.y_plus_button.Disable()
- self.y_minus_button.Disable()
+ self.y_minus_button.Disable()
+ self.ref_lvl_plus_button.Disable()
+ self.ref_lvl_minus_button.Disable()
##################################################
# Event handlers
@@ -191,10 +207,12 @@
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))
- def _on_decr_y_axis(self, event):
self.parent.set_y_per_div(common.get_clean_decr(self.parent.y_per_div))
+ def _on_incr_x_divs(self, event):
self.parent.set_x_per_div(common.get_clean_incr(self.parent.x_per_div))
+ def _on_decr_x_divs(self, event):
self.parent.set_x_per_div(common.get_clean_decr(self.parent.x_per_div))
+ def _on_incr_y_divs(self, event):
self.parent.set_y_per_div(common.get_clean_incr(self.parent.y_per_div))
+ def _on_decr_y_divs(self, event):
self.parent.set_y_per_div(common.get_clean_decr(self.parent.y_per_div))
+ def _on_incr_ref_lvl(self, event):
self.parent.set_y_off(self.parent.y_off + self.parent.y_per_div)
+ def _on_decr_ref_lvl(self, event):
self.parent.set_y_off(self.parent.y_off - self.parent.y_per_div)
def _on_run(self, event): self.parent.set_run(not self.parent.running)
##################################################
@@ -217,6 +235,7 @@
#check num inputs
assert num_inputs <= len(CHANNEL_COLOR_SPECS)
#setup
+ self.mutex = mutex.mutex()
self.running = True
self.num_inputs = num_inputs
self.sample_rate = sample_rate
@@ -225,14 +244,19 @@
else: self.autorange_index = None
self.autorange_ts = 0
self.input_index = 0
+ #triggering
self.trigger_index = 0
self.trigger_mode_index = 1
self.trigger_level_index = 0
+ #x grid settings
self.x_divs = 8
self.x_per_div = x_per_div
+ self.x_off = 0
+ #y grid settings
self.y_divs = 8
if y_per_div is None: self.y_per_div = 1
else: self.y_per_div = y_per_div
+ self.y_off = 0
self.scope = scope
self.frame_rate = frame_rate
self.frame_counter = 0
@@ -266,39 +290,46 @@
for i, samples in enumerate(sampleses):
#number of samples to scale to the screen
num_samps =
int(self.x_per_div*self.x_divs*self.sample_rate)
+ #trigger level (must do before ac coupling)
+ if i == self.trigger_index:
+ 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*(numpy.max(samples)-numpy.min(samples))/2
+ numpy.average(samples))
#ac coupling
if self.ac_couple[i]: samples = samples -
numpy.average(samples)
#autorange
if self.autorange_index == i and \
- time.time() - self.autorange_ts >
AUTORANGE_UPDATE_RATE:
- rms =
numpy.average(numpy.square(samples))**.5
- mean = numpy.average(samples)
- y_per_div =
common.get_clean_num(4*(rms+mean)/self.y_divs)
+ time.time() - self.autorange_ts >
AUTORANGE_UPDATE_RATE:
+ min = numpy.min(samples)
+ max = numpy.max(samples)
+ #adjust the y per div
+ y_per_div =
common.get_clean_num(1.5*(max-min)/self.y_divs)
if self.y_per_div != y_per_div:
self.set_y_per_div(y_per_div)
+ #adjust the y offset
+ y_off =
self.y_per_div*round((max+min)/2/self.y_per_div)
+ if self.y_off != y_off:
self.set_y_off(y_off)
self.autorange_ts = time.time()
#handle num samps out of bounds
- if num_samps > len(samples) or num_samps < 2:
continue
+ while num_samps > len(samples): samples =
numpy.concatenate((samples, samples))
+ if num_samps < 2: num_samps = 0
#plot samples
self.plotter.set_waveform(
channel=i+1,
- samples=samples[:num_samps],
- offset=0.0,
+ samples=samples[:num_samps],
color_spec=CHANNEL_COLOR_SPECS[i],
- )
+ )
#update the plotter
self.plotter.update()
self.frame_counter = (self.frame_counter + 1)%self.decim
- def update(self):
+ def update(self): self.mutex.lock(self._update, None)
+ def _update(self, arg=None):
#update the frame decimation
self.decim = max(1,
int(self.sample_rate/self.scope.get_samples_per_output_record()/self.frame_rate))
#update the scope
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)
+
self.scope.set_trigger_mode(TRIGGER_MODES[self.trigger_mode_index][1])
self.scope.set_sample_rate(self.sample_rate)
#update the x axis
exp = common.get_exp(self.x_per_div)
@@ -307,14 +338,23 @@
elif exp > -8: 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)
+ self.plotter.set_x_grid(
+ scalar*self.x_off,
+ scalar*self.x_per_div*self.x_divs + scalar*self.x_off,
+ scalar*self.x_per_div,
+ )
#update the y axis
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.plotter.set_y_grid(
+ -1*self.y_per_div*self.y_divs/2.0 + self.y_off,
+ self.y_per_div*self.y_divs/2.0 + self.y_off,
+ self.y_per_div,
+ )
+ #update control panel and plotter
self.control_panel.update()
- #update the plotter
self.plotter.update()
+ #unlock mutex
+ self.mutex.unlock()
##################################################
# Set parameters on-the-fly
@@ -322,9 +362,15 @@
def set_x_per_div(self, x_per_div):
self.x_per_div = x_per_div
self.update()
+ def set_x_off(self, x_off):
+ self.x_off = x_off
+ self.update()
def set_y_per_div(self, y_per_div):
self.y_per_div = y_per_div
self.update()
+ def set_y_off(self, y_off):
+ self.y_off = y_off
+ self.update()
def set_input_index(self, input_index):
self.input_index = input_index
self.update()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8753 - gnuradio/branches/developers/jblum/gr-wxglgui/src/python,
jblum <=