Subversion Repositories group.NITPanels

Rev

Rev 19 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 pfowler 1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Linq;
7
using System.Text;
8
using System.Threading.Tasks;
9
using System.Windows.Forms;
10
 
11
namespace NITNavComm {
12
    public partial class NITAudioSelForm : Form {
13
 
14
        private NITAudioSelDevice device = null;
15
 
16
        public NITAudioSelForm() {
17
            InitializeComponent();
18
 
19
            this.controlStatus(false);
16 pfowler 20
            this.lstAudioDevices.Items.Clear();
3 pfowler 21
        }
22
 
23
        private void controlStatus(bool status) {
24
            cmdUpdate.Enabled = status;
25
            inputTimer.Enabled = status;
26
        }
27
 
28
        public void UpdateDevice() {
29
            this.UpdateInput();
30
            this.UpdateDisplay();
31
        }
32
 
33
        public void UpdateDisplay() {
34
 
35
        }
36
 
37
        public void UpdateInput() {
38
            device.updateInput();
39
            button0.Checked = device.isButtonSet(0);
40
            button1.Checked = device.isButtonSet(1);
41
            button2.Checked = device.isButtonSet(2);
42
            button3.Checked = device.isButtonSet(3);
43
            button4.Checked = device.isButtonSet(4);
44
            button5.Checked = device.isButtonSet(5);
45
            button6.Checked = device.isButtonSet(6);
46
            button7.Checked = device.isButtonSet(7);
47
 
48
            this.led0.On = device.isLedSet(0);
49
            this.led1.On = device.isLedSet(1);
50
            this.led2.On = device.isLedSet(2);
51
            this.led3.On = device.isLedSet(3);
52
            this.led4.On = device.isLedSet(4);
53
            this.led5.On = device.isLedSet(5);
54
            this.led6.On = device.isLedSet(6);
55
            this.led7.On = device.isLedSet(7);
19 pfowler 56
            this.ledPwr.On = device.isLedPwrSet();
3 pfowler 57
 
22 pfowler 58
            float setVolume = NITPanels.map_f(device.analogValue, NITAudioSelDevice.DEV_ANALOG_MIN, 255, 0.00F, 1.00F);
59
            float devVolume = device.volcontrol.getDeviceVolume();
60
            if (setVolume != devVolume)
61
                device.volcontrol.setDeviceVolume(setVolume);
16 pfowler 62
 
22 pfowler 63
            uint volPercent = NITPanels.map_ui(this.device.analogValue, NITAudioSelDevice.DEV_ANALOG_MIN, 255, 0, 100);
64
            txtVol.Text = Convert.ToString(volPercent);
16 pfowler 65
        }
66
 
19 pfowler 67
 
3 pfowler 68
        public void setDevice(NITAudioSelDevice audiosel) {
69
            this.device = audiosel;
70
 
16 pfowler 71
            foreach (string audio in device.volcontrol.devices) {
72
                lstAudioDevices.Items.Add(audio);
73
            }
22 pfowler 74
            lstAudioDevices.SelectedIndex = (int)device.volcontrol.selectedDeviceIndex;
16 pfowler 75
 
3 pfowler 76
            if (!this.device.isOpen())
77
                this.device.Open();
78
 
79
            if (this.device.isOpen())
80
                this.controlStatus(true);
81
        }
82
 
22 pfowler 83
        private void cmdUpdate_Click(object sender, EventArgs e) {
84
            /*
85
            uint selectedAudioDevice = (uint)this.lstAudioDevices.SelectedIndex;
86
            txtAnalog.Text = Convert.ToString(device.analogValue);
87
            float volume = map_f(device.analogValue, 5, 255, 0.00F, 1.00F);
88
            txtScalar.Text = Convert.ToString(volume);
89
            device.volcontrol.setDeviceVolume(selectedAudioDevice, volume);
90
            txtVol.Text = Convert.ToString(device.volcontrol.getDeviceVolume(selectedAudioDevice));
91
            */
92
 
93
            this.device.UpdateDisplay();
94
        }
95
 
3 pfowler 96
        private void inputTimer_Tick(object sender, EventArgs e) {
97
            this.UpdateInput();
98
        }
99
 
100
        private void cmdClose_Click(object sender, EventArgs e) {
101
            if (this.device != null && device.isOpen()) {
102
                device.ClearDisplay();
103
            }
104
            this.Close();
105
        }
106
 
107
        private void led0_Click(object sender, EventArgs e) {
108
            bool status = this.device.isLedSet(0);
109
            this.device.setLed(0, !status);
110
            this.device.UpdateDisplay();
111
        }
112
 
113
        private void led1_Click(object sender, EventArgs e) {
114
            bool status = this.device.isLedSet(1);
115
            this.device.setLed(1, !status);
116
            this.device.UpdateDisplay();
117
        }
118
 
119
        private void led2_Click(object sender, EventArgs e) {
120
            bool status = this.device.isLedSet(2);
121
            this.device.setLed(2, !status);
122
            this.device.UpdateDisplay();
123
        }
124
 
125
        private void led3_Click(object sender, EventArgs e) {
126
            bool status = this.device.isLedSet(3);
127
            this.device.setLed(3, !status);
128
            this.device.UpdateDisplay();
129
        }
130
 
131
        private void led4_Click(object sender, EventArgs e) {
132
            bool status = this.device.isLedSet(4);
133
            this.device.setLed(4, !status);
134
            this.device.UpdateDisplay();
135
        }
136
 
137
        private void led5_Click(object sender, EventArgs e) {
138
            bool status = this.device.isLedSet(5);
139
            this.device.setLed(5, !status);
140
            this.device.UpdateDisplay();
141
        }
142
 
143
        private void led6_Click(object sender, EventArgs e) {
144
            bool status = this.device.isLedSet(6);
145
            this.device.setLed(6, !status);
146
            this.device.UpdateDisplay();
147
        }
148
 
149
        private void led7_Click(object sender, EventArgs e) {
150
            bool status = this.device.isLedSet(7);
151
            this.device.setLed(7, !status);
152
            this.device.UpdateDisplay();
153
        }
19 pfowler 154
 
155
        private void ledPwr_Click(object sender, EventArgs e) {
156
            bool status = this.device.isLedPwrSet();
157
            this.device.setLedPwr(!status);
158
            this.device.UpdateDisplay();
159
        }
22 pfowler 160
 
161
        private void lstAudioDevices_SelectedIndexChanged(object sender, EventArgs e) {
162
            device.volcontrol.selectedDeviceIndex = (uint)lstAudioDevices.SelectedIndex;
163
            Properties.Settings.Default.volcontroldevice = device.volcontrol.getDeviceName();
164
            Properties.Settings.Default.Save();
165
        }
3 pfowler 166
    }
167
}