├── .gitattributes
├── .gitignore
├── .nuget
├── NuGet.Config
├── NuGet.exe
└── NuGet.targets
├── Icon.png
├── README.md
├── Raspberry.System.nuspec
├── Raspberry.System
├── Board.cs
├── ConnectorPinout.cs
├── Model.cs
├── Processor.cs
├── Properties
│ └── AssemblyInfo.cs
├── Raspberry.System.csproj
└── Timers
│ ├── HighResolutionTimer.cs
│ ├── ITimer.cs
│ ├── Interop.cs
│ ├── StandardTimer.cs
│ ├── TimeSpanUtility.cs
│ └── Timer.cs
├── RaspberrySharp.System.sln
└── Test.Board
├── Program.cs
├── Properties
└── AssemblyInfo.cs
└── Test.Board.csproj
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
2 | bin
3 | obj
4 |
5 | # mstest test results
6 | TestResults
7 |
8 | # user files
9 | **.user
10 | **.suo
11 | **.sdf
12 |
13 | # resharper
14 | /_[Rr]e[Ss]harper.*
15 | *.[Rr]e[Ss]harper.*
16 | *.[Rr]e[Ss]harper
17 |
18 | # OS generated files
19 | [Tt]humbs.db
20 | [Dd]esktop.ini
21 |
22 | RaspberrySharp.System.userprefs
--------------------------------------------------------------------------------
/.nuget/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.nuget/NuGet.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raspberry-sharp/raspberry-sharp-system/2b481482a80e7063d794e16f69516bcb4022864f/.nuget/NuGet.exe
--------------------------------------------------------------------------------
/.nuget/NuGet.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildProjectDirectory)\..\
5 |
6 |
7 | false
8 |
9 |
10 | false
11 |
12 |
13 | true
14 |
15 |
16 | false
17 |
18 |
19 |
20 |
21 |
22 |
26 |
27 |
28 |
29 |
30 | $([System.IO.Path]::Combine($(SolutionDir), ".nuget"))
31 | $([System.IO.Path]::Combine($(ProjectDir), "packages.config"))
32 |
33 |
34 |
35 |
36 | $(SolutionDir).nuget
37 | packages.config
38 |
39 |
40 |
41 |
42 | $(NuGetToolsPath)\NuGet.exe
43 | @(PackageSource)
44 |
45 | "$(NuGetExePath)"
46 | mono --runtime=v4.0.30319 $(NuGetExePath)
47 |
48 | $(TargetDir.Trim('\\'))
49 |
50 | -RequireConsent
51 | -NonInteractive
52 |
53 | "$(SolutionDir) "
54 | "$(SolutionDir)"
55 |
56 |
57 | $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)
58 | $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols
59 |
60 |
61 |
62 | RestorePackages;
63 | $(BuildDependsOn);
64 |
65 |
66 |
67 |
68 | $(BuildDependsOn);
69 | BuildPackage;
70 |
71 |
72 |
73 |
74 |
75 |
76 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
91 |
92 |
95 |
96 |
97 |
98 |
100 |
101 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
133 |
134 |
135 |
136 |
--------------------------------------------------------------------------------
/Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raspberry-sharp/raspberry-sharp-system/2b481482a80e7063d794e16f69516bcb4022864f/Icon.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raspberry-sharp/raspberry-sharp-system/2b481482a80e7063d794e16f69516bcb4022864f/README.md
--------------------------------------------------------------------------------
/Raspberry.System.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Raspberry.System
5 | 0.0.0
6 | Raspberry.System
7 | Eric Bézine
8 | Raspberry-Sharp
9 | http://opensource.org/licenses/GPL-2.0
10 | https://github.com/raspberry-sharp/raspberry-sharp-system/wiki
11 | https://raw.github.com/raspberry-sharp/raspberry-sharp-system/master/Icon.png
12 | true
13 |
14 | Raspberry.System is a Mono/.NET assembly providing access to Raspberry Pi system features.
15 |
16 | It is an initiative of the Raspberry# Community, aimed at providing tools and information concerning use of Raspberry Pi boards with Mono/.NET framework.
17 | Visit project [Github site](https://github.com/raspberry-sharp/raspberry-sharp-system/) for documentation and samples.
18 |
19 | Raspberry.System is a Mono/.NET assembly providing access to Raspberry Pi system features.
20 | en-US
21 | Raspberry Pi Mono System Timers
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/Raspberry.System/Board.cs:
--------------------------------------------------------------------------------
1 | #region References
2 |
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Globalization;
6 | using System.IO;
7 |
8 | #endregion
9 |
10 | namespace Raspberry
11 | {
12 | ///
13 | /// Represents the Raspberry Pi mainboard.
14 | ///
15 | ///
16 | /// Version and revisions are based on .
17 | /// for information.
18 | ///
19 | public class Board
20 | {
21 | #region Fields
22 |
23 | private static readonly Lazy board = new Lazy(LoadBoard);
24 |
25 | private readonly Dictionary settings;
26 | private readonly Lazy model;
27 | private readonly Lazy connectorPinout;
28 |
29 | #endregion
30 |
31 | #region Instance Management
32 |
33 | private Board(Dictionary settings)
34 | {
35 | model = new Lazy(LoadModel);
36 | connectorPinout = new Lazy(LoadConnectorPinout);
37 |
38 | this.settings = settings;
39 | }
40 |
41 | #endregion
42 |
43 | #region Properties
44 |
45 | ///
46 | /// Gets the current mainboard configuration.
47 | ///
48 | public static Board Current
49 | {
50 | get { return board.Value; }
51 | }
52 |
53 | ///
54 | /// Gets a value indicating whether this instance is a Raspberry Pi.
55 | ///
56 | ///
57 | /// true if this instance is a Raspberry Pi; otherwise, false.
58 | ///
59 | public bool IsRaspberryPi
60 | {
61 | get
62 | {
63 | return Processor != Processor.Unknown;
64 | }
65 | }
66 |
67 | ///
68 | /// Gets the processor name.
69 | ///
70 | ///
71 | /// The name of the processor.
72 | ///
73 | public string ProcessorName
74 | {
75 | get
76 | {
77 | string hardware;
78 | return settings.TryGetValue("Hardware", out hardware) ? hardware : null;
79 | }
80 | }
81 |
82 | ///
83 | /// Gets the processor.
84 | ///
85 | ///
86 | /// The processor.
87 | ///
88 | public Processor Processor
89 | {
90 | get
91 | {
92 | Processor processor;
93 | return Enum.TryParse(ProcessorName, true, out processor) ? processor : Processor.Unknown;
94 | }
95 | }
96 |
97 | ///
98 | /// Gets the board firmware version.
99 | ///
100 | public int Firmware
101 | {
102 | get
103 | {
104 | string revision;
105 | int firmware;
106 | if (settings.TryGetValue("Revision", out revision)
107 | && !string.IsNullOrEmpty(revision)
108 | && int.TryParse(revision, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out firmware))
109 | return firmware;
110 |
111 | return 0;
112 | }
113 | }
114 |
115 | ///
116 | /// Gets the serial number.
117 | ///
118 | public string SerialNumber
119 | {
120 | get {
121 | string serial;
122 | if (settings.TryGetValue("Serial", out serial)
123 | && !string.IsNullOrEmpty(serial))
124 | return serial;
125 |
126 | return null;
127 | }
128 | }
129 |
130 | ///
131 | /// Gets a value indicating whether Raspberry Pi board is overclocked.
132 | ///
133 | ///
134 | /// true if Raspberry Pi is overclocked; otherwise, false.
135 | ///
136 | public bool IsOverclocked
137 | {
138 | get
139 | {
140 | var firmware = Firmware;
141 | return (firmware & 0xFFFF0000) != 0;
142 | }
143 | }
144 |
145 | ///
146 | /// Gets the model.
147 | ///
148 | ///
149 | /// The model.
150 | ///
151 | public Model Model
152 | {
153 | get { return model.Value; }
154 | }
155 |
156 | ///
157 | /// Gets the connector revision.
158 | ///
159 | ///
160 | /// The connector revision.
161 | ///
162 | /// See for more information.
163 | public ConnectorPinout ConnectorPinout
164 | {
165 | get { return connectorPinout.Value; }
166 | }
167 |
168 | #endregion
169 |
170 | #region Private Helpers
171 |
172 | private static Board LoadBoard()
173 | {
174 | try
175 | {
176 | const string filePath = "/proc/cpuinfo";
177 |
178 | var cpuInfo = File.ReadAllLines(filePath);
179 | var settings = new Dictionary();
180 | var suffix = string.Empty;
181 |
182 | foreach(var l in cpuInfo)
183 | {
184 | var separator = l.IndexOf(':');
185 |
186 | if (!string.IsNullOrWhiteSpace(l) && separator > 0)
187 | {
188 | var key = l.Substring(0, separator).Trim();
189 | var val = l.Substring(separator + 1).Trim();
190 | if (string.Equals(key, "processor", StringComparison.InvariantCultureIgnoreCase))
191 | suffix = "." + val;
192 |
193 | settings.Add(key + suffix, val);
194 | }
195 | else
196 | suffix = "";
197 | }
198 |
199 | return new Board(settings);
200 | }
201 | catch
202 | {
203 | return new Board(new Dictionary());
204 | }
205 | }
206 |
207 | private Model LoadModel()
208 | {
209 | var firmware = Firmware;
210 | switch (firmware & 0xFFFF)
211 | {
212 | case 0x2:
213 | case 0x3:
214 | return Model.BRev1;
215 |
216 | case 0x4:
217 | case 0x5:
218 | case 0x6:
219 | case 0xd:
220 | case 0xe:
221 | case 0xf:
222 | return Model.BRev2;
223 |
224 | case 0x7:
225 | case 0x8:
226 | case 0x9:
227 | return Model.A;
228 |
229 | case 0x10:
230 | return Model.BPlus;
231 |
232 | case 0x11:
233 | return Model.ComputeModule;
234 |
235 | case 0x12:
236 | return Model.APlus;
237 |
238 | case 0x1040:
239 | case 0x1041:
240 | return Model.B2;
241 |
242 | case 0x0092:
243 | case 0x0093:
244 | return Model.Zero;
245 |
246 | case 0x2082:
247 | return Model.B3;
248 |
249 | default:
250 | return Model.Unknown;
251 | }
252 | }
253 |
254 | private ConnectorPinout LoadConnectorPinout()
255 | {
256 | switch (Model)
257 | {
258 | case Model.BRev1:
259 | return ConnectorPinout.Rev1;
260 |
261 | case Model.BRev2:
262 | case Model.A:
263 | return ConnectorPinout.Rev2;
264 |
265 | case Model.BPlus:
266 | case Model.ComputeModule:
267 | case Model.APlus:
268 | case Model.B2:
269 | case Model.Zero:
270 | case Model.B3:
271 | return ConnectorPinout.Plus;
272 |
273 | default:
274 | return ConnectorPinout.Unknown;
275 | }
276 | }
277 |
278 | #endregion
279 | }
280 | }
--------------------------------------------------------------------------------
/Raspberry.System/ConnectorPinout.cs:
--------------------------------------------------------------------------------
1 | namespace Raspberry
2 | {
3 | ///
4 | /// The Raspberry Pi connector pinout revision.
5 | ///
6 | public enum ConnectorPinout
7 | {
8 | ///
9 | /// Connector pinout is unknown.
10 | ///
11 | Unknown,
12 |
13 | ///
14 | /// The first revision, as of Model B rev1.
15 | ///
16 | Rev1,
17 |
18 | ///
19 | /// The second revision, as of Model B rev2.
20 | ///
21 | Rev2,
22 |
23 | ///
24 | /// The third revision, as of Model B+.
25 | ///
26 | Plus,
27 | }
28 | }
--------------------------------------------------------------------------------
/Raspberry.System/Model.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 |
4 | namespace Raspberry
5 | {
6 | ///
7 | /// The Rasperry Pi model.
8 | ///
9 | public enum Model
10 | {
11 | ///
12 | /// Unknown model.
13 | ///
14 | Unknown,
15 |
16 | ///
17 | /// Model A.
18 | ///
19 | A,
20 |
21 | ///
22 | /// Model A+.
23 | ///
24 | APlus,
25 |
26 | ///
27 | /// Model B rev1.
28 | ///
29 | BRev1,
30 |
31 | ///
32 | /// Model B rev2.
33 | ///
34 | BRev2,
35 |
36 | ///
37 | /// Model B+.
38 | ///
39 | BPlus,
40 |
41 | ///
42 | /// Compute module.
43 | ///
44 | ComputeModule,
45 |
46 | ///
47 | /// Pi 2 Model B.
48 | ///
49 | B2,
50 |
51 | ///
52 | /// Pi Zero.
53 | ///
54 | Zero,
55 |
56 | ///
57 | /// Pi 3 Model B.
58 | ///
59 | B3
60 | }
61 |
62 | ///
63 | /// Provides extension methods for .
64 | ///
65 | public static class ModelExtensionMethods
66 | {
67 | ///
68 | /// Gets the model display name.
69 | ///
70 | /// The model.
71 | /// The display name, if known; otherwise, null.
72 | public static string GetDisplayName(this Model model)
73 | {
74 | switch (model)
75 | {
76 | case Model.Unknown:
77 | return null;
78 | case Model.A:
79 | return "Raspberry Pi Model A";
80 | case Model.APlus:
81 | return "Raspberry Pi Model A+";
82 | case Model.BRev1:
83 | return "Raspberry Pi Model B rev1";
84 | case Model.BRev2:
85 | return "Raspberry Pi Model B rev2";
86 | case Model.BPlus:
87 | return "Raspberry Pi Model B+";
88 | case Model.ComputeModule:
89 | return "Raspberry Pi Compute Module";
90 | case Model.B2:
91 | return "Raspberry Pi 2 Model B";
92 | case Model.Zero:
93 | return "Raspberry Pi Zero";
94 | case Model.B3:
95 | return "Raspberry Pi 3 Model B";
96 |
97 | default:
98 | throw new ArgumentOutOfRangeException("model");
99 | }
100 | }
101 | }
102 | }
--------------------------------------------------------------------------------
/Raspberry.System/Processor.cs:
--------------------------------------------------------------------------------
1 | namespace Raspberry
2 | {
3 | ///
4 | /// The Raspberry Pi processor.
5 | ///
6 | public enum Processor
7 | {
8 | ///
9 | /// Processor is unknown.
10 | ///
11 | Unknown,
12 |
13 | ///
14 | /// Processor is a BCM2708.
15 | ///
16 | Bcm2708,
17 |
18 | ///
19 | /// Processor is a BCM2709.
20 | ///
21 | Bcm2709
22 | }
23 | }
--------------------------------------------------------------------------------
/Raspberry.System/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("Raspberry.System")]
8 | [assembly: AssemblyDescription("Raspberry Pi System Mono Library")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("Raspberry#")]
11 | [assembly: AssemblyProduct("Raspberry.System")]
12 | [assembly: AssemblyCopyright("www.raspberry-sharp.org, 2012-2013")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("da7e973a-7d7c-461c-aca2-e9de7809fb86")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("1.2.0.0")]
35 | [assembly: AssemblyFileVersion("1.2.0.0")]
36 |
--------------------------------------------------------------------------------
/Raspberry.System/Raspberry.System.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | {2C0C9AAF-4EDD-4C79-961B-E7BC4FC4EB0C}
9 | Library
10 | Properties
11 | Raspberry
12 | Raspberry.System
13 | v4.0
14 | 512
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 | bin\Debug\Raspberry.System.xml
25 |
26 |
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 | bin\Release\Raspberry.System.xml
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
60 |
--------------------------------------------------------------------------------
/Raspberry.System/Timers/HighResolutionTimer.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/raspberry-sharp/raspberry-sharp-system/2b481482a80e7063d794e16f69516bcb4022864f/Raspberry.System/Timers/HighResolutionTimer.cs
--------------------------------------------------------------------------------
/Raspberry.System/Timers/ITimer.cs:
--------------------------------------------------------------------------------
1 | #region References
2 |
3 | using System;
4 |
5 | #endregion
6 |
7 | namespace Raspberry.Timers
8 | {
9 | ///
10 | /// Provides an interface for a timer.
11 | ///
12 | public interface ITimer
13 | {
14 | #region Properties
15 |
16 | ///
17 | /// Gets or sets the interval.
18 | ///
19 | ///
20 | /// The interval.
21 | ///
22 | TimeSpan Interval { get; set; }
23 |
24 | ///
25 | /// Gets or sets the action.
26 | ///
27 | ///
28 | /// The action.
29 | ///
30 | Action Action { get; set; }
31 |
32 | #endregion
33 |
34 | #region Methods
35 |
36 | ///
37 | /// Starts this instance.
38 | ///
39 | /// The delay before the first occurence.
40 | void Start(TimeSpan startDelay);
41 |
42 | ///
43 | /// Stops this instance.
44 | ///
45 | void Stop();
46 |
47 | #endregion
48 | }
49 | }
--------------------------------------------------------------------------------
/Raspberry.System/Timers/Interop.cs:
--------------------------------------------------------------------------------
1 | #region References
2 |
3 | using System;
4 | using System.Runtime.InteropServices;
5 |
6 | #endregion
7 |
8 | namespace Raspberry.Timers
9 | {
10 | internal static class Interop
11 | {
12 | #region Constants
13 |
14 | public static int CLOCK_MONOTONIC_RAW = 4;
15 |
16 | #endregion
17 |
18 | #region Classes
19 |
20 | public struct timespec
21 | {
22 | public IntPtr tv_sec; /* seconds */
23 | public IntPtr tv_nsec; /* nanoseconds */
24 | }
25 |
26 | #endregion
27 |
28 | #region Methods
29 |
30 | [DllImport("libc.so.6")]
31 | public static extern int nanosleep(ref timespec req, ref timespec rem);
32 |
33 | #endregion
34 | }
35 | }
--------------------------------------------------------------------------------
/Raspberry.System/Timers/StandardTimer.cs:
--------------------------------------------------------------------------------
1 | #region References
2 |
3 | using System;
4 |
5 | #endregion
6 |
7 | namespace Raspberry.Timers
8 | {
9 | ///
10 | /// Represents a timer.
11 | ///
12 | public class StandardTimer : ITimer
13 | {
14 | #region Fields
15 |
16 | private TimeSpan interval;
17 | private Action action;
18 |
19 | private bool isStarted;
20 | private System.Threading.Timer timer;
21 |
22 | #endregion
23 |
24 | #region Properties
25 |
26 | ///
27 | /// Gets or sets the interval, in milliseconds.
28 | ///
29 | ///
30 | /// The interval, in milliseconds.
31 | ///
32 | public TimeSpan Interval
33 | {
34 | get { return interval; }
35 | set
36 | {
37 | interval = value;
38 | if (isStarted)
39 | Start(TimeSpan.Zero);
40 | }
41 | }
42 |
43 | ///
44 | /// Gets or sets the action.
45 | ///
46 | ///
47 | /// The action.
48 | ///
49 | public Action Action
50 | {
51 | get { return action; }
52 | set
53 | {
54 | if (value == null)
55 | Stop();
56 |
57 | action = value;
58 | }
59 | }
60 |
61 | #endregion
62 |
63 | #region Methods
64 |
65 | ///
66 | /// Starts this instance.
67 | ///
68 | /// The delay before the first occurence, in milliseconds.
69 | public void Start(TimeSpan startDelay)
70 | {
71 | lock (this)
72 | {
73 | if (!isStarted && interval.TotalMilliseconds >= 1)
74 | {
75 | isStarted = true;
76 | timer = new System.Threading.Timer(OnElapsed, null, startDelay, interval);
77 | }
78 | else
79 | Stop();
80 | }
81 | }
82 |
83 | ///
84 | /// Stops this instance.
85 | ///
86 | public void Stop()
87 | {
88 | lock (this)
89 | {
90 | if (isStarted)
91 | {
92 | isStarted = false;
93 | timer.Dispose();
94 | timer = null;
95 | }
96 | }
97 | }
98 |
99 | #endregion
100 |
101 | #region Private Helpers
102 |
103 | private void NoOp(){}
104 |
105 | private void OnElapsed(object state)
106 | {
107 | (Action ?? NoOp)();
108 | }
109 |
110 | #endregion
111 | }
112 | }
--------------------------------------------------------------------------------
/Raspberry.System/Timers/TimeSpanUtility.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Raspberry.Timers
4 | {
5 | ///
6 | /// Provides utilities for .
7 | ///
8 | public static class TimeSpanUtility
9 | {
10 | ///
11 | /// Creates a timespan from a number of microseconds.
12 | ///
13 | /// The microseconds.
14 | ///
15 | public static TimeSpan FromMicroseconds(double microseconds)
16 | {
17 | return TimeSpan.FromTicks((long)(microseconds/10));
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/Raspberry.System/Timers/Timer.cs:
--------------------------------------------------------------------------------
1 | #region References
2 |
3 | using System;
4 | using System.Threading;
5 |
6 | #endregion
7 |
8 | namespace Raspberry.Timers
9 | {
10 | ///
11 | /// Provides access to timing features.
12 | ///
13 | public static class Timer
14 | {
15 | #region Methods
16 |
17 | ///
18 | /// Creates a timer.
19 | ///
20 | /// The timer.
21 | ///
22 | /// The created timer is the most suitable for the current platform.
23 | ///
24 | public static ITimer Create()
25 | {
26 | return Board.Current.IsRaspberryPi
27 | ? (ITimer) new HighResolutionTimer()
28 | : new StandardTimer();
29 | }
30 |
31 | ///
32 | /// Sleeps during the specified time.
33 | ///
34 | /// The time.
35 | public static void Sleep(TimeSpan time)
36 | {
37 | if (time.TotalMilliseconds < 0)
38 | return;
39 |
40 | if (Board.Current.IsRaspberryPi)
41 | HighResolutionTimer.Sleep(time);
42 | else
43 | Thread.Sleep(time);
44 | }
45 |
46 | #endregion
47 | }
48 | }
--------------------------------------------------------------------------------
/RaspberrySharp.System.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.31101.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DE3AA526-5A9D-465A-B9B0-7A07AE6824B5}"
7 | ProjectSection(SolutionItems) = preProject
8 | Icon.png = Icon.png
9 | Raspberry.System.nuspec = Raspberry.System.nuspec
10 | README.md = README.md
11 | EndProjectSection
12 | EndProject
13 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Raspberry.System", "Raspberry.System\Raspberry.System.csproj", "{2C0C9AAF-4EDD-4C79-961B-E7BC4FC4EB0C}"
14 | EndProject
15 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.Board", "Test.Board\Test.Board.csproj", "{51780F8A-E5F5-4DC8-84B4-B282800A3396}"
16 | EndProject
17 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{9D7C7530-F5CB-49BF-891B-7E1C705510EF}"
18 | ProjectSection(SolutionItems) = preProject
19 | .nuget\NuGet.Config = .nuget\NuGet.Config
20 | .nuget\NuGet.exe = .nuget\NuGet.exe
21 | .nuget\NuGet.targets = .nuget\NuGet.targets
22 | EndProjectSection
23 | EndProject
24 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{7102091A-58D6-4ACC-90B7-6729AEF0586F}"
25 | EndProject
26 | Global
27 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
28 | Debug|Any CPU = Debug|Any CPU
29 | Debug|Mixed Platforms = Debug|Mixed Platforms
30 | Debug|x86 = Debug|x86
31 | Release|Any CPU = Release|Any CPU
32 | Release|Mixed Platforms = Release|Mixed Platforms
33 | Release|x86 = Release|x86
34 | EndGlobalSection
35 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
36 | {2C0C9AAF-4EDD-4C79-961B-E7BC4FC4EB0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 | {2C0C9AAF-4EDD-4C79-961B-E7BC4FC4EB0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 | {2C0C9AAF-4EDD-4C79-961B-E7BC4FC4EB0C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
39 | {2C0C9AAF-4EDD-4C79-961B-E7BC4FC4EB0C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
40 | {2C0C9AAF-4EDD-4C79-961B-E7BC4FC4EB0C}.Debug|x86.ActiveCfg = Debug|Any CPU
41 | {2C0C9AAF-4EDD-4C79-961B-E7BC4FC4EB0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
42 | {2C0C9AAF-4EDD-4C79-961B-E7BC4FC4EB0C}.Release|Any CPU.Build.0 = Release|Any CPU
43 | {2C0C9AAF-4EDD-4C79-961B-E7BC4FC4EB0C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
44 | {2C0C9AAF-4EDD-4C79-961B-E7BC4FC4EB0C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
45 | {2C0C9AAF-4EDD-4C79-961B-E7BC4FC4EB0C}.Release|x86.ActiveCfg = Release|Any CPU
46 | {51780F8A-E5F5-4DC8-84B4-B282800A3396}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47 | {51780F8A-E5F5-4DC8-84B4-B282800A3396}.Debug|Any CPU.Build.0 = Debug|Any CPU
48 | {51780F8A-E5F5-4DC8-84B4-B282800A3396}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
49 | {51780F8A-E5F5-4DC8-84B4-B282800A3396}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
50 | {51780F8A-E5F5-4DC8-84B4-B282800A3396}.Debug|x86.ActiveCfg = Debug|Any CPU
51 | {51780F8A-E5F5-4DC8-84B4-B282800A3396}.Release|Any CPU.ActiveCfg = Release|Any CPU
52 | {51780F8A-E5F5-4DC8-84B4-B282800A3396}.Release|Any CPU.Build.0 = Release|Any CPU
53 | {51780F8A-E5F5-4DC8-84B4-B282800A3396}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
54 | {51780F8A-E5F5-4DC8-84B4-B282800A3396}.Release|Mixed Platforms.Build.0 = Release|Any CPU
55 | {51780F8A-E5F5-4DC8-84B4-B282800A3396}.Release|x86.ActiveCfg = Release|Any CPU
56 | EndGlobalSection
57 | GlobalSection(SolutionProperties) = preSolution
58 | HideSolutionNode = FALSE
59 | EndGlobalSection
60 | GlobalSection(NestedProjects) = preSolution
61 | {51780F8A-E5F5-4DC8-84B4-B282800A3396} = {7102091A-58D6-4ACC-90B7-6729AEF0586F}
62 | EndGlobalSection
63 | EndGlobal
64 |
--------------------------------------------------------------------------------
/Test.Board/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Raspberry;
3 |
4 | namespace Test.Board
5 | {
6 | class Program
7 | {
8 | static void Main()
9 | {
10 | var board = Raspberry.Board.Current;
11 |
12 | if (!board.IsRaspberryPi)
13 | Console.WriteLine("System is not a Raspberry Pi");
14 | else
15 | {
16 | Console.WriteLine("Raspberry Pi running on {0} processor", board.Processor);
17 | Console.WriteLine("Firmware rev{0}, board model {1} ({2})", board.Firmware, board.Model, board.Model.GetDisplayName() ?? "Unknown");
18 | Console.WriteLine();
19 | Console.WriteLine("Serial number: {0}", board.SerialNumber);
20 | }
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Test.Board/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("Test.Board")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("Test.Board")]
12 | [assembly: AssemblyCopyright("www.raspberry-sharp.org, 2012")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("ee76e8af-1cd4-4e5a-b8ad-eaa07f219ec9")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/Test.Board/Test.Board.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | {51780F8A-E5F5-4DC8-84B4-B282800A3396}
9 | Exe
10 | Properties
11 | Test.Board
12 | Test.Board
13 | v4.0
14 | Client
15 | 512
16 |
17 |
18 | AnyCPU
19 | true
20 | full
21 | false
22 | bin\Debug\
23 | DEBUG;TRACE
24 | prompt
25 | 4
26 |
27 |
28 | AnyCPU
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | {2C0C9AAF-4EDD-4C79-961B-E7BC4FC4EB0C}
47 | Raspberry.System
48 |
49 |
50 |
51 |
58 |
--------------------------------------------------------------------------------