Subversion Repositories group.electronics

Rev

Rev 166 | Rev 168 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 166 Rev 167
Line 11... Line 11...
11
        public Control(Command command) {
11
        public Control(Command command) {
12
            commands.Add(command);
12
            commands.Add(command);
13
        }
13
        }
14
 
14
 
15
        public List<Command> commands = new List<Command>();
15
        public List<Command> commands = new List<Command>();
16
        public Utils.InputPair data { get; set; }       // The data from the panel
16
        //public Utils.InputPair data { get; set; }       // The data from the panel
-
 
17
        public jsdata data { get; set; }
17
        public Boolean updated { get; set; }
18
        public Boolean updated { get; set; }
18
 
19
 
19
        public abstract void Tick();
20
        public abstract void Tick();
20
    }
21
    }
21
 
22
 
Line 29... Line 30...
29
            this.pin = pin;
30
            this.pin = pin;
30
        }
31
        }
31
 
32
 
32
        public override void Tick() {
33
        public override void Tick() {
33
            UInt64 chg = (UInt64)(data.prev >> pin) & 0x01;
34
            UInt64 chg = (UInt64)(data.prev >> pin) & 0x01;
34
            UInt64 norm = (UInt64)(data.curr >> pin) & 0x01;
35
            UInt64 norm = (UInt64)(data.buttons >> pin) & 0x01;
35
            this.value = 0;
36
            this.value = 0;
36
 
37
 
37
            if ((UInt64)(norm) == 1) {
38
            if ((UInt64)(norm) == 1) {
38
                value = (UInt64)(invert ? 0 : 1);
39
                value = (UInt64)(invert ? 0 : 1);
39
            } else {
40
            } else {
Line 64... Line 65...
64
        }
65
        }
65
 
66
 
66
        public override void Tick() {
67
        public override void Tick() {
67
            UInt64 chg0 = (UInt64)(data.prev >> pin0) & 0x01;
68
            UInt64 chg0 = (UInt64)(data.prev >> pin0) & 0x01;
68
            UInt64 chg1 = (UInt64)(data.prev >> pin1) & 0x01;
69
            UInt64 chg1 = (UInt64)(data.prev >> pin1) & 0x01;
69
            UInt64 nrm0 = (UInt64)(data.curr >> pin0) & 0x01;
70
            UInt64 nrm0 = (UInt64)(data.buttons >> pin0) & 0x01;
70
            UInt64 nrm1 = (UInt64)(data.curr >> pin1) & 0x01;
71
            UInt64 nrm1 = (UInt64)(data.buttons >> pin1) & 0x01;
71
            this.value = 1;
72
            this.value = 1;
72
 
73
 
73
            if ((UInt64)nrm0 == 1)
74
            if ((UInt64)nrm0 == 1)
74
                this.value = (UInt64)(invert ? 2 : 0);
75
                this.value = (UInt64)(invert ? 2 : 0);
75
            else if ((uint)nrm1 == 1)
76
            else if ((uint)nrm1 == 1)
Line 83... Line 84...
83
                }
84
                }
84
            }
85
            }
85
        }
86
        }
86
    }
87
    }
87
 
88
 
-
 
89
    public class Potentiometer : Control {
-
 
90
        public int channel { get; set; }
-
 
91
 
-
 
92
        public Boolean invert { get; set; }
-
 
93
 
-
 
94
        public Potentiometer(Command command, int channel) : base(command) {
-
 
95
            this.channel = channel;
-
 
96
        }
-
 
97
 
-
 
98
        public override void Tick() {
-
 
99
            //this.value = data.axis[channel].
-
 
100
            UInt16 tmpval = 0;
-
 
101
            int changed = data.axis[channel].getPosition(ref tmpval);
-
 
102
            this.value = tmpval;
-
 
103
            
-
 
104
 
-
 
105
            if (changed == 0) {
-
 
106
                foreach (Command cmd in this.commands) {
-
 
107
                    cmd.data = this.data;
-
 
108
                    if (cmd.Send(this.value) == 0)
-
 
109
                        Console.Write(cmd.ToString());
-
 
110
                }
-
 
111
            }
-
 
112
        }
-
 
113
    }
-
 
114
 
88
    public class Selector : Control {
115
    public class Selector : Control {
89
        int[] pins;
116
        int[] pins;
90
 
117
 
91
 
118
 
92
        public Selector(Command command, int[] pins) : base(command) {
119
        public Selector(Command command, int[] pins) : base(command) {
Line 104... Line 131...
104
            for (int i = 0; i < pins.Length; i++) // Create a mask of how many selection points there are
131
            for (int i = 0; i < pins.Length; i++) // Create a mask of how many selection points there are
105
                mask |= (UInt64)1 << i;
132
                mask |= (UInt64)1 << i;
106
 
133
 
107
            for (int i = 0; i < pins.Length; i++) {
134
            for (int i = 0; i < pins.Length; i++) {
108
                chg |= (UInt64)(data.prev >> (pins[i] - i)); // Narrow down to the previsouly selected bit
135
                chg |= (UInt64)(data.prev >> (pins[i] - i)); // Narrow down to the previsouly selected bit
109
                norm |= (UInt64)(data.curr >> (pins[i] - i)); // Narrow down to the currently selected bit
136
                norm |= (UInt64)(data.buttons >> (pins[i] - i)); // Narrow down to the currently selected bit
110
 
137
 
111
                if ((UInt64)((data.curr >> pins[i]) & 0x01) == 1) { // Decode the value we need to use
138
                if ((UInt64)((data.buttons >> pins[i]) & 0x01) == 1) { // Decode the value we need to use
112
                    value = (UInt64)i;
139
                    value = (UInt64)i;
113
                }
140
                }
114
            }
141
            }
115
                           
142
                           
116
            norm &= mask; // Remove any bits from above
143
            norm &= mask; // Remove any bits from above