Subversion Repositories group.electronics

Rev

Rev 178 | 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 {
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
 
178 pfowler 54
    public class CommandVJSAxis : Command {
55
        HID_USAGES axis;
56
        uint id = 0;
57
 
58
 
59
        public CommandVJSAxis(uint id, HID_USAGES axis) {
60
            this.axis = axis;
61
            this.id = id;
62
        }
63
 
64
        public override int Send() {
65
            int newval = (int)this.value;
66
            bool result = Globals.vjoy.SetAxis(newval, this.id, this.axis);
67
            if (result)
68
                return 0;
69
            return 1;
70
        }
71
 
72
        public override int Send(UInt64 value) {
73
            this.value = value;
74
            return this.Send();
75
        }
180 pfowler 76
 
77
        public override string ToString() {
78
            return "VJSAxis:" + id.ToString() + ":" + base.value + "\n";
79
        }
178 pfowler 80
    }
81
 
162 pfowler 82
    public class CommandVKey : Command {
176 pfowler 83
        OSInput osi;
84
        OSInput.VirtualKeyCodes key;
162 pfowler 85
 
176 pfowler 86
        public CommandVKey(OSInput.VirtualKeyCodes vkey) : base() {
87
            this.key = vkey;
88
            osi = new OSInput(vkey);
162 pfowler 89
        }
90
 
91
        public override int Send() {
164 pfowler 92
            if (this.value == 1) {
176 pfowler 93
                this.osi.Send();
164 pfowler 94
                return 0;
95
            }
162 pfowler 96
            return 1;
97
        }
98
 
166 pfowler 99
        public override int Send(UInt64 value) {
162 pfowler 100
            this.value = value;
164 pfowler 101
            return this.Send();
162 pfowler 102
        }
103
 
104
        public override string ToString() {
105
            return "VKey:" + key.ToString() + ":" + base.value + "\n";
106
        }
107
    }
108
 
165 pfowler 109
    public class CommandMouseButton : Command {
110
 
111
        public static int MB_LEFT = 1;
112
        public static int MB_RIGHT = 2;
113
        // 1 = Left
114
        // 2 = Right
115
        // 3 = ?
116
        int button = 0;
117
 
118
        public CommandMouseButton(int button) : base() {
119
            this.button = button;
120
 
121
        }
122
 
123
        public override int Send() {
124
            if (button == 0)
125
                return 1;
126
 
127
            switch (button) {
128
                case 1:
129
                    if (this.value == 1)
130
                        Globals.SendKey.Mouse.LeftButtonDown();
131
                    else
132
                        Globals.SendKey.Mouse.LeftButtonUp();
133
                    break;
134
                case 2:
135
                    if (this.value == 1)
136
                        Globals.SendKey.Mouse.RightButtonDown();
137
                    else
138
                        Globals.SendKey.Mouse.RightButtonUp();
139
                    break;
140
                case 3:
141
                    if (this.value == 1)
142
                        Globals.SendKey.Mouse.XButtonDown(0);
143
                    else
144
                        Globals.SendKey.Mouse.XButtonUp(0);
145
                    break;
146
            }
147
            return 0;
148
        }
149
 
166 pfowler 150
        public override int Send(UInt64 value) {
165 pfowler 151
            this.value = value;
152
            return this.Send();
153
        }
154
 
155
        public override string ToString() {
156
            return "Mouse:" + this.button + "=" + base.value + "\n";
157
        }
158
    }
159
 
162 pfowler 160
    public class CommandTrackIRKey : Command {
177 pfowler 161
        VirtualKeyCode key;
162 pfowler 162
 
177 pfowler 163
        public CommandTrackIRKey(VirtualKeyCode vkey) : base() {
162 pfowler 164
            this.key = vkey;
165
        }
166
 
167
        public override int Send() {
164 pfowler 168
            if (this.value == 1) {
177 pfowler 169
                Globals.SendKey.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
170
                Utils.delayms(1);
171
                Globals.SendKey.Keyboard.KeyPress(key);
172
                Globals.SendKey.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
164 pfowler 173
                return 0;
174
            }
162 pfowler 175
            return 1;
176
        }
177
 
166 pfowler 178
        public override int Send(UInt64 value) {
162 pfowler 179
            this.value = value;
164 pfowler 180
            return this.Send();
162 pfowler 181
        }
182
 
183
        public override string ToString() {
184
            return "TrackIR:" + key.ToString() + ":" + base.value + "\n";
185
        }
186
    }
187
 
188
    public class CommandIf : Command {
189
        private Control ctl { get; set; }
190
        private Dictionary<uint, Command> opts;
191
 
192
        public CommandIf(Control control, Dictionary<uint, Command> opts) {
193
            this.ctl = control;
194
            this.opts = opts;
195
        }
196
 
197
        public override int Send() {
198
            Command cmd;
199
 
200
            ctl.data = this.data;
201
            ctl.Tick();
202
 
166 pfowler 203
            if (opts.TryGetValue((uint)ctl.value, out cmd)) {
162 pfowler 204
                cmd.value = this.value;
205
                cmd.data = this.data;
206
                cmd.Send(this.value);
207
                Console.Write(cmd.ToString());
164 pfowler 208
                return 0;
162 pfowler 209
            }
164 pfowler 210
            return 1;
162 pfowler 211
        }
212
 
166 pfowler 213
        public override int Send(UInt64 value) {
162 pfowler 214
            this.value = value;
164 pfowler 215
            return this.Send();
162 pfowler 216
        }
217
 
218
        public override string ToString() {
219
            return "";
220
            //return "CommandIf:" + this.value + "\n";
221
        }
222
    }
161 pfowler 223
}