Subversion Repositories group.electronics

Rev

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

Rev 162 Rev 163
Line 8... Line 8...
8
using System.Timers;
8
using System.Timers;
9
using WindowsInput;
9
using WindowsInput;
10
using WindowsInput.Native;
10
using WindowsInput.Native;
11
 
11
 
12
namespace nitdcscore {
12
namespace nitdcscore {
13
    public struct devdata {
-
 
14
        public uint prev_input;
-
 
15
        public uint cur_input;
-
 
16
        public ushort cur_adc;
-
 
17
        public ushort prev_adc;
-
 
18
        public ushort max_adc;
-
 
19
        public ushort adc_thres;
-
 
20
 
-
 
21
        public int id;
-
 
22
        public string name;
-
 
23
        public string function;
-
 
24
    }
-
 
25
 
13
 
26
    public class mcp2221 {
14
    public class mcp2221 : i2cmaster {
27
        public MchpUsbI2c usbi2c = new MchpUsbI2c();
15
        public MchpUsbI2c usbi2c = new MchpUsbI2c();
28
        public Boolean hasAHFS { get; set; }
-
 
29
        public Boolean hasAAP { get; set; }
-
 
30
 
-
 
31
        int idx { get; set; }
-
 
32
        int devcount { get; set; }
-
 
33
 
16
 
-
 
17
        public List<Panel> panels = new List<Panel>();
34
        public uint speed { get; set; }
18
        public uint speed { get; set; }
35
 
-
 
36
        Timer refresh = new Timer();
19
        Timer refresh = new Timer();
37
        Timer delay = new Timer();
-
 
38
 
-
 
39
        private readonly Object lockobject = new object();
-
 
40
        public List<Panel> panels = new List<Panel>();
-
 
41
 
20
 
42
 
21
 
43
        public mcp2221() {
22
        public mcp2221() {
44
            speed = 400000;
23
            speed = 400000;
45
            idx = 0;
-
 
46
 
24
 
47
            refresh.Interval = 20;
25
            refresh.Interval = 20;
48
            refresh.AutoReset = true;
26
            refresh.AutoReset = true;
49
            refresh.Elapsed += refresh_Elapsed;
27
            refresh.Elapsed += refresh_Elapsed;
50
            refresh.Enabled = false;
28
            refresh.Enabled = false;
51
 
29
 
52
            usbi2c.Settings.GetConnectionStatus();
30
            usbi2c.Settings.GetConnectionStatus();
53
            devcount = usbi2c.Management.GetDevCount();
31
            int devcount = usbi2c.Management.GetDevCount();
54
            Console.WriteLine(devcount.ToString() + " devices found");
32
            Console.WriteLine(devcount.ToString() + " devices found");
55
            for (int i = 0; i < devcount; i++) {
33
            for (int i = 0; i < devcount; i++) {
-
 
34
 
56
                int rslt = usbi2c.Management.SelectDev(i);
35
                if (this.SelectDev(i) != 0) {
-
 
36
                    Console.WriteLine("Could not attach device #: " + i);
57
                usbi2c.Settings.GetConnectionStatus();
37
                    continue;
-
 
38
                }
-
 
39
 
58
                string usbDescriptor = this.usbi2c.Settings.GetUsbStringDescriptor();
40
                string usbDescriptor = this.usbi2c.Settings.GetUsbStringDescriptor();
59
                if (usbDescriptor == "AHCP/FSCP Panel") {
41
                if (usbDescriptor == "AHCP/FSCP Panel") {
60
                    this.hasAHFS = true;
-
 
61
                    panels.Add(new Panel_AHFS(this));
42
                    panels.Add(new Panel_AHFS(this));
62
                    Console.WriteLine("Found AHCP/FSCP Panel");
43
                    Console.WriteLine("Found AHCP/FSCP Panel");
63
                } else if (usbDescriptor == "AAP Panel") {
44
                } else if (usbDescriptor == "AAP Panel") {
64
                    this.hasAAP = true;
-
 
65
                    panels.Add(new Panel_AAP(this));
45
                    panels.Add(new Panel_AAP(this));
66
                    Console.WriteLine("Found AAP Panel");
46
                    Console.WriteLine("Found AAP Panel");
67
                } else if (usbDescriptor == "Multi-Panel Combo") {
47
                } else if (usbDescriptor == "Multi-Panel Combo") {
68
                    panels.Add(new NitMultiPanel(this));
48
                    panels.Add(new NitMultiPanel(this));
69
                    Console.WriteLine("Found Multi-Panel Combo");
49
                    Console.WriteLine("Found Multi-Panel Combo");
Line 77... Line 57...
77
        public Boolean Enabled {
57
        public Boolean Enabled {
78
            get {
58
            get {
79
                return enabled;
59
                return enabled;
80
            }
60
            }
81
            set {
61
            set {
82
                if (this.devcount == 0) {
62
                if (panels.Count == 0) {
83
                    this.enabled = false;
63
                    this.enabled = false;
84
                    refresh.Enabled = false;
64
                    refresh.Enabled = false;
85
                    return;
65
                    return;
86
                }
66
                }
87
 
67
 
Line 96... Line 76...
96
            if (!Enabled)
76
            if (!Enabled)
97
                return;
77
                return;
98
 
78
 
99
            refresh.Enabled = false;
79
            refresh.Enabled = false;
100
            foreach (Panel panel in panels) {
80
            foreach (Panel panel in panels) {
101
                usbi2c.Management.SelectDev(panel.id);
81
                if (this.SelectDev(panel.id) != 0)
102
                usbi2c.Settings.GetConnectionStatus();
82
                    continue;
103
 
83
 
104
                if (!panel.inputChanged)
84
                if (!panel.inputChanged)
105
                    panel.Refresh();
85
                    panel.Refresh();
106
 
86
 
107
                if (panel.inputChanged)
87
                if (panel.inputChanged)
Line 109... Line 89...
109
            }
89
            }
110
            refresh.Enabled = true;
90
            refresh.Enabled = true;
111
 
91
 
112
        }
92
        }
113
 
93
 
-
 
94
        public int SelectDev(int id) {
-
 
95
 
-
 
96
            int rslt = usbi2c.Management.SelectDev(id);
-
 
97
            usbi2c.Settings.GetConnectionStatus();
-
 
98
 
-
 
99
            return rslt;
-
 
100
        }
-
 
101
 
114
        public byte ReadGpio(byte pinNum) {
102
        public byte ReadGpio(byte pinNum) {
115
            return Convert.ToByte(usbi2c.Functions.ReadGpioPinValue(pinNum));
103
            return Convert.ToByte(usbi2c.Functions.ReadGpioPinValue(pinNum));
116
        }
104
        }
117
 
105
 
118
        public ushort ReadADC(byte pinNum) {
106
        public ushort ReadADC(byte pinNum) {