139 |
pfowler |
1 |
using System;
|
|
|
2 |
using System.Collections.Generic;
|
|
|
3 |
using System.ComponentModel;
|
|
|
4 |
using System.Data;
|
|
|
5 |
using System.Drawing;
|
|
|
6 |
using System.Text;
|
|
|
7 |
using System.Threading.Tasks;
|
|
|
8 |
using System.Windows.Forms;
|
|
|
9 |
|
153 |
pfowler |
10 |
using Microsoft.FlightSimulator.SimConnect;
|
|
|
11 |
using System.Runtime.InteropServices;
|
|
|
12 |
|
139 |
pfowler |
13 |
namespace NITNavComm
|
|
|
14 |
{
|
|
|
15 |
public partial class MainForm : Form
|
|
|
16 |
{
|
|
|
17 |
|
|
|
18 |
private NITPanels panels = new NITPanels();
|
153 |
pfowler |
19 |
private SimConnect hSimConnect = null;
|
139 |
pfowler |
20 |
|
155 |
pfowler |
21 |
private FSXObject fsx = new FSXObject();
|
153 |
pfowler |
22 |
|
155 |
pfowler |
23 |
private NITNavCommDevice comm1;
|
|
|
24 |
private NITNavCommDevice comm2;
|
153 |
pfowler |
25 |
|
139 |
pfowler |
26 |
public MainForm() {
|
|
|
27 |
InitializeComponent();
|
|
|
28 |
|
|
|
29 |
Devices_Rescan();
|
153 |
pfowler |
30 |
txtStatus.Text = "Running";
|
139 |
pfowler |
31 |
|
|
|
32 |
}
|
|
|
33 |
|
153 |
pfowler |
34 |
|
|
|
35 |
private void SimConnect_Connect() {
|
|
|
36 |
if (hSimConnect == null) {
|
|
|
37 |
try {
|
|
|
38 |
hSimConnect = new SimConnect("Managed Data Request", base.Handle, 0x402, null, 0);
|
155 |
pfowler |
39 |
fsx.hSimConnect = this.hSimConnect;
|
153 |
pfowler |
40 |
txtSimConnect.Text = "Available";
|
|
|
41 |
this.SimConnect_InitDataRequest();
|
|
|
42 |
} catch (COMException) {
|
|
|
43 |
Log("Could not connect to FSX");
|
|
|
44 |
txtSimConnect.Text = "Failed";
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
private void SimConnect_Disconnect() {
|
|
|
50 |
this.InitFsxClosed();
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
protected override void DefWndProc(ref Message m) {
|
|
|
54 |
if (m.Msg == 0x402) {
|
|
|
55 |
if (hSimConnect != null) {
|
|
|
56 |
hSimConnect.ReceiveMessage();
|
|
|
57 |
}
|
|
|
58 |
} else {
|
|
|
59 |
base.DefWndProc(ref m);
|
|
|
60 |
}
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
private void SimConnect_InitDataRequest() {
|
|
|
64 |
try {
|
|
|
65 |
|
155 |
pfowler |
66 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM1_SWAP_FREQ, "COM_STBY_RADIO_SWAP");
|
|
|
67 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_SWAP_FREQ, "NAV1_RADIO_SWAP");
|
|
|
68 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM_RADIO_WHOLE_INC, "COM_RADIO_WHOLE_INC");
|
|
|
69 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM_RADIO_WHOLE_DEC, "COM_RADIO_WHOLE_DEC");
|
|
|
70 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM_RADIO_FRACT_INC, "COM_RADIO_FRACT_INC");
|
|
|
71 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM_RADIO_FRACT_DEC, "COM_RADIO_FRACT_DEC");
|
|
|
72 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_RADIO_WHOLE_INC, "NAV1_RADIO_WHOLE_INC");
|
|
|
73 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_RADIO_WHOLE_DEC, "NAV1_RADIO_WHOLE_DEC");
|
|
|
74 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_RADIO_FRACT_INC, "NAV1_RADIO_FRACT_INC");
|
|
|
75 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_RADIO_FRACT_DEC, "NAV1_RADIO_FRACT_DEC");
|
153 |
pfowler |
76 |
|
155 |
pfowler |
77 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_SWAP_FREQ, "COM2_RADIO_SWAP");
|
|
|
78 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_SWAP_FREQ, "NAV2_RADIO_SWAP");
|
|
|
79 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_RADIO_WHOLE_INC, "COM2_RADIO_WHOLE_INC");
|
|
|
80 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_RADIO_WHOLE_DEC, "COM2_RADIO_WHOLE_DEC");
|
|
|
81 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_RADIO_FRACT_INC, "COM2_RADIO_FRACT_INC");
|
|
|
82 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_RADIO_FRACT_DEC, "COM2_RADIO_FRACT_DEC");
|
|
|
83 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_RADIO_WHOLE_INC, "NAV2_RADIO_WHOLE_INC");
|
|
|
84 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_RADIO_WHOLE_DEC, "NAV2_RADIO_WHOLE_DEC");
|
|
|
85 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_RADIO_FRACT_INC, "NAV2_RADIO_FRACT_INC");
|
|
|
86 |
hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_RADIO_FRACT_DEC, "NAV2_RADIO_FRACT_DEC");
|
153 |
pfowler |
87 |
|
155 |
pfowler |
88 |
hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AIRCRAFT, "Atc Type", "", SIMCONNECT_DATATYPE.STRING32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
89 |
hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AIRCRAFT, "ATC Model", "", SIMCONNECT_DATATYPE.STRING32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
90 |
hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AIRCRAFT, "ATC ID", "", SIMCONNECT_DATATYPE.STRING32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
91 |
hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AIRCRAFT, "Title", "", SIMCONNECT_DATATYPE.STRING128, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
92 |
hSimConnect.RegisterDataDefineStruct<FSXObject.Aircraft_Data>(FSXObject.DEFINITIONS.AIRCRAFT);
|
153 |
pfowler |
93 |
|
155 |
pfowler |
94 |
hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AVIONICS, "Avionics Master Switch", "bool", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED);
|
|
|
95 |
hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AVIONICS, "Com Status:1", "Enum", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
|
|
|
96 |
hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AVIONICS, "Com Status:2", "Enum", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
|
|
|
97 |
hSimConnect.RegisterDataDefineStruct<FSXObject.Avionics_Data>(FSXObject.DEFINITIONS.AVIONICS);
|
153 |
pfowler |
98 |
|
155 |
pfowler |
99 |
// NavComm1 Frequencies
|
|
|
100 |
hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM1_DATA, "Com Active Frequency:1", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
101 |
hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM1_DATA, "Com Standby Frequency:1", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
102 |
hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM1_DATA, "Nav Active Frequency:1", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
103 |
hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM1_DATA, "Nav Standby Frequency:1", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
104 |
hSimConnect.RegisterDataDefineStruct<FSXObject.NavCom_Data>(FSXObject.DEFINITIONS.NAVCOM1_DATA);
|
153 |
pfowler |
105 |
|
155 |
pfowler |
106 |
// NavComm2 Frequencies
|
|
|
107 |
hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM2_DATA, "Com Active Frequency:2", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
108 |
hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM2_DATA, "Com Standby Frequency:2", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
109 |
hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM2_DATA, "Nav Active Frequency:2", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
110 |
hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM2_DATA, "Nav Standby Frequency:2", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
111 |
hSimConnect.RegisterDataDefineStruct<FSXObject.NavCom_Data>(FSXObject.DEFINITIONS.NAVCOM2_DATA);
|
|
|
112 |
|
153 |
pfowler |
113 |
hSimConnect.OnRecvOpen += new SimConnect.RecvOpenEventHandler(SimConnect_OnRecvOpen);
|
|
|
114 |
hSimConnect.OnRecvQuit += new SimConnect.RecvQuitEventHandler(SimConnect_OnRecvQuit);
|
|
|
115 |
hSimConnect.OnRecvException += new SimConnect.RecvExceptionEventHandler(SimConnect_OnRecvException);
|
|
|
116 |
hSimConnect.OnRecvSimobjectData += new SimConnect.RecvSimobjectDataEventHandler(SimConnect_OnRecvSimObjectData);
|
|
|
117 |
hSimConnect.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(SimConnect_OnRecvSimObjectDataByType);
|
|
|
118 |
|
|
|
119 |
// Request for aircrat data. This will also configure auto-updates for other required data.
|
155 |
pfowler |
120 |
hSimConnect.RequestDataOnSimObjectType(FSXObject.DATA_REQUESTS.AIRCRAFT, FSXObject.DEFINITIONS.AIRCRAFT, 0, SIMCONNECT_SIMOBJECT_TYPE.USER);
|
153 |
pfowler |
121 |
|
|
|
122 |
} catch (COMException e) {
|
|
|
123 |
Log(e.Message);
|
|
|
124 |
}
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
private void SimConnect_OnRecvOpen(SimConnect sender, SIMCONNECT_RECV_OPEN data) {
|
|
|
128 |
Log("Connected to FSX.");
|
|
|
129 |
txtSimConnect.Text = "Connected";
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
private void SimConnect_OnRecvQuit(SimConnect sender, SIMCONNECT_RECV data) {
|
|
|
133 |
Log("FSX has exited.");
|
|
|
134 |
this.SimConnect_Disconnect();
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
private void SimConnect_OnRecvException(SimConnect sender, SIMCONNECT_RECV_EXCEPTION data) {
|
|
|
138 |
Log("SimConnect Exception: " + (uint)(data.dwException));
|
|
|
139 |
}
|
|
|
140 |
|
155 |
pfowler |
141 |
// Automatic updates on various variables. Set through InitFsxReady
|
153 |
pfowler |
142 |
private void SimConnect_OnRecvSimObjectData(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA data) {
|
155 |
pfowler |
143 |
|
153 |
pfowler |
144 |
switch (data.dwRequestID) {
|
|
|
145 |
|
155 |
pfowler |
146 |
|
|
|
147 |
case ((uint)FSXObject.DATA_REQUESTS.NAVCOM1_REQ): {
|
|
|
148 |
FSXObject.NavCom_Data navcomdata = (FSXObject.NavCom_Data)data.dwData[0];
|
|
|
149 |
if (comm1 != null && comm1.isOpen())
|
|
|
150 |
comm1.setNavComFreqs(navcomdata);
|
153 |
pfowler |
151 |
break;
|
|
|
152 |
}
|
155 |
pfowler |
153 |
|
|
|
154 |
case ((uint)FSXObject.DATA_REQUESTS.NAVCOM2_REQ): {
|
|
|
155 |
FSXObject.NavCom_Data navcomdata = (FSXObject.NavCom_Data)data.dwData[0];
|
|
|
156 |
if (comm2 != null && comm2.isOpen())
|
|
|
157 |
comm2.setNavComFreqs(navcomdata);
|
|
|
158 |
break;
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
case ((uint)FSXObject.DATA_REQUESTS.AVIONICS): {
|
|
|
162 |
FSXObject.Avionics_Data avionics = (FSXObject.Avionics_Data)data.dwData[0];
|
|
|
163 |
/*
|
|
|
164 |
Log("Avionics: "
|
|
|
165 |
+ avionics.avionics_master + ", "
|
|
|
166 |
+ "Com1: " + avionics.com1_status + ", "
|
|
|
167 |
+ "Com2: " + avionics.com2_status + ", "
|
|
|
168 |
);
|
|
|
169 |
*/
|
|
|
170 |
|
|
|
171 |
if (!avionics.avionics_master || avionics.com1_status != 0) { // If avionics master off or com1 in shutdown
|
|
|
172 |
if (comm1 != null && comm1.isOpen() && comm1.simStatus == 0) // and the device is connected
|
|
|
173 |
comm1.powerDown(); // Power down the device
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
if (comm1 != null && comm1.isOpen() // If comm1 device is active
|
|
|
177 |
&& comm1.simStatus != 0 // and connected to fsx
|
|
|
178 |
&& avionics.avionics_master // and avionics master is on
|
|
|
179 |
&& avionics.com1_status == 0) { // and comm1 functioning
|
|
|
180 |
comm1.powerUp(); // Power it up
|
|
|
181 |
|
|
|
182 |
hSimConnect.RequestDataOnSimObject(
|
|
|
183 |
FSXObject.DATA_REQUESTS.NAVCOM1_REQ,
|
|
|
184 |
FSXObject.DEFINITIONS.NAVCOM1_DATA,
|
|
|
185 |
this.fsx.simdata.objectid,
|
|
|
186 |
SIMCONNECT_PERIOD.ONCE,
|
|
|
187 |
SIMCONNECT_DATA_REQUEST_FLAG.DEFAULT,
|
|
|
188 |
0, 0, 0);
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
if (!avionics.avionics_master || avionics.com2_status != 0) { // If avionics master off or com1 in shutdown
|
|
|
192 |
if (comm2 != null && comm2.isOpen() && comm2.simStatus == 0) // and the device is connected
|
|
|
193 |
comm2.powerDown(); // Power down the device
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
if (comm2 != null && comm2.isOpen() // If comm1 device is active
|
|
|
197 |
&& comm2.simStatus != 0 // and connected to fsx
|
|
|
198 |
&& avionics.avionics_master // and avionics master is on
|
|
|
199 |
&& avionics.com2_status == 0) { // and comm1 functioning
|
|
|
200 |
comm2.powerUp(); // Power it up
|
|
|
201 |
|
|
|
202 |
hSimConnect.RequestDataOnSimObject(
|
|
|
203 |
FSXObject.DATA_REQUESTS.NAVCOM2_REQ,
|
|
|
204 |
FSXObject.DEFINITIONS.NAVCOM2_DATA,
|
|
|
205 |
this.fsx.simdata.objectid,
|
|
|
206 |
SIMCONNECT_PERIOD.ONCE,
|
|
|
207 |
SIMCONNECT_DATA_REQUEST_FLAG.DEFAULT,
|
|
|
208 |
0, 0, 0);
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
break;
|
|
|
212 |
}
|
153 |
pfowler |
213 |
}
|
|
|
214 |
}
|
|
|
215 |
|
|
|
216 |
private void SimConnect_OnRecvSimObjectDataByType(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE data) {
|
|
|
217 |
switch (data.dwRequestID) {
|
|
|
218 |
|
|
|
219 |
// Request basic aircraft data to get the object ID
|
155 |
pfowler |
220 |
case ((uint)FSXObject.DATA_REQUESTS.AIRCRAFT): {
|
153 |
pfowler |
221 |
uint ObjectID = data.dwObjectID;
|
155 |
pfowler |
222 |
FSXObject.Aircraft_Data aircraftdata = (FSXObject.Aircraft_Data)data.dwData[0];
|
153 |
pfowler |
223 |
|
155 |
pfowler |
224 |
this.fsx.simdata.objectid = ObjectID;
|
|
|
225 |
this.fsx.simdata.aircraft = aircraftdata;
|
|
|
226 |
|
153 |
pfowler |
227 |
this.InitFsxReady();
|
|
|
228 |
|
|
|
229 |
break;
|
|
|
230 |
}
|
|
|
231 |
}
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
private void InitFsxReady() {
|
|
|
235 |
|
|
|
236 |
|
|
|
237 |
Log("Aircraft: "
|
155 |
pfowler |
238 |
+ this.fsx.simdata.aircraft.atc_id + ", "
|
|
|
239 |
+ this.fsx.simdata.aircraft.atc_model + ", "
|
|
|
240 |
+ this.fsx.simdata.aircraft.atc_type + ", "
|
|
|
241 |
+ this.fsx.simdata.aircraft.title
|
153 |
pfowler |
242 |
);
|
155 |
pfowler |
243 |
|
153 |
pfowler |
244 |
hSimConnect.RequestDataOnSimObject(
|
155 |
pfowler |
245 |
FSXObject.DATA_REQUESTS.NAVCOM1_REQ,
|
|
|
246 |
FSXObject.DEFINITIONS.NAVCOM1_DATA,
|
|
|
247 |
this.fsx.simdata.objectid,
|
153 |
pfowler |
248 |
SIMCONNECT_PERIOD.SIM_FRAME,
|
|
|
249 |
SIMCONNECT_DATA_REQUEST_FLAG.CHANGED,
|
|
|
250 |
0, 0, 0);
|
|
|
251 |
|
155 |
pfowler |
252 |
hSimConnect.RequestDataOnSimObject(
|
|
|
253 |
FSXObject.DATA_REQUESTS.NAVCOM2_REQ,
|
|
|
254 |
FSXObject.DEFINITIONS.NAVCOM2_DATA,
|
|
|
255 |
this.fsx.simdata.objectid,
|
|
|
256 |
SIMCONNECT_PERIOD.SIM_FRAME,
|
|
|
257 |
SIMCONNECT_DATA_REQUEST_FLAG.CHANGED,
|
|
|
258 |
0, 0, 0);
|
|
|
259 |
|
|
|
260 |
hSimConnect.RequestDataOnSimObject(
|
|
|
261 |
FSXObject.DATA_REQUESTS.AVIONICS,
|
|
|
262 |
FSXObject.DEFINITIONS.AVIONICS,
|
|
|
263 |
this.fsx.simdata.objectid,
|
|
|
264 |
SIMCONNECT_PERIOD.SIM_FRAME,
|
|
|
265 |
SIMCONNECT_DATA_REQUEST_FLAG.CHANGED,
|
|
|
266 |
0, 0, 0);
|
|
|
267 |
|
153 |
pfowler |
268 |
inputTimer.Enabled = true;
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
private void InitFsxClosed() {
|
|
|
272 |
|
155 |
pfowler |
273 |
if (comm1 != null && comm1.isOpen())
|
|
|
274 |
comm1.blankDisplay();
|
|
|
275 |
|
|
|
276 |
if (comm2 != null && comm2.isOpen())
|
|
|
277 |
comm2.blankDisplay();
|
|
|
278 |
|
|
|
279 |
if (hSimConnect != null) {
|
|
|
280 |
hSimConnect.Dispose();
|
|
|
281 |
txtSimConnect.Text = "Available";
|
|
|
282 |
} else {
|
|
|
283 |
txtSimConnect.Text = "Failed";
|
|
|
284 |
hSimConnect = null;
|
|
|
285 |
}
|
|
|
286 |
|
153 |
pfowler |
287 |
}
|
|
|
288 |
|
139 |
pfowler |
289 |
private void Devices_Rescan() {
|
|
|
290 |
Log("Scanning for devices...");
|
|
|
291 |
|
|
|
292 |
panels.UsbScan();
|
|
|
293 |
|
|
|
294 |
this.deviceGrid.DataSource = panels.devices;
|
|
|
295 |
this.txtDevices.Text = panels.devices.Count.ToString();
|
|
|
296 |
|
|
|
297 |
if (panels.devices.Count > 0) {
|
|
|
298 |
this.cmDevTest.Enabled = true;
|
|
|
299 |
Log(panels.devices.Count.ToString() + " devices found during scan.");
|
155 |
pfowler |
300 |
|
|
|
301 |
foreach (NITDevice device in panels.devices) {
|
|
|
302 |
if (device.type == "NITNavComm") {
|
|
|
303 |
if (comm1 == null) {
|
|
|
304 |
comm1 = (NITNavCommDevice)device;
|
|
|
305 |
comm1.assigned = 1;
|
|
|
306 |
} else if (comm2 == null) {
|
|
|
307 |
comm2 = (NITNavCommDevice)device;
|
|
|
308 |
comm2.assigned = 2;
|
|
|
309 |
}
|
|
|
310 |
} else if (device.type == "NITAudioSel") {
|
|
|
311 |
// @TODO: Add other devices
|
|
|
312 |
}
|
|
|
313 |
}
|
|
|
314 |
|
139 |
pfowler |
315 |
} else {
|
|
|
316 |
Log("No devices found, check connections and rescan.");
|
|
|
317 |
}
|
153 |
pfowler |
318 |
|
155 |
pfowler |
319 |
|
139 |
pfowler |
320 |
}
|
|
|
321 |
|
|
|
322 |
private void cmdRescan_Click(object sender, EventArgs e) {
|
|
|
323 |
this.Devices_Rescan();
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
private void cmdDevRescan_Click(object sender, EventArgs e) {
|
|
|
327 |
this.Devices_Rescan();
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
private void cmDevTest_Click(object sender, EventArgs e) {
|
155 |
pfowler |
331 |
NITDevice device = (NITDevice) this.deviceGrid.CurrentRow.DataBoundItem;
|
139 |
pfowler |
332 |
|
155 |
pfowler |
333 |
if (!device.Open()) {
|
|
|
334 |
Log("Could not open device " + device.type + "(" + device.serial + ").");
|
139 |
pfowler |
335 |
return;
|
|
|
336 |
}
|
155 |
pfowler |
337 |
if (device.type == "NITNavComm") {
|
|
|
338 |
NITCommNavForm form = new NITCommNavForm();
|
|
|
339 |
form.setDevice((NITNavCommDevice)device);
|
|
|
340 |
form.Show(this);
|
|
|
341 |
} else if (device.type == "NITAudioSel") {
|
|
|
342 |
Log("Not implemented for NITAudioSel");
|
|
|
343 |
} else {
|
|
|
344 |
Log("No device type for " + device.type + " (" + device.serial + ").");
|
|
|
345 |
}
|
139 |
pfowler |
346 |
}
|
|
|
347 |
|
|
|
348 |
public void Log(string msg) {
|
|
|
349 |
txtLog.AppendText(msg + "\r\n");
|
|
|
350 |
}
|
|
|
351 |
|
|
|
352 |
public void Log(byte[] buffer) {
|
|
|
353 |
StringBuilder sb = new StringBuilder();
|
|
|
354 |
foreach (byte data in buffer) {
|
|
|
355 |
sb.Append(data.ToString("X") + " ");
|
|
|
356 |
}
|
|
|
357 |
Log(sb.ToString());
|
155 |
pfowler |
358 |
}
|
139 |
pfowler |
359 |
|
155 |
pfowler |
360 |
private void quitNITPanels() {
|
|
|
361 |
//this.InitFsxClosed();
|
|
|
362 |
|
|
|
363 |
inputTimer.Enabled = false;
|
|
|
364 |
|
|
|
365 |
if (comm1 != null && comm1.isOpen())
|
|
|
366 |
comm1.Close();
|
|
|
367 |
|
|
|
368 |
if (comm2 != null && comm2.isOpen())
|
|
|
369 |
comm2.Close();
|
|
|
370 |
|
|
|
371 |
Application.Exit();
|
|
|
372 |
}
|
|
|
373 |
|
139 |
pfowler |
374 |
private void quitToolStripMenuItem_Click(object sender, EventArgs e) {
|
|
|
375 |
if (QuestionBox("Exit NIT Panels?", "Exiting will disable NIT Panels. Continue?")) {
|
155 |
pfowler |
376 |
this.quitNITPanels();
|
139 |
pfowler |
377 |
}
|
|
|
378 |
}
|
|
|
379 |
|
|
|
380 |
public bool QuestionBox(string caption, string message) {
|
|
|
381 |
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
|
|
|
382 |
DialogResult result;
|
|
|
383 |
|
|
|
384 |
result = MessageBox.Show(message, caption, buttons);
|
|
|
385 |
|
|
|
386 |
if (result == System.Windows.Forms.DialogResult.Yes) {
|
|
|
387 |
return true;
|
|
|
388 |
}
|
|
|
389 |
return false;
|
|
|
390 |
}
|
|
|
391 |
|
|
|
392 |
private void txtLog_VisibleChanged(object sender, EventArgs e) {
|
|
|
393 |
if (txtLog.Visible) {
|
|
|
394 |
txtLog.SelectionStart = txtLog.TextLength;
|
|
|
395 |
txtLog.ScrollToCaret();
|
|
|
396 |
}
|
|
|
397 |
}
|
|
|
398 |
|
153 |
pfowler |
399 |
private void cmdSimConnect_Click(object sender, EventArgs e) {
|
|
|
400 |
if (hSimConnect != null)
|
|
|
401 |
this.SimConnect_Disconnect();
|
|
|
402 |
|
|
|
403 |
this.SimConnect_Connect();
|
|
|
404 |
}
|
|
|
405 |
|
|
|
406 |
private void cmdRequest_Click(object sender, EventArgs e) {
|
155 |
pfowler |
407 |
|
153 |
pfowler |
408 |
}
|
|
|
409 |
|
|
|
410 |
private void inputTimer_Tick(object sender, EventArgs e) {
|
155 |
pfowler |
411 |
if (comm1 != null && comm1.isOpen()) {
|
|
|
412 |
comm1.updateInput();
|
|
|
413 |
comm1.simButtons(this.fsx);
|
|
|
414 |
}
|
153 |
pfowler |
415 |
|
155 |
pfowler |
416 |
if (comm2 != null && comm2.isOpen()) {
|
|
|
417 |
comm2.updateInput();
|
|
|
418 |
comm2.simButtons(this.fsx);
|
153 |
pfowler |
419 |
}
|
|
|
420 |
|
155 |
pfowler |
421 |
}
|
153 |
pfowler |
422 |
|
155 |
pfowler |
423 |
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) {
|
|
|
424 |
this.quitNITPanels();
|
153 |
pfowler |
425 |
}
|
|
|
426 |
|
139 |
pfowler |
427 |
}
|
|
|
428 |
}
|