Subversion Repositories group.electronics

Rev

Rev 176 | 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
 
54
    public class CommandVKey : Command {
176 pfowler 55
        OSInput osi;
56
        OSInput.VirtualKeyCodes key;
162 pfowler 57
 
176 pfowler 58
        public CommandVKey(OSInput.VirtualKeyCodes vkey) : base() {
59
            this.key = vkey;
60
            osi = new OSInput(vkey);
162 pfowler 61
        }
62
 
63
        public override int Send() {
164 pfowler 64
            if (this.value == 1) {
176 pfowler 65
                this.osi.Send();
164 pfowler 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 {
177 pfowler 133
        VirtualKeyCode key;
162 pfowler 134
 
177 pfowler 135
        public CommandTrackIRKey(VirtualKeyCode vkey) : base() {
162 pfowler 136
            this.key = vkey;
137
        }
138
 
139
        public override int Send() {
164 pfowler 140
            if (this.value == 1) {
177 pfowler 141
                Globals.SendKey.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
142
                Utils.delayms(1);
143
                Globals.SendKey.Keyboard.KeyPress(key);
144
                Globals.SendKey.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
164 pfowler 145
                return 0;
146
            }
162 pfowler 147
            return 1;
148
        }
149
 
166 pfowler 150
        public override int Send(UInt64 value) {
162 pfowler 151
            this.value = value;
164 pfowler 152
            return this.Send();
162 pfowler 153
        }
154
 
155
        public override string ToString() {
156
            return "TrackIR:" + key.ToString() + ":" + base.value + "\n";
157
        }
158
    }
159
 
160
    public class CommandIf : Command {
161
        private Control ctl { get; set; }
162
        private Dictionary<uint, Command> opts;
163
 
164
        public CommandIf(Control control, Dictionary<uint, Command> opts) {
165
            this.ctl = control;
166
            this.opts = opts;
167
        }
168
 
169
        public override int Send() {
170
            Command cmd;
171
 
172
            ctl.data = this.data;
173
            ctl.Tick();
174
 
166 pfowler 175
            if (opts.TryGetValue((uint)ctl.value, out cmd)) {
162 pfowler 176
                cmd.value = this.value;
177
                cmd.data = this.data;
178
                cmd.Send(this.value);
179
                Console.Write(cmd.ToString());
164 pfowler 180
                return 0;
162 pfowler 181
            }
164 pfowler 182
            return 1;
162 pfowler 183
        }
184
 
166 pfowler 185
        public override int Send(UInt64 value) {
162 pfowler 186
            this.value = value;
164 pfowler 187
            return this.Send();
162 pfowler 188
        }
189
 
190
        public override string ToString() {
191
            return "";
192
            //return "CommandIf:" + this.value + "\n";
193
        }
194
    }
161 pfowler 195
}