Subversion Repositories group.electronics

Rev

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