Subversion Repositories group.electronics

Rev

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

Rev 163 Rev 164
Line 1... Line 1...
1
using MCP2221;
1
using MCP2221;
2
using System;
2
using System;
3
using System.Collections.Generic;
3
using System.Collections.Generic;
-
 
4
using System.Diagnostics;
4
using System.Linq;
5
using System.Linq;
5
using System.Reflection;
6
using System.Reflection;
6
using System.Text;
7
using System.Text;
7
using System.Threading.Tasks;
8
using System.Threading.Tasks;
8
using System.Timers;
9
using System.Timers;
Line 15... Line 16...
15
        public MchpUsbI2c usbi2c = new MchpUsbI2c();
16
        public MchpUsbI2c usbi2c = new MchpUsbI2c();
16
 
17
 
17
        public List<Panel> panels = new List<Panel>();
18
        public List<Panel> panels = new List<Panel>();
18
        public uint speed { get; set; }
19
        public uint speed { get; set; }
19
        Timer refresh = new Timer();
20
        Timer refresh = new Timer();
-
 
21
        Timer display = new Timer();
-
 
22
        TimeSpan ts = new TimeSpan();
-
 
23
        UInt64 refreshCount = 0;
20
 
24
 
21
 
25
 
22
        public mcp2221() {
26
        public mcp2221() {
23
            speed = 400000;
27
            speed = 400000;
24
 
28
 
25
            refresh.Interval = 20;
29
            refresh.Interval = 5;
26
            refresh.AutoReset = true;
30
            refresh.AutoReset = true;
27
            refresh.Elapsed += refresh_Elapsed;
31
            refresh.Elapsed += refresh_Elapsed;
28
            refresh.Enabled = false;
32
            refresh.Enabled = false;
29
 
33
 
-
 
34
            display.Interval = 1000;
-
 
35
            display.AutoReset = true;
-
 
36
            display.Enabled = false;
-
 
37
            display.Elapsed += display_Elapsed;
-
 
38
 
30
            usbi2c.Settings.GetConnectionStatus();
39
            usbi2c.Settings.GetConnectionStatus();
31
            int devcount = usbi2c.Management.GetDevCount();
40
            int devcount = usbi2c.Management.GetDevCount();
32
            Console.WriteLine(devcount.ToString() + " devices found");
41
            Console.WriteLine(devcount.ToString() + " devices found");
33
            for (int i = 0; i < devcount; i++) {
42
            for (int i = 0; i < devcount; i++) {
34
 
43
 
Line 51... Line 60...
51
            }
60
            }
52
 
61
 
53
            
62
            
54
        }
63
        }
55
 
64
 
-
 
65
        void display_Elapsed(object sender, ElapsedEventArgs e) {
-
 
66
            Double avg = ts.TotalMilliseconds / refreshCount;
-
 
67
            Console.WriteLine("Average Refresh: " + avg);
-
 
68
        }
-
 
69
 
56
        private Boolean enabled;
70
        private Boolean enabled;
57
        public Boolean Enabled {
71
        public Boolean Enabled {
58
            get {
72
            get {
59
                return enabled;
73
                return enabled;
60
            }
74
            }
Line 74... Line 88...
74
 
88
 
75
        void refresh_Elapsed(object sender, ElapsedEventArgs e) {
89
        void refresh_Elapsed(object sender, ElapsedEventArgs e) {
76
            if (!Enabled)
90
            if (!Enabled)
77
                return;
91
                return;
78
 
92
 
-
 
93
            Stopwatch sw = new Stopwatch();
-
 
94
            sw.Start();
79
            refresh.Enabled = false;
95
            refresh.Enabled = false;
80
            foreach (Panel panel in panels) {
96
            foreach (Panel panel in panels) {
81
                if (this.SelectDev(panel.id) != 0)
97
                if (this.SelectDev(panel.id) != 0)
82
                    continue;
98
                    continue;
83
 
99
 
Line 86... Line 102...
86
 
102
 
87
                if (panel.inputChanged)
103
                if (panel.inputChanged)
88
                    panel.Input();
104
                    panel.Input();
89
            }
105
            }
90
            refresh.Enabled = true;
106
            refresh.Enabled = true;
91
 
-
 
-
 
107
            sw.Stop();
-
 
108
            ts += sw.Elapsed;
-
 
109
            refreshCount++;
92
        }
110
        }
93
 
111
 
94
        public int SelectDev(int id) {
112
        public int SelectDev(int id) {
95
 
113
 
96
            int rslt = usbi2c.Management.SelectDev(id);
114
            int rslt = usbi2c.Management.SelectDev(id);