Subversion Repositories group.electronics

Rev

Rev 156 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 157
Line 13... Line 13...
13
namespace NITNavComm
13
namespace NITNavComm
14
{
14
{
15
    public partial class MainForm : Form
15
    public partial class MainForm : Form
16
    {
16
    {
17
 
17
 
18
        private NITPanels panels = new NITPanels();
18
        public NITPanels panels = new NITPanels();
19
        private SimConnect hSimConnect = null;
-
 
20
 
-
 
21
        private FSXObject fsx = new FSXObject();
19
        public FSXObject fsx = new FSXObject();
22
 
-
 
23
        private NITNavCommDevice comm1;
-
 
24
        private NITNavCommDevice comm2;
-
 
25
        private NITAudioSelDevice audiosel;
-
 
26
 
20
 
27
        public MainForm() {
21
        public MainForm() {
28
            InitializeComponent();
22
            InitializeComponent();
29
 
23
 
30
            Devices_Rescan();
24
            Devices_Rescan();
Line 32... Line 26...
32
 
26
 
33
        }
27
        }
34
 
28
 
35
 
29
 
36
        private void SimConnect_Connect() {
30
        private void SimConnect_Connect() {
37
            if (hSimConnect == null) {
31
            if (fsx.hSimConnect == null) {
38
                try {
32
                try {
39
                    hSimConnect = new SimConnect("Managed Data Request", base.Handle, 0x402, null, 0);
33
                    fsx.hSimConnect = new SimConnect("Managed Data Request", base.Handle, 0x402, null, 0);
40
                    fsx.hSimConnect = this.hSimConnect;
-
 
41
                    txtSimConnect.Text = "Available";
34
                    txtSimConnect.Text = "Available";
-
 
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
 
42
                    this.SimConnect_InitDataRequest();
46
                    this.SimConnect_InitDataRequest();
43
                } catch (COMException) {
47
                } catch (COMException) {
44
                    Log("Could not connect to FSX");
48
                    Log("Could not connect to FSX");
45
                    txtSimConnect.Text = "Failed";
49
                    txtSimConnect.Text = "Failed";
46
                }
50
                }
Line 51... Line 55...
51
            this.InitFsxClosed();
55
            this.InitFsxClosed();
52
        }
56
        }
53
 
57
 
54
        protected override void DefWndProc(ref Message m) {
58
        protected override void DefWndProc(ref Message m) {
55
            if (m.Msg == 0x402) {
59
            if (m.Msg == 0x402) {
56
                if (hSimConnect != null) {
60
                if (fsx.hSimConnect != null) {
57
                    hSimConnect.ReceiveMessage();
61
                    fsx.hSimConnect.ReceiveMessage();
58
                }
62
                }
59
            } else {
63
            } else {
60
                base.DefWndProc(ref m);
64
                base.DefWndProc(ref m);
61
            }
65
            }
62
        }
66
        }
63
 
67
 
64
        private void SimConnect_InitDataRequest() {
68
        private void SimConnect_InitDataRequest() {
65
            try {
69
            try {
-
 
70
 
-
 
71
                foreach (NITDevice device in panels.devices) {
66
                if (audiosel != null && audiosel.isOpen())
72
                    if (device.isOpen())
67
                    audiosel.MapEvents(fsx);
73
                        device.MapEvents();
-
 
74
                }
68
 
75
 
69
 
76
 
-
 
77
 
70
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM1_SWAP_FREQ, "COM_STBY_RADIO_SWAP");
78
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM1_SWAP_FREQ, "COM_STBY_RADIO_SWAP");
71
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_SWAP_FREQ, "NAV1_RADIO_SWAP");
79
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_SWAP_FREQ, "NAV1_RADIO_SWAP");
72
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM_RADIO_WHOLE_INC, "COM_RADIO_WHOLE_INC");
80
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM_RADIO_WHOLE_INC, "COM_RADIO_WHOLE_INC");
73
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM_RADIO_WHOLE_DEC, "COM_RADIO_WHOLE_DEC");
81
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM_RADIO_WHOLE_DEC, "COM_RADIO_WHOLE_DEC");
74
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM_RADIO_FRACT_INC, "COM_RADIO_FRACT_INC");
82
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM_RADIO_FRACT_INC, "COM_RADIO_FRACT_INC");
75
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM_RADIO_FRACT_DEC, "COM_RADIO_FRACT_DEC");
83
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM_RADIO_FRACT_DEC, "COM_RADIO_FRACT_DEC");
76
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_RADIO_WHOLE_INC, "NAV1_RADIO_WHOLE_INC");
84
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_RADIO_WHOLE_INC, "NAV1_RADIO_WHOLE_INC");
77
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_RADIO_WHOLE_DEC, "NAV1_RADIO_WHOLE_DEC");
85
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_RADIO_WHOLE_DEC, "NAV1_RADIO_WHOLE_DEC");
78
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_RADIO_FRACT_INC, "NAV1_RADIO_FRACT_INC");
86
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_RADIO_FRACT_INC, "NAV1_RADIO_FRACT_INC");
79
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_RADIO_FRACT_DEC, "NAV1_RADIO_FRACT_DEC");
87
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV1_RADIO_FRACT_DEC, "NAV1_RADIO_FRACT_DEC");
80
 
