3 # Copyright 2005 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING. If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
25 from gnuradio.wxgui import form
27 class tx_debug_gui(wx.Frame):
28 def __init__(self, tx_subdev, title="Tx Debug"):
29 wx.Frame.__init__(self, None, -1, title)
31 self.subdev = tx_subdev
32 self.subdev._u.set_verbose(True)
34 self.CreateStatusBar (1)
36 self.panel = wx.Panel(self, -1)
37 self.vbox = wx.BoxSizer(wx.VERTICAL)
38 self.panel.SetSizer(self.vbox)
39 self.panel.SetAutoLayout(True)
43 self.vbox.Fit(self.panel)
45 self.frame_vbox = wx.BoxSizer(wx.VERTICAL)
46 self.frame_vbox.Add(self.panel, 1, wx.EXPAND)
47 self.SetSizer(self.frame_vbox)
48 self.SetAutoLayout(True)
49 self.frame_vbox.Fit(self)
51 # ----------------------------------------------------------------
53 def _write_9862(self, regno, v):
54 return self.subdev._u._write_9862(self.subdev._which, regno, v)
56 def _set_dac_offset(self, i_or_q, offset, offset_pin):
57 return self.subdev._u.set_dac_offset(self.subdev._which * 2 + i_or_q, offset, offset_pin)
59 def _set_dac_fine_gain(self, i_or_q, gain, coarse):
60 return self._write_9862(14 + i_or_q, (coarse & 0xC0) | (gain & 0x3f))
62 def _create_form(self):
63 self._create_dac_offset()
64 self._create_dac_fine_gain()
67 # ----------------------------------------------------------------
69 def _create_dac_offset(self):
71 sbs = wx.StaticBoxSizer(wx.StaticBox(self.panel), wx.VERTICAL)
73 hbox = wx.BoxSizer(wx.HORIZONTAL)
74 hbox.Add(wx.StaticText(self.panel, -1, "DAC Offset"), 5, 0)
78 self._create_dac_offset_helper(sbs, 0)
79 self._create_dac_offset_helper(sbs, 1)
81 self.vbox.Add(sbs, 0, wx.EXPAND)
83 def _create_dac_offset_helper(self, vbox, i_or_q):
86 drive_positive = kv['drive_positive']
87 dac_offset = kv['dac_offset']
88 print "drive_positive =", drive_positive
89 print "dac_offset[%d] = %4d" % (i_or_q, dac_offset)
91 # FIXME signed magnitude??
92 # dac_offset = signed_mag10(dac_offset)
93 return self._set_dac_offset(i_or_q, dac_offset, int(drive_positive))
96 # not clear from doc if this is really 2's comp or 10-bit signed magnitude
97 # we'll guess it's 10-bit signed mag
99 return (1 << 9) | min(511, max(0, abs(x)))
101 return (0 << 9) | min(511, max(0, abs(x)))
104 hbox = wx.BoxSizer(wx.HORIZONTAL)
105 vbox.Add(hbox, 0, wx.EXPAND)
106 myform['drive_positive'] = form.checkbox_field(parent=self.panel, sizer=hbox,
107 callback=myform.check_input_and_call(doit),
110 myform['dac_offset'] = form.slider_field(parent=self.panel, sizer=hbox,
111 callback=myform.check_input_and_call(doit),
112 min=-512, max=511, value=0,
115 # ----------------------------------------------------------------
117 def _create_dac_fine_gain(self):
118 sbs = wx.StaticBoxSizer(wx.StaticBox(self.panel), wx.VERTICAL)
120 hbox = wx.BoxSizer(wx.HORIZONTAL)
121 hbox.Add(wx.StaticText(self.panel, -1, "DAC Gain"), 5, 0)
124 self._create_dac_gain_helper(sbs, 0)
125 self._create_dac_gain_helper(sbs, 1)
127 self.vbox.Add(sbs, 0, wx.EXPAND)
129 def _create_dac_gain_helper(self, vbox, i_or_q):
136 dac_gain = kv['dac_gain']
137 coarse_s = kv['coarse']
138 print "dac_gain[%d] = %4d" % (i_or_q, dac_gain)
139 print "coarse = ", coarse_s
140 return self._set_dac_fine_gain(i_or_q, dac_gain, d[coarse_s])
143 hbox = wx.BoxSizer(wx.HORIZONTAL)
144 vbox.Add(hbox, 0, wx.EXPAND)
145 myform['coarse'] = form.radiobox_field(parent=self.panel, sizer=hbox,
146 callback=myform.check_input_and_call(doit),
147 choices=['1/11', '1/2', '1/1'],
148 weight=1, value='1/1')
149 myform['dac_gain'] = form.slider_field(parent=self.panel, sizer=hbox,
150 callback=myform.check_input_and_call(doit),
151 min=-32, max=31, value=0,
155 # ----------------------------------------------------------------
157 def _create_pga(self):
158 sbs = wx.StaticBoxSizer(wx.StaticBox(self.panel), wx.VERTICAL)
160 form.quantized_slider_field(parent=self.panel, sizer=sbs, label="PGA",
161 weight=3, range=self.subdev.gain_range(),
162 callback=self.subdev.set_gain)
164 self.vbox.Add(sbs, 0, wx.EXPAND)
167 # ----------------------------------------------------------------
170 def _set_status_msg(self, msg):
171 self.GetStatusBar().SetStatusText(msg, 0)
174 if False and __name__ == '__main__':
176 class demo_app (wx.App):
178 wx.App.__init__(self)
181 frame = tx_debug_gui(None, "Debug TX")
183 self.SetTopWindow (frame)