Subversion Repositories group.electronics

Rev

Rev 162 | Rev 165 | 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;
164 pfowler 46
            Globals.bios.SendData(this.ToString());
47
            return 0;
48
 
161 pfowler 49
        }
50
 
51
        public override string ToString() {
52
            return cmd + " " + base.value + "\n";
53
        }
54
    }
162 pfowler 55
 
56
    public class CommandVKey : Command {
57
        VirtualKeyCode key;
58
 
59
        public CommandVKey(VirtualKeyCode vkey)
60
            : base() {
61
                this.key = vkey;
62
 
63
        }
64
 
65
        public override int Send() {
164 pfowler 66
            if (this.value == 1) {
67
                Globals.SendKey.Keyboard.KeyPress(key);
68
                return 0;
69
            }
162 pfowler 70
            return 1;
71
        }
72
 
73
        public override int Send(uint value) {
74
            this.value = value;
164 pfowler 75
            return this.Send();
162 pfowler 76
        }
77
 
78
        public override string ToString() {
79
            return "VKey:" + key.ToString() + ":" + base.value + "\n";
80
        }
81
    }
82
 
83
    public class CommandTrackIRKey : Command {
84
        VirtualKeyCode key;
85
 
86
        public CommandTrackIRKey(VirtualKeyCode vkey)
87
            : base() {
88
            this.key = vkey;
89
 
90
        }
91
 
92
        public override int Send() {
164 pfowler 93
            if (this.value == 1) {
94
                Globals.SendKey.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
95
                Utils.delayms(1);
96
                Globals.SendKey.Keyboard.KeyPress(key);
97
                Globals.SendKey.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
98
                return 0;
99
            }
162 pfowler 100
            return 1;
101
        }
102
 
103
        public override int Send(uint value) {
104
            this.value = value;
164 pfowler 105
            return this.Send();
162 pfowler 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());
164 pfowler 133
                return 0;
162 pfowler 134
            }
164 pfowler 135
            return 1;
162 pfowler 136
        }
137
 
138
        public override int Send(uint value) {
139
            this.value = value;
164 pfowler 140
            return this.Send();
162 pfowler 141
        }
142
 
143
        public override string ToString() {
144
            return "";
145
            //return "CommandIf:" + this.value + "\n";
146
        }
147
    }
161 pfowler 148
}