88
 
81
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_SWAP_FREQ, "COM2_RADIO_SWAP");
89
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_SWAP_FREQ, "COM2_RADIO_SWAP");
82
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_SWAP_FREQ, "NAV2_RADIO_SWAP");
90
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_SWAP_FREQ, "NAV2_RADIO_SWAP");
83
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_RADIO_WHOLE_INC, "COM2_RADIO_WHOLE_INC");
91
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_RADIO_WHOLE_INC, "COM2_RADIO_WHOLE_INC");
84
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_RADIO_WHOLE_DEC, "COM2_RADIO_WHOLE_DEC");
92
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_RADIO_WHOLE_DEC, "COM2_RADIO_WHOLE_DEC");
85
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_RADIO_FRACT_INC, "COM2_RADIO_FRACT_INC");
93
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_RADIO_FRACT_INC, "COM2_RADIO_FRACT_INC");
86
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_RADIO_FRACT_DEC, "COM2_RADIO_FRACT_DEC");
94
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.COM2_RADIO_FRACT_DEC, "COM2_RADIO_FRACT_DEC");
87
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_RADIO_WHOLE_INC, "NAV2_RADIO_WHOLE_INC");
95
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_RADIO_WHOLE_INC, "NAV2_RADIO_WHOLE_INC");
88
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_RADIO_WHOLE_DEC, "NAV2_RADIO_WHOLE_DEC");
96
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_RADIO_WHOLE_DEC, "NAV2_RADIO_WHOLE_DEC");
89
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_RADIO_FRACT_INC, "NAV2_RADIO_FRACT_INC");
97
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_RADIO_FRACT_INC, "NAV2_RADIO_FRACT_INC");
90
                hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_RADIO_FRACT_DEC, "NAV2_RADIO_FRACT_DEC");
98
                fsx.hSimConnect.MapClientEventToSimEvent(FSXObject.EVENT_ID.NAV2_RADIO_FRACT_DEC, "NAV2_RADIO_FRACT_DEC");
-
 
99
 
-
 
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);
91
 
118
 
92
                hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AIRCRAFT, "Atc Type", "", SIMCONNECT_DATATYPE.STRING32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
119
                fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AIRCRAFT, "Atc Type", "", SIMCONNECT_DATATYPE.STRING32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
93
                hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AIRCRAFT, "ATC Model", "", 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);
94
                hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AIRCRAFT, "ATC ID", "", 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);
95
                hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AIRCRAFT, "Title", "", SIMCONNECT_DATATYPE.STRING128, 0.0f, SimConnect.SIMCONNECT_UNUSED);
122
                fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AIRCRAFT, "Title", "", SIMCONNECT_DATATYPE.STRING128, 0.0f, SimConnect.SIMCONNECT_UNUSED);
96
                hSimConnect.RegisterDataDefineStruct<FSXObject.Aircraft_Data>(FSXObject.DEFINITIONS.AIRCRAFT);
123
                fsx.hSimConnect.RegisterDataDefineStruct<FSXObject.Aircraft_Data>(FSXObject.DEFINITIONS.AIRCRAFT);
97
 
124
 
98
                hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AVIONICS, "Avionics Master Switch", "bool", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED);
125
                fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AVIONICS, "Avionics Master Switch", "bool", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED);
99
                hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AVIONICS, "Com Status:1", "Enum", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
126
                fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AVIONICS, "Com Status:1", "Enum", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
100
                hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AVIONICS, "Com Status:2", "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);
101
                hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AVIONICS, "Nav Available:1", "bool", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED);
128
                fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AVIONICS, "Nav Available:1", "bool", SIMCONNECT_DATATYPE.INT32, 0, SimConnect.SIMCONNECT_UNUSED);
102
                hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.AVIONICS, "Nav Available:2", "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);
103
                hSimConnect.RegisterDataDefineStruct<FSXObject.Avionics_Data>(FSXObject.DEFINITIONS.AVIONICS);
