未验证 提交 a81914ef 编写于 作者: D DazFahy 提交者: GitHub

Added LLC200D3SH binding (#1090)

* Add Llc200d3sh device

Adding a binding for the LLC200D3SH Optomax digital liquid level switch

* Update README.md

Correct spelling mistake

* Code Review Changes

Updates from pull request code review

* Remove code

Remove copy of old code

* Update README.md

Update readme file

* Update README.md

Update readme

* Code Review Changes

Changes from the code review

* Code Review Changes

Changes from code review
Co-authored-by: NDarren Fahy <dfahy@tvcl.co.uk>
上级 7d9d4079
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>
<ItemGroup>
<Compile Include="*.cs" />
<Compile Remove="samples\**" />
<None Include="README.md" />
<ProjectReference Include="$(MainLibraryPath)System.Device.Gpio.csproj" />
</ItemGroup>
</Project>

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LiquidLevel", "LiquidLevel.csproj", "{A3AEC821-6C98-466F-BE03-27C967FBA962}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{499ADFE6-29AB-4182-8EA3-C06B80B54C5E}"
ProjectSection(SolutionItems) = preProject
samples\README.md = samples\README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Llc200d3sh.Sample", "samples\Llc200d3sh.Sample.csproj", "{6A38157B-7F9E-4003-A346-D898C86AE8FA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiquidLevelSwitch.Sample", "samples\LiquidLevelSwitch.Sample.csproj", "{2675D556-74B1-40DA-B1F8-4CE2733463CF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A3AEC821-6C98-466F-BE03-27C967FBA962}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A3AEC821-6C98-466F-BE03-27C967FBA962}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3AEC821-6C98-466F-BE03-27C967FBA962}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3AEC821-6C98-466F-BE03-27C967FBA962}.Release|Any CPU.Build.0 = Release|Any CPU
{6A38157B-7F9E-4003-A346-D898C86AE8FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6A38157B-7F9E-4003-A346-D898C86AE8FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A38157B-7F9E-4003-A346-D898C86AE8FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A38157B-7F9E-4003-A346-D898C86AE8FA}.Release|Any CPU.Build.0 = Release|Any CPU
{2675D556-74B1-40DA-B1F8-4CE2733463CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2675D556-74B1-40DA-B1F8-4CE2733463CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2675D556-74B1-40DA-B1F8-4CE2733463CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2675D556-74B1-40DA-B1F8-4CE2733463CF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{6A38157B-7F9E-4003-A346-D898C86AE8FA} = {499ADFE6-29AB-4182-8EA3-C06B80B54C5E}
{2675D556-74B1-40DA-B1F8-4CE2733463CF} = {499ADFE6-29AB-4182-8EA3-C06B80B54C5E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3C7588E5-BCAE-4AF2-B436-96DAFE199C0F}
EndGlobalSection
EndGlobal
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Device.Gpio;
namespace Iot.Device.LiquidLevel
{
/// <summary>
/// Supports any single pin output digital liquid level switch which is configured
/// </summary>
public class LiquidLevelSwitch : IDisposable
{
private readonly int _dataPin;
private readonly PinValue _liquidPresentPinState;
private readonly bool _shouldDispose;
private GpioController _controller;
/// <summary>Creates a new instance of the LiquidLevelSwitch.</summary>
/// <param name="dataPin">The data pin</param>
/// <param name="liquidPresentPinState">Data pin state representing liquid being present</param>
/// <param name="pinNumberingScheme">Use the logical or physical pin layout</param>
/// <param name="gpioController">A Gpio Controller if you want to use a specific one</param>
/// <param name="shouldDispose">True to dispose the Gpio Controller</param>
public LiquidLevelSwitch(int dataPin, PinValue liquidPresentPinState, GpioController gpioController = null, PinNumberingScheme pinNumberingScheme = PinNumberingScheme.Logical, bool shouldDispose = true)
{
_controller = gpioController ?? new GpioController(pinNumberingScheme);
_dataPin = dataPin;
_liquidPresentPinState = liquidPresentPinState;
_controller.OpenPin(_dataPin, PinMode.Input);
_shouldDispose = shouldDispose || gpioController == null;
}
/// <summary>
/// Determines whether liquid is present.
/// </summary>
/// <returns><code>true</code> if liquid is present, otherwise <code>false</code>.</returns>
public bool IsLiquidPresent()
{
return _controller.Read(_dataPin) == _liquidPresentPinState;
}
/// <summary>
/// Dispose Buzzer.
/// </summary>
public void Dispose()
{
if (_shouldDispose)
{
_controller?.Dispose();
_controller = null;
}
}
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Device.Gpio;
namespace Iot.Device.LiquidLevel
{
/// <summary>
/// Optomax LLC200D3SH digital liquid level switch
/// </summary>
public class Llc200d3sh : LiquidLevelSwitch
{
/// <summary>Creates a new instance of the Llc200d3sh.</summary>
/// <param name="pin">The data pin</param>
/// <param name="pinNumberingScheme">Use the logical or physical pin layout</param>
/// <param name="gpioController">A Gpio Controller if you want to use a specific one</param>
/// <param name="shouldDispose">True to dispose the Gpio Controller</param>
public Llc200d3sh(int pin, GpioController gpioController = null, PinNumberingScheme pinNumberingScheme = PinNumberingScheme.Logical, bool shouldDispose = true)
: base(pin, PinValue.Low, gpioController, pinNumberingScheme, shouldDispose)
{
}
}
}
# Digital liquid level switch
Digital liquid level switches are devices that can detect the presence of liquid/water. GPIO can be used to communicate with the devices.
## Device Family
The implementation supports any single pin output digital liquid level switch.
## Usage
```c#
using (LiquidLevelSwitch sensor = new LiquidLevelSwitch(23, PinValue.Low))
{
while (true)
{
// read liquid level switch
Console.WriteLine($"Detected: {sensor.IsLiquidPresent()}");
Console.WriteLine();
Thread.Sleep(1000);
}
}
```
An example on how to use the specific LLC200D3SH device binding is available in the [samples](samples) folder.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>
<ItemGroup>
<None Remove="rpi-llc200d3sh.fzz" />
<None Remove="rpi-llc200d3sh_bb.png" />
</ItemGroup>
<ItemGroup>
<Compile Include="LiquidLevelSwitch.sample.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LiquidLevel.csproj" />
<ProjectReference Include="$(MainLibraryPath)System.Device.Gpio.csproj" />
</ItemGroup>
</Project>
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Device.Gpio;
using System.Threading;
using Iot.Device.LiquidLevel;
namespace LiquidLevel.Sample
{
internal class Program
{
public static void Main(string[] args)
{
using (LiquidLevelSwitch sensor = new LiquidLevelSwitch(23, PinValue.Low))
{
while (true)
{
// read liquid level switch
Console.WriteLine($"Detected: {sensor.IsLiquidPresent()}");
Console.WriteLine();
Thread.Sleep(1000);
}
}
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>
<ItemGroup>
<None Remove="rpi-llc200d3sh.fzz" />
<None Remove="rpi-llc200d3sh_bb.png" />
</ItemGroup>
<ItemGroup>
<Compile Include="Llc200d3sh.sample.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LiquidLevel.csproj" />
<ProjectReference Include="$(MainLibraryPath)System.Device.Gpio.csproj" />
</ItemGroup>
</Project>
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Threading;
namespace Iot.Device.LiquidLevel.Samples
{
internal class Program
{
public static void Main(string[] args)
{
using (Llc200d3sh sensor = new Llc200d3sh(23))
{
while (true)
{
// read liquid level switch
Console.WriteLine($"Detected: {sensor.IsLiquidPresent()}");
Console.WriteLine();
Thread.Sleep(1000);
}
}
}
}
}
# Digital liquid level switch Samples
## LLC200D3SH Circuit
The following fritzing diagram illustrates one way to wire up the Optomax LLC200D3SH digital liquid level switch with a Raspberry Pi.
![Raspberry Pi Breadboard diagram](rpi-llc200d3sh_bb.png)
## Code
Define the LLC200D3SH sensor using the LiquidLevelSwitch class.
```C#
using (Llc200d3sh sensor = new Llc200d3sh(23))
{
while (true)
{
// read liquid level switch
Console.WriteLine($"Detected: {sensor.IsLiquidPresent()}");
Console.WriteLine();
Thread.Sleep(1000);
}
}
```
## References
- LLC200D3SH sensor ([Datasheet](https://cdn-shop.adafruit.com/product-files/3397/3397_datasheet_actual.pdf))
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册