I'm having some python coding issues with a slider I'm trying to
implement. The code is based on usrp_wfm_rcv_pll.py, which uses the
powermate to adjust either frequency or volume. I would like to replace
the volume slider with a gain slider, which exists in the original but
which is not controlled by the powermate.
My code is below, and the symptoms are that while the new gain slider
moves, the value shown does not update until I click the powermate button
to switch to frequency control. Any suggestions?
Thanks!
eric
# control area form at bottom
self.myform = myform = form.form()
hbox = wx.BoxSizer(wx.HORIZONTAL)
hbox.Add((5,0), 0)
myform['freq'] = form.float_field(
parent=self.panel, sizer=hbox, label="Carrier Freq", weight=1,
callback=myform.check_input_and_call(_form_set_freq,
self._set_status_msg))
hbox.Add((5,0), 0)
myform['freq_slider'] = \
form.quantized_slider_field(parent=self.panel, sizer=hbox,
weight=3,
range=(.5e6, 3.5e6, 0.001e6),
callback=self.set_freq)
hbox.Add((5,0), 0)
vbox.Add(hbox, 0, wx.EXPAND)
hbox = wx.BoxSizer(wx.HORIZONTAL)
hbox.Add((5,0), 0)
myform['gain'] = \
form.quantized_slider_field(parent=self.panel, sizer=hbox,
label="Gain",
weight=3,
range=self.subdev.gain_range(),
callback=self.subdev.set_gain)
hbox.Add((5,0), 0)
vbox.Add(hbox, 0, wx.EXPAND)
try:
self.knob = powermate.powermate(self.frame)
self.rot = 0
powermate.EVT_POWERMATE_ROTATE (self.frame, self.on_rotate)
powermate.EVT_POWERMATE_BUTTON (self.frame, self.on_button)
except:
print "FYI: No Powermate or Contour Knob found"
def on_rotate (self, event):
self.rot += event.delta
if (self.state == "FREQ"):
if self.rot >= 3:
self.set_freq(self.freq + .001e6)
self.rot -= 3
elif self.rot <=-3:
self.set_freq(self.freq - .001e6)
self.rot += 3
else:
step = self.subdev.gain_range()[2]
if self.rot >= 3:
self.set_gain(self.gain + step)
self.rot -= 3
elif self.rot <=-3:
self.set_gain(self.gain - step)
self.rot += 3
def on_button (self, event):
if event.value == 0: # button up
return
self.rot = 0
if self.state == "FREQ":
self.state = "GAIN"
else:
self.state = "FREQ"
self.update_status_bar ()
def set_gain (self, gain):
g = self.subdev.gain_range()
self.gain = max(g[0], min(g[1], gain))
#self.gain_control.set_k(10**(self.gain/10))
self.myform['gain'].set_value(self.gain)
self.update_status_bar ()
def set_freq(self, target_freq):
"""
Set the center frequency we're interested in.
@param target_freq: frequency in Hz
@rypte: bool
Tuning is a two step process. First we ask the front-end to
tune as close to the desired frequency as it can. Then we use
the result of that operation and our target_frequency to
determine the value for the digital down converter.
"""
r = usrp.tune(self.u, 0, self.subdev, target_freq)
if r:
self.freq = target_freq
self.myform['freq'].set_value(target_freq) # update
displayed value
self.myform['freq_slider'].set_value(target_freq) # update
displayed value
self.update_status_bar()
self._set_status_msg("OK", 0)
return True
self._set_status_msg("Failed", 0)
return False
def set_gain(self, gain):
self.gain=gain
self.myform['gain'].set_value(gain) # update displayed value
self.subdev.set_gain(gain)
def update_status_bar (self):
msg = "Gain:%r Setting:%s" % (self.gain, self.state)
self._set_status_msg(msg, 1)
self.src_fft.set_baseband_freq(self.freq)
def gain_range(self):
return (0, 20, 1)
************************************
Eric H. Matlis, Ph.D.
Aerospace & Mechanical Engineering Dept.
120 Hessert Center for Aerospace Research
University of Notre Dame
Notre Dame, IN 46556-5684
Phone: (574) 631-6054
Fax: (574) 631-8355
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio