|
1 |
| -<<<<<<< HEAD |
2 |
| -using System; |
3 |
| -using System.Linq; |
4 |
| -using System.Threading; |
5 |
| -using Raspberry.IO.GeneralPurpose; |
6 |
| - |
7 |
| -namespace Raspberry.IO.Console |
8 |
| -{ |
9 |
| - class Program |
10 |
| - { |
11 |
| - private class Status |
12 |
| - { |
13 |
| - public Connection Connection { get; set; } |
14 |
| - public int Current { get; set; } |
15 |
| - public bool Descending { get; set; } |
16 |
| - } |
17 |
| - |
18 |
| - static void Main(string[] args) |
19 |
| - { |
20 |
| - var driverName = args.SkipWhile(a => a != "-driver").Skip(1).DefaultIfEmpty("memory").First(); |
21 |
| - |
22 |
| - IConnectionDriver driver; |
23 |
| - switch(driverName) |
24 |
| - { |
25 |
| - case "memory": |
26 |
| - driver = new ConnectionMemoryDriver(); |
27 |
| - break; |
28 |
| - case "file": |
29 |
| - driver = new ConnectionFileDriver(); |
30 |
| - break; |
31 |
| - default: |
32 |
| - throw new InvalidOperationException("Unsupported driver"); |
33 |
| - } |
34 |
| - |
35 |
| - var speed = args.SkipWhile(a => a != "-speed").Skip(1).Select(int.Parse).DefaultIfEmpty(250).First(); |
36 |
| - |
37 |
| - var mainboard = Mainboard.Current; |
38 |
| - System.Console.WriteLine("Running on Raspberry firmware rev{0}, board rev{1}, processor {2}", mainboard.FirmwareRevision, mainboard.BoardRevision, mainboard.Processor); |
39 |
| - System.Console.WriteLine("Using {0} driver, frequency {1:0.##}hz", driverName, 1000.0 / speed); |
40 |
| - |
41 |
| - var pins = new PinConfiguration[] |
42 |
| - { |
43 |
| - ConnectorPin.P1Pin26.Output().Named("Led1").Active(), |
44 |
| - ConnectorPin.P1Pin24.Output().Named("Led2"), |
45 |
| - ConnectorPin.P1Pin22.Output().Named("Led3").Active(), |
46 |
| - ConnectorPin.P1Pin15.Output().Named("Led4"), |
47 |
| - ConnectorPin.P1Pin13.Output().Named("Led5").Active(), |
48 |
| - ConnectorPin.P1Pin11.Output().Named("Led6"), |
49 |
| - ConnectorPin.P1Pin3.Input().Reversed() |
50 |
| - }; |
51 |
| - |
52 |
| - using (var connection = new Connection(driver, pins)) |
53 |
| - { |
54 |
| - var status = new Status { Connection = connection }; |
55 |
| - |
56 |
| - connection.InputPinChanged += delegate(object sender, PinStatusEventArgs pinStatusEventArgs) |
57 |
| - { |
58 |
| - System.Console.WriteLine("[{0:HH:mm:ss}] Pin {1}: {2}", DateTime.UtcNow, (int)pinStatusEventArgs.Pin.Pin, pinStatusEventArgs.IsActive); |
59 |
| - if (pinStatusEventArgs.IsActive) |
60 |
| - status.Descending = !status.Descending; |
61 |
| - }; |
62 |
| - |
63 |
| - using (new Timer(Animate, status, 0, speed)) |
64 |
| - System.Console.ReadLine(); |
65 |
| - } |
66 |
| - } |
67 |
| - |
68 |
| - private static void Animate(object state) |
69 |
| - { |
70 |
| - var status = (Status) state; |
71 |
| - |
72 |
| - var connection = status.Connection; |
73 |
| - var i = status.Current; |
74 |
| - |
75 |
| - connection["Led1"] = (i == 0); |
76 |
| - connection["Led2"] = (i == 1); |
77 |
| - connection["Led3"] = (i == 2); |
78 |
| - connection["Led4"] = (i == 3); |
79 |
| - connection["Led5"] = (i == 4); |
80 |
| - connection["Led6"] = (i == 5); |
81 |
| - |
82 |
| - if (!status.Descending) |
83 |
| - status.Current = (i + 1) % 6; |
84 |
| - else |
85 |
| - status.Current = (6 + (i - 1)) % 6; |
86 |
| - |
87 |
| - /* |
88 |
| - connection["Led1"] = (i & 0x1) == 0x1; |
89 |
| - connection["Led2"] = (i & 0x20) == 0x20; |
90 |
| - connection["Led3"] = (i & 0x4) == 0x4; |
91 |
| - connection["Led4"] = (i & 0x10) == 0x10; |
92 |
| - connection["Led5"] = (i & 0x8) == 0x8; |
93 |
| - connection["Led6"] = (i & 0x40) == 0x40; |
94 |
| -
|
95 |
| - status.Current = (i + 1) % 0x40; |
96 |
| - */ |
97 |
| - } |
98 |
| - } |
99 |
| -} |
100 |
| -======= |
101 |
| -using System; |
102 |
| -using System.Linq; |
103 |
| -using System.Threading; |
104 |
| -using Raspberry.IO.GeneralPurpose; |
105 |
| - |
106 |
| -namespace Raspberry.IO.Console |
107 |
| -{ |
108 |
| - class Program |
109 |
| - { |
110 |
| - private class Status |
111 |
| - { |
112 |
| - public Connection Connection { get; set; } |
113 |
| - public int Current { get; set; } |
114 |
| - public bool Descending { get; set; } |
115 |
| - } |
116 |
| - |
117 |
| - static void Main(string[] args) |
118 |
| - { |
119 |
| - var driverName = args.SkipWhile(a => a != "-driver").Skip(1).DefaultIfEmpty("memory").First(); |
120 |
| - |
121 |
| - IConnectionDriver driver; |
122 |
| - switch(driverName) |
123 |
| - { |
124 |
| - case "memory": |
125 |
| - driver = new ConnectionMemoryDriver(); |
126 |
| - break; |
127 |
| - case "file": |
128 |
| - driver = new ConnectionFileDriver(); |
129 |
| - break; |
130 |
| - default: |
131 |
| - throw new InvalidOperationException("Unsupported driver"); |
132 |
| - } |
133 |
| - |
134 |
| - var speed = args.SkipWhile(a => a != "-speed").Skip(1).Select(int.Parse).DefaultIfEmpty(250).First(); |
135 |
| - |
136 |
| - var mainboard = Mainboard.Current; |
137 |
| - System.Console.WriteLine("Running on Raspberry firmware rev{0}, board rev{1}, processor {2}", mainboard.FirmwareRevision, mainboard.BoardRevision, mainboard.Processor); |
138 |
| - System.Console.WriteLine("Using {0} driver, frequency {1:0.##}hz", driverName, 1000.0 / speed); |
139 |
| - |
140 |
| - var pins = new PinConfiguration[] |
141 |
| - { |
142 |
| - ConnectorPin.P1Pin26.Output().Named("Led1").Active(), |
143 |
| - ConnectorPin.P1Pin24.Output().Named("Led2"), |
144 |
| - ConnectorPin.P1Pin22.Output().Named("Led3").Active(), |
145 |
| - ConnectorPin.P1Pin15.Output().Named("Led4"), |
146 |
| - ConnectorPin.P1Pin13.Output().Named("Led5").Active(), |
147 |
| - ConnectorPin.P1Pin11.Output().Named("Led6"), |
148 |
| - ConnectorPin.P1Pin3.Input().Reversed() |
149 |
| - }; |
150 |
| - |
151 |
| - using (var connection = new Connection(driver, pins)) |
152 |
| - { |
153 |
| - var status = new Status { Connection = connection }; |
154 |
| - |
155 |
| - connection.InputPinChanged += delegate(object sender, PinStatusEventArgs pinStatusEventArgs) |
156 |
| - { |
157 |
| - System.Console.WriteLine("[{0:HH:mm:ss}] Pin {1}: {2}", DateTime.UtcNow, (int)pinStatusEventArgs.Pin.Pin, pinStatusEventArgs.IsActive); |
158 |
| - if (pinStatusEventArgs.IsActive) |
159 |
| - status.Descending = !status.Descending; |
160 |
| - }; |
161 |
| - |
162 |
| - using (new Timer(Animate, status, 0, speed)) |
163 |
| - System.Console.ReadLine(); |
164 |
| - } |
165 |
| - } |
166 |
| - |
167 |
| - private static void Animate(object state) |
168 |
| - { |
169 |
| - var status = (Status) state; |
170 |
| - |
171 |
| - var connection = status.Connection; |
172 |
| - var i = status.Current; |
173 |
| - |
174 |
| - connection["Led1"] = (i == 0); |
175 |
| - connection["Led2"] = (i == 1); |
176 |
| - connection["Led3"] = (i == 2); |
177 |
| - connection["Led4"] = (i == 3); |
178 |
| - connection["Led5"] = (i == 4); |
179 |
| - connection["Led6"] = (i == 5); |
180 |
| - |
181 |
| - if (!status.Descending) |
182 |
| - status.Current = (i + 1) % 6; |
183 |
| - else |
184 |
| - status.Current = (6 + (i - 1)) % 6; |
185 |
| - |
186 |
| - /* |
187 |
| - connection["Led1"] = (i & 0x1) == 0x1; |
188 |
| - connection["Led2"] = (i & 0x20) == 0x20; |
189 |
| - connection["Led3"] = (i & 0x4) == 0x4; |
190 |
| - connection["Led4"] = (i & 0x10) == 0x10; |
191 |
| - connection["Led5"] = (i & 0x8) == 0x8; |
192 |
| - connection["Led6"] = (i & 0x40) == 0x40; |
193 |
| -
|
194 |
| - status.Current = (i + 1) % 0x40; |
195 |
| - */ |
196 |
| - } |
197 |
| - } |
198 |
| -} |
199 |
| ->>>>>>> Initial Import |
| 1 | +using System; |
| 2 | +using System.Linq; |
| 3 | +using System.Threading; |
| 4 | +using Raspberry.IO.GeneralPurpose; |
| 5 | + |
| 6 | +namespace Raspberry.IO.Console |
| 7 | +{ |
| 8 | + class Program |
| 9 | + { |
| 10 | + private class Status |
| 11 | + { |
| 12 | + public Connection Connection { get; set; } |
| 13 | + public int Current { get; set; } |
| 14 | + public bool Descending { get; set; } |
| 15 | + } |
| 16 | + |
| 17 | + static void Main(string[] args) |
| 18 | + { |
| 19 | + var driverName = args.SkipWhile(a => a != "-driver").Skip(1).DefaultIfEmpty("memory").First(); |
| 20 | + |
| 21 | + IConnectionDriver driver; |
| 22 | + switch(driverName) |
| 23 | + { |
| 24 | + case "memory": |
| 25 | + driver = new ConnectionMemoryDriver(); |
| 26 | + break; |
| 27 | + case "file": |
| 28 | + driver = new ConnectionFileDriver(); |
| 29 | + break; |
| 30 | + default: |
| 31 | + throw new InvalidOperationException("Unsupported driver"); |
| 32 | + } |
| 33 | + |
| 34 | + var speed = args.SkipWhile(a => a != "-speed").Skip(1).Select(int.Parse).DefaultIfEmpty(250).First(); |
| 35 | + |
| 36 | + var mainboard = Mainboard.Current; |
| 37 | + System.Console.WriteLine("Running on Raspberry firmware rev{0}, board rev{1}, processor {2}", mainboard.FirmwareRevision, mainboard.BoardRevision, mainboard.Processor); |
| 38 | + System.Console.WriteLine("Using {0} driver, frequency {1:0.##}hz", driverName, 1000.0 / speed); |
| 39 | + |
| 40 | + var pins = new PinConfiguration[] |
| 41 | + { |
| 42 | + ConnectorPin.P1Pin26.Output().Named("Led1").Active(), |
| 43 | + ConnectorPin.P1Pin24.Output().Named("Led2"), |
| 44 | + ConnectorPin.P1Pin22.Output().Named("Led3").Active(), |
| 45 | + ConnectorPin.P1Pin15.Output().Named("Led4"), |
| 46 | + ConnectorPin.P1Pin13.Output().Named("Led5").Active(), |
| 47 | + ConnectorPin.P1Pin11.Output().Named("Led6"), |
| 48 | + ConnectorPin.P1Pin3.Input().Reversed() |
| 49 | + }; |
| 50 | + |
| 51 | + using (var connection = new Connection(driver, pins)) |
| 52 | + { |
| 53 | + var status = new Status { Connection = connection }; |
| 54 | + |
| 55 | + connection.InputPinChanged += delegate(object sender, PinStatusEventArgs pinStatusEventArgs) |
| 56 | + { |
| 57 | + System.Console.WriteLine("[{0:HH:mm:ss}] Pin {1}: {2}", DateTime.UtcNow, (int)pinStatusEventArgs.Pin.Pin, pinStatusEventArgs.IsActive); |
| 58 | + if (pinStatusEventArgs.IsActive) |
| 59 | + status.Descending = !status.Descending; |
| 60 | + }; |
| 61 | + |
| 62 | + using (new Timer(Animate, status, 0, speed)) |
| 63 | + System.Console.ReadLine(); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + private static void Animate(object state) |
| 68 | + { |
| 69 | + var status = (Status) state; |
| 70 | + |
| 71 | + var connection = status.Connection; |
| 72 | + var i = status.Current; |
| 73 | + |
| 74 | + connection["Led1"] = (i == 0); |
| 75 | + connection["Led2"] = (i == 1); |
| 76 | + connection["Led3"] = (i == 2); |
| 77 | + connection["Led4"] = (i == 3); |
| 78 | + connection["Led5"] = (i == 4); |
| 79 | + connection["Led6"] = (i == 5); |
| 80 | + |
| 81 | + if (!status.Descending) |
| 82 | + status.Current = (i + 1) % 6; |
| 83 | + else |
| 84 | + status.Current = (6 + (i - 1)) % 6; |
| 85 | + |
| 86 | + /* |
| 87 | + connection["Led1"] = (i & 0x1) == 0x1; |
| 88 | + connection["Led2"] = (i & 0x20) == 0x20; |
| 89 | + connection["Led3"] = (i & 0x4) == 0x4; |
| 90 | + connection["Led4"] = (i & 0x10) == 0x10; |
| 91 | + connection["Led5"] = (i & 0x8) == 0x8; |
| 92 | + connection["Led6"] = (i & 0x40) == 0x40; |
| 93 | +
|
| 94 | + status.Current = (i + 1) % 0x40; |
| 95 | + */ |
| 96 | + } |
| 97 | + } |
| 98 | +} |
0 commit comments