Subversion Repositories group.electronics

Rev

Rev 155 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
155 pfowler 1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
 
7
using Microsoft.FlightSimulator.SimConnect;
8
using System.Runtime.InteropServices;
9
 
10
namespace NITNavComm {
11
    public class FSXObject {
12
 
13
        public SimData simdata;
14
        public SimConnect hSimConnect = null;
15
 
16
        public enum DATA_REQUESTS {
17
            AIRCRAFT,
18
            AVIONICS,
19
            NAVCOM1_REQ,
156 pfowler 20
            NAVCOM2_REQ,
21
            AUDIOSEL_REQ
155 pfowler 22
        }
23
 
24
        public enum DEFINITIONS {
25
            AIRCRAFT,
26
            AVIONICS,
27
            NAVCOM1_DATA,
156 pfowler 28
            NAVCOM2_DATA,
29
            AUDIOSEL_DATA
155 pfowler 30
        }
31
 
32
        public enum EVENT_ID {
156 pfowler 33
            // AudioSel Events, these go first to make mapping easy (0-7)
34
            COM1_TRANSMIT_SELECT,
35
            COM2_TRANSMIT_SELECT,
36
            COM_RECEIVE_ALL_TOGGLE,
37
            RADIO_VOR1_IDENT_TOGGLE,
38
            RADIO_VOR2_IDENT_TOGGLE,
39
            MARKER_SOUND_TOGGLE,
40
            RADIO_DME1_IDENT_TOGGLE,
41
            RADIO_ADF_IDENT_TOGGLE,
42
 
43
            // NavCom1 Events
155 pfowler 44
            COM1_SWAP_FREQ,
45
            NAV1_SWAP_FREQ,
46
            COM_RADIO_WHOLE_INC,
47
            COM_RADIO_WHOLE_DEC,
48
            COM_RADIO_FRACT_INC,
49
            COM_RADIO_FRACT_DEC,
50
            NAV1_RADIO_WHOLE_INC,
51
            NAV1_RADIO_WHOLE_DEC,
52
            NAV1_RADIO_FRACT_INC,
53
            NAV1_RADIO_FRACT_DEC,
156 pfowler 54
 
55
            // NavComm2 Events
155 pfowler 56
            COM2_SWAP_FREQ,
57
            NAV2_SWAP_FREQ,
58
            COM2_RADIO_WHOLE_INC,
59
            COM2_RADIO_WHOLE_DEC,
60
            COM2_RADIO_FRACT_INC,
61
            COM2_RADIO_FRACT_DEC,
62
            NAV2_RADIO_WHOLE_INC,
63
            NAV2_RADIO_WHOLE_DEC,
64
            NAV2_RADIO_FRACT_INC,
65
            NAV2_RADIO_FRACT_DEC,
156 pfowler 66
 
155 pfowler 67
        }
68
 
69
        public enum GROUP_ID {
70
            NAVCOM1,
156 pfowler 71
            NAVCOM2,
72
            AUDIOSEL
155 pfowler 73
        }
74
 
75
        public struct SimData {
76
            public uint objectid;
77
            public Aircraft_Data aircraft;
78
        }
79
 
80
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
81
        public struct NavCom_Data {
82
            public double Freq0;
83
            public double Freq1;
84
            public double Freq2;
85
            public double Freq3;
86
        }
87
 
88
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
156 pfowler 89
        public struct AudioSel_Data {
90
            public double com1;
91
            public double com2;
92
            public double comb;
93
            public double vor1;
94
            public double vor2;
95
            public double mkr;
96
            public double dme;
97
            public double adf;
98
        }
99
 
100
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
155 pfowler 101
        public struct Avionics_Data {
102
            public bool avionics_master;
103
            public double com1_status;
104
            public double com2_status;
156 pfowler 105
            public bool nav1_available;
106
            public bool nav2_available;
155 pfowler 107
        }
108
 
109
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
110
        public struct Aircraft_Data {
111
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
112
            public string atc_type;
113
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
114
            public string atc_model;
115
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
116
            public string atc_id;
117
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
118
            public string title;
119
        }
120
 
121
        public FSXObject() {
122
            this.simdata = new SimData();
123
        }
124
 
156 pfowler 125
        private void transmitEvent(Enum eventid, Enum groupid) {
126
            this.transmitEvent(eventid, groupid, 1);
127
        }
128
 
129
        private void transmitEvent(Enum eventid, Enum groupid, uint data) {
155 pfowler 130
            this.hSimConnect.TransmitClientEvent(
131
                this.simdata.objectid,
156 pfowler 132
                eventid, data, groupid,
155 pfowler 133
                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY
134
            );
135
        }
136
 
156 pfowler 137
        private void requestData(Enum dataRequest, Enum definition) {
138
            hSimConnect.RequestDataOnSimObject(
139
                dataRequest,
140
                definition,
155 pfowler 141
                this.simdata.objectid,
156 pfowler 142
                SIMCONNECT_PERIOD.ONCE,
143
                SIMCONNECT_DATA_REQUEST_FLAG.DEFAULT,
144
                0, 0, 0);
155 pfowler 145
        }
146
 
156 pfowler 147
        // Individual data requests
148
        public void requestNavComm1Data() {
149
            this.requestData(FSXObject.DATA_REQUESTS.NAVCOM1_REQ, FSXObject.DEFINITIONS.NAVCOM1_DATA);
150
        }
151
 
152
        public void requestNavComm2Data() {
153
            this.requestData(FSXObject.DATA_REQUESTS.NAVCOM2_REQ, FSXObject.DEFINITIONS.NAVCOM2_DATA);
154
        }
155
 
156
        public void requestAudioSelData() {
157
            this.requestData(FSXObject.DATA_REQUESTS.AUDIOSEL_REQ, FSXObject.DEFINITIONS.AUDIOSEL_DATA);
158
        }
159
 
160
        // AudioSel Events
161
        public void AudioSelButton(int button) {
162
            this.transmitEvent((FSXObject.EVENT_ID)button, FSXObject.GROUP_ID.AUDIOSEL);
163
        }
164
 
165
 
166
        // NavComm1 Events
167
        public void Comm1DecFract() {
168
            this.transmitEvent(FSXObject.EVENT_ID.COM_RADIO_FRACT_DEC, FSXObject.GROUP_ID.NAVCOM1);
169
        }
170
 
171
        public void Comm1DecWhole() {
172
            this.transmitEvent(FSXObject.EVENT_ID.COM_RADIO_WHOLE_DEC, FSXObject.GROUP_ID.NAVCOM1);
173
        }
174
 
155 pfowler 175
        public void Comm1IncFract() {
156 pfowler 176
            this.transmitEvent(FSXObject.EVENT_ID.COM_RADIO_FRACT_INC, FSXObject.GROUP_ID.NAVCOM1);
155 pfowler 177
        }
178
 
179
        public void Comm1IncWhole() {
156 pfowler 180
            this.transmitEvent(FSXObject.EVENT_ID.COM_RADIO_WHOLE_INC, FSXObject.GROUP_ID.NAVCOM1);
155 pfowler 181
        }
182
 
183
        public void Comm1SwapFreq() {
156 pfowler 184
            this.transmitEvent(FSXObject.EVENT_ID.COM1_SWAP_FREQ, FSXObject.GROUP_ID.NAVCOM1);
155 pfowler 185
        }
186
 
187
        public void Nav1DecFract() {
156 pfowler 188
            this.transmitEvent(FSXObject.EVENT_ID.NAV1_RADIO_FRACT_DEC, FSXObject.GROUP_ID.NAVCOM1);
155 pfowler 189
        }
190
 
191
        public void Nav1DecWhole() {
156 pfowler 192
            this.transmitEvent(FSXObject.EVENT_ID.NAV1_RADIO_WHOLE_DEC, FSXObject.GROUP_ID.NAVCOM1);
155 pfowler 193
        }
194
 
195
        public void Nav1IncFract() {
156 pfowler 196
            this.transmitEvent(FSXObject.EVENT_ID.NAV1_RADIO_FRACT_INC, FSXObject.GROUP_ID.NAVCOM1);
155 pfowler 197
        }
198
 
199
        public void Nav1IncWhole() {
156 pfowler 200
            this.transmitEvent(FSXObject.EVENT_ID.NAV1_RADIO_WHOLE_INC, FSXObject.GROUP_ID.NAVCOM1);
155 pfowler 201
        }
202
 
203
        public void Nav1SwapFreq() {
156 pfowler 204
            this.transmitEvent(FSXObject.EVENT_ID.NAV1_SWAP_FREQ, FSXObject.GROUP_ID.NAVCOM1);
155 pfowler 205
        }
206
 
207
 
156 pfowler 208
        // NavComm2 Events
155 pfowler 209
        public void Comm2DecFract() {
156 pfowler 210
            this.transmitEvent(FSXObject.EVENT_ID.COM2_RADIO_FRACT_DEC, FSXObject.GROUP_ID.NAVCOM2);
155 pfowler 211
        }
212
 
213
        public void Comm2DecWhole() {
156 pfowler 214
            this.transmitEvent(FSXObject.EVENT_ID.COM2_RADIO_WHOLE_DEC, FSXObject.GROUP_ID.NAVCOM2);
155 pfowler 215
        }
216
 
217
        public void Comm2IncFract() {
156 pfowler 218
            this.transmitEvent(FSXObject.EVENT_ID.COM2_RADIO_FRACT_INC, FSXObject.GROUP_ID.NAVCOM2);
155 pfowler 219
        }
220
 
221
        public void Comm2IncWhole() {
156 pfowler 222
            this.transmitEvent(FSXObject.EVENT_ID.COM2_RADIO_WHOLE_INC, FSXObject.GROUP_ID.NAVCOM2);
155 pfowler 223
        }
224
 
225
        public void Comm2SwapFreq() {
156 pfowler 226
            this.transmitEvent(FSXObject.EVENT_ID.COM2_SWAP_FREQ, FSXObject.GROUP_ID.NAVCOM2);
155 pfowler 227
        }
228
 
229
        public void Nav2DecFract() {
156 pfowler 230
            this.transmitEvent(FSXObject.EVENT_ID.NAV2_RADIO_FRACT_DEC, FSXObject.GROUP_ID.NAVCOM2);
155 pfowler 231
        }
232
 
233
        public void Nav2DecWhole() {
156 pfowler 234
            this.transmitEvent(FSXObject.EVENT_ID.NAV2_RADIO_WHOLE_DEC, FSXObject.GROUP_ID.NAVCOM2);
155 pfowler 235
        }
236
 
237
        public void Nav2IncFract() {
156 pfowler 238
            this.transmitEvent(FSXObject.EVENT_ID.NAV2_RADIO_FRACT_INC, FSXObject.GROUP_ID.NAVCOM2);
155 pfowler 239
        }
240
 
241
        public void Nav2IncWhole() {
156 pfowler 242
            this.transmitEvent(FSXObject.EVENT_ID.NAV2_RADIO_WHOLE_INC, FSXObject.GROUP_ID.NAVCOM2);
155 pfowler 243
        }
244
 
245
        public void Nav2SwapFreq() {
156 pfowler 246
            this.transmitEvent(FSXObject.EVENT_ID.NAV2_SWAP_FREQ, FSXObject.GROUP_ID.NAVCOM2);
155 pfowler 247
        }
156 pfowler 248
 
249
 
250
 
155 pfowler 251
    }
252
}