提交 8599c190 编写于 作者: J John Tasler 提交者: John Tasler

Added RPi detection for Windows. Moved linux detection constants out of the...

Added RPi detection for Windows. Moved linux detection constants out of the primary GpioController.cs file.
上级 6e34fdcf
......@@ -12,9 +12,10 @@
<Compile Remove="winmd\**" />
<EmbeddedResource Remove="winmd\**" />
<None Remove="winmd\**" />
<PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0" /> <!-- This is Windows specific -->
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.1" />
<PackageReference Include="System.Memory" Version="4.5.1" />
<PackageReference Include="System.Runtime.InteropServices.WindowsRuntime" Version="4.3.0" />
<PackageReference Include="System.Runtime.InteropServices.WindowsRuntime" Version="4.3.0" /> <!-- This is Windows specific -->
</ItemGroup>
<ItemGroup Condition="'$(TargetsLinux)' == 'true'">
<!--Excluding Windows implementations-->
......
......@@ -6,7 +6,7 @@ using System.Threading;
namespace System.Device.Gpio.Drivers
{
public partial class Windows10Driver : GpioDriver
public class Windows10Driver : GpioDriver
{
public Windows10Driver()
{
......
......@@ -10,7 +10,7 @@ using WinGpio = global::Windows.Devices.Gpio;
namespace System.Device.Gpio.Drivers
{
public partial class Windows10Driver : GpioDriver
public class Windows10Driver : GpioDriver
{
#region Fields
private static readonly WinGpio.GpioController s_winGpioController = WinGpio.GpioController.GetDefault();
......
......@@ -10,6 +10,10 @@ namespace System.Device.Gpio
{
public sealed partial class GpioController
{
private const string CpuInfoPath = "/proc/cpuinfo";
private const string RaspberryPiHardware = "BCM2835";
private const string HummingBoardHardware = @"Freescale i.MX6 Quad/DualLite (Device Tree)";
/// <summary>
/// Controller that takes in a numbering scheme. Will default to use the driver that best applies given the platform the program is running on.
/// </summary>
......@@ -25,7 +29,7 @@ namespace System.Device.Gpio
/// <returns>A driver which works on the current running board.</returns>
private static GpioDriver GetBestDriverForBoard()
{
string[] cpuInfoLines = File.ReadAllLines(_cpuInfoPath);
string[] cpuInfoLines = File.ReadAllLines(CpuInfoPath);
Regex regex = new Regex(@"Hardware\s*:\s*(.*)");
foreach (string cpuInfoLine in cpuInfoLines)
{
......@@ -34,11 +38,11 @@ namespace System.Device.Gpio
{
if (match.Groups.Count > 1)
{
if (match.Groups[1].Value == _raspberryPiHardware)
if (match.Groups[1].Value == RaspberryPiHardware)
{
return new RaspberryPi3Driver();
}
if (match.Groups[1].Value == _hummingBoardHardware)
if (match.Groups[1].Value == HummingBoardHardware)
{
return new HummingboardDriver();
}
......
......@@ -3,18 +3,47 @@
// See the LICENSE file in the project root for more information.
using System.Device.Gpio.Drivers;
using Microsoft.Win32;
namespace System.Device.Gpio
{
public sealed partial class GpioController
{
private const string BaseBoardProductRegistryValue = @"SYSTEM\HardwareConfig\Current\BaseBoardProduct";
private const string RaspberryPi2Product = "Raspberry Pi 2";
private const string RaspberryPi3Product = "Raspberry Pi 3";
// private const string HummingBoardProduct = @"Freescale i.MX6 Quad/DualLite (Device Tree)"; // TODO: Figure out the right string here
/// <summary>
/// Controller that takes in a numbering scheme. Will default to use the driver that best applies given the platform the program is running on.
/// </summary>
/// <param name="pinNumberingScheme">The numbering scheme used to represent pins on the board.</param>
public GpioController(PinNumberingScheme pinNumberingScheme)
: this(pinNumberingScheme, new Windows10Driver())
: this(pinNumberingScheme, GetBestDriverForBoard())
{
}
/// <summary>
/// Private method that tries to get the best applicable driver for the board you are running in.
/// </summary>
/// <returns>A driver which works on the current running board.</returns>
private static GpioDriver GetBestDriverForBoard()
{
string baseBoardProduct = Registry.LocalMachine.GetValue(BaseBoardProductRegistryValue, string.Empty).ToString();
if (baseBoardProduct.StartsWith($"{RaspberryPi3Product} ") || baseBoardProduct == RaspberryPi3Product ||
baseBoardProduct.StartsWith($"{RaspberryPi2Product} ") || baseBoardProduct == RaspberryPi2Product)
{
return new RaspberryPi3Driver();
}
// TODO: Ditto for the Hummingboard and any other ones that .NET Core will know about.
// This really feels like it needs a driver-based pattern, where each driver exposes a static method:
// public static bool IsSpecificToCurrentHardware { get; }
// The GpioController could use reflection to find all GpioDriver-derived classes and call this
// static method to determine if the driver considers itself to be the best match for the environment.
// Default for Windows IoT Core on a non-specific device
return new Windows10Driver();
}
}
}
}
\ No newline at end of file
......@@ -20,9 +20,6 @@ namespace System.Device.Gpio
{
private GpioDriver _driver;
private HashSet<int> _openPins;
private const string _cpuInfoPath = "/proc/cpuinfo";
private const string _raspberryPiHardware = "BCM2835";
private const string _hummingBoardHardware = @"Freescale i.MX6 Quad/DualLite (Device Tree)";
/// <summary>
/// The numbering scheme used to identify pins on the board.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册