1 #include "lms7002_pnlLimeLightPAD_view.h"
2 #include <map>
3 #include "lms7002_gui_utilities.h"
4 using namespace lime;
5 
lms7002_pnlLimeLightPAD_view(wxWindow * parent)6 lms7002_pnlLimeLightPAD_view::lms7002_pnlLimeLightPAD_view( wxWindow* parent )
7 :
8 pnlLimeLightPAD_view( parent )
9 {
10 
11 }
12 
lms7002_pnlLimeLightPAD_view(wxWindow * parent,wxWindowID id,const wxPoint & pos,const wxSize & size,long style)13 lms7002_pnlLimeLightPAD_view::lms7002_pnlLimeLightPAD_view( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
14     : pnlLimeLightPAD_view(parent, id, pos, size, style), lmsControl(nullptr)
15 {
16     //ids for updating from chip
17     wndId2Enum[rgrDIQ1_DS] = LMS7param(DIQ1_DS);
18     wndId2Enum[chkDIQ1_PE] = LMS7param(DIQ1_PE);
19     wndId2Enum[rgrDIQ2_DS] = LMS7param(DIQ2_DS);
20     wndId2Enum[chkDIQ2_PE] = LMS7param(DIQ2_PE);
21     wndId2Enum[rgrRX_MUX] = LMS7param(RX_MUX);
22     wndId2Enum[chkFCLK1_PE] = LMS7param(FCLK1_PE);
23     wndId2Enum[chkFCLK2_PE] = LMS7param(FCLK2_PE);
24     wndId2Enum[chkIQ_SEL_EN_1_PE] = LMS7param(IQ_SEL_EN_1_PE);
25     wndId2Enum[chkIQ_SEL_EN_2_PE] = LMS7param(IQ_SEL_EN_2_PE);
26     wndId2Enum[cmbLML1_AIP] = LMS7param(LML1_AIP);
27     wndId2Enum[cmbLML1_AQP] = LMS7param(LML1_AQP);
28     wndId2Enum[cmbLML1_BIP] = LMS7param(LML1_BIP);
29     wndId2Enum[cmbLML1_BQP] = LMS7param(LML1_BQP);
30     wndId2Enum[cmbLML1_RX_PRE] = LMS7param(LML1_RF2BB_PRE);
31     wndId2Enum[cmbLML1_RX_PST] = LMS7param(LML1_RF2BB_PST);
32     wndId2Enum[cmbLML1_S0S] = LMS7param(LML1_S0S);
33     wndId2Enum[cmbLML1_S1S] = LMS7param(LML1_S1S);
34     wndId2Enum[cmbLML1_S2S] = LMS7param(LML1_S2S);
35     wndId2Enum[cmbLML1_S3S] = LMS7param(LML1_S3S);
36     wndId2Enum[cmbLML1_TX_PRE] = LMS7param(LML1_BB2RF_PRE);
37     wndId2Enum[cmbLML1_TX_PST] = LMS7param(LML1_BB2RF_PST);
38     wndId2Enum[cmbLML2_AIP] = LMS7param(LML2_AIP);
39     wndId2Enum[cmbLML2_AQP] = LMS7param(LML2_AQP);
40     wndId2Enum[cmbLML2_BIP] = LMS7param(LML2_BIP);
41     wndId2Enum[cmbLML2_BQP] = LMS7param(LML2_BQP);
42     wndId2Enum[cmbLML2_RX_PRE] = LMS7param(LML2_RF2BB_PRE);
43     wndId2Enum[cmbLML2_RX_PST] = LMS7param(LML2_RF2BB_PST);
44     wndId2Enum[cmbLML2_S0S] = LMS7param(LML2_S0S);
45     wndId2Enum[cmbLML2_S1S] = LMS7param(LML2_S1S);
46     wndId2Enum[cmbLML2_S2S] = LMS7param(LML2_S2S);
47     wndId2Enum[cmbLML2_S3S] = LMS7param(LML2_S3S);
48     wndId2Enum[cmbLML2_TX_PRE] = LMS7param(LML2_BB2RF_PRE);
49     wndId2Enum[cmbLML2_TX_PST] = LMS7param(LML2_BB2RF_PST);
50     wndId2Enum[rgrLML_MODE1] = LMS7param(LML1_MODE);
51     wndId2Enum[rgrLML_MODE2] = LMS7param(LML2_MODE);
52     wndId2Enum[rgrLML_TXNRXIQ1] = LMS7param(LML1_TXNRXIQ);
53     wndId2Enum[rgrLML_TXNRXIQ2] = LMS7param(LML2_TXNRXIQ);
54     wndId2Enum[chkLRST_RX_A] = LMS7param(LRST_RX_A);
55     wndId2Enum[chkLRST_RX_B] = LMS7param(LRST_RX_B);
56     wndId2Enum[chkLRST_TX_A] = LMS7param(LRST_TX_A);
57     wndId2Enum[chkLRST_TX_B] = LMS7param(LRST_TX_B);
58     wndId2Enum[cmbMCLK1SRC] = LMS7param(MCLK1SRC);
59     wndId2Enum[cmbRXTSPCLKA_DIV] = LMS7param(RXTSPCLKA_DIV);
60     wndId2Enum[chkMCLK1_PE] = LMS7param(MCLK1_PE);
61     wndId2Enum[cmbMCLK2SRC] = LMS7param(MCLK2SRC);
62     wndId2Enum[cmbTXTSPCLKA_DIV] = LMS7param(TXTSPCLKA_DIV);
63     wndId2Enum[chkMCLK2_PE] = LMS7param(MCLK2_PE);
64     wndId2Enum[chkMIMO_SISO] = LMS7param(MIMO_SISO);
65     wndId2Enum[chkMOD_EN] = LMS7param(MOD_EN);
66     wndId2Enum[chkMRST_RX_A] = LMS7param(MRST_RX_A);
67     wndId2Enum[chkMRST_RX_B] = LMS7param(MRST_RX_B);
68     wndId2Enum[chkMRST_TX_A] = LMS7param(MRST_TX_A);
69     wndId2Enum[chkMRST_TX_B] = LMS7param(MRST_TX_B);
70     wndId2Enum[chkRXDIVEN] = LMS7param(RXDIVEN);
71     wndId2Enum[chkRXEN_A] = LMS7param(RXEN_A);
72     wndId2Enum[chkRXEN_B] = LMS7param(RXEN_B);
73     wndId2Enum[cmbRXRDCLK_MUX] = LMS7param(RXRDCLK_MUX);
74     wndId2Enum[cmbRXWRCLK_MUX] = LMS7param(RXWRCLK_MUX);
75     wndId2Enum[chkRX_CLK_PE] = LMS7param(RX_CLK_PE);
76     wndId2Enum[chkSCLK_PE] = LMS7param(SCLK_PE);
77     wndId2Enum[rgrSCL_DS] = LMS7param(SCL_DS);
78     wndId2Enum[chkSCL_PE] = LMS7param(SCL_PE);
79     wndId2Enum[rgrSDA_DS] = LMS7param(SDA_DS);
80     wndId2Enum[chkSDA_PE] = LMS7param(SDA_PE);
81     wndId2Enum[rgrSDIO_DS] = LMS7param(SDIO_DS);
82     wndId2Enum[chkSDIO_PE] = LMS7param(SDIO_PE);
83     wndId2Enum[chkSDO_PE] = LMS7param(SDO_PE);
84     wndId2Enum[chkSEN_PE] = LMS7param(SEN_PE);
85     wndId2Enum[rgrSPIMODE] = LMS7param(SPIMODE);
86     wndId2Enum[chkSRST_RXFIFO] = LMS7param(SRST_RXFIFO);
87     wndId2Enum[chkSRST_TXFIFO] = LMS7param(SRST_TXFIFO);
88     wndId2Enum[chkTXDIVEN] = LMS7param(TXDIVEN);
89     wndId2Enum[chkTXEN_A] = LMS7param(TXEN_A);
90     wndId2Enum[chkTXEN_B] = LMS7param(TXEN_B);
91     wndId2Enum[rgrTX_MUX] = LMS7param(TX_MUX);
92     wndId2Enum[chkTXNRX1_PE] = LMS7param(TXNRX1_PE);
93     wndId2Enum[chkTXNRX2_PE] = LMS7param(TXNRX2_PE);
94     wndId2Enum[cmbTXRDCLK_MUX] = LMS7param(TXRDCLK_MUX);
95     wndId2Enum[cmbTXWRCLK_MUX] = LMS7param(TXWRCLK_MUX);
96     wndId2Enum[chkTX_CLK_PE] = LMS7param(TX_CLK_PE);
97     wndId2Enum[rgrLML_FIDM1] = LMS7param(LML1_FIDM);
98     wndId2Enum[rgrLML_FIDM2] = LMS7param(LML2_FIDM);
99     wndId2Enum[chkFCLK1_INV] = LMS7param(FCLK1_INV);
100     wndId2Enum[chkFCLK2_INV] = LMS7param(FCLK2_INV);
101     wndId2Enum[cmbMCLK1DLY] = LMS7param(MCLK1DLY);
102     wndId2Enum[cmbMCLK2DLY] = LMS7param(MCLK2DLY);
103     wndId2Enum[rgrDIQDIRCTR2] = LMS7param(DIQDIRCTR2);
104     wndId2Enum[rgrDIQDIR2] = LMS7param(DIQDIR2);
105     wndId2Enum[rgrDIQDIRCTR1] = LMS7param(DIQDIRCTR1);
106     wndId2Enum[rgrDIQDIR1] = LMS7param(DIQDIR1);
107     wndId2Enum[rgrENABLEDIRCTR2] = LMS7param(ENABLEDIRCTR2);
108     wndId2Enum[rgrENABLEDIR2] = LMS7param(ENABLEDIR2);
109     wndId2Enum[rgrENABLEDIRCTR1] = LMS7param(ENABLEDIRCTR1);
110     wndId2Enum[rgrENABLEDIR1] = LMS7param(ENABLEDIR1);
111     wndId2Enum[chkMCLK1_INV] = LMS7param(MCLK1_INV);
112     wndId2Enum[chkMCLK2_INV] = LMS7param(MCLK2_INV);
113     wndId2Enum[cmbFCLK1_DLY] = LMS7param(FCLK1_DLY);
114     wndId2Enum[cmbFCLK2_DLY] = LMS7param(FCLK2_DLY);
115     wndId2Enum[cmbMCLK1_DLY] = LMS7param(MCLK1_DLY);
116     wndId2Enum[cmbMCLK2_DLY] = LMS7param(MCLK2_DLY);
117     wndId2Enum[chkLML1_TRXIQPULSE] = LMS7param(LML1_TRXIQPULSE);
118     wndId2Enum[chkLML2_TRXIQPULSE] = LMS7param(LML2_TRXIQPULSE);
119     wndId2Enum[chkLML1_SISODDR] = LMS7param(LML1_SISODDR);
120     wndId2Enum[chkLML2_SISODDR] = LMS7param(LML2_SISODDR);
121 
122     LMS7002_WXGUI::UpdateTooltips(wndId2Enum, true);
123 }
124 
Initialize(lms_device_t * pControl)125 void lms7002_pnlLimeLightPAD_view::Initialize(lms_device_t* pControl)
126 {
127     lmsControl = pControl;
128     assert(lmsControl != nullptr);
129     uint16_t value;
130     if (LMS_ReadParam(lmsControl,LMS7param(MASK),&value)!=0  || value != 0)
131          value = 1;
132     chkMCLK1_INV->Enable(value);
133     chkMCLK2_INV->Enable(value);
134     cmbFCLK1_DLY->Enable(value);
135     cmbFCLK2_DLY->Enable(value);
136     cmbMCLK1_DLY->Enable(value);
137     cmbMCLK2_DLY->Enable(value);
138     chkLML1_TRXIQPULSE->Enable(value);
139     chkLML2_TRXIQPULSE->Enable(value);
140     chkLML1_SISODDR->Enable(value);
141     chkLML2_SISODDR->Enable(value);
142 
143 }
144 
ParameterChangeHandler(wxSpinEvent & event)145 void lms7002_pnlLimeLightPAD_view::ParameterChangeHandler(wxSpinEvent& event)
146 {
147     wxCommandEvent evt;
148     evt.SetInt(event.GetInt());
149     evt.SetId(event.GetId());
150     evt.SetEventObject(event.GetEventObject());
151     ParameterChangeHandler(evt);
152 }
153 
ParameterChangeHandler(wxCommandEvent & event)154 void lms7002_pnlLimeLightPAD_view::ParameterChangeHandler(wxCommandEvent& event)
155 {
156     assert(lmsControl != nullptr);
157     LMS7Parameter parameter;
158     try
159     {
160         parameter = wndId2Enum.at(reinterpret_cast<wxWindow*>(event.GetEventObject()));
161     }
162     catch (std::exception & e)
163     {
164         std::cout << "Control element(ID = " << event.GetId() << ") don't have assigned LMS parameter." << std::endl;
165         return;
166     }
167     LMS_WriteParam(lmsControl,parameter,event.GetInt());
168 }
169 
onbtnReadVerRevMask(wxCommandEvent & event)170 void lms7002_pnlLimeLightPAD_view::onbtnReadVerRevMask( wxCommandEvent& event )
171 {
172     uint16_t value = 0;
173 
174     LMS_ReadParam(lmsControl,LMS7param(VER),&value);
175     lblVER->SetLabel(wxString::Format(_("%i"), value));
176 
177     LMS_ReadParam(lmsControl,LMS7param(REV),&value);
178     lblREV->SetLabel(wxString::Format(_("%i"), value));
179 
180     LMS_ReadParam(lmsControl,LMS7param(MASK),&value);
181     lblMASK->SetLabel(wxString::Format(_("%i"), value));
182 }
183 
UpdateGUI()184 void lms7002_pnlLimeLightPAD_view::UpdateGUI()
185 {
186     wxArrayString padStrenghts;
187     uint16_t value = 0;
188     LMS_ReadParam(lmsControl, LMS7_MASK, &value);
189     if(value == 0)
190     {
191         padStrenghts.push_back("4 mA");
192         padStrenghts.push_back("8 mA");
193     }
194     else
195     {
196         padStrenghts.push_back("8 mA");
197         padStrenghts.push_back("12 mA");
198     }
199     wxRadioBox* padStrenghtCtrl[] = {rgrSDA_DS, rgrSCL_DS, rgrSDIO_DS, rgrDIQ2_DS, rgrDIQ1_DS};
200     for(auto i : padStrenghtCtrl)
201     {
202         i->SetString(0, padStrenghts[0]);
203         i->SetString(1, padStrenghts[1]);
204     }
205     LMS7002_WXGUI::UpdateControlsByMap(this, lmsControl, wndId2Enum);
206 }
207