Subversion Repositories group.electronics

Rev

Rev 161 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
160 pfowler 1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
 
7
namespace nitdcscore {
8
    public interface IPanel {
9
        int Init();
10
        int Refresh();
11
        int Input();
12
    }
13
 
14
    public abstract class Panel : IPanel {
15
        protected mcp2221 mcp;
16
        public int id { get; set; }
17
        public String name { get; set; }
18
        public String serialno { get; set; }
19
 
20
        private Boolean enabled;
21
        public Boolean Enabled {
22
            get {
23
                return enabled;
24
            }
25
            set {
26
                this.enabled = true;
27
            }
28
        }
29
 
30
        public Panel(ref mcp2221 mcp) {
31
            this.mcp = mcp;
32
            this.mcp.usbi2c.Management.GetSelectedDevInfo();
33
            this.id = this.mcp.usbi2c.Management.GetSelectedDevNum();
34
            this.name = this.mcp.usbi2c.Settings.GetUsbStringDescriptor();
35
        }
36
 
37
        public virtual int Init() {
38
 
39
 
40
            return 1;
41
        }
42
        public abstract int Refresh();
43
        public abstract int Input();
44
    }
45
 
46
    public struct panel_input {
47
        public uint prev;
48
        public uint curr;
49
    }
50
 
51
    public class Panel_AAP : Panel {
52
 
53
        panel_input input;
54
 
55
        public Panel_AAP(ref mcp2221 mcp) : base(ref mcp) {
56
            input.curr = 0;
57
            input.prev = 0;
58
 
59
        }
60
 
61
        public override int Init() {
62
            // Enable the mcp23017
63
            mcp.WriteGpio(3, 0);
64
            Utils.delayms(500);
65
            mcp.WriteGpio(3, 1);
66
            //this.delayms();
67
 
68
            // Set io dir, pullups and rev polarity
69
            byte[] data;
70
            data = new byte[] { 0x00, 0xff, 0xff, 0xff, 0xff }; // All inputs & polarity
71
            mcp.WriteI2cData(0x40, data, 5);
72
            data = new byte[] { 0x0c, 0xff, 0xff }; // All pullups = on
73
            mcp.WriteI2cData(0x40, data, 3);
74
 
75
            //refresh_aap(devid);
76
 
77
            return 1;
78
        }
79
        public override int Refresh() {
80
 
81
            return 1;
82
        }
83
 
84
        public override int Input() {
85
 
86
            return 1;
87
        }
88
    }
89
}