130
                fsx.hSimConnect.RegisterDataDefineStruct<FSXObject.Avionics_Data>(FSXObject.DEFINITIONS.AVIONICS);
104
 
131
 
105
                // NavComm1 Frequencies
132
                // NavComm1 Frequencies
106
                hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM1_DATA, "Com Active Frequency:1", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
133
                fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM1_DATA, "Com Active Frequency:1", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
107
                hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM1_DATA, "Com Standby 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);
108
                hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM1_DATA, "Nav Active 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);
109
                hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM1_DATA, "Nav Standby 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);
110
                hSimConnect.RegisterDataDefineStruct<FSXObject.NavCom_Data>(FSXObject.DEFINITIONS.NAVCOM1_DATA);
137
                fsx.hSimConnect.RegisterDataDefineStruct<FSXObject.NavCom_Data>(FSXObject.DEFINITIONS.NAVCOM1_DATA);
111
 
138
 
112
                // NavComm2 Frequencies
139
                // NavComm2 Frequencies
113
                hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM2_DATA, "Com Active Frequency:2", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
140
                fsx.hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM2_DATA, "Com Active Frequency:2", "Number", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
114
                hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM2_DATA, "Com Standby 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);
115
                hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM2_DATA, "Nav Active 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);
116
                hSimConnect.AddToDataDefinition(FSXObject.DEFINITIONS.NAVCOM2_DATA, "Nav Standby 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);
117
                hSimConnect.RegisterDataDefineStruct<FSXObject.NavCom_Data>(FSXObject.DEFINITIONS.NAVCOM2_DATA);
144
                fsx.hSimConnect.RegisterDataDefineStruct<FSXObject.NavCom_Data>(FSXObject.DEFINITIONS.NAVCOM2_DATA);
118
 
145
 
119
                hSimConnect.OnRecvOpen += new SimConnect.RecvOpenEventHandler(SimConnect_OnRecvOpen);
146
                fsx.hSimConnect.OnRecvOpen += new SimConnect.RecvOpenEventHandler(SimConnect_OnRecvOpen);
120
                hSimConnect.OnRecvQuit += new SimConnect.RecvQuitEventHandler(SimConnect_OnRecvQuit);
147
                fsx.hSimConnect.OnRecvQuit += new SimConnect.RecvQuitEventHandler(SimConnect_OnRecvQuit);
121
                hSimConnect.OnRecvException += new SimConnect.RecvExceptionEventHandler(SimConnect_OnRecvException);
148
                fsx.hSimConnect.OnRecvException += new SimConnect.RecvExceptionEventHandler(SimConnect_OnRecvException);
122
                hSimConnect.OnRecvSimobjectData += new SimConnect.RecvSimobjectDataEventHandler(SimConnect_OnRecvSimObjectData);
149
                fsx.hSimConnect.OnRecvSimobjectData += new SimConnect.RecvSimobjectDataEventHandler(SimConnect_OnRecvSimObjectData);
123
                hSimConnect.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(SimConnect_OnRecvSimObjectDataByType);
150
                fsx.hSimConnect.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(SimConnect_OnRecvSimObjectDataByType);
124
 
151
 
125
                // Request for aircrat data. This will also configure auto-updates for other required data.
152
                // Request for aircrat data. This will also configure auto-updates for other required data.
126
                hSimConnect.RequestDataOnSimObjectType(FSXObject.DATA_REQUESTS.AIRCRAFT, FSXObject.DEFINITIONS.AIRCRAFT, 0, SIMCONNECT_SIMOBJECT_TYPE.USER);
153
                fsx.hSimConnect.RequestDataOnSimObjectType(FSXObject.DATA_REQUESTS.AIRCRAFT, FSXObject.DEFINITIONS.AIRCRAFT, 0, SIMCONNECT_SIMOBJECT_TYPE.USER);
127
 
154
 
128
            } catch (COMException e) {
155
            } catch (COMException e) {
129
                Log(e.Message);
156
                Log(e.Message);
130
            }
157
            }
131
        }
158
        }
Line 144... Line 171...
144
            Log("SimConnect Exception: " + (uint)(data.dwException));
171
            Log("SimConnect Exception: " + (uint)(data.dwException));
145
        }
172
        }
146
 
173
 
147
        // Automatic updates on various variables. Set through InitFsxReady
174
        // Automatic updates on various variables. Set through InitFsxReady
