Subversion Repositories group.NITPanels

Rev

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

Rev 19 Rev 22
Line 19... Line 19...
19
        public const byte USBCMD_READ_BUTTONS = 100;
19
        public const byte USBCMD_READ_BUTTONS = 100;
20
        public const byte USBCMD_LEDS_SET = 101;
20
        public const byte USBCMD_LEDS_SET = 101;
21
        public const byte USBCMD_GET_ANALOG = 102;
21
        public const byte USBCMD_GET_ANALOG = 102;
22
        public const byte USBCMD_SET_POWER_LED = 103;
22
        public const byte USBCMD_SET_POWER_LED = 103;
23
 
23
 
-
 
24
        // The min analg value we'll ever read from the pot
-
 
25
        // If the analog val ever drops below this, a uint to int
-
 
26
        //  conversion will make the number >17k. If its not low enough
-
 
27
        //  the volume will never be able to be musted. Should probably 
-
 
28
        //  be calibrated or the protection resistor removed from the 
-
 
29
        //  analog pot ground line
-
 
30
        public const uint DEV_ANALOG_MIN = 4;
-
 
31
 
24
        private int simStatus { get; set; }
32
        private int simStatus { get; set; }
25
        public byte ledStatus { get; set; }
33
        public byte ledStatus { get; set; }
26
        public byte buttonStatus { get; set; }
34
        public byte buttonStatus { get; set; }
27
        public byte analogValue { get; set; }
35
        public byte analogValue { get; set; }
28
        public byte powerLedStatus { get; set; }
36
        public byte powerLedStatus { get; set; }
Line 64... Line 72...
64
 
72
 
65
            inputTimer.Enabled = false;
73
            inputTimer.Enabled = false;
66
            inputTimer.AutoReset = true;
74
            inputTimer.AutoReset = true;
67
            inputTimer.Interval = NITPanels.CFG_INPUT_TIMER_INTERVAL;
75
            inputTimer.Interval = NITPanels.CFG_INPUT_TIMER_INTERVAL;
68
            inputTimer.Elapsed += inputTimer_Elapsed;
76
            inputTimer.Elapsed += inputTimer_Elapsed;
-
 
77
 
-
 
78
            // VolControl Stuff
-
 
79
            // Default the user setting to the first device it not already set
-
 
80
            if (Properties.Settings.Default.volcontroldevice == ""
-
 
81
                && volcontrol.deviceCount > 0) {
-
 
82
                Properties.Settings.Default.volcontroldevice = volcontrol.devices.ElementAt(0);
-
 
83
                Properties.Settings.Default.Save();
-
 
84
            }
-
 
85
 
-
 
86
            // Retrieve the user setting for the selected device, find its index
-
 
87
            if (volcontrol.deviceCount > 0) {
-
 
88
                string selectedDevice = Properties.Settings.Default.volcontroldevice;
-
 
89
                for (int i = 0; i < volcontrol.deviceCount; i++) {
-
 
90
                    if (selectedDevice == volcontrol.devices.ElementAt(i)) {
-
 
91
                        volcontrol.selectedDeviceIndex = (uint)i;
-
 
92
                        break;
-
 
93
                    }
-
 
94
                }
-
 
95
            }
69
        }
96
        }
70
 
97
 
71
        void inputTimer_Elapsed(object sender, ElapsedEventArgs e) {
98
        void inputTimer_Elapsed(object sender, ElapsedEventArgs e) {
72
            this.SimButtons();
99
            this.SimButtons();
73
        }
100
        }
Line 97... Line 124...
97
        public override void FsxReady() {
124
        public override void FsxReady() {
98
            this.powerUp();
125
            this.powerUp();
99
        }
126
        }
100
 
127
 
101
        public override void reAssign() {
128
        public override void reAssign() {
102
            if (this.simStatus != 0)
129
            if (this.simStatus != 0  && this.fsx != null)
103
                return;
130
                return;
104
 
131
 
105
            this.fsx.requestAudioSelData();
132
            this.fsx.requestAudioSelData();
106
        }
133
        }
107
 
134
 
Line 125... Line 152...
125
                return;
152
                return;
126
 
153
 
127
            if (data.dwRequestID != (uint)FSXObject.DATA_REQUESTS.AUDIOSEL_REQ)
154
            if (data.dwRequestID != (uint)FSXObject.DATA_REQUESTS.AUDIOSEL_REQ)
128
                return;
155
                return;
129
 
156
 
130
 
-
 
131
            FSXObject.AudioSel_Data audioseldata = (FSXObject.AudioSel_Data)data.dwData[0];
157
            FSXObject.AudioSel_Data audioseldata = (FSXObject.AudioSel_Data)data.dwData[0];
132
            this.setLed(0, audioseldata.com1);
158
            this.setLed(0, audioseldata.com1);
133
            this.setLed(1, audioseldata.com2);
159
            this.setLed(1, audioseldata.com2);
134
            this.setLed(2, audioseldata.comb);
160
            this.setLed(2, audioseldata.comb);
135
            this.setLed(3, audioseldata.vor1);
161
            this.setLed(3, audioseldata.vor1);
Line 154... Line 180...
154
                if (NITPanels.readBit(this.buttonStatus, i)) {      // Check an audio button is pressed
180
                if (NITPanels.readBit(this.buttonStatus, i)) {      // Check an audio button is pressed
155
                    this.fsx.AudioSelButton(i);                          //  and if so, send of the audio select event
181
                    this.fsx.AudioSelButton(i);                          //  and if so, send of the audio select event
156
                    timers[i].Enabled = true;                       //  and start up a timer to debounce the button
182
                    timers[i].Enabled = true;                       //  and start up a timer to debounce the button
157
                }
183
                }
158
            }
184
            }
-
 
185
 
-
 
186
 
-
 
187
            // VolControl Stuff
-
 
188
            float setVolume = NITPanels.map_f(this.analogValue, DEV_ANALOG_MIN, 255, 0.00F, 1.00F);
-
 
189
            float devVolume = this.volcontrol.getDeviceVolume();
-
 
190
            if (setVolume != devVolume)
-
 
191
                this.volcontrol.setDeviceVolume(setVolume);
-
 
192
 
159
        }
193
        }
160
 
194
 
161
        public void updateInput() {
195
        public void updateInput() {
162
            byte[] data = new byte[8];
196
            byte[] data = new byte[8];
163
            int transferred;
197
            int transferred;