Imported Upstream version 3.0.4
[debian/gnuradio] / gr-usrp / src / flexrf_debug_gui.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2005 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
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 3, or (at your option)
10 # any later version.
11
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.
16
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.
21
22
23 import sys
24 import wx
25 from gnuradio.wxgui import form
26
27 class flexrf_debug_gui(wx.Frame):
28     def __init__(self, flexrf, title="Flexrf Debug"):
29         wx.Frame.__init__(self, None, -1, title)
30
31         self.flexrf = flexrf
32         
33         self.CreateStatusBar (1)
34
35         self.panel = wx.Panel(self, -1)
36         self.vbox = wx.BoxSizer(wx.VERTICAL)
37         self.panel.SetSizer(self.vbox)
38         self.panel.SetAutoLayout(True)
39
40         self._create_form()
41
42         self.vbox.Fit(self.panel)
43
44         self.frame_vbox = wx.BoxSizer(wx.VERTICAL)
45         self.frame_vbox.Add(self.panel, 1, wx.EXPAND)
46         self.SetSizer(self.frame_vbox)
47         self.SetAutoLayout(True)
48         self.frame_vbox.Fit(self)
49         
50     def _create_form(self):
51         self._create_set_freq()
52         self._create_write_fpga()
53         self._create_write_all()
54         self._create_write_it()
55         #self._create_set_gain()
56         
57     # ----------------------------------------------------------------
58
59     def _create_set_freq(self):
60
61         def _set_freq(kv):
62             return self.flexrf.set_freq(kv['freq'])[0]
63
64         sbs = wx.StaticBoxSizer(wx.StaticBox(self.panel), wx.HORIZONTAL)
65         sbs.Add((5,0), 0.1)       # stretchy space
66         #sbs.Add(wx.StaticText(self.panel, -1, "set_freq "), 0, 0)
67         #sbs.Add((5,0), 0.1)       # stretchy space
68         myform = form.form()
69         myform['freq'] = form.float_field(self.panel, sbs, "Set Frequency")
70         sbs.Add((5,0), 0.1)       # stretchy space
71         sbs.Add(form.button_with_callback(self.panel, "Do It!",
72                                           self._generic_doit(_set_freq, myform)), 1, wx.EXPAND)
73         sbs.Add((5,0), 0.1)       # stretchy space
74         self.vbox.Add(sbs, 0, wx.EXPAND)
75
76
77     def _create_write_fpga(self):
78
79         def _write_fpga(kv):
80             return self.flexrf._u._write_fpga_reg(kv['regno'], kv['value'])
81
82         sbs = wx.StaticBoxSizer(wx.StaticBox(self.panel), wx.HORIZONTAL)
83         sbs.Add((5,0), 0.1)       # stretchy space
84         sbs.Add(wx.StaticText(self.panel, -1, "write_fpga_reg "), 0, 0)
85         sbs.Add((5,0), 0.1)       # stretchy space
86         myform = form.form()
87         myform['regno'] = form.int_field(self.panel, sbs, "regno")
88         sbs.Add((5,0), 0.1)       # stretchy space
89         myform['value'] = form.int_field(self.panel, sbs, "value")
90         sbs.Add((5,0), 0.1)       # stretchy space
91         sbs.Add(form.button_with_callback(self.panel, "Do It!",
92                                           self._generic_doit(_write_fpga, myform)), 1, wx.EXPAND)
93         sbs.Add((5,0), 0.1)       # stretchy space
94         self.vbox.Add(sbs, 0, wx.EXPAND)
95
96
97     def _create_write_all(self):
98
99         def _write_all(kv):
100             self.flexrf._write_all(kv['R'], kv['control'], kv['N'])   # void
101             return  True
102
103         sbs = wx.StaticBoxSizer(wx.StaticBox(self.panel), wx.HORIZONTAL)
104         sbs.Add((5,0), 0.1)       # stretchy space
105         sbs.Add(wx.StaticText(self.panel, -1, "write_all "), 0, 0)
106         sbs.Add((5,0), 0.1)       # stretchy space
107         myform = form.form()
108         myform['R'] = form.int_field(self.panel, sbs, "R")
109         sbs.Add((5,0), 0.1)       # stretchy space
110         myform['control'] = form.int_field(self.panel, sbs, "control")
111         sbs.Add((5,0), 0.1)       # stretchy space
112         myform['N'] = form.int_field(self.panel, sbs, "N")
113         sbs.Add((5,0), 0.1)       # stretchy space
114         sbs.Add(form.button_with_callback(self.panel, "Do It!",
115                                           self._generic_doit(_write_all, myform)), 1, wx.EXPAND)
116         sbs.Add((5,0), 0.1)       # stretchy space
117         self.vbox.Add(sbs, 0, wx.EXPAND)
118
119
120     def _create_write_it(self):
121
122         def _write_it(kv):
123             self.flexrf._write_it(kv['v'])      # void
124             return True
125
126         sbs = wx.StaticBoxSizer(wx.StaticBox(self.panel), wx.HORIZONTAL)
127         sbs.Add((5,0), 0.1)       # stretchy space
128         sbs.Add(wx.StaticText(self.panel, -1, "write_it "), 0, 0)
129         sbs.Add((5,0), 0.1)       # stretchy space
130         myform = form.form()
131         myform['v'] = form.int_field(self.panel, sbs, "24-bit value")
132         sbs.Add((5,0), 0.1)       # stretchy space
133         sbs.Add(form.button_with_callback(self.panel, "Do It!",
134                                           self._generic_doit(_write_it, myform)), 1, wx.EXPAND)
135         sbs.Add((5,0), 0.1)       # stretchy space
136         self.vbox.Add(sbs, 0, wx.EXPAND)
137
138
139     # ----------------------------------------------------------------
140     
141     def _set_status_msg(self, msg):
142         self.GetStatusBar().SetStatusText(msg, 0)
143
144     def _generic_doit(self, callback, form):
145
146         def button_callback():
147             errors = form.check_input_for_errors()
148             if errors:
149                 self._set_status_msg(errors[0])
150                 print '\n'.join(tuple(errors))
151             else:
152                 kv = form.get_key_vals()
153                 if callback(kv):
154                     self._set_status_msg("OK")
155                 else:
156                     self._set_status_msg("Failed")
157
158         return button_callback
159
160
161         
162 if False and __name__ == '__main__':
163
164     class demo_app (wx.App):
165         def __init__ (self):
166             wx.App.__init__(self)
167
168         def OnInit (self):
169             frame = flexrf_debug_gui(None, "Debug FlexRF TX")
170             frame.Show(True)
171             self.SetTopWindow (frame)
172             return True
173
174     app = demo_app()
175     app.MainLoop()
176