148
        private void SimConnect_OnRecvSimObjectData(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA data) {
175
        private void SimConnect_OnRecvSimObjectData(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA data) {
-
 
176
            if (data.dwRequestID == (uint)FSXObject.DATA_REQUESTS.AUDIOSEL_REQ)
-
 
177
                MainForm.NITMessageBox("Debug", "AudioSel data");
149
 
178
 
150
            foreach (NITDevice device in panels.devices) {
179
            foreach (NITDevice device in panels.devices) {
151
                if (device.isOpen())
180
                if (device.isOpen()) {
152
                    device.FsxEvent(fsx, data);
181
                    device.FsxEvent(data);
153
            } 
-
 
154
 
-
 
155
            /* 
-
 
156
            switch (data.dwRequestID) {
-
 
157
                case ((uint)FSXObject.DATA_REQUESTS.AVIONICS): {
-
 
158
                    FSXObject.Avionics_Data avionics = (FSXObject.Avionics_Data)data.dwData[0];
-
 
159
                    break;
-
 
160
                }
182
                }
161
            }*/
183
            } 
162
        }
184
        }
163
 
185
 
164
        private void SimConnect_OnRecvSimObjectDataByType(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE data) {
186
        private void SimConnect_OnRecvSimObjectDataByType(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE data) {
165
            switch (data.dwRequestID) {
187
            switch (data.dwRequestID) {
166
 
-
 
167
                // Request basic aircraft data to get the object ID
188
                // Request basic aircraft data to get the object ID
168
                case ((uint)FSXObject.DATA_REQUESTS.AIRCRAFT): {
189
                case ((uint)FSXObject.DATA_REQUESTS.AIRCRAFT): {
169
                        uint ObjectID = data.dwObjectID;
190
                        uint ObjectID = data.dwObjectID;
170
                        FSXObject.Aircraft_Data aircraftdata = (FSXObject.Aircraft_Data)data.dwData[0];
191
                        FSXObject.Aircraft_Data aircraftdata = (FSXObject.Aircraft_Data)data.dwData[0];
171
 
192
 
172
                        this.fsx.simdata.objectid = ObjectID;
193
                        this.fsx.simdata.objectid = ObjectID;
173
                        this.fsx.simdata.aircraft = aircraftdata;
194
                        this.fsx.simdata.aircraft = aircraftdata;
174
 
195
 
-
 
196
                        this.fsx.FsxReady();
175
                        this.InitFsxReady();                      
197
                        this.InitFsxReady();
176
 
198
 
177
                        break;
199
                        break;
178
                    }
200
                    }
179
            }           
201
            }           
180
        }
202
        }
181
 
203
 
182
        private void InitFsxReady() {
204
        private void InitFsxReady() {
183
 
205
 
184
 
-
 
185
            Log("Aircraft: "
206
            Log("Aircraft: "
186
                + this.fsx.simdata.aircraft.atc_id + ", "
207
                + this.fsx.simdata.aircraft.atc_id + ", "
187
                + this.fsx.simdata.aircraft.atc_model + ", "
208
                + this.fsx.simdata.aircraft.atc_model + ", "
188
                + this.fsx.simdata.aircraft.atc_type + ", "
209
                + this.fsx.simdata.aircraft.atc_type + ", "
189
                + this.fsx.simdata.aircraft.title
210
                + this.fsx.simdata.aircraft.title
190
            );
211
            );
191
 
212
 
192
            foreach (NITDevice device in panels.devices) {
-
 
193
                if (device.isOpen())
-
 
194
                    device.fsx = this.fsx;
-
 
195
                device.FsxReady(this.fsx);
-
 
196
            } 
-
 
197
 
-
 
198
            fsx.hSimConnect.RequestDataOnSimObject(
-
 
199
                FSXObject.DATA_REQUESTS.NAVCOM1_REQ,
-
 
200
                FSXObject.DEFINITIONS.NAVCOM1_DATA,
-
 
201
                fsx.simdata.objectid,
-
 
202
                SIMCONNECT_PERIOD.SIM_FRAME,
-
 
203
                SIMCONNECT_DATA_REQUEST_FLAG.CHANGED,
-
 
204
                0, 0, 0);
-
 
205
 
-
 
206
            fsx.hSimConnect.RequestDataOnSimObject(
-
 
207
                FSXObject.DATA_REQUESTS.NAVCOM2_REQ,
-
 
208
                FSXObject.DEFINITIONS.NAVCOM2_DATA,
-
 
209
                fsx.simdata.objectid,
-
 
210
                SIMCONNECT_PERIOD.SIM_FRAME,
-
 
211
                SIMCONNECT_DATA_REQUEST_FLAG.CHANGED,
-
 
212
                0, 0, 0);            
-
 
213
 
-
 
214
            hSimConnect.RequestDataOnSimObject(
-
 
215
                FSXObject.DATA_REQUESTS.AVIONICS,
-
 
216
                FSXObject.DEFINITIONS.AVIONICS,
-
 
217
                this.fsx.simdata.objectid,
-
 
218
                SIMCONNECT_PERIOD.SIM_FRAME,
-
 
219
                SIMCONNECT_DATA_REQUEST_FLAG.CHANGED,
-
 
220
                0, 0, 0);
-
 
221
 
-
 
222
            inputTimer.Enabled = true;
213
            inputTimer.Enabled = true;
223
        }
214
        }
224
 
215
 
225
        private void InitFsxClosed() {
216
        private void InitFsxClosed() {
226
            if (hSimConnect != null) {
217
            if (fsx.hSimConnect != null) {
227
                hSimConnect.Dispose();
218
                fsx.hSimConnect.Dispose();
228
                txtSimConnect.Text = "Available";
219
                txtSimConnect.Text = "Available";
229
            } else {
220
            } else {
230
                txtSimConnect.Text = "Failed";
221
                txtSimConnect.Text = "Failed";
231
                hSimConnect = null;
222
                fsx.hSimConnect = null;
232
            }
223
            }
233
        }
224
        }
234
 
225
 
235
        private void Devices_Rescan() {
226
        private void Devices_Rescan() {
236
            Log("Scanning for devices...");
227
            Log("Scanning for devices...");
Line 242... Line 233...
242
 
233
 
243
            if (panels.devices.Count > 0) {
234
            if (panels.devices.Count > 0) {
244
                this.cmDevTest.Enabled = true;
235
                this.cmDevTest.Enabled = true;
245
                Log(panels.devices.Count.ToString() + " devices found during scan.");
236
                Log(panels.devices.Count.ToString() + " devices found during scan.");
246
 
237
 
247
                foreach (NITDevice device in panels.devices) {
-
 
248
                    if (device.type == "NITNavComm") {
-
 
249
                        if (comm1 == null) {
-
 
250
                            comm1 = (NITNavCommDevice)device;
-
 
251
                            comm1.assigned = 1;
-
 
252
                        } else if (comm2 == null) {
-
 
253
                            comm2 = (NITNavCommDevice)device;
-
 
254
                            comm2.assigned = 2;
-
 
255
                        }
-
 
256
                    } else if (device.type == "NITAudioSel") {
-
 
257
                        if (audiosel == null) {
-
 
258
                            audiosel = (NITAudioSelDevice)device;
-
 
259
                            audiosel.assigned = 1;
-
 
260
                        }
-
 
261
                    }
-
 
262
                }
-
 
263
 
-
 
264
            } else {
238
            } else {
265
                Log("No devices found, check connections and rescan.");
239
                Log("No devices found, check connections and rescan.");
266
            }
240
            }
267
 
-
 
268
            
-
 
269
        }
241
        }
270
 
242
 
-
 
243
 
-
 
244
 
271
        private void cmdRescan_Click(object sender, EventArgs e) {
245
        private void cmdRescan_Click(object sender, EventArgs e) {
272
            this.Devices_Rescan();
246
            this.Devices_Rescan();
273
        }
247
        }
274
 
248
 
275
        private void cmdDevRescan_Click(object sender, EventArgs e) {
249
        private void cmdDevRescan_Click(object sender, EventArgs e) {
Line 349... Line 323...
349
                txtLog.ScrollToCaret();
323
                txtLog.ScrollToCaret();
350
            }
324
            }
351
        }
325
        }
352
 
326
 
353
        private void cmdSimConnect_Click(object sender, EventArgs e) {
327
        private void cmdSimConnect_Click(object sender, EventArgs e) {
354
            if (hSimConnect != null)
328
            if (fsx.hSimConnect != null)
355
                this.SimConnect_Disconnect();
329
                this.SimConnect_Disconnect();
356
 
330
 
357
            this.SimConnect_Connect();
331
            this.SimConnect_Connect();
358
        }
332
        }
359
 
333
 
Line 362... Line 336...
362
        }
336
        }
363
 
337
 
364
        private void inputTimer_Tick(object sender, EventArgs e) {
338
        private void inputTimer_Tick(object sender, EventArgs e) {
365
            foreach (NITDevice device in panels.devices) {
339
            foreach (NITDevice device in panels.devices) {
366
                if (device.isOpen())
340
                if (device.isOpen())
367
                    device.SimButtons(this.fsx);
341
                    device.SimButtons();
368
            }
342
            }
369
 
343
 
370
        }
344
        }
371
 
345
 
372
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e) {
346
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e) {