Subversion Repositories group.electronics

Rev

Rev 164 | Rev 166 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
161 pfowler 1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
162 pfowler 6
using WindowsInput.Native;
161 pfowler 7
 
8
namespace nitdcscore {
9
    public abstract class Command {
10
        public uint value { get; set; }
162 pfowler 11
        public nitdcscore.Utils.InputPair data { get; set; }
161 pfowler 12
 
13
        public Command() {
14
            value = 0;
15
        }
16
        public abstract int Send();
17
        public abstract int Send(uint value);
18
 
19
    }
20
 
21
    public class CommandDCS : Command {
22
        public String cmd { get; set; }
23
 
24
        public CommandDCS()
25
            : base() {
26
            this.cmd = "";
27
        }
28
 
29
        public CommandDCS(String cmd)
30
            : base() {
31
            this.cmd = cmd;
32
        }
33
 
34
        public override int Send() {
35
            if (this.cmd.Equals(""))
36
                return -1;
37
 
38
            return Globals.bios.SendData(this.ToString());
39
        }
40
 
41
        public override int Send(uint value) {
42
            if (this.cmd.Equals(""))
43
                return -1;
44
 
45
            this.value = value;
164 pfowler 46
            Globals.bios.SendData(this.ToString());
47
            return 0;
48
 
161 pfowler 49
        }
50
 
51
        public override string ToString() {
52
            return cmd + " " + base.value + "\n";
53
        }
54
    }
162 pfowler 55
 
56
    public class CommandVKey : Command {
57
        VirtualKeyCode key;
58
 
59
        public CommandVKey(VirtualKeyCode vkey)
60
            : base() {
61
                this.key = vkey;
62
 
63
        }
64
 
65
        public override int Send() {
164 pfowler 66
            if (this.value == 1) {
67
                Globals.SendKey.Keyboard.KeyPress(key);
68
                return 0;
69
            }
162 pfowler 70
            return 1;
71
        }
72
 
73
        public override int Send(uint value) {
74
            this.value = value;
164 pfowler 75
            return this.Send();
162 pfowler 76
        }
77
 
78
        public override string ToString() {
79
            return "VKey:" + key.ToString() + ":" + base.value + "\n";
80
        }
81
    }
82
 
165 pfowler 83
    public class CommandMouseButton : Command {
84
 
85
        public static int MB_LEFT = 1;
86
        public static int MB_RIGHT = 2;
87
        // 1 = Left
88
        // 2 = Right
89
        // 3 = ?
90
        int button = 0;
91
 
92
        public CommandMouseButton(int button) : base() {
93
            this.button = button;
94
 
95
        }
96
 
97
        public override int Send() {
98
            if (button == 0)
99
                return 1;
100
 
101
            switch (button) {
102
                case 1:
103
                    if (this.value == 1)
104
                        Globals.SendKey.Mouse.LeftButtonDown();
105
                    else
106
                        Globals.SendKey.Mouse.LeftButtonUp();
107
                    break;
108
                case 2:
109
                    if (this.value == 1)
110
                        Globals.SendKey.Mouse.RightButtonDown();
111
                    else
112
                        Globals.SendKey.Mouse.RightButtonUp();
113
                    break;
114
                case 3:
115
                    if (this.value == 1)
116
                        Globals.SendKey.Mouse.XButtonDown(0);
117
                    else
118
                        Globals.SendKey.Mouse.XButtonUp(0);
119
                    break;
120
            }
121
            return 0;
122
        }
123
 
124
        public override int Send(uint value) {
125
            this.value = value;
126
            return this.Send();
127
        }
128
 
129
        public override string ToString() {
130
            return "Mouse:" + this.button + "=" + base.value + "\n";
131
        }
132
    }
133
 
162 pfowler 134
    public class CommandTrackIRKey : Command {
135
        VirtualKeyCode key;
136
 
137
        public CommandTrackIRKey(VirtualKeyCode vkey)
138
            : base() {
139
            this.key = vkey;
140
 
141
        }
142
 
143
        public override int Send() {
164 pfowler 144
            if (this.value == 1) {
145
                Globals.SendKey.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
146
                Utils.delayms(1);
147
                Globals.SendKey.Keyboard.KeyPress(key);
148
                Globals.SendKey.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
149
                return 0;
150
            }
162 pfowler 151
            return 1;
152
        }
153
 
154
        public override int Send(uint value) {
155
            this.value = value;
164 pfowler 156
            return this.Send();
162 pfowler 157
        }
158
 
159
        public override string ToString() {
160
            return "TrackIR:" + key.ToString() + ":" + base.value + "\n";
161
        }
162
    }
163
 
164
    public class CommandIf : Command {
165
        private Control ctl { get; set; }
166
        private Dictionary<uint, Command> opts;
167
 
168
        public CommandIf(Control control, Dictionary<uint, Command> opts) {
169
            this.ctl = control;
170
            this.opts = opts;
171
        }
172
 
173
        public override int Send() {
174
            Command cmd;
175
 
176
            ctl.data = this.data;
177
            ctl.Tick();
178
 
179
            if (opts.TryGetValue(ctl.value, out cmd)) {
180
                cmd.value = this.value;
181
                cmd.data = this.data;
182
                cmd.Send(this.value);
183
                Console.Write(cmd.ToString());
164 pfowler 184
                return 0;
162 pfowler 185
            }
164 pfowler 186
            return 1;
162 pfowler 187
        }
188
 
189
        public override int Send(uint value) {
190
            this.value = value;
164 pfowler 191
            return this.Send();
162 pfowler 192
        }
193
 
194
        public override string ToString() {
195
            return "";
196
            //return "CommandIf:" + this.value + "\n";
197
        }
198
    }
161 pfowler 199
}