Subversion Repositories group.electronics

Rev

Rev 180 | 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 {
166 pfowler 10
        public UInt64 value { get; set; }
167 pfowler 11
        public jsdata data { get; set; }
161 pfowler 12
 
13
        public Command() {
14
            value = 0;
15
        }
16
        public abstract int Send();
166 pfowler 17
        public abstract int Send(UInt64 value);
161 pfowler 18
 
19
    }
20
 
21
    public class CommandDCS : Command {
22
        public String cmd { get; set; }
23
 
166 pfowler 24
        public CommandDCS() : base() {
161 pfowler 25
            this.cmd = "";
26
        }
27
 
166 pfowler 28
        public CommandDCS(String cmd) : base() {
161 pfowler 29
            this.cmd = cmd;
30
        }
31
 
32
        public override int Send() {
33
            if (this.cmd.Equals(""))
34
                return -1;
35
 
36
            return Globals.bios.SendData(this.ToString());
37
        }
38
 
166 pfowler 39
        public override int Send(UInt64 value) {
161 pfowler 40
            if (this.cmd.Equals(""))
41
                return -1;
42
 
43
            this.value = value;
164 pfowler 44
            Globals.bios.SendData(this.ToString());
45
            return 0;
46
 
161 pfowler 47
        }
48
 
49
        public override string ToString() {
50
            return cmd + " " + base.value + "\n";
51
        }
52
    }
162 pfowler 53
 
181 pfowler 54
    public class CommandDCSMap : Command {
55
        public String cmd { get; set; }
56
        public Dictionary<UInt64, String> map { get; set; }
57
 
58
        //public CommandDCSMap(Dictionary<UInt64, String> map) : base() {
59
        //    this.cmd = "";
60
        //}
61
 
62
        public CommandDCSMap(String cmd, Dictionary<UInt64, String> map) : base() {
63
            this.cmd = cmd;
64
            this.map = map;
65
        }
66
 
67
        public override int Send() {
68
            String send;
69
            if (this.map.TryGetValue(this.value, out send))
70
                Globals.bios.SendData(this.ToString());
71
 
72
            return 0;
73
        }
74
 
75
        public override int Send(UInt64 value) {
76
 
77
            this.value = value;
78
            return this.Send();
79
 
80
        }
81
 
82
        public override string ToString() {
83
            String send;
84
            if (this.map.TryGetValue(this.value, out send))
85
                return cmd + " " + send + "\n";
86
 
87
            return cmd + ":" + this.value + " <null>";
88
        }
89
    }
90
 
178 pfowler 91
    public class CommandVJSAxis : Command {
92
        HID_USAGES axis;
93
        uint id = 0;
94
 
95
 
96
        public CommandVJSAxis(uint id, HID_USAGES axis) {
97
            this.axis = axis;
98
            this.id = id;
99
        }
100
 
101
        public override int Send() {
102
            int newval = (int)this.value;
103
            bool result = Globals.vjoy.SetAxis(newval, this.id, this.axis);
104
            if (result)
105
                return 0;
106
            return 1;
107
        }
108
 
109
        public override int Send(UInt64 value) {
110
            this.value = value;
111
            return this.Send();
112
        }
180 pfowler 113
 
114
        public override string ToString() {
115
            return "VJSAxis:" + id.ToString() + ":" + base.value + "\n";
116
        }
178 pfowler 117
    }
118
 
162 pfowler 119
    public class CommandVKey : Command {
176 pfowler 120
        OSInput osi;
121
        OSInput.VirtualKeyCodes key;
162 pfowler 122
 
176 pfowler 123
        public CommandVKey(OSInput.VirtualKeyCodes vkey) : base() {
124
            this.key = vkey;
125
            osi = new OSInput(vkey);
162 pfowler 126
        }
127
 
128
        public override int Send() {
164 pfowler 129
            if (this.value == 1) {
176 pfowler 130
                this.osi.Send();
164 pfowler 131
                return 0;
132
            }
162 pfowler 133
            return 1;
134
        }
135
 
166 pfowler 136
        public override int Send(UInt64 value) {
162 pfowler 137
            this.value = value;
164 pfowler 138
            return this.Send();
162 pfowler 139
        }
140
 
141
        public override string ToString() {
142
            return "VKey:" + key.ToString() + ":" + base.value + "\n";
143
        }
144
    }
