commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r10470 - in gnuradio/branches/developers/jblum/gui_gut


From: jblum
Subject: [Commit-gnuradio] r10470 - in gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python: . plotter
Date: Thu, 19 Feb 2009 19:11:27 -0700 (MST)

Author: jblum
Date: 2009-02-19 19:11:26 -0700 (Thu, 19 Feb 2009)
New Revision: 10470

Modified:
   
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/channel_plotter.py
   
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scope_window.py
   
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scopesink_gl.py
Log:
trigger control w/ incr/decr buttons, 50% button, and trigger line on display

Modified: 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/channel_plotter.py
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/channel_plotter.py
  2009-02-20 00:37:29 UTC (rev 10469)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/plotter/channel_plotter.py
  2009-02-20 02:11:26 UTC (rev 10470)
@@ -189,7 +189,7 @@
                        txt.draw_text(wx.Point(x_off - w, self.padding_top/2 - 
h/2))
                        x_off -= w + 4*LEGEND_BOX_PADDING
 
-       def set_waveform(self, channel, samples, color_spec, marker=None, 
trig_off=0):
+       def set_waveform(self, channel, samples=[], color_spec=(0, 0, 0), 
marker=None, trig_off=0):
                """
                Set the waveform for a given channel.
                @param channel the channel key

Modified: 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scope_window.py
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scope_window.py 
    2009-02-20 00:37:29 UTC (rev 10469)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scope_window.py 
    2009-02-20 02:11:26 UTC (rev 10470)
@@ -43,25 +43,16 @@
        ('Normal', gr.gr_TRIG_MODE_NORM),
 )
 TRIGGER_SLOPES = (
-       ('Positive', gr.gr_TRIG_SLOPE_POS),
-       ('Negative', gr.gr_TRIG_SLOPE_NEG),
+       ('Positive +', gr.gr_TRIG_SLOPE_POS),
+       ('Negative -', gr.gr_TRIG_SLOPE_NEG),
 )
-TRIGGER_LEVELS = (
-       ('Automatic', None),
-       ('+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),
        (0, 1, 0),
        (1, 0, 0),
        (1, 0, 1),
 )
+TRIGGER_COLOR_SPEC = (1, .4, 0)
 AUTORANGE_UPDATE_RATE = 0.5 #sec
 MARKER_TYPES = (
        ('Dot Small', 1.0),
@@ -90,6 +81,11 @@
                control_box.AddStretchSpacer()
                control_box.Add(common.LabelText(self, 'Trigger Options'), 0, 
wx.ALIGN_CENTER)
                control_box.AddSpacer(2)
+               #trigger channel
+               choices = [('Channel %d'%(i+1), i) for i in 
range(parent.num_inputs)]
+               self.trigger_channel_chooser = common.DropDownController(self, 
'Channel', choices, parent.ext_controller, parent.trigger_channel_key)
+               parent.ext_controller.subscribe(parent.trigger_mode_key, lambda 
x: self.trigger_channel_chooser.Disable(x==gr.gr_TRIG_MODE_FREE))
+               control_box.Add(self.trigger_channel_chooser, 0, wx.EXPAND)
                #trigger mode
                self.trigger_mode_chooser = common.DropDownController(self, 
'Mode', TRIGGER_MODES, parent.ext_controller, parent.trigger_mode_key)
                control_box.Add(self.trigger_mode_chooser, 0, wx.EXPAND)
@@ -98,14 +94,20 @@
                parent.ext_controller.subscribe(parent.trigger_mode_key, lambda 
x: self.trigger_slope_chooser.Disable(x==gr.gr_TRIG_MODE_FREE))
                control_box.Add(self.trigger_slope_chooser, 0, wx.EXPAND)
                #trigger level
-               self.trigger_level_chooser = common.DropDownController(self, 
'Level', TRIGGER_LEVELS, parent, SCOPE_TRIGGER_LEVEL_KEY)
-               parent.ext_controller.subscribe(parent.trigger_mode_key, lambda 
x: self.trigger_level_chooser.Disable(x==gr.gr_TRIG_MODE_FREE))
-               control_box.Add(self.trigger_level_chooser, 0, wx.EXPAND)
-               #trigger channel
-               choices = [('Channel %d'%(i+1), i) for i in 
range(parent.num_inputs)]
-               self.trigger_channel_chooser = common.DropDownController(self, 
'Channel', choices, parent.ext_controller, parent.trigger_channel_key)
-               parent.ext_controller.subscribe(parent.trigger_mode_key, lambda 
x: self.trigger_channel_chooser.Disable(x==gr.gr_TRIG_MODE_FREE))
-               control_box.Add(self.trigger_channel_chooser, 0, wx.EXPAND)
+               hbox = wx.BoxSizer(wx.HORIZONTAL)
+               control_box.Add(hbox, 0, wx.EXPAND)
+               hbox.Add(wx.StaticText(self, -1, ' Level '), 1, 
wx.ALIGN_CENTER_VERTICAL)
+               trigger_level_button = wx.Button(self, label='50%', 
style=wx.BU_EXACTFIT)
+               def trigger_level_button_disable(x):
+                       if x==gr.gr_TRIG_MODE_FREE: 
trigger_level_button.Disable()
+                       else: trigger_level_button.Enable()
+               parent.ext_controller.subscribe(parent.trigger_mode_key, 
trigger_level_button_disable)
+               trigger_level_button.Bind(wx.EVT_BUTTON, 
self.parent.set_auto_trigger_level)
+               hbox.Add(trigger_level_button, 0, wx.ALIGN_CENTER_VERTICAL)
+               hbox.AddSpacer(10)
+               trigger_level_buttons = common.IncrDecrButtons(self, 
self._on_incr_trigger_level, self._on_decr_trigger_level)
+               parent.ext_controller.subscribe(parent.trigger_mode_key, lambda 
x: trigger_level_buttons.Disable(x==gr.gr_TRIG_MODE_FREE))
+               hbox.Add(trigger_level_buttons, 0, wx.ALIGN_CENTER_VERTICAL)
                #axes options
                SPACING = 15
                control_box.AddStretchSpacer()
@@ -213,6 +215,13 @@
                self.scope_mode_box.ShowItems(not mode)
                self.xy_mode_box.ShowItems(mode)
                self.control_box.Layout()
+       #trigger level
+       def _on_incr_trigger_level(self, event):
+               self.parent.ext_controller[self.parent.trigger_level_key] += \
+                       self.parent[Y_PER_DIV_KEY]/3.
+       def _on_decr_trigger_level(self, event):
+               self.parent.ext_controller[self.parent.trigger_level_key] -= \
+                       self.parent[Y_PER_DIV_KEY]/3.
        #incr/decr divs
        def _on_incr_t_divs(self, event):
                self.parent.set_t_per_div(
@@ -324,13 +333,22 @@
                self._register_set_prop(self, SCOPE_X_CHANNEL_KEY, 0)
                self._register_set_prop(self, SCOPE_Y_CHANNEL_KEY, num_inputs-1)
                self._register_set_prop(self, FRAME_RATE_KEY, frame_rate)
-               self._register_set_prop(self, SCOPE_TRIGGER_LEVEL_KEY, None)
                self._register_set_prop(self, MARKER_KEY, DEFAULT_MARKER_TYPE)
+               self.ext_controller[self.trigger_level_key] = 0
                self.ext_controller[self.trigger_channel_key] = 0
                self.ext_controller[self.trigger_mode_key] = 
gr.gr_TRIG_MODE_AUTO
                self.ext_controller[self.trigger_slope_key] = 
gr.gr_TRIG_SLOPE_POS
-               #register events
+               #register events for trigger
+               self.ext_controller.subscribe(self.trigger_level_key, 
self.update_trigger)
+               self.ext_controller.subscribe(self.trigger_mode_key, 
self.update_trigger)
+               for key in (
+                       T_PER_DIV_KEY, T_OFF_KEY, T_DIVS_KEY,
+                       Y_PER_DIV_KEY, Y_OFF_KEY, Y_DIVS_KEY,
+                       SCOPE_XY_MODE_KEY,
+               ): self.subscribe(key, self.update_trigger)
+               #register events for message
                self.ext_controller.subscribe(msg_key, self.handle_msg)
+               #register events for grid
                for key in (
                        T_PER_DIV_KEY, X_PER_DIV_KEY, Y_PER_DIV_KEY,
                        T_OFF_KEY, X_OFF_KEY, Y_OFF_KEY,
@@ -343,6 +361,7 @@
                        MARKER_KEY,
                ): self.subscribe(key, self.update_grid)
                #initial update
+               self.update_trigger()
                self.update_grid()
 
        def handle_msg(self, msg):
@@ -366,6 +385,40 @@
                self.handle_samples()
                self.frame_rate_ts = time.time()
 
+       def set_auto_trigger_level(self, *args):
+               """
+               Use the current trigger channel and samples to calculate the 
50% level.
+               """
+               if not self.sampleses: return
+               samples = 
self.sampleses[self.ext_controller[self.trigger_channel_key]]
+               self.ext_controller[self.trigger_level_key] = 
(numpy.max(samples)+numpy.min(samples))/2
+
+       def update_trigger(self, *args):
+               """
+               Redraw the trigger line with current settings.
+               """
+               #keep trigger level within range
+               if self.ext_controller[self.trigger_level_key] > 
self.get_y_max():
+                       self.ext_controller[self.trigger_level_key] = 
self.get_y_max()
+                       return
+               if self.ext_controller[self.trigger_level_key] < 
self.get_y_min():
+                       self.ext_controller[self.trigger_level_key] = 
self.get_y_min()
+                       return
+               #disable the trigger channel
+               if self[SCOPE_XY_MODE_KEY] or 
self.ext_controller[self.trigger_mode_key] == gr.gr_TRIG_MODE_FREE:
+                       self.plotter.set_waveform(channel='Trig')
+               else: #show trigger channel
+                       trigger_level = 
self.ext_controller[self.trigger_level_key]
+                       self.plotter.set_waveform(
+                               channel='Trig',
+                               samples=(
+                                       [self.get_t_min(), self.get_t_max()],
+                                       [trigger_level, trigger_level]
+                               ),
+                               color_spec=TRIGGER_COLOR_SPEC,
+                       )
+               self.plotter.update()
+
        def handle_samples(self):
                """
                Handle the cached samples from the scope input.
