Subversion Repositories group.NITPanels

Rev

Rev 16 | Go to most recent revision | 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
        }
58
 
16 pfowler 59
        private void cmdUpdate_Click(object sender, EventArgs e) {
19 pfowler 60
            uint selectAudioDevice = (uint)this.lstAudioDevices.SelectedIndex;
16 pfowler 61
 
19 pfowler 62
            txtAnalog.Text = Convert.ToString(device.analogValue);
63
            float volume = map_f(device.analogValue, 5, 255, 0.00F, 1.00F);
64
            txtScalar.Text = Convert.ToString(volume);
65
            device.volcontrol.setDeviceVolume(selectAudioDevice, volume);
66
            txtVol.Text = Convert.ToString(device.volcontrol.getDeviceVolume(selectAudioDevice));
67
            this.device.powerLedStatus = 0;
68
            this.device.UpdateDisplay();
69
 
16 pfowler 70
        }
71
 
19 pfowler 72
        private float map_f(uint x, uint in_min, uint in_max, float out_min, float out_max) {
73
            float var = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
74
            return var;
75
        }
76
 
3 pfowler 77
        public void setDevice(NITAudioSelDevice audiosel) {
78
            this.device = audiosel;
79
 
16 pfowler 80
            foreach (string audio in device.volcontrol.devices) {
81
                lstAudioDevices.Items.Add(audio);
82
            }
83
 
3 pfowler 84
            if (!this.device.isOpen())
85
                this.device.Open();
86
 
87
            if (this.device.isOpen())
88
                this.controlStatus(true);
89
        }
90
 
91
        private void inputTimer_Tick(object sender, EventArgs e) {
92
            this.UpdateInput();
93
        }
94
 
95
        private void cmdClose_Click(object sender, EventArgs e) {
96
            if (this.device != null && device.isOpen()) {
97
                device.ClearDisplay();
98
            }
99
            this.Close();
100
        }
101
 
102
        private void led0_Click(object sender, EventArgs e) {
103
            bool status = this.device.isLedSet(0);
104
            this.device.setLed(0, !status);
105
            this.device.UpdateDisplay();
106
        }
107
 
108
        private void led1_Click(object sender, EventArgs e) {
109
            bool status = this.device.isLedSet(1);
110
            this.device.setLed(1, !status);
111
            this.device.UpdateDisplay();
112
        }
113
 
114
        private void led2_Click(object sender, EventArgs e) {
115
            bool status = this.device.isLedSet(2);
116
            this.device.setLed(2, !status);
117
            this.device.UpdateDisplay();
118
        }
119
 
120
        private void led3_Click(object sender, EventArgs e) {
121
            bool status = this.device.isLedSet(3);
122
            this.device.setLed(3, !status);
123
            this.device.UpdateDisplay();
124
        }
125
 
126
        private void led4_Click(object sender, EventArgs e) {
127
            bool status = this.device.isLedSet(4);
128
            this.device.setLed(4, !status);
129
            this.device.UpdateDisplay();
130
        }
131
 
132
        private void led5_Click(object sender, EventArgs e) {
133
            bool status = this.device.isLedSet(5);
134
            this.device.setLed(5, !status);
135
            this.device.UpdateDisplay();
136
        }
137
 
138
        private void led6_Click(object sender, EventArgs e) {
139
            bool status = this.device.isLedSet(6);
140
            this.device.setLed(6, !status);
141
            this.device.UpdateDisplay();
142
        }
143
 
144
        private void led7_Click(object sender, EventArgs e) {
145
            bool status = this.device.isLedSet(7);
146
            this.device.setLed(7, !status);
147
            this.device.UpdateDisplay();
148
        }
19 pfowler 149
 
150
        private void ledPwr_Click(object sender, EventArgs e) {
151
            bool status = this.device.isLedPwrSet();
152
            this.device.setLedPwr(!status);
153
            this.device.UpdateDisplay();
154
        }
3 pfowler 155
    }
156
}