Skip to content

Commit

Permalink
Adding Iot.Device.Bindings package (#155)
Browse files Browse the repository at this point in the history
* Adding Iot.Device.Bindings package

* Adding missing tag
  • Loading branch information
joperezr authored Jan 28, 2019
1 parent 9598969 commit 84af045
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 18 deletions.
7 changes: 4 additions & 3 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

<Target Name="BuildProduct">
<ItemGroup>
<_BuildProductProjects Include="$(MSBuildThisFileDirectory)src\**\*.csproj" />
<_ExcludeBuildProductProjects Include="$(MSBuildThisFileDirectory)src\Iot.Device.Bindings\Iot.Device.Bindings.csproj" />
<_BuildProductProjects Include="$(MSBuildThisFileDirectory)src\**\*.csproj" Exclude="@(_ExcludeBuildProductProjects)" />
</ItemGroup>

<MSBuild Projects="@(_BuildProductProjects)" />
Expand All @@ -38,7 +39,6 @@

<Target Name="BuildSamples">
<ItemGroup>
<_ExcludeBuildSampleProjects Include="$(MSBuildThisFileDirectory)samples\pwm-led\pwm-led.csproj" />
<_ExcludeBuildSampleProjects Include="$(MSBuildThisFileDirectory)samples\serialport-arduino\arduino-demo.csproj" />
<_BuildSampleProjects Include="$(MSBuildThisFileDirectory)samples\**\*.csproj" Exclude="@(_ExcludeBuildSampleProjects)" />
</ItemGroup>
Expand All @@ -59,7 +59,8 @@

<Target Name="Pack">
<ItemGroup>
<_ProjectsToPackage Include="$(MSBuildThisFileDirectory)src\**\*.csproj" />
<_ProjectsToPackage Include="$(MSBuildThisFileDirectory)src\Iot.Device.Bindings\Iot.Device.Bindings.csproj" />
<_ProjectsToPackage Include="$(MSBuildThisFileDirectory)src\System.Device.Gpio\System.Device.Gpio.csproj" />
</ItemGroup>

<MSBuild Projects="@(_ProjectsToPackage)" Targets="Pack" />
Expand Down
2 changes: 1 addition & 1 deletion samples/led-more-blinking-lights/Volume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System;
using System.Device.Spi;
using System.Device.Spi.Drivers;
using Iot.Device;
using Iot.Device.Mcp3008;

public class Volume : IDisposable
{
Expand Down
12 changes: 12 additions & 0 deletions src/Iot.Device.Bindings/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project>
<!-- Packaging related properties -->
<PropertyGroup>
<MajorVersion>0</MajorVersion>
<MinorVersion>1</MinorVersion>
<Description>This preview package provides a set of Device Bindings that use System.Device.Gpio package to communicate with a microcontroller.</Description>
<Copyright>Microsoft Corporation, All rights reserved.</Copyright>
<PackageTags>.NET Core GPIO Pins SPI I2C PWM BCM2835 BCM2837 RPi IoT Device Bindings</PackageTags>
</PropertyGroup>

<Import Project="..\..\Directory.Build.props" />
</Project>
35 changes: 35 additions & 0 deletions src/Iot.Device.Bindings/Iot.Device.Bindings.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>Latest</LangVersion>
<EnableDefaultItems>false</EnableDefaultItems>
<IsPackable>true</IsPackable>
<DeviceRoot>$(MSBuildThisFileDirectory)../devices/</DeviceRoot>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);PackageRefAssembly</TargetsForTfmSpecificContentInPackage>
<!--Disabling default items so samples source won't get build by the main library-->
</PropertyGroup>

<ItemGroup>
<_ExcludeFromCompile Include="$(DeviceRoot)**/samples/**/*.cs" />
<_ExcludeFromCompile Include="$(DeviceRoot)**/tests/**/*.cs" />
<_ExcludeFromCompile Include="$(DeviceRoot)**/obj/**/*.cs" />
<Compile Include="$(DeviceRoot)**/*.cs" Exclude="@(_ExcludeFromCompile)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(MSBuildThisFileDirectory)../System.Device.Gpio/System.Device.Gpio.csproj">
<AdditionalProperties>RuntimeIdentifier=linux</AdditionalProperties>
</ProjectReference>
</ItemGroup>

<Target Name="PackageRefAssembly">
<ItemGroup>
<TfmSpecificPackageFile Include="$(TargetRefPath)">
<PackagePath>ref/$(TargetFramework)</PackagePath>
</TfmSpecificPackageFile>
</ItemGroup>
</Target>

</Project>
10 changes: 5 additions & 5 deletions src/devices/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<NoWarn>$(NoWarn);CS8321</NoWarn>
<DeterministicSourcePaths>false</DeterministicSourcePaths>
<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup>
<NoWarn>$(NoWarn);CS8321</NoWarn>
<DeterministicSourcePaths>false</DeterministicSourcePaths>
<IsPackable>false</IsPackable>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/devices/Mcp3008/Mcp3008.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Device.Gpio;
using System.Device.Spi;

namespace Iot.Device
namespace Iot.Device.Mcp3008
{
public class Mcp3008 : IDisposable
{
Expand Down
12 changes: 6 additions & 6 deletions src/devices/Mcp3008/samples/Mcp3008.Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void Main(string[] args)
// the two implementations.

// SPI implementation
Mcp3008 GetMcp3008WithSpi()
Mcp3008.Mcp3008 GetMcp3008WithSpi()
{
Console.WriteLine("Using SPI protocol.");

Expand All @@ -33,27 +33,27 @@ Mcp3008 GetMcp3008WithSpi()
};

var spi = new UnixSpiDevice(connection);
var mcp3008 = new Mcp3008(spi);
var mcp3008 = new Mcp3008.Mcp3008(spi);
return mcp3008;
}

// GPIO (via bit banging) implementation
Mcp3008 GetMcp3008WithGpio()
Mcp3008.Mcp3008 GetMcp3008WithGpio()
{
Console.WriteLine("Using GPIO pins.");
var mcp3008 = new Mcp3008(18, 23, 24, 25);
var mcp3008 = new Mcp3008.Mcp3008(18, 23, 24, 25);
return mcp3008;
}

Mcp3008 mcp = GetMcp3008WithSpi();
Mcp3008.Mcp3008 mcp = GetMcp3008WithSpi();
// Uncomment next line to use GPIO instead.
// Mcp3008 mcp = GetMcp3008WithGpio();

using (mcp)
{
while (true)
{
double value = mcp.Read(0, Mcp3008.InputConfiguration.SingleEnded);
double value = mcp.Read(0, Mcp3008.Mcp3008.InputConfiguration.SingleEnded);
value = value / 10.24;
value = Math.Round(value);
Console.WriteLine(value);
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Si7021/Si7021.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System;
using System.Device.I2c;

namespace Iot.Device
namespace Iot.Device.Si7021
{
public class Si7021 : IDisposable
{
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Si7021/samples/Si7021.sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static void Main(string[] args)

var i2cSettings = new I2cConnectionSettings(BusId, Si7021Address);
var i2cDevice = new Windows10I2cDevice(i2cSettings);
var i2CSi7021 = new Si7021(i2cDevice);
var i2CSi7021 = new Si7021.Si7021(i2cDevice);

using (i2CSi7021)
{
Expand Down

0 comments on commit 84af045

Please sign in to comment.