@@ -373,12 +426,6 @@
                """
                if not self.sampleses: return
                sampleses = self.sampleses
-               trigger_level = self[SCOPE_TRIGGER_LEVEL_KEY]
-               if trigger_level is None: 
self.ext_controller[self.trigger_level_key] = ''
-               else:
-                       samples = 
sampleses[self.ext_controller[self.trigger_channel_key]]
-                       self.ext_controller[self.trigger_level_key] = \
-                               
trigger_level*(numpy.max(samples)-numpy.min(samples))/2 + numpy.average(samples)
                #ac coupling
                if self[AC_COUPLE_KEY]:
                        sampleses = [samples - numpy.average(samples) for 
samples in sampleses]
@@ -411,11 +458,7 @@
                        )
                        #turn off each waveform
                        for i, samples in enumerate(sampleses):
-                               self.plotter.set_waveform(
-                                       channel='Ch%d'%(i+1),
-                                       samples=[],
-                                       color_spec=CHANNEL_COLOR_SPECS[i],
-                               )
+                               self.plotter.set_waveform(channel='Ch%d'%(i+1))
                else:
                        #autorange
                        if self[AUTORANGE_KEY] and time.time() - 
self.autorange_ts > AUTORANGE_UPDATE_RATE:
@@ -452,60 +495,36 @@
                                                trig_off=self.trigger_offset,
                                        )
                        #turn XY channel off
-                       self.plotter.set_waveform(
-                               channel='XY',
-                               samples=[],
-                               color_spec=CHANNEL_COLOR_SPECS[0],
-                       )
+                       self.plotter.set_waveform(channel='XY')
                #update the plotter
                self.plotter.update()
 
+       def get_t_min(self): return self[T_OFF_KEY]
+       def get_t_max(self): return self[T_PER_DIV_KEY]*self[T_DIVS_KEY] + 
self[T_OFF_KEY]
+       def get_x_min(self): return -1*self[X_PER_DIV_KEY]*self[X_DIVS_KEY]/2.0 
+ self[X_OFF_KEY]
+       def get_x_max(self): return self[X_PER_DIV_KEY]*self[X_DIVS_KEY]/2.0 + 
self[X_OFF_KEY]
+       def get_y_min(self): return -1*self[Y_PER_DIV_KEY]*self[Y_DIVS_KEY]/2.0 
+ self[Y_OFF_KEY]
+       def get_y_max(self): return self[Y_PER_DIV_KEY]*self[Y_DIVS_KEY]/2.0 + 
self[Y_OFF_KEY]
+
        def update_grid(self, *args):
                """
                Update the grid to reflect the current settings:
                xy divisions, xy offset, xy mode setting
                """
-               #grid parameters
-               t_per_div = self[T_PER_DIV_KEY]
-               x_per_div = self[X_PER_DIV_KEY]
-               y_per_div = self[Y_PER_DIV_KEY]
-               t_off = self[T_OFF_KEY]
-               x_off = self[X_OFF_KEY]
-               y_off = self[Y_OFF_KEY]
-               t_divs = self[T_DIVS_KEY]
-               x_divs = self[X_DIVS_KEY]
-               y_divs = self[Y_DIVS_KEY]
                if self[SCOPE_XY_MODE_KEY]:
                        #update the x axis
                        
self.plotter.set_x_label('Ch%d'%(self[SCOPE_X_CHANNEL_KEY]+1))
-                       self.plotter.set_x_grid(
-                               -1*x_per_div*x_divs/2.0 + x_off,
-                               x_per_div*x_divs/2.0 + x_off,
-                               x_per_div,
-                       )
+                       self.plotter.set_x_grid(self.get_x_min(), 
self.get_x_max(), self[X_PER_DIV_KEY])
                        #update the y axis
                        
self.plotter.set_y_label('Ch%d'%(self[SCOPE_Y_CHANNEL_KEY]+1))
-                       self.plotter.set_y_grid(
-                               -1*y_per_div*y_divs/2.0 + y_off,
-                               y_per_div*y_divs/2.0 + y_off,
-                               y_per_div,
-                       )
+                       self.plotter.set_y_grid(self.get_y_min(), 
self.get_y_max(), self[Y_PER_DIV_KEY])
                else:
                        #update the t axis
-                       coeff, exp, prefix = 
common.get_si_components(t_per_div*t_divs + t_off)
+                       coeff, exp, prefix = 
common.get_si_components(self.get_t_max())
                        self.plotter.set_x_label('Time', prefix+'s')
-                       self.plotter.set_x_grid(
-                               t_off,
-                               t_per_div*t_divs + t_off,
-                               t_per_div,
-                               10**(-exp),
-                       )
+                       self.plotter.set_x_grid(self.get_t_min(), 
self.get_t_max(), self[T_PER_DIV_KEY], 10**(-exp))
                        #update the y axis
                        self.plotter.set_y_label('Counts')
-                       self.plotter.set_y_grid(
-                               -1*y_per_div*y_divs/2.0 + y_off,
-                               y_per_div*y_divs/2.0 + y_off,
-                               y_per_div,
-                       )
+                       self.plotter.set_y_grid(self.get_y_min(), 
self.get_y_max(), self[Y_PER_DIV_KEY])
                #redraw current sample
                self.handle_samples()

Modified: 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scopesink_gl.py
===================================================================
--- 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scopesink_gl.py 
    2009-02-20 00:37:29 UTC (rev 10469)
+++ 
gnuradio/branches/developers/jblum/gui_guts/gr-wxgui/src/python/scopesink_gl.py 
    2009-02-20 02:11:26 UTC (rev 10470)
@@ -78,10 +78,8 @@
                self.controller.publish(SAMPLE_RATE_KEY, scope.sample_rate)
                self.controller.subscribe(DECIMATION_KEY, 
scope.set_decimation_count)
                self.controller.publish(DECIMATION_KEY, 
scope.get_decimation_count)
-               def set_trigger_level(level):
-                       if level == '': scope.set_trigger_level_auto()
-                       else: scope.set_trigger_level(level)
-               self.controller.subscribe(SCOPE_TRIGGER_LEVEL_KEY, 
set_trigger_level)
+               self.controller.subscribe(SCOPE_TRIGGER_LEVEL_KEY, 
scope.set_trigger_level)
+               self.controller.publish(SCOPE_TRIGGER_LEVEL_KEY, 
scope.get_trigger_level)
                self.controller.subscribe(SCOPE_TRIGGER_MODE_KEY, 
scope.set_trigger_mode)
                self.controller.publish(SCOPE_TRIGGER_MODE_KEY, 
scope.get_trigger_mode)
                self.controller.subscribe(SCOPE_TRIGGER_SLOPE_KEY, 
scope.set_trigger_slope)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]