Subversion Repositories group.electronics

Rev

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

Rev Author Line No. Line
171 pfowler 1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using WindowsInput.Native;
7
 
8
namespace nitdcscore {
9
    public class Panel_AAP : Panel {
10
 
11
        private mcp23017 chip0;
12
 
13
        public Panel_AAP(mcp2221 mcp) : base(mcp) {
14
            chip0 = new mcp23017(mcp, 0x20);
15
 
16
            this.Init();
17
        }
18
 
19
        public override int Init() {
20
            this.addControl(new Switch2Pos(new CommandTrackIRKey(VirtualKeyCode.F9), 16));
21
            this.addControl(new Switch2Pos(new CommandTrackIRKey(VirtualKeyCode.F11), 17));
22
            this.addControl(new Switch2Pos(new CommandTrackIRKey(VirtualKeyCode.F7), 12));
23
            this.addControl(new Switch2Pos(new CommandVKey(VirtualKeyCode.SPACE), 13));
24
            this.addControl(new Switch2Pos(new CommandVKey(VirtualKeyCode.RETURN), 14));
25
            this.addControl(new Switch2Pos(new CommandVKey(VirtualKeyCode.VOLUME_MUTE), 15));
26
            this.addControl(new Switch2Pos(new CommandDCS("AAP_CDUPWR"), 11));
27
            this.addControl(new Switch2Pos(new CommandDCS("AAP_EGIPWR"), 10));
28
            this.addControl(new Switch3Pos(new CommandDCS("AAP_STEER"), 9, 8));
29
            this.addControl(new Selector(new CommandDCS("AAP_STEERPT"), new int[] { 4, 5, 6 }));
30
            this.addControl(new Selector(new CommandDCS("AAP_PAGE"), new int[] { 0, 1, 2, 3 }));
31
 
32
            // Enable the mcp23017
33
            mcp.WriteGpio(3, 0);
34
            Utils.delayms(10);
35
            mcp.WriteGpio(3, 1);
36
 
37
            // Set io dir, pullups and rev polarity
38
            chip0.SetIODirection(0xff, 0xff);
39
            chip0.SetIOPolarity(0xff, 0xff);
40
            chip0.SetIOPullups(0xff, 0xff);
41
 
42
            this.Refresh();
43
            data.prev = data.buttons;
44
            data.changed = false;
45
 
46
            return 1;
47
        }
48
        public override int Refresh() {
49
            byte[] bytes;
50
            int rslt = 0;
51
            rslt = chip0.GetIO(out bytes);
52
 
53
            // Join all our buttons into a single inputs
54
            uint gpio = (uint)((1 - mcp.ReadGpio(0)) | ((1 - mcp.ReadGpio(1)) << 1));
55
            data.buttons = (uint)gpio << 16;
56
            data.buttons |= (uint)bytes[0] << 8;
57
            data.buttons |= (uint)bytes[1];
58
 
59
            if (data.buttons != data.prev)
60
                data.changed = true;
61
            else
62
                data.changed = false;
63
 
64
            return rslt;
65
        }
66
 
67
        public override int Input() {
68
            //Console.WriteLine(input.curr.ToString("X"));
69
            foreach (Control control in this.controls) {
70
                control.data = this.data;
71
                control.Tick();
72
            }
73
            data.prev = data.buttons;
74
            data.changed = false;
75
            return 1;
76
        }
77
    }
78
}