Subversion Repositories group.electronics

Rev

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

Rev 164 Rev 166
Line 4... Line 4...
4
using System.Text;
4
using System.Text;
5
using System.Threading.Tasks;
5
using System.Threading.Tasks;
6
 
6
 
7
namespace nitdcscore {
7
namespace nitdcscore {
8
    public abstract class Control {
8
    public abstract class Control {
9
        public uint value { get; set; }
9
        public UInt64 value { get; set; }
10
 
10
 
11
        public Control(Command command) {
11
        public Control(Command command) {
12
            commands.Add(command);
12
            commands.Add(command);
13
        }
13
        }
14
 
14
 
Line 28... Line 28...
28
            this.invert = invert;
28
            this.invert = invert;
29
            this.pin = pin;
29
            this.pin = pin;
30
        }
30
        }
31
 
31
 
32
        public override void Tick() {
32
        public override void Tick() {
33
            uint chg = (uint)(data.prev >> pin) & 0x01;
33
            UInt64 chg = (UInt64)(data.prev >> pin) & 0x01;
34
            uint norm = (uint)(data.curr >> pin) & 0x01;
34
            UInt64 norm = (UInt64)(data.curr >> pin) & 0x01;
35
            this.value = 0;
35
            this.value = 0;
36
            
36
 
37
            if ((uint)(norm) == 1) {
37
            if ((UInt64)(norm) == 1) {
38
                value = (uint)(invert ? 0 : 1);
38
                value = (UInt64)(invert ? 0 : 1);
39
            } else {
39
            } else {
40
                value = (uint)(invert ? 1 : 0);
40
                value = (UInt64)(invert ? 1 : 0);
41
            }
41
            }
42
 
42
 
43
            if (this.commands != null && norm != chg) {
43
            if (this.commands != null && norm != chg) {
44
                foreach (Command cmd in this.commands) {
44
                foreach (Command cmd in this.commands) {
45
                    cmd.data = this.data;
45
                    cmd.data = this.data;
Line 62... Line 62...
62
            this.invert = invert;
62
            this.invert = invert;
63
            
63
            
64
        }
64
        }
65
 
65
 
66
        public override void Tick() {
66
        public override void Tick() {
67
            uint chg0 = (uint)(data.prev >> pin0) & 0x01;
67
            UInt64 chg0 = (UInt64)(data.prev >> pin0) & 0x01;
68
            uint chg1 = (uint)(data.prev >> pin1) & 0x01;
68
            UInt64 chg1 = (UInt64)(data.prev >> pin1) & 0x01;
69
            uint nrm0 = (uint)(data.curr >> pin0) & 0x01;
69
            UInt64 nrm0 = (UInt64)(data.curr >> pin0) & 0x01;
70
            uint nrm1 = (uint)(data.curr >> pin1) & 0x01;
70
            UInt64 nrm1 = (UInt64)(data.curr >> pin1) & 0x01;
71
            this.value = 1;
71
            this.value = 1;
72
            
72
 
73
            if ((uint)nrm0 == 1)
73
            if ((UInt64)nrm0 == 1)
74
                this.value = (uint)(invert ? 2 : 0);
74
                this.value = (UInt64)(invert ? 2 : 0);
75
            else if ((uint)nrm1 == 1)
75
            else if ((uint)nrm1 == 1)
76
                this.value = (uint)(invert ? 0 : 2);
76
                this.value = (UInt64)(invert ? 0 : 2);
77
 
77
 
78
            if (this.commands != null &&  ((nrm0 != chg0) || (nrm1 != chg1))) {
78
            if (this.commands != null &&  ((nrm0 != chg0) || (nrm1 != chg1))) {
79
                foreach (Command cmd in this.commands) {
79
                foreach (Command cmd in this.commands) {
80
                    cmd.data = this.data;
80
                    cmd.data = this.data;
81
                    if (cmd.Send(this.value) == 0)
81
                    if (cmd.Send(this.value) == 0)
Line 96... Line 96...
96
 
96
 
97
        public override void Tick() {
97
        public override void Tick() {
98
            // This is a rather complicated way  to check what the previous select
98
            // This is a rather complicated way  to check what the previous select
99
            //  was, and was the current selection is. Not really needed, but hoping it 
99
            //  was, and was the current selection is. Not really needed, but hoping it 
100
            //  might come in handy for something else down the line.
100
            //  might come in handy for something else down the line.
101
            uint chg = 0;
101
            UInt64 chg = 0;
102
            uint norm = 0;
102
            UInt64 norm = 0;
103
            uint mask = 0;
103
            UInt64 mask = 0;
104
            for (int i = 0; i < pins.Length; i++) // Create a mask of how many selection points there are
104
            for (int i = 0; i < pins.Length; i++) // Create a mask of how many selection points there are
105
                mask |= (uint)1 << i;
105
                mask |= (UInt64)1 << i;
106
 
106
 
107
            for (int i = 0; i < pins.Length; i++) {
107
            for (int i = 0; i < pins.Length; i++) {
108
                chg |= (uint)(data.prev >> (pins[i] -i )); // Narrow down to the previsouly selected bit
108
                chg |= (UInt64)(data.prev >> (pins[i] - i)); // Narrow down to the previsouly selected bit
109
                norm |= (uint)(data.curr >> (pins[i] -i )); // Narrow down to the currently selected bit
109
                norm |= (UInt64)(data.curr >> (pins[i] - i)); // Narrow down to the currently selected bit
110
 
110
 
111
                if ((uint)((data.curr >> pins[i]) & 0x01) == 1) { // Decode the value we need to use
111
                if ((UInt64)((data.curr >> pins[i]) & 0x01) == 1) { // Decode the value we need to use
112
                    value = (uint)i;
112
                    value = (UInt64)i;
113
                }
113
                }
114
            }
114
            }
115
                           
115
                           
116
            norm &= mask; // Remove any bits from above
116
            norm &= mask; // Remove any bits from above
117
            chg &= mask;
117
            chg &= mask;