Skip to content

Commit 21be188

Browse files
author
Eric Bézine
committed
Introducing Raspberry# System
1 parent fdd5b91 commit 21be188

18 files changed

+845
-4
lines changed

.gitattributes

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ bin
33
obj
44

55
# mstest test results
6-
TestResults
6+
TestResults
7+
8+
# user files
9+
**.user
10+
**.suo

Icon.png

30.3 KB
Loading

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
raspberry-sharp-system
2-
======================
1+
Raspberry# System
2+
=================
33

4-
A .NET/Mono Library for Raspberry Pi
4+
See the **[Raspberry\# System Wiki](raspberry-sharp-system/wiki)** for full documentation and samples.
5+
6+
Introduction
7+
------------
8+
Raspberry# System is a .NET/Mono Library for Raspberry Pi. This project is an initiative of the [Raspberry#](http://www.raspberry-sharp.org) Community.
9+
10+
Current release is an early public release. Some features may not have been extensively tested.
11+
Raspberry# System currently supports high resolution timer, as well as Raspberry Pi system board identification.
12+
13+
Features
14+
--------
15+
16+
### Raspberry.System
17+
Raspberry.System provides utilities for Raspberry Pi boards, while using .NET concepts, syntax and case.
18+
You can easily add a reference to it in your Visual Studio projects using the **[Raspberry.System Nuget](https://www.nuget.org/packages/Raspberry.System)**.
19+
20+
It currently support the following features:
21+
+ Automatic detection of various Raspberry Pi revisions, for now **Raspberry B rev1 and rev2**
22+
+ High resolution (about 1µs) timers

Raspberry.System.nuspec

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3+
<metadata>
4+
<id>Raspberry.System</id>
5+
<version>0.0.0</version>
6+
<title>Raspberry.System</title>
7+
<authors>Eric Bézine</authors>
8+
<owners>Raspberry-Sharp</owners>
9+
<licenseUrl>http://opensource.org/licenses/GPL-2.0</licenseUrl>
10+
<projectUrl>https://github.com/raspberry-sharp/raspberry-sharp-system/wiki</projectUrl>
11+
<iconUrl>https://raw.github.com/raspberry-sharp/raspberry-sharp-system/master/Icon.png</iconUrl>
12+
<requireLicenseAcceptance>true</requireLicenseAcceptance>
13+
<description>
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+
Parts of this work are based on [BCM2835 C library](http://www.open.com.au/mikem/bcm2835/).
18+
19+
Visit project [Github site](https://github.com/raspberry-sharp/raspberry-sharp-system/) for documentation and samples.
20+
</description>
21+
<summary>Raspberry.System is a Mono/.NET assembly providing access to Raspberry Pi system features.</summary>
22+
<language>en-US</language>
23+
<tags>Raspberry Pi Mono System Timers</tags>
24+
<frameworkAssemblies>
25+
<frameworkAssembly assemblyName="System.Configuration" targetFramework="net40" />
26+
<frameworkAssembly assemblyName="System.Core" targetFramework="net40" />
27+
</frameworkAssemblies>
28+
</metadata>
29+
<files>
30+
<file src="Raspberry.System\bin\release\Raspberry.System.dll" target="lib\net40" />
31+
<file src="Raspberry.System\bin\release\Raspberry.System.pdb" target="lib\net40" />
32+
<file src="Raspberry.System\bin\release\Raspberry.System.xml" target="lib\net40" />
33+
<file src="Raspberry.System\bin\release\libbcm2835.so" target="lib\net40" />
34+
<file src="Raspberry.System\**\*.cs" target="src" />
35+
</files>
36+
</package>

Raspberry.System/Board.cs

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#region References
2+
3+
using System;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Linq;
7+
8+
#endregion
9+
10+
namespace Raspberry
11+
{
12+
/// <summary>
13+
/// Represents the Raspberry Pi mainboard.
14+
/// </summary>
15+
public class Board
16+
{
17+
#region Fields
18+
19+
private static readonly Lazy<Board> board = new Lazy<Board>(LoadBoard);
20+
private readonly Dictionary<string, string> settings;
21+
22+
private const string raspberryPiProcessor = "BCM2708";
23+
24+
#endregion
25+
26+
#region Instance Management
27+
28+
private Board(Dictionary<string, string> settings)
29+
{
30+
this.settings = settings;
31+
}
32+
33+
#endregion
34+
35+
#region Properties
36+
37+
/// <summary>
38+
/// Gets the current mainboard configuration.
39+
/// </summary>
40+
public static Board Current
41+
{
42+
get { return board.Value; }
43+
}
44+
45+
/// <summary>
46+
/// Gets a value indicating whether this instance is a Raspberry Pi.
47+
/// </summary>
48+
/// <value>
49+
/// <c>true</c> if this instance is a Raspberry Pi; otherwise, <c>false</c>.
50+
/// </value>
51+
public bool IsRaspberryPi
52+
{
53+
get { return string.Equals(Processor, raspberryPiProcessor, StringComparison.InvariantCultureIgnoreCase); }
54+
}
55+
56+
/// <summary>
57+
/// Gets the processor.
58+
/// </summary>
59+
public string Processor
60+
{
61+
get
62+
{
63+
string hardware;
64+
return settings.TryGetValue("Hardware", out hardware) ? hardware : null;
65+
}
66+
}
67+
68+
/// <summary>
69+
/// Gets the board firmware version.
70+
/// </summary>
71+
public int Firmware
72+
{
73+
get
74+
{
75+
string revision;
76+
int firmware;
77+
if (settings.TryGetValue("Revision", out revision) && !string.IsNullOrEmpty(revision) && int.TryParse(revision, out firmware))
78+
return firmware;
79+
80+
return 0;
81+
}
82+
}
83+
84+
/// <summary>
85+
/// Gets the serial number.
86+
/// </summary>
87+
public string SerialNumber
88+
{
89+
get {
90+
string serial;
91+
if (settings.TryGetValue("Serial", out serial) && !string.IsNullOrEmpty(serial))
92+
return serial;
93+
94+
return null;
95+
}
96+
}
97+
98+
/// <summary>
99+
/// Gets the board revision.
100+
/// </summary>
101+
public int Revision
102+
{
103+
get
104+
{
105+
var firmware = Firmware;
106+
switch (firmware)
107+
{
108+
case 2:
109+
case 3:
110+
return 1;
111+
case 4:
112+
case 5:
113+
case 6:
114+
return 2;
115+
116+
default:
117+
return 0;
118+
}
119+
}
120+
}
121+
122+
#endregion
123+
124+
#region Private Helpers
125+
126+
private static Board LoadBoard()
127+
{
128+
try
129+
{
130+
const string filePath = "/proc/cpuinfo";
131+
var settings = File.ReadAllLines(filePath)
132+
.Where(l => !string.IsNullOrEmpty(l))
133+
.Select(l =>
134+
{
135+
var separator = l.IndexOf(':');
136+
if (separator < 0)
137+
return new KeyValuePair<string, string>(l, null);
138+
else
139+
return new KeyValuePair<string, string>(l.Substring(0, separator).Trim(), l.Substring(separator + 1).Trim());
140+
})
141+
.ToDictionary(p => p.Key, p => p.Value);
142+
143+
return new Board(settings);
144+
}
145+
catch
146+
{
147+
return new Board(new Dictionary<string, string>());
148+
}
149+
}
150+
151+
#endregion
152+
}
153+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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("")]
11+
[assembly: AssemblyProduct("Raspberry.System")]
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("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.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{2C0C9AAF-4EDD-4C79-961B-E7BC4FC4EB0C}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>Raspberry</RootNamespace>
12+
<AssemblyName>Raspberry.System</AssemblyName>
13+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
<DocumentationFile>bin\Debug\Raspberry.System.xml</DocumentationFile>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
<DocumentationFile>bin\Release\Raspberry.System.xml</DocumentationFile>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="System" />
37+
<Reference Include="System.Core" />
38+
</ItemGroup>
39+
<ItemGroup>
40+
<Compile Include="Board.cs" />
41+
<Compile Include="Timers\Interop.cs" />
42+
<Compile Include="Properties\AssemblyInfo.cs" />
43+
<Compile Include="Timers\HighResolutionTimer.cs" />
44+
<Compile Include="Timers\ITimer.cs" />
45+
<Compile Include="Timers\StandardTimer.cs" />
46+
<Compile Include="Timers\Timer.cs" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<None Include="libbcm2835.so">
50+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
51+
</None>
52+
</ItemGroup>
53+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
54+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
55+
Other similar extension points exist, see Microsoft.Common.targets.
56+
<Target Name="BeforeBuild">
57+
</Target>
58+
<Target Name="AfterBuild">
59+
</Target>
60+
-->
61+
</Project>

0 commit comments

Comments
 (0)