Subversion Repositories group.electronics

Rev

Rev 155 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 155 Rev 156
Line 3... Line 3...
3
using System.Linq;
3
using System.Linq;
4
using System.Text;
4
using System.Text;
5
using System.Threading.Tasks;
5
using System.Threading.Tasks;
6
using System.Data;
6
using System.Data;
7
 
7
 
-
 
8
using Microsoft.FlightSimulator.SimConnect;
-
 
9
 
8
using LibUsbDotNet;
10
using LibUsbDotNet;
9
using LibUsbDotNet.Main;
11
using LibUsbDotNet.Main;
10
using LibUsbDotNet.DeviceNotify;
12
using LibUsbDotNet.DeviceNotify;
11
 
13
 
12
 
14
 
Line 23... Line 25...
23
            this.pid = pid;
25
            this.pid = pid;
24
        }
26
        }
25
 
27
 
26
    }
28
    }
27
 
29
 
28
    public class NITDevice : Device {
30
    public abstract class NITDevice : Device {
29
        public int id { get; set; }
31
        public int id { get; set; }
30
        public string hw { get; set; }
32
        public string hw { get; set; }
31
        public string sw { get; set; }
33
        public string sw { get; set; }
32
        public string status { get; set; }
34
        public string status { get; set; }
33
        public string serial { get; set; }
35
        public string serial { get; set; }
34
        public int assigned { get; set; }
36
        public int assigned { get; set; }
35
 
37
 
-
 
38
        public FSXObject fsx { get; set; }
-
 
39
 
36
        protected UsbDevice usbDevice;
40
        protected UsbDevice usbDevice;
37
        public UsbRegistry usbRegistry { get; set; }
41
        public UsbRegistry usbRegistry { get; set; }
38
 
42
 
39
        public NITDevice(UsbRegistry usbRegistry, string type, int vid, int pid) : base(type, vid, pid) {
43
        public NITDevice(UsbRegistry usbRegistry, string type, int vid, int pid) : base(type, vid, pid) {
40
            this.id = -1;
44
            this.id = -1;
Line 56... Line 60...
56
                this.usbDevice.Open();
60
                this.usbDevice.Open();
57
                
61
                
58
            return true;
62
            return true;
59
        }
63
        }
60
 
64
 
61
        public bool Close() {
65
        public virtual bool Close() {
62
            if (this.usbDevice == null)
66
            if (this.usbDevice == null)
63
                return false;
67
                return false;
64
 
68
 
65
            if (this.usbDevice.IsOpen)
69
            if (this.usbDevice.IsOpen)
66
                this.usbDevice.Close();
70
                this.usbDevice.Close();
Line 99... Line 103...
99
            this.hw = data[0].ToString();
103
            this.hw = data[0].ToString();
100
            this.sw = data[1].ToString();
104
            this.sw = data[1].ToString();
101
            return success;
105
            return success;
102
        }
106
        }
103
 
107
 
-
 
108
        // Virtual Functions
-
 
109
        abstract public void MapEvents(FSXObject fsx);
-
 
110
        abstract public void FsxEvent(FSXObject fsx, SIMCONNECT_RECV_SIMOBJECT_DATA data);
-
 
111
        abstract public void FsxReady(FSXObject fsx);
-
 
112
        abstract public void SimButtons(FSXObject fsx);
-
 
113
 
104
    }
114
    }
105
 
115
 
106
    class NITPanels {
116
    class NITPanels {
107
 
117
 
-
 
118
        public static int CFG_BUTTON_DEBOUNCE_TIME = 500;
-
 
119
 
108
        public List<NITDevice> devices { get; set; }
120
        public List<NITDevice> devices { get; set; }
109
 
121
 
110
        public NITPanels() {
122
        public NITPanels() {
111
            devices = new List<NITDevice>();
123
            devices = new List<NITDevice>();
112
        }
124
        }
Line 131... Line 143...
131
                                case ("NITNavComm"): {
143
                                case ("NITNavComm"): {
132
                                    found = new NITNavCommDevice(usbReg, device.type, device.vid, device.pid);
144
                                    found = new NITNavCommDevice(usbReg, device.type, device.vid, device.pid);
133
                                    break;
145
                                    break;
134
                                }
146
                                }
135
                                case ("NITAudioSel"): {
147
                                case ("NITAudioSel"): {
136
                                    found = new NITDevice(usbReg, device.type, device.vid, device.pid);
148
                                    found = new NITAudioSelDevice(usbReg, device.type, device.vid, device.pid);
137
                                    break;
149
                                    break;
138
                                }
150
                                }
139
                            }
151
                            }
140
 
152
 
141
                            found.id = idCount;
153
                            found.id = idCount;
Line 162... Line 174...
162
 
174
 
163
            return idCount;
175
            return idCount;
164
 
176
 
165
        }
177
        }
166
 
178
 
-
 
179
        public static bool readBit(byte data, int bitNum) {
-
 
180
            return (data & (1 << bitNum)) != 0;
-
 
181
        }
-
 
182
 
-
 
183
        public static byte setBit(byte data, int bitNum) {
-
 
184
            return (byte)(data | (1 << bitNum));
-
 
185
        }
-
 
186
 
-
 
187
        public static byte clearBit(byte data, int bitNum) {
-
 
188
            return (byte)(data & ~(1 << bitNum));
-
 
189
        }
-
 
190
 
167
    }
191
    }
168
}
192
}