Subversion Repositories group.electronics

Rev

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