44using System . Collections . Generic ;
55using System . Globalization ;
66using System . IO ;
7- using System . Linq ;
87
98#endregion
109
@@ -19,9 +18,9 @@ public class Board
1918 #region Fields
2019
2120 private static readonly Lazy < Board > board = new Lazy < Board > ( LoadBoard ) ;
22- private readonly Dictionary < string , string > settings ;
2321
24- private const string raspberryPiProcessor = "BCM2708" ;
22+ private readonly Dictionary < string , string > settings ;
23+ private readonly HashSet < string > raspberryPiProcessors = new HashSet < string > ( new [ ] { "BCM2708" , "BCM2709" } , StringComparer . InvariantCultureIgnoreCase ) ;
2524
2625 #endregion
2726
@@ -52,7 +51,7 @@ public static Board Current
5251 /// </value>
5352 public bool IsRaspberryPi
5453 {
55- get { return string . Equals ( Processor , raspberryPiProcessor , StringComparison . InvariantCultureIgnoreCase ) ; }
54+ get { return raspberryPiProcessors . Contains ( Processor ) ; }
5655 }
5756
5857 /// <summary>
@@ -76,7 +75,9 @@ public int Firmware
7675 {
7776 string revision ;
7877 int firmware ;
79- if ( settings . TryGetValue ( "Revision" , out revision ) && ! string . IsNullOrEmpty ( revision ) && int . TryParse ( revision , NumberStyles . HexNumber , CultureInfo . InvariantCulture , out firmware ) )
78+ if ( settings . TryGetValue ( "Revision" , out revision )
79+ && ! string . IsNullOrEmpty ( revision )
80+ && int . TryParse ( revision , NumberStyles . HexNumber , CultureInfo . InvariantCulture , out firmware ) )
8081 return firmware ;
8182
8283 return 0 ;
@@ -90,7 +91,8 @@ public string SerialNumber
9091 {
9192 get {
9293 string serial ;
93- if ( settings . TryGetValue ( "Serial" , out serial ) && ! string . IsNullOrEmpty ( serial ) )
94+ if ( settings . TryGetValue ( "Serial" , out serial )
95+ && ! string . IsNullOrEmpty ( serial ) )
9496 return serial ;
9597
9698 return null ;
@@ -139,6 +141,10 @@ public char Model
139141 case 0x10 :
140142 return 'B' ;
141143
144+ case 0x1040 :
145+ case 0x1041 :
146+ return '2' ;
147+
142148 default :
143149 return ( char ) 0 ;
144150 }
@@ -175,6 +181,10 @@ public int Revision
175181
176182 case 0x10 :
177183 return 3 ; // Model B+, rev3
184+
185+ case 0x1040 :
186+ case 0x1041 :
187+ return 4 ;
178188
179189 default :
180190 return 0 ; // Unknown
@@ -191,16 +201,27 @@ private static Board LoadBoard()
191201 try
192202 {
193203 const string filePath = "/proc/cpuinfo" ;
194- var settings = File . ReadAllLines ( filePath )
195- . Where ( l => ! string . IsNullOrEmpty ( l ) )
196- . Select ( l =>
204+
205+ var cpuInfo = File . ReadAllLines ( filePath ) ;
206+ var settings = new Dictionary < string , string > ( ) ;
207+ var suffix = string . Empty ;
208+
209+ foreach ( var l in cpuInfo )
210+ {
211+ var separator = l . IndexOf ( ':' ) ;
212+
213+ if ( ! string . IsNullOrWhiteSpace ( l ) && separator > 0 )
197214 {
198- var separator = l . IndexOf ( ':' ) ;
199- return separator >= 0
200- ? new KeyValuePair < string , string > ( l . Substring ( 0 , separator ) . Trim ( ) , l . Substring ( separator + 1 ) . Trim ( ) )
201- : new KeyValuePair < string , string > ( l , null ) ;
202- } )
203- . ToDictionary ( p => p . Key , p => p . Value ) ;
215+ var key = l . Substring ( 0 , separator ) . Trim ( ) ;
216+ var val = l . Substring ( separator + 1 ) . Trim ( ) ;
217+ if ( string . Equals ( key , "processor" , StringComparison . InvariantCultureIgnoreCase ) )
218+ suffix = "." + val ;
219+
220+ settings . Add ( key + suffix , val ) ;
221+ }
222+ else
223+ suffix = "" ;
224+ }
204225
205226 return new Board ( settings ) ;
206227 }
0 commit comments