Subversion Repositories group.electronics

Rev

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