Subversion Repositories group.electronics

Rev

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
 
7
namespace nitdcscore {
8
    public class Panel_AHFS : Panel {
9
 
10
        private mcp23017[] chips;
11
 
12
        public Panel_AHFS(mcp2221 mcp) : base(mcp) {
13
            chips = new mcp23017[2] { new mcp23017(mcp, 0x20), new mcp23017(mcp, 0x21) };
14
            this.Init();
15
        }
16
 
17
        public override int Init() {
18
            //AHCP
19
            this.addControl(new Switch3Pos(new CommandDCS("AHCP_MASTER_ARM"), 8, 9));   // Train - Safe - Arm
20
            this.addControl(new Switch3Pos(new CommandDCS("AHCP_GUNPAC"), 10, 11));     // Gunarm - Safe - Arm
21
            this.addControl(new Switch3Pos(new CommandDCS("AHCP_LASER_ARM"), 12, 13));  // Train - Safe - Arm
22
            this.addControl(new Switch2Pos(new CommandDCS("AHCP_TGP"), 14));            // Off - On
23
            this.addControl(new Switch3Pos(new CommandDCS("AHCP_ALT_SCE"), 0, 1));      // Radar  - Delta - Baro
24
            this.addControl(new Switch2Pos(new CommandDCS("AHCP_HUD_DAYNIGHT"), 2));    // Night - Day
25
            this.addControl(new Switch2Pos(new CommandDCS("AHCP_HUD_MODE"), 15));       // Stby - Norm
26
            this.addControl(new Switch2Pos(new CommandDCS("AHCP_CICU"), 3));            // Off - On
27
            this.addControl(new Switch2Pos(new CommandDCS("AHCP_JTRS"), 4));            // Off - On
28
            this.addControl(new Switch3Pos(new CommandDCS("AHCP_IFFCC"), 6, 5));        // Off - Test - On
29
            this.addControl(new Switch2Pos(new CommandDCS("HARS_FAST_ERECT"), 7));      // Off - On
30
            this.addControl(new Potentiometer(new CommandDCS("ALCP_RCVR_LTS"), 0));     // 0x00 - 0xFFFF
31
 
32
            // Fuel System
33
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_AMPL"), 16));
34
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_BOOST_MAIN_L"), 24));
35
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_BOOST_MAIN_R"), 25));
36
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_BOOST_WING_L"), 26));
37
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_BOOST_WING_R"), 27));
38
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_CROSSFEED"), 28));
39
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_EXT_TANKS_FUS"), 30));
40
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_EXT_TANKS_WING"), 31));
41
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_FD_MAIN_L"), 20, true));
42
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_FD_MAIN_R"), 21, true));
43
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_FD_WING_L"), 18, true));
44
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_FD_WING_R"), 19, true));
45
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_LINE_CHECK"), 17));
46
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_RCVR_LEVER"), 23));
47
            this.addControl(new Switch2Pos(new CommandDCS("FSCP_TK_GATE"), 29));
48
 
49
            mcp.WriteGpio(3, 0);
50
            Utils.delayms(10);
51
            // Enable the mcp23017
52
            mcp.WriteGpio(3, 1);
53
 
54
            // Set io dir, pullups and rev polarity
55
            chips[0].SetIODirection(0xff, 0xff);
56
            chips[0].SetIOPolarity(0xf0, 0xff);
57
            chips[0].SetIOPullups(0xff, 0xff);
58
 
59
            chips[1].SetIODirection(0xff, 0xff);
60
            chips[1].SetIOPolarity(0xff, 0xff);
61
            chips[1].SetIOPullups(0xff, 0xff);
62
 
63
            // Get the initial values
64
            this.Refresh();
65
            data.prev = data.buttons;
66
            data.axis[0].prev = data.axis[0].value;
67
            data.changed = false;
68
 
69
            return 0;
70
        }
71
 
72
        public override int Refresh() {
73
 
74
            byte[] bytes;
75
            int rslt = 0;
76
            rslt = chips[0].GetIO(out bytes);
77
 
78
            data.buttons = (uint)bytes[0] << 24;
79
            data.buttons |= (uint)bytes[1] << 16;
80
 
81
            rslt = chips[1].GetIO(out bytes);
82
 
83
            data.buttons |= (uint)bytes[0] << 8;
84
            data.buttons |= (uint)bytes[1];
85
 
86
            data.axis[0].value = mcp.ReadADC(1);
87
 
88
            if ((data.buttons != data.prev) || (data.axis[0].prev != data.axis[0].value))
89
                data.changed = true;
90
            else
91
                data.changed = false;
92
 
93
            return 1;
94
        }
95
 
96
        public override int Input() {
97
 
98
            foreach (Control control in this.controls) {
99
                control.data = this.data;
100
                control.Tick();
101
            }
102
            data.prev = data.buttons;
103
            data.axis[0].prev = data.axis[0].value;
104
            data.changed = false;
105
            return 1;
106
        }
107
    }
108
}