Subversion Repositories group.electronics

Rev

Rev 161 | Rev 164 | 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 {
10
        public uint 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();
17
        public abstract int Send(uint value);
18
 
19
    }
20
 
21
    public class CommandDCS : Command {
22
        public String cmd { get; set; }
23
 
24
        public CommandDCS()
25
            : base() {
26
            this.cmd = "";
27
        }
28
 
29
        public CommandDCS(String cmd)
30
            : base() {
31
            this.cmd = cmd;
32
        }
33
 
34
        public override int Send() {
35
            if (this.cmd.Equals(""))
36
                return -1;
37
 
38
            return Globals.bios.SendData(this.ToString());
39
        }
40
 
41
        public override int Send(uint value) {
42
            if (this.cmd.Equals(""))
43
                return -1;
44
 
45
            this.value = value;
46
 
47
            return Globals.bios.SendData(this.ToString());
48
        }
49
 
50
        public override string ToString() {
51
            return cmd + " " + base.value + "\n";
52
        }
53
    }
162 pfowler 54
 
55
    public class CommandVKey : Command {
56
        VirtualKeyCode key;
57
 
58
        public CommandVKey(VirtualKeyCode vkey)
59
            : base() {
60
                this.key = vkey;
61
 
62
        }
63
 
64
        public override int Send() {
65
            Globals.SendKey.Keyboard.KeyPress(key);
66
            return 1;
67
        }
68
 
69
        public override int Send(uint value) {
70
            this.value = value;
71
            if (this.value == 1)
72
                this.Send();
73
            else return 1;
74
            return 0;
75
        }
76
 
77
        public override string ToString() {
78
            return "VKey:" + key.ToString() + ":" + base.value + "\n";
79
        }
80
    }
81
 
82
    public class CommandTrackIRKey : Command {
83
        VirtualKeyCode key;
84
 
85
        public CommandTrackIRKey(VirtualKeyCode vkey)
86
            : base() {
87
            this.key = vkey;
88
 
89
        }
90
 
91
        public override int Send() {
92
            Globals.SendKey.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
93
            Utils.delayms(1);
94
            Globals.SendKey.Keyboard.KeyPress(key);
95
            Globals.SendKey.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
96
            return 1;
97
        }
98
 
99
        public override int Send(uint value) {
100
            this.value = value;
101
            if (this.value == 1)
102
                this.Send();
103
            else 
104
                return 1;
105
            return 0;
106
        }
107
 
108
        public override string ToString() {
109
            return "TrackIR:" + key.ToString() + ":" + base.value + "\n";
110
        }
111
    }
112
 
113
    public class CommandIf : Command {
114
        private Control ctl { get; set; }
115
        private Dictionary<uint, Command> opts;
116
 
117
        public CommandIf(Control control, Dictionary<uint, Command> opts) {
118
            this.ctl = control;
119
            this.opts = opts;
120
        }
121
 
122
        public override int Send() {
123
            Command cmd;
124
 
125
            ctl.data = this.data;
126
            ctl.Tick();
127
 
128
            if (opts.TryGetValue(ctl.value, out cmd)) {
129
                cmd.value = this.value;
130
                cmd.data = this.data;
131
                cmd.Send(this.value);
132
                Console.Write(cmd.ToString());
133
                return 1;
134
            }
135
            return 0;
136
        }
137
 
138
        public override int Send(uint value) {
139
            this.value = value;
140
            if (this.value == 1)
141
                this.Send();
142
            return 1;
143
        }
144
 
145
        public override string ToString() {
146
            return "";
147
            //return "CommandIf:" + this.value + "\n";
148
        }
149
    }
161 pfowler 150
}