Marine systems simulation
program2.h
1#ifndef SCONSOLE_H
2#define SCONSOLE_H
3#include "Joystick.h"
4#include "ui_SConsole.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
11
12
13
14class ShipConsoleChild :public QWidget, public Ui::ShipConsole{
15 Q_OBJECT
16
17public:
18 ShipConsoleChild(QWidget *Parent=0):QWidget(Parent){
19 }
20
21 void SetSocket( int _fd )
22 {
23 sockfd = _fd;
24 }
25
26 void SetMSPanelID( long long id)
27 {
28 MSPanelID = id;
29 }
30
31 void SetShipConsoleID( long long id)
32 {
33 ShipConsoleID = id;
34 }
35
36 void setupWidgets()
37 {
38 QwtDialSimpleNeedle *needle = new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow, true, Qt::red, QColor(Qt::gray).light(130));
39 MainEngineRight->setRange(-1.0,1.,0.01);
40 MainEngineRight->setNeedle(needle);
41 MainEngineLeft->setRange(-1.0,1.,0.01);
42 MainEngineLeft->setNeedle(needle);
43 Rudder->setRange(-1.0,1.,0.01);
44 Rudder->setNeedle(needle);
45
46
47
48
49
50
51 Slider->setHandleSize( 30, 16 );
52 Slider->setRange(-1.0, 1.0, 1.0, 0); // paging disabled
53
54 KnobX->setRange(0.0,1.0,0.01);
55 KnobY->setRange(0.0,1.0,0.01);
56 KnobZ->setRange(0.0,1.0,0.01);
57
58
59
60
61 Button0->setCheckable(true);
62 Button1->setCheckable(true);
63 Button2->setCheckable(true);
64 Button3->setCheckable(true);
65
66 checkBox->setCheckable(true);
67
68
69
70
71
72
73 }
74
75signals:
76 void JoystickUpdated( long long id, joyData_t data);
77private slots:
78 void UpdateAndSend()
79 {
80 std::map<long long,joyData_t>::iterator it;
81 UpdateInputState(this->winId());
82
83 //send
84 for( it = Joysticks.begin(); it != Joysticks.end(); it++)
85 {
86 LPDIRECTINPUTDEVICE8 dev = it->second.dev;
87 send(sockfd,(const char *) &it->second.data, sizeof(myStruct), 0);
88 emit JoystickUpdated(it->first,it->second);
89 }
90 }
91
92
93 void UpdateJoystickData(long long id,joyData_t data)
94 {
95 if( id == ShipConsoleID){
96 MainEngineRight->setValue( data.data.rglSlider[0]/1000. );
97 MainEngineLeft->setValue(data.data.rotAxis[2]/1000.);
98 Rudder->setValue(data.data.rotAxis[0]/1000. );
99
100
101 //Slider->setValue( data.data.rglSlider[0]/1000. );
102
103
104
105 }
106 if(id == MSPanelID){
107
108 KnobX->setValue( data.data.posAxis[0]/1000. );
109 KnobY->setValue( data.data.posAxis[1]/1000. );
110 KnobZ->setValue( data.data.posAxis[2]/1000. );
111
112
113 if(data.data.rgbButtons[0]/128 == 1)
114 Button0->setChecked(true);
115 else Button0->setChecked(false);
116
117 if(data.data.rgbButtons[1]/128 == 1)
118 Button1->setChecked(true);
119 else Button1->setChecked(false);
120 if(data.data.rgbButtons[2]/128 == 1)
121 Button2->setChecked(true);
122 else Button2->setChecked(false);
123 if(data.data.rgbButtons[3]/128 == 1)
124 Button3->setChecked(true);
125 else Button3->setChecked(false);
126
127 if(data.data.rgbButtons[17]/128 == 1)
128 checkBox->setChecked(true);
129 else checkBox->setChecked(false);
130
131
132 }
133
134
135 }
136
137private:
138 int sockfd;
139 long long ShipConsoleID;
140 long long MSPanelID;
141
142};
143
144
145#endif
Definition: program2.h:14
Definition: Joystick.h:78
Definition: myStruct.h:5