Skip to content

Commit b0fcd8c

Browse files
author
Eric Bézine
committed
Updated Board.Revision
Added Board.Model and updated Board.Revision to reflect evolution in Raspberry boards and models
1 parent ab20049 commit b0fcd8c

File tree

3 files changed

+57
-13
lines changed

3 files changed

+57
-13
lines changed

Raspberry.System/Board.cs

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using System;
44
using System.Collections.Generic;
5+
using System.Globalization;
56
using System.IO;
67
using System.Linq;
78

@@ -12,6 +13,7 @@ namespace Raspberry
1213
/// <summary>
1314
/// Represents the Raspberry Pi mainboard.
1415
/// </summary>
16+
/// <remarks>Version and revisions are based on <see cref="http://raspberryalphaomega.org.uk/2013/02/06/automatic-raspberry-pi-board-revision-detection-model-a-b1-and-b2/"/>.</remarks>
1517
public class Board
1618
{
1719
#region Fields
@@ -74,7 +76,7 @@ public int Firmware
7476
{
7577
string revision;
7678
int firmware;
77-
if (settings.TryGetValue("Revision", out revision) && !string.IsNullOrEmpty(revision) && int.TryParse(revision, out firmware))
79+
if (settings.TryGetValue("Revision", out revision) && !string.IsNullOrEmpty(revision) && int.TryParse(revision, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out firmware))
7880
return firmware;
7981

8082
return 0;
@@ -95,26 +97,68 @@ public string SerialNumber
9597
}
9698
}
9799

100+
/// <summary>
101+
/// Gets the model.
102+
/// </summary>
103+
/// <returns>The model name (<c>A</c> or <c>B</c>) if known; otherwise, <c>(char)0</c>.</returns>
104+
public char Model
105+
{
106+
get
107+
{
108+
var firmware = Firmware;
109+
switch(firmware)
110+
{
111+
case 0x7:
112+
case 0x8:
113+
case 0x9:
114+
return 'A';
115+
116+
case 0x2:
117+
case 0x3:
118+
case 0x4:
119+
case 0x5:
120+
case 0x6:
121+
case 0xd:
122+
case 0xe:
123+
case 0xf:
124+
return 'B';
125+
126+
default:
127+
return (char)0;
128+
}
129+
}
130+
}
131+
98132
/// <summary>
99133
/// Gets the board revision.
100134
/// </summary>
135+
/// <returns>The board revision for the given <see cref="Model"/> if known; otherwise, <c>0</c>.</returns>
101136
public int Revision
102137
{
103138
get
104139
{
105140
var firmware = Firmware;
106141
switch (firmware)
107142
{
108-
case 2:
109-
case 3:
110-
return 1;
111-
case 4:
112-
case 5:
113-
case 6:
114-
return 2;
143+
case 0x7:
144+
case 0x8:
145+
case 0x9:
146+
return 1; // Model A, rev1
147+
148+
case 0x2:
149+
case 0x3:
150+
return 1; // Model B, rev1
151+
152+
case 0x4:
153+
case 0x5:
154+
case 0x6:
155+
case 0xd:
156+
case 0xe:
157+
case 0xf:
158+
return 2; // Model B, rev2
115159

116160
default:
117-
return 0;
161+
return 0; // Unknown
118162
}
119163
}
120164
}

Raspberry.System/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[assembly: AssemblyConfiguration("")]
1010
[assembly: AssemblyCompany("")]
1111
[assembly: AssemblyProduct("Raspberry.System")]
12-
[assembly: AssemblyCopyright("www.raspberry-sharp.org, 2012")]
12+
[assembly: AssemblyCopyright("www.raspberry-sharp.org, 2012-2013")]
1313
[assembly: AssemblyTrademark("")]
1414
[assembly: AssemblyCulture("")]
1515

@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.0.0.0")]
35-
[assembly: AssemblyFileVersion("1.0.0.0")]
34+
[assembly: AssemblyVersion("1.1.0.0")]
35+
[assembly: AssemblyFileVersion("1.1.0.0")]

Test.Board/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ static void Main(string[] args)
1313
else
1414
{
1515
Console.WriteLine("Raspberry Pi running on {0} processor", board.Processor);
16-
Console.WriteLine("Firmware rev{0}, board rev{1}", board.Firmware, board.Revision);
16+
Console.WriteLine("Firmware rev{0}, board model {1} rev{2}", board.Firmware, board.Model, board.Revision);
1717
Console.WriteLine();
1818
Console.WriteLine("Serial number: {0}", board.SerialNumber);
1919
}

0 commit comments

Comments
 (0)