Marine systems simulation
SPanel.h
1#ifndef SPANEL_H
2#define SPANEL_H
3#include "Joystick.h"
4#include "ui_SPanel.h"
5#include "qwt_dial_needle.h"
6#include "qwt_slider.h"
7#include "qwt_knob.h"
8#include "qpushbutton.h"
9#include "qpalette.h"
10#include "qwt_plot.h"
11#include <qwt_plot_curve.h>
12#include <qwt_plot_grid.h>
13#include <myOutputStruct.h>
14#include "server.h"
15
16
20
21
22
23class ShipPanelChild :public QWidget, public Ui::ShipPanel{
24 Q_OBJECT
25
26
27
28public:
29
30 ShipPanelChild(QWidget *Parent=0):QWidget(Parent){
31
33 for(int i=0; i<32; i++){
34 permval.rgbButtons[i] = 0;
35 updateval.rgbButtons[i] = 0;
36 X = 0;
37 };
38
39 for(int i=0; i<2; i++)
40 permval.rglSlider[i]=0;
41
42 for(int i=0; i<4; i++)
43 permval.rgdwPOV[i]=0;
44
45 for(int i=0; i<3; i++){
46 permval.posAxis[i]=0;
47 permval.rotAxis[i]=0;
48 }
49
50
51 }
52
53 void SetSocket( int _fd )
54 {
55 sockfd = _fd;
56 }
57
58 void SetMSPanelID( long long id)
59 {
60 MSPanelID = id;
61 }
62
63 void SetShipConsoleID( long long id)
64 {
65 ShipConsoleID = id;
66 }
67
68 void setupWidgets()
69 {
70
71
75
76
77 QwtDialSimpleNeedle *needle = new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow, true, Qt::red, QColor(Qt::gray).light(130));
78 Winch1->setRange(-1.0,1.0,0.01);
79 Winch1->setNeedle(needle);
80 // QwtDialSimpleNeedle *needle2 = new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow, true, Qt::red, QColor(Qt::gray).light(130));
81 Winch2->setRange(-1.0,1.0,0.01);
82 Winch2->setNeedle(needle);
83
84 Winch1->setScaleArc(-150.0, 150.0);
85 Winch2->setScaleArc(-150.0, 150.0);
86
87 Slider1->setRange(-1.0, 1.0, 0.01); // paging disabled
88 Slider2->setRange(-1.0, 1.0, 0.01); // paging disabled
89
90 WinchButton1->setCheckable(true);
91 WinchButton2->setCheckable(true);
92
93 // Initialization
94
95 WinchButton1->setChecked(false);
96 WinchButton1->setStyleSheet("* { background-color: rgb(255,0,0) }");
97 WinchButton1->setText("Off");
98
99 WinchButton2->setChecked(false);
100 WinchButton2->setStyleSheet("* { background-color: rgb(255,0,0) }");
101 WinchButton2->setText("Off");
102
103 }
104
105signals:
106 void JoystickUpdated( long long id, joyData_t data);
107private slots:
108
109 void updateWinch(struct myOutputStruct FHSimData)
110 {
111 Winch1->setValue(FHSimData.winch[0]);
112 Winch2->setValue(FHSimData.winch[1]);
113
114 }
115
119 void GenerateData(struct myOutputStruct FHSimData)
120 {
121 Y1 = FHSimData.winch[2];
122 Y2 = FHSimData.winch[3];
123 //Y1 = 10000 * sin((double)X / 360 * 3.1415 * 10) + rand() % 4000 - 2000;
124 //X = X+.1;
125 X = FHSimData.time;
126
127 leftGraph->appendData(X,Y1);
128 leftGraph2->appendData2(X,Y2);
129
130 }
131
135
136 void UpdateAndSend()
137 {
138 std::map<long long,joyData_t>::iterator it;
139 UpdateInputState(this->winId());
140
141 //send
142 for( it = Joysticks.begin(); it != Joysticks.end(); it++)
143 {
144 LPDIRECTINPUTDEVICE8 dev = it->second.dev;
145 //send(sockfd,(const char *) &it->second.data, sizeof(myStruct), 0);
146 emit JoystickUpdated(it->first,it->second);
147 //send(sockfd,(const char *) &it->second, sizeof(myStruct), 0);
148 }
149
150 }
151
155
156 void UpdateJoystickData(long long id,joyData_t data)
157 {
158 Slider1->setValue( data.data.posAxis[2]/1000. );
159 Slider2->setValue( data.data.rotAxis[0]/1000. );
160 //Slider3->setValue( data.data.rotAxis[2]/1000. );
161 //Slider4->setValue( data.data.rglSlider[0]/1000. );
162
163 //KnobX->setValue( data.data.posAxis[0] / 1000. );
164 //KnobY->setValue( data.data.posAxis[1] / 1000. );
165
169
170 if( id == 2943300896){
171 permval.GuidData1 = data.data.GuidData1;
172
173 for(int i=1; i<3; i++)
174 permval.rotAxis[i]= data.data.rotAxis[i];
175
176 if(WinchButton1->isChecked())
177 permval.rotAxis[0] = data.data.rotAxis[0] *(-1); // inverting the signal for winch1 to get a more intuitive winch control
178 else permval.rotAxis[0] = 0.0;
179
180 for(int i=0; i<2; i++)
181 permval.posAxis[i]= data.data.posAxis[i];
182
183 if(WinchButton2->isChecked())
184 permval.posAxis[2]= data.data.posAxis[2] *(-1); // inverting the signal for winch2 to get a more intuitive winch control
185 else permval.posAxis[2]= 0.0;
186
187
188 for(int i=0; i<2; i++)
189 permval.rglSlider[i] = data.data.rglSlider[i];
190
191
192 for(int i=0; i<32; i++){
193
194 if(data.data.rgbButtons[i]){
195 permval.rgbButtons[i] = 128*(!permval.rgbButtons[i]);
196 }
197 }
198
199
203 send(sockfd,(const char *) &permval, sizeof(myStruct), 0);
204
205 }
206
207
211
212 if(data.data.rgbButtons[0]/128 == 1){
213
214 if(WinchButton1->isChecked()){
215 WinchButton1->setChecked(false);
216 WinchButton1->setStyleSheet("* { background-color: rgb(255,0,0) }");
217 WinchButton1->setText("Off");
218 }
219 else {
220 WinchButton1->setChecked(true);
221 WinchButton1->setStyleSheet("* { background-color: rgb(0,255,0) }");
222 WinchButton1->setText("On");
223 }
224 }
225
226 if(data.data.rgbButtons[1]/128 == 1){
227
228 if(WinchButton2->isChecked()){
229 WinchButton2->setChecked(false);
230 WinchButton2->setStyleSheet("* { background-color: rgb(255,0,0) }");
231 WinchButton2->setText("Off");
232 }
233 else {
234 WinchButton2->setChecked(true);
235 WinchButton2->setStyleSheet("* { background-color: rgb(0,255,0) }");
236 WinchButton2->setText("On");
237 }
238 }
239
240 if(WinchButton1->isChecked())
241 Slider1->setValue(data.data.posAxis[2] *(-1) / 1000.0);
242 else Slider1->setValue(0.0);
243
244 if(WinchButton2->isChecked())
245 Slider2->setValue(data.data.rotAxis[0] *(-1) / 1000.0);
246 else Slider2->setValue(0.0);
247 }
248
249private:
250 int sockfd;
251 long long ShipConsoleID;
252 long long MSPanelID;
253 myStruct_t updateval; // Holds the current joystick values
254 myStruct_t permval; // Holds permanent values for the "hold" buttons
255 double X, Y1, Y2;
256 int graphInterval;
257
258};
259
260#endif
Definition: SPanel.h:23
ShipPanelChild(QWidget *Parent=0)
Definition: SPanel.h:30
Definition: Joystick.h:78
Definition: myOutputStruct.h:5
Definition: myStruct.h:5