Subversion Repositories group.electronics

Rev

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