145
 
165 pfowler 146
    public class CommandMouseButton : Command {
147
 
148
        public static int MB_LEFT = 1;
149
        public static int MB_RIGHT = 2;
150
        // 1 = Left
151
        // 2 = Right
152
        // 3 = ?
153
        int button = 0;
154
 
155
        public CommandMouseButton(int button) : base() {
156
            this.button = button;
157
 
158
        }
159
 
160
        public override int Send() {
161
            if (button == 0)
162
                return 1;
163
 
164
            switch (button) {
165
                case 1:
166
                    if (this.value == 1)
167
                        Globals.SendKey.Mouse.LeftButtonDown();
168
                    else
169
                        Globals.SendKey.Mouse.LeftButtonUp();
170
                    break;
171
                case 2:
172
                    if (this.value == 1)
173
                        Globals.SendKey.Mouse.RightButtonDown();
174
                    else
175
                        Globals.SendKey.Mouse.RightButtonUp();
176
                    break;
177
                case 3:
178
                    if (this.value == 1)
179
                        Globals.SendKey.Mouse.XButtonDown(0);
180
                    else
181
                        Globals.SendKey.Mouse.XButtonUp(0);
182
                    break;
183
            }
184
            return 0;
185
        }
186
 
166 pfowler 187
        public override int Send(UInt64 value) {
165 pfowler 188
            this.value = value;
189
            return this.Send();
190
        }
191
 
192
        public override string ToString() {
193
            return "Mouse:" + this.button + "=" + base.value + "\n";
194
        }
195
    }
196
 
162 pfowler 197
    public class CommandTrackIRKey : Command {
177 pfowler 198
        VirtualKeyCode key;
162 pfowler 199
 
177 pfowler 200
        public CommandTrackIRKey(VirtualKeyCode vkey) : base() {
162 pfowler 201
            this.key = vkey;
202
        }
203
 
204
        public override int Send() {
164 pfowler 205
            if (this.value == 1) {
177 pfowler 206
                Globals.SendKey.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
207
                Utils.delayms(1);
208
                Globals.SendKey.Keyboard.KeyPress(key);
209
                Globals.SendKey.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
164 pfowler 210
                return 0;
211
            }
162 pfowler 212
            return 1;
213
        }
214
 
166 pfowler 215
        public override int Send(UInt64 value) {
162 pfowler 216
            this.value = value;
164 pfowler 217
            return this.Send();
162 pfowler 218
        }
219
 
220
        public override string ToString() {
221
            return "TrackIR:" + key.ToString() + ":" + base.value + "\n";
222
        }
223
    }
224
 
225
    public class CommandIf : Command {
226
        private Control ctl { get; set; }
227
        private Dictionary<uint, Command> opts;
228
 
229
        public CommandIf(Control control, Dictionary<uint, Command> opts) {
230
            this.ctl = control;
231
            this.opts = opts;
232
        }
233
 
234
        public override int Send() {
235
            Command cmd;
236
 
237
            ctl.data = this.data;
238
            ctl.Tick();
239
 
166 pfowler 240
            if (opts.TryGetValue((uint)ctl.value, out cmd)) {
162 pfowler 241
                cmd.value = this.value;
242
                cmd.data = this.data;
243
                cmd.Send(this.value);
244
                Console.Write(cmd.ToString());
164 pfowler 245
                return 0;
162 pfowler 246
            }
164 pfowler 247
            return 1;
162 pfowler 248
        }
249
 
166 pfowler 250
        public override int Send(UInt64 value) {
162 pfowler 251
            this.value = value;
164 pfowler 252
            return this.Send();
162 pfowler 253
        }
254
 
255
        public override string ToString() {
256
            return "";
257
            //return "CommandIf:" + this.value + "\n";
258
        }
259
    }
161 pfowler 260
}