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 |
|
157 |
pfowler |
18 |
public NITPanels panels = new NITPanels();
|
|
|
19 |
public FSXObject fsx = new FSXObject();
|
139 |
pfowler |
20 |
|
|
|
21 |
public MainForm() {
|
|
|
22 |
InitializeComponent();
|
|
|
23 |
|
|
|
24 |
Devices_Rescan();
|
153 |
pfowler |
25 |
txtStatus.Text = "Running";
|
139 |
pfowler |
26 |
|
|
|
27 |
}
|
|
|
28 |
|
153 |
pfowler |
29 |
|
|
|
30 |
private void SimConnect_Connect() {
|
157 |
pfowler |
31 |
if (fsx.hSimConnect == null) {
|
153 |
pfowler |
32 |
try {
|
157 |
pfowler |
33 |
fsx.hSimConnect = new SimConnect("Managed Data Request", base.Handle, 0x402, null, 0);
|
153 |
pfowler |
34 |
txtSimConnect.Text = "Available";
|
157 |
pfowler |
35 |
|
|
|
36 |
fsx.FsxInit();
|
|
|
37 |
|
|
|
38 |
// Make our devices aware of the fsx object
|
|
|
39 |
// Let the device to any Fsx initilization
|
|
|
40 |
foreach (NITDevice device in panels.devices) {
|
|
|
41 |
if (device.isOpen()) {
|
|
|
42 |
device.fsx = this.fsx;
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
|
153 |
pfowler |
46 |
this.SimConnect_InitDataRequest();
|
|
|
47 |
} catch (COMException) {
|
|
|
48 |
Log("Could not connect to FSX");
|
|
|
49 |
txtSimConnect.Text = "Failed";
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
private void SimConnect_Disconnect() {
|
|
|
55 |
this.InitFsxClosed();
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
protected override void DefWndProc(ref Message m) {
|
|
|
59 |
if (m.Msg == 0x402) {
|
157 |
pfowler |
60 |
if (fsx.hSimConnect != null) {
|
|
|
61 |
fsx.hSimConnect.ReceiveMessage();
|
153 |
pfowler |
62 |
}
|
|
|
63 |
} else {
|
|
|
64 |
base.DefWndProc(ref m);
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
private void SimConnect_InitDataRequest() {
|
|
|
69 |
try {
|
|
|
70 |
|
157 |
pfowler |
71 |
foreach (NITDevice device in panels.devices) {
|
|
|
72 |
if (device.isOpen())
|
|
|
73 |
device.MapEvents();
|
|
|
74 |
}
|
156 |
pfowler |
75 |
|
153 |
pfowler |
76 |
|
|
|
77 |
|
157 |
pfowler |
78 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM1_SWAP_FREQ, "COM_STBY_RADIO_SWAP");
|
|
|
79 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_SWAP_FREQ, "NAV1_RADIO_SWAP");
|
|
|
80 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM_RADIO_WHOLE_INC, "COM_RADIO_WHOLE_INC");
|
|
|
81 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM_RADIO_WHOLE_DEC, "COM_RADIO_WHOLE_DEC");
|
|
|
82 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM_RADIO_FRACT_INC, "COM_RADIO_FRACT_INC");
|
|
|
83 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM_RADIO_FRACT_DEC, "COM_RADIO_FRACT_DEC");
|
|
|
84 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_RADIO_WHOLE_INC, "NAV1_RADIO_WHOLE_INC");
|
|
|
85 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_RADIO_WHOLE_DEC, "NAV1_RADIO_WHOLE_DEC");
|
|
|
86 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_RADIO_FRACT_INC, "NAV1_RADIO_FRACT_INC");
|
|
|
87 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_RADIO_FRACT_DEC, "NAV1_RADIO_FRACT_DEC");
|
153 |
pfowler |
88 |
|
157 |
pfowler |
89 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_SWAP_FREQ, "COM2_RADIO_SWAP");
|
|
|
90 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_SWAP_FREQ, "NAV2_RADIO_SWAP");
|
|
|
91 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_RADIO_WHOLE_INC, "COM2_RADIO_WHOLE_INC");
|
|
|
92 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_RADIO_WHOLE_DEC, "COM2_RADIO_WHOLE_DEC");
|
|
|
93 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_RADIO_FRACT_INC, "COM2_RADIO_FRACT_INC");
|
|
|
94 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_RADIO_FRACT_DEC, "COM2_RADIO_FRACT_DEC");
|
|
|
95 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_RADIO_WHOLE_INC, "NAV2_RADIO_WHOLE_INC");
|
|
|
96 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_RADIO_WHOLE_DEC, "NAV2_RADIO_WHOLE_DEC");
|
|
|
97 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_RADIO_FRACT_INC, "NAV2_RADIO_FRACT_INC");
|
|
|
98 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_RADIO_FRACT_DEC, "NAV2_RADIO_FRACT_DEC");
|
153 |
pfowler |
99 |
|
157 |
pfowler |
100 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM1_TRANSMIT_SELECT, "COM1_TRANSMIT_SELECT");
|
|
|
101 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_TRANSMIT_SELECT, "COM2_TRANSMIT_SELECT");
|
|
|
102 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM_RECEIVE_ALL_TOGGLE, "COM_RECEIVE_ALL_TOGGLE");
|
|
|
103 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.RADIO_VOR1_IDENT_TOGGLE, "RADIO_VOR1_IDENT_TOGGLE");
|
|
|
104 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.RADIO_VOR2_IDENT_TOGGLE, "RADIO_VOR2_IDENT_TOGGLE");
|
|
|
105 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.MARKER_SOUND_TOGGLE, "MARKER_SOUND_TOGGLE");
|
|
|
106 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.RADIO_DME1_IDENT_TOGGLE, "RADIO_DME1_IDENT_TOGGLE");
|
|
|
107 |
fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.RADIO_ADF_IDENT_TOGGLE, "RADIO_ADF_IDENT_TOGGLE");
|
|
|
108 |
|
|
|
109 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AUDIOSEL_DATA, "COM TRANSMIT:1", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
110 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AUDIOSEL_DATA, "COM TRANSMIT:2", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
111 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AUDIOSEL_DATA, "COM RECIEVE ALL", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
112 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AUDIOSEL_DATA, "NAV SOUND:1", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
113 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AUDIOSEL_DATA, "NAV SOUND:2", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
114 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AUDIOSEL_DATA, "MARKER SOUND", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
115 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AUDIOSEL_DATA, "DME SOUND", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
116 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AUDIOSEL_DATA, "ADF SOUND:1", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
117 |
fsx.hSimConnect.RegisterDataDefineStruct<FSXObject.AudioSel_Data>(FSXObject.DEFINITIONS.AUDIOSEL_DATA);
|
|
|
118 |
|
|
|
119 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AIRCRAFT, "Atc Type", "", SIMCONNECT_DATATYPE.STRING32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
120 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AIRCRAFT, "ATC Model", "", SIMCONNECT_DATATYPE.STRING32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
121 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AIRCRAFT, "ATC ID", "", SIMCONNECT_DATATYPE.STRING32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
122 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AIRCRAFT, "Title", "", SIMCONNECT_DATATYPE.STRING128, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
123 |
fsx.hSimConnect.RegisterDataDefineStruct<FSXObject.Aircraft_Data>(FSXObject.DEFINITIONS.AIRCRAFT);
|
|
|
124 |
|
|
|
125 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AVIONICS, "Avionics Master Switch", "bool", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED);
|
|
|
126 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AVIONICS, "Com Status:1", "Enum", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
|
|
|
127 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AVIONICS, "Com Status:2", "Enum", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
|
|
|
128 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AVIONICS, "Nav Available:1", "bool", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED);
|
|
|
129 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AVIONICS, "Nav Available:2", "bool", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED);
|
|
|
130 |
fsx.hSimConnect.RegisterDataDefineStruct<FSXObject.Avionics_Data>(FSXObject.DEFINITIONS.AVIONICS);
|
|
|
131 |
|
155 |
pfowler |
132 |
// NavComm1 Frequencies
|
157 |
pfowler |
133 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM1_DATA, "Com Active Frequency:1", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
134 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM1_DATA, "Com Standby Frequency:1", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
135 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM1_DATA, "Nav Active Frequency:1", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
136 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM1_DATA, "Nav Standby Frequency:1", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
137 |
fsx.hSimConnect.RegisterDataDefineStruct<FSXObject.NavCom_Data>(FSXObject.DEFINITIONS.NAVCOM1_DATA);
|
153 |
pfowler |
138 |
|
155 |
pfowler |
139 |
// NavComm2 Frequencies
|
157 |
pfowler |
140 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM2_DATA, "Com Active Frequency:2", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
141 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM2_DATA, "Com Standby Frequency:2", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
142 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM2_DATA, "Nav Active Frequency:2", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
143 |
fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM2_DATA, "Nav Standby Frequency:2", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
|
|
|
144 |
fsx.hSimConnect.RegisterDataDefineStruct<FSXObject.NavCom_Data>(FSXObject.DEFINITIONS.NAVCOM2_DATA);
|
155 |
pfowler |
145 |
|
157 |
pfowler |
146 |
fsx.hSimConnect.OnRecvOpen += new SimConnect.RecvOpenEventHandler(SimConnect_OnRecvOpen);
|
|
|
147 |
fsx.hSimConnect.OnRecvQuit += new SimConnect.RecvQuitEventHandler(SimConnect_OnRecvQuit);
|
|
|
148 |
fsx.hSimConnect.OnRecvException += new SimConnect.RecvExceptionEventHandler(SimConnect_OnRecvException);
|
|
|
149 |
fsx.hSimConnect.OnRecvSimobjectData += new SimConnect.RecvSimobjectDataEventHandler(SimConnect_OnRecvSimObjectData);
|
|
|
150 |
fsx.hSimConnect.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(SimConnect_OnRecvSimObjectDataByType);
|
153 |
pfowler |
151 |
|
|
|
152 |
// Request for aircrat data. This will also configure auto-updates for other required data.
|
157 |
pfowler |
153 |
fsx.hSimConnect.RequestDataOnSimObjectType(FSXObject.DATA_REQUESTS.AIRCRAFT, FSXObject.DEFINITIONS.AIRCRAFT, 0, SIMCONNECT_SIMOBJECT_TYPE.USER);
|
153 |
pfowler |
154 |
|
|
|
155 |
} catch (COMException e) {
|
|
|
156 |
Log(e.Message);
|
|
|
157 |
}
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
private void SimConnect_OnRecvOpen(SimConnect sender, SIMCONNECT_RECV_OPEN data) {
|
|
|
161 |
Log("Connected to FSX.");
|
|
|
162 |
txtSimConnect.Text = "Connected";
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
private void SimConnect_OnRecvQuit(SimConnect sender, SIMCONNECT_RECV data) {
|
|
|
166 |
Log("FSX has exited.");
|
|
|
167 |
this.SimConnect_Disconnect();
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
private void SimConnect_OnRecvException(SimConnect sender, SIMCONNECT_RECV_EXCEPTION data) {
|
|
|
171 |
Log("SimConnect Exception: " + (uint)(data.dwException));
|
|
|
172 |
}
|
|
|
173 |
|
155 |
pfowler |
174 |
// Automatic updates on various variables. Set through InitFsxReady
|
153 |
pfowler |
175 |
private void SimConnect_OnRecvSimObjectData(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA data) {
|
157 |
pfowler |
176 |
if (data.dwRequestID == (uint)FSXObject.DATA_REQUESTS.AUDIOSEL_REQ)
|
|
|
177 |
MainForm.NITMessageBox("Debug", "AudioSel data");
|
153 |
pfowler |
178 |
|
156 |
pfowler |
179 |
foreach (NITDevice device in panels.devices) {
|
157 |
pfowler |
180 |
if (device.isOpen()) {
|
|
|
181 |
device.FsxEvent(data);
|
|
|
182 |
}
|
156 |
pfowler |
183 |
}
|
153 |
pfowler |
184 |
}
|
|
|
185 |
|
|
|
186 |
private void SimConnect_OnRecvSimObjectDataByType(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE data) {
|
|
|
187 |
switch (data.dwRequestID) {
|
|
|
188 |
// Request basic aircraft data to get the object ID
|
155 |
pfowler |
189 |
case ((uint)FSXObject.DATA_REQUESTS.AIRCRAFT): {
|
153 |
pfowler |
190 |
uint ObjectID = data.dwObjectID;
|
155 |
pfowler |
191 |
FSXObject.Aircraft_Data aircraftdata = (FSXObject.Aircraft_Data)data.dwData[0];
|
153 |
pfowler |
192 |
|
155 |
pfowler |
193 |
this.fsx.simdata.objectid = ObjectID;
|
|
|
194 |
this.fsx.simdata.aircraft = aircraftdata;
|
|
|
195 |
|
157 |
pfowler |
196 |
this.fsx.FsxReady();
|
|
|
197 |
this.InitFsxReady();
|
153 |
pfowler |
198 |
|
|
|
199 |
break;
|
|
|
200 |
}
|
|
|
201 |
}
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
private void InitFsxReady() {
|
|
|
205 |
|
|
|
206 |
Log("Aircraft: "
|
155 |
pfowler |
207 |
+ this.fsx.simdata.aircraft.atc_id + ", "
|
|
|
208 |
+ this.fsx.simdata.aircraft.atc_model + ", "
|
|
|
209 |
+ this.fsx.simdata.aircraft.atc_type + ", "
|
|
|
210 |
+ this.fsx.simdata.aircraft.title
|
153 |
pfowler |
211 |
);
|
155 |
pfowler |
212 |
|
153 |
pfowler |
213 |
inputTimer.Enabled = true;
|
|
|
214 |
}
|
|
|
215 |
|
|
|
216 |
private void InitFsxClosed() {
|
157 |
pfowler |
217 |
if (fsx.hSimConnect != null) {
|
|
|
218 |
fsx.hSimConnect.Dispose();
|
155 |
pfowler |
219 |
txtSimConnect.Text = "Available";
|
|
|
220 |
} else {
|
|
|
221 |
txtSimConnect.Text = "Failed";
|
157 |
pfowler |
222 |
fsx.hSimConnect = null;
|
155 |
pfowler |
223 |
}
|
153 |
pfowler |
224 |
}
|
|
|
225 |
|
139 |
pfowler |
226 |
private void Devices_Rescan() {
|
|
|
227 |
Log("Scanning for devices...");
|
|
|
228 |
|
|
|
229 |
panels.UsbScan();
|
|
|
230 |
|
|
|
231 |
this.deviceGrid.DataSource = panels.devices;
|
|
|
232 |
this.txtDevices.Text = panels.devices.Count.ToString();
|
|
|
233 |
|
|
|
234 |
if (panels.devices.Count > 0) {
|
|
|
235 |
this.cmDevTest.Enabled = true;
|
|
|
236 |
Log(panels.devices.Count.ToString() + " devices found during scan.");
|
155 |
pfowler |
237 |
|
139 |
pfowler |
238 |
} else {
|
|
|
239 |
Log("No devices found, check connections and rescan.");
|
|
|
240 |
}
|
|
|
241 |
}
|
|
|
242 |
|
157 |
pfowler |
243 |
|
|
|
244 |
|
139 |
pfowler |
245 |
private void cmdRescan_Click(object sender, EventArgs e) {
|
|
|
246 |
this.Devices_Rescan();
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
private void cmdDevRescan_Click(object sender, EventArgs e) {
|
|
|
250 |
this.Devices_Rescan();
|
|
|
251 |
}
|
|
|
252 |
|
|
|
253 |
private void cmDevTest_Click(object sender, EventArgs e) {
|
155 |
pfowler |
254 |
NITDevice device = (NITDevice) this.deviceGrid.CurrentRow.DataBoundItem;
|
139 |
pfowler |
255 |
|
155 |
pfowler |
256 |
if (!device.Open()) {
|
|
|
257 |
Log("Could not open device " + device.type + "(" + device.serial + ").");
|
139 |
pfowler |
258 |
return;
|
|
|
259 |
}
|
155 |
pfowler |
260 |
if (device.type == "NITNavComm") {
|
|
|
261 |
NITCommNavForm form = new NITCommNavForm();
|
|
|
262 |
form.setDevice((NITNavCommDevice)device);
|
|
|
263 |
form.Show(this);
|
|
|
264 |
} else if (device.type == "NITAudioSel") {
|
156 |
pfowler |
265 |
NITAudioSelForm form = new NITAudioSelForm();
|
|
|
266 |
form.setDevice((NITAudioSelDevice)device);
|
|
|
267 |
form.Show(this);
|
155 |
pfowler |
268 |
} else {
|
|
|
269 |
Log("No device type for " + device.type + " (" + device.serial + ").");
|
|
|
270 |
}
|
139 |
pfowler |
271 |
}
|
|
|
272 |
|
|
|
273 |
public void Log(string msg) {
|
|
|
274 |
txtLog.AppendText(msg + "\r\n");
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
public void Log(byte[] buffer) {
|
|
|
278 |
StringBuilder sb = new StringBuilder();
|
|
|
279 |
foreach (byte data in buffer) {
|
|
|
280 |
sb.Append(data.ToString("X") + " ");
|
|
|
281 |
}
|
|
|
282 |
Log(sb.ToString());
|
155 |
pfowler |
283 |
}
|
139 |
pfowler |
284 |
|
155 |
pfowler |
285 |
private void quitNITPanels() {
|
|
|
286 |
inputTimer.Enabled = false;
|
|
|
287 |
|
156 |
pfowler |
288 |
foreach (NITDevice device in panels.devices) {
|
|
|
289 |
if (device.isOpen())
|
|
|
290 |
device.Close();
|
|
|
291 |
}
|
|
|
292 |
|
155 |
pfowler |
293 |
Application.Exit();
|
|
|
294 |
}
|
|
|
295 |
|
139 |
pfowler |
296 |
private void quitToolStripMenuItem_Click(object sender, EventArgs e) {
|
156 |
pfowler |
297 |
if (MainForm.QuestionBox("Exit NIT Panels?", "Exiting will disable NIT Panels. Continue?")) {
|
155 |
pfowler |
298 |
this.quitNITPanels();
|
139 |
pfowler |
299 |
}
|
|
|
300 |
}
|
|
|
301 |
|
156 |
pfowler |
302 |
|
|
|
303 |
public static bool QuestionBox(string caption, string message) {
|
139 |
pfowler |
304 |
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
|
|
|
305 |
DialogResult result;
|
|
|
306 |
|
|
|
307 |
result = MessageBox.Show(message, caption, buttons);
|
|
|
308 |
|
|
|
309 |
if (result == System.Windows.Forms.DialogResult.Yes) {
|
|
|
310 |
return true;
|
|
|
311 |
}
|
|
|
312 |
return false;
|
|
|
313 |
}
|
|
|
314 |
|
156 |
pfowler |
315 |
public static void NITMessageBox(string caption, string message) {
|
|
|
316 |
MessageBoxButtons buttons = MessageBoxButtons.OK;
|
|
|
317 |
MessageBox.Show(message, caption, buttons);
|
|
|
318 |
}
|
|
|
319 |
|
139 |
pfowler |
320 |
private void txtLog_VisibleChanged(object sender, EventArgs e) {
|
|
|
321 |
if (txtLog.Visible) {
|
|
|
322 |
txtLog.SelectionStart = txtLog.TextLength;
|
|
|
323 |
txtLog.ScrollToCaret();
|
|
|
324 |
}
|
|
|
325 |
}
|
|
|
326 |
|
153 |
pfowler |
327 |
private void cmdSimConnect_Click(object sender, EventArgs e) {
|
157 |
pfowler |
328 |
if (fsx.hSimConnect != null)
|
153 |
pfowler |
329 |
this.SimConnect_Disconnect();
|
|
|
330 |
|
|
|
331 |
this.SimConnect_Connect();
|
|
|
332 |
}
|
|
|
333 |
|
|
|
334 |
private void cmdRequest_Click(object sender, EventArgs e) {
|
155 |
pfowler |
335 |
|
153 |
pfowler |
336 |
}
|
|
|
337 |
|
|
|
338 |
private void inputTimer_Tick(object sender, EventArgs e) {
|
156 |
pfowler |
339 |
foreach (NITDevice device in panels.devices) {
|
|
|
340 |
if (device.isOpen())
|
157 |
pfowler |
341 |
device.SimButtons();
|
155 |
pfowler |
342 |
}
|
153 |
pfowler |
343 |
|
155 |
pfowler |
344 |
}
|
153 |
pfowler |
345 |
|
155 |
pfowler |
346 |
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) {
|
|
|
347 |
this.quitNITPanels();
|
153 |
pfowler |
348 |
}
|
|
|
349 |
|
156 |
pfowler |
350 |
private void debugTimer_Tick(object sender, EventArgs e) {
|
|
|
351 |
|
|
|
352 |
}
|
|
|
353 |
|
139 |
pfowler |
354 |
}
|
|
|
355 |
}
|