Adding Bl1750fvi (#28)
This commit is contained in:
Родитель
9a8013fbf6
Коммит
88442b67d7
|
@ -0,0 +1,121 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.Device.I2c;
|
||||
using System.Device.Model;
|
||||
using UnitsNet;
|
||||
|
||||
namespace Iot.Device.Bh1750fvi
|
||||
{
|
||||
/// <summary>
|
||||
/// Ambient Light Sensor BH1750FVI
|
||||
/// </summary>
|
||||
[Interface("Ambient Light Sensor BH1750FVI")]
|
||||
public class Bh1750fvi : IDisposable
|
||||
{
|
||||
private const byte DefaultLightTransmittance = 0b_0100_0101;
|
||||
|
||||
private I2cDevice _i2cDevice;
|
||||
|
||||
private double _lightTransmittance;
|
||||
|
||||
/// <summary>
|
||||
/// BH1750FVI Light Transmittance, from 27.20% to 222.50%
|
||||
/// </summary>
|
||||
[Property]
|
||||
public double LightTransmittance
|
||||
{
|
||||
get => _lightTransmittance;
|
||||
set
|
||||
{
|
||||
SetLightTransmittance(value);
|
||||
_lightTransmittance = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// BH1750FVI Measuring Mode
|
||||
/// </summary>
|
||||
[Property]
|
||||
public MeasuringMode MeasuringMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// BH1750FVI Illuminance (Lux)
|
||||
/// </summary>
|
||||
[Telemetry]
|
||||
public Illuminance Illuminance => GetIlluminance();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the BH1750FVI
|
||||
/// </summary>
|
||||
/// <param name="i2cDevice">The I2C device used for communication.</param>
|
||||
/// <param name="measuringMode">The measuring mode of BH1750FVI</param>
|
||||
/// <param name="lightTransmittance">BH1750FVI Light Transmittance, from 27.20% to 222.50%</param>
|
||||
public Bh1750fvi(I2cDevice i2cDevice, MeasuringMode measuringMode = MeasuringMode.ContinuouslyHighResolutionMode, double lightTransmittance = 1)
|
||||
{
|
||||
_i2cDevice = i2cDevice ?? throw new ArgumentNullException(nameof(i2cDevice));
|
||||
|
||||
_i2cDevice.WriteByte((byte)Command.PowerOn);
|
||||
_i2cDevice.WriteByte((byte)Command.Reset);
|
||||
|
||||
LightTransmittance = lightTransmittance;
|
||||
MeasuringMode = measuringMode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set BH1750FVI Light Transmittance
|
||||
/// </summary>
|
||||
/// <param name="transmittance">Light Transmittance, from 27.20% to 222.50%</param>
|
||||
private void SetLightTransmittance(double transmittance)
|
||||
{
|
||||
if (transmittance > 2.225 || transmittance < 0.272)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(transmittance), $"{nameof(transmittance)} needs to be in the range of 27.20% to 222.50%.");
|
||||
}
|
||||
|
||||
byte val = (byte)(DefaultLightTransmittance / transmittance);
|
||||
|
||||
_i2cDevice.WriteByte((byte)((byte)Command.MeasurementTimeHigh | (val >> 5)));
|
||||
_i2cDevice.WriteByte((byte)((byte)Command.MeasurementTimeLow | (val & 0b_0001_1111)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get BH1750FVI Illuminance
|
||||
/// </summary>
|
||||
/// <returns>Illuminance (Default unit: Lux)</returns>
|
||||
private Illuminance GetIlluminance()
|
||||
{
|
||||
if (MeasuringMode == MeasuringMode.OneTimeHighResolutionMode || MeasuringMode == MeasuringMode.OneTimeHighResolutionMode2 || MeasuringMode == MeasuringMode.OneTimeLowResolutionMode)
|
||||
{
|
||||
_i2cDevice.WriteByte((byte)Command.PowerOn);
|
||||
}
|
||||
|
||||
SpanByte readBuff = new byte[2];
|
||||
|
||||
_i2cDevice.WriteByte((byte)MeasuringMode);
|
||||
_i2cDevice.Read(readBuff);
|
||||
|
||||
ushort raw = BinaryPrimitives.ReadUInt16BigEndian(readBuff);
|
||||
|
||||
double result = raw / (1.2 * _lightTransmittance);
|
||||
|
||||
if (MeasuringMode == MeasuringMode.ContinuouslyHighResolutionMode2 || MeasuringMode == MeasuringMode.OneTimeHighResolutionMode2)
|
||||
{
|
||||
result *= 2;
|
||||
}
|
||||
|
||||
return Illuminance.FromLux(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleanup
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_i2cDevice?.Dispose();
|
||||
_i2cDevice = null!;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<NanoFrameworkProjectSystemPath>$(MSBuildToolsPath)..\..\..\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectTypeGuids>{11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<ProjectGuid>{2A6DCC87-4291-4830-8CDC-208C5BEA65FC}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<RootNamespace>Iot.Device.Bh1750fvi</RootNamespace>
|
||||
<AssemblyName>Iot.Device.Bh1750fvi</AssemblyName>
|
||||
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
|
||||
<DocumentationFile>bin\$(Configuration)\Iot.Device.Bh1750fvi.xml</DocumentationFile>
|
||||
<LangVersion>9.0</LangVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
|
||||
<ItemGroup>
|
||||
<Reference Include="mscorlib">
|
||||
<HintPath>packages\nanoFramework.CoreLibrary.1.10.4-preview.11\lib\mscorlib.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Device.I2c">
|
||||
<HintPath>packages\nanoFramework.System.Device.I2c.1.0.1-preview.33\lib\System.Device.I2c.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnitsNet.Illuminance, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>packages\UnitsNet.nanoFramework.Illuminance.4.92.1\lib\UnitsNet.Illuminance.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<Compile Include="Bh1750fvi.cs" />
|
||||
<Compile Include="Command.cs" />
|
||||
<Compile Include="I2cAddress.cs" />
|
||||
<Compile Include="MeasuringMode.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<None Include="*.md" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
|
||||
<Import Project="..\..\src\System.Device.Model\System.Device.Model.projitems" Label="Shared" />
|
||||
<Import Project="..\..\src\BinaryPrimitives\BinaryPrimitives.projitems" Label="Shared" />
|
||||
<ProjectExtensions>
|
||||
<ProjectCapabilities>
|
||||
<ProjectConfigurationsDeclaredAsItems />
|
||||
</ProjectCapabilities>
|
||||
</ProjectExtensions>
|
||||
<Import Project="packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets" Condition="Exists('packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText> This project references NuGet package(s) that are missing on this computer.Enable NuGet Package Restore to download them.For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>nanoFramework.Iot.Device.Bh1750fvi</id>
|
||||
<version>$version$</version>
|
||||
<title>nanoFramework.Iot.Device.Bh1750fvi</title>
|
||||
<authors>nanoFramework project contributors</authors>
|
||||
<owners>nanoFramework project contributors,dotnetfoundation</owners>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<license type="file">LICENSE.md</license>
|
||||
<releaseNotes>
|
||||
</releaseNotes>
|
||||
<developmentDependency>false</developmentDependency>
|
||||
<projectUrl>https://github.com/nanoframework/nanoFramework.IoT.Device</projectUrl>
|
||||
<iconUrl>https://secure.gravatar.com/avatar/97d0e092247f0716db6d4b47b7d1d1ad</iconUrl>
|
||||
<icon>images\nf-logo.png</icon>
|
||||
<repository type="git" url="https://github.com/nanoframework/nanoFramework.IoT.Device" commit="$commit$" />
|
||||
<copyright>Copyright (c) .NET Foundation and Contributors</copyright>
|
||||
<description>This package includes the .NET IoT Core binding Iot.Device.Bh1750fvi for .NET nanoFramework C# projects.</description>
|
||||
<summary>Iot.Device.Bh1750fvi assembly for .NET nanoFramework C# projects</summary>
|
||||
<tags>nanoFramework C# csharp netmf netnf Iot.Device.Bh1750fvi</tags>
|
||||
<dependencies>
|
||||
<dependency id="nanoFramework.CoreLibrary" version="1.10.4-preview.11" />
|
||||
<dependency id="nanoFramework.System.Device.I2c" version="1.0.1-preview.33" />
|
||||
<dependency id="UnitsNet.nanoFramework.Illuminance" version="4.92.0" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="bin\Release\Iot.Device.Bh1750fvi.dll" target="lib\Iot.Device.Bh1750fvi.dll" />
|
||||
<file src="bin\Release\Iot.Device.Bh1750fvi.pdb" target="lib\Iot.Device.Bh1750fvi.pdb" />
|
||||
<file src="bin\Release\Iot.Device.Bh1750fvi.pdbx" target="lib\Iot.Device.Bh1750fvi.pdbx" />
|
||||
<file src="bin\Release\Iot.Device.Bh1750fvi.pe" target="lib\Iot.Device.Bh1750fvi.pe" />
|
||||
<file src="bin\Release\Iot.Device.Bh1750fvi.xml" target="lib\Iot.Device.Bh1750fvi.xml" />
|
||||
<file src="readme.md" target="" />
|
||||
<file src="..\..\assets\nf-logo.png" target="images" />
|
||||
<file src="..\..\LICENSE.md" target="" />
|
||||
</files>
|
||||
</package>
|
|
@ -0,0 +1,48 @@
|
|||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30413.136
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Bh1750fvi", "Bh1750fvi.nfproj", "{2A6DCC87-4291-4830-8CDC-208C5BEA65FC}"
|
||||
EndProject
|
||||
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Bh1750fvi.Samples", "samples\Bh1750fvi.Samples.nfproj", "{15CE15B2-AE83-4670-90A2-E36C3A9EFB03}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared Project", "Shared Project", "{DDFFEC3A-0FFB-4CF6-BB2E-30C09AFCDB1F}"
|
||||
EndProject
|
||||
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "System.Device.Model", "..\..\src\System.Device.Model\System.Device.Model.shproj", "{23325B14-3651-4879-9697-9846FF123FEB}"
|
||||
EndProject
|
||||
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "BinaryPrimitives", "..\..\src\BinaryPrimitives\BinaryPrimitives.shproj", "{3F28B003-6318-4E21-A9B6-6C0DBD0BDBFD}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||
..\..\src\System.Device.Model\System.Device.Model.projitems*{23325b14-3651-4879-9697-9846ff123feb}*SharedItemsImports = 13
|
||||
..\..\src\BinaryPrimitives\BinaryPrimitives.projitems*{3f28b003-6318-4e21-a9b6-6c0dbd0bdbfd}*SharedItemsImports = 13
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{2A6DCC87-4291-4830-8CDC-208C5BEA65FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2A6DCC87-4291-4830-8CDC-208C5BEA65FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2A6DCC87-4291-4830-8CDC-208C5BEA65FC}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
{2A6DCC87-4291-4830-8CDC-208C5BEA65FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2A6DCC87-4291-4830-8CDC-208C5BEA65FC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2A6DCC87-4291-4830-8CDC-208C5BEA65FC}.Release|Any CPU.Deploy.0 = Release|Any CPU
|
||||
{15CE15B2-AE83-4670-90A2-E36C3A9EFB03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{15CE15B2-AE83-4670-90A2-E36C3A9EFB03}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{15CE15B2-AE83-4670-90A2-E36C3A9EFB03}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
{15CE15B2-AE83-4670-90A2-E36C3A9EFB03}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{15CE15B2-AE83-4670-90A2-E36C3A9EFB03}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{15CE15B2-AE83-4670-90A2-E36C3A9EFB03}.Release|Any CPU.Deploy.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{23325B14-3651-4879-9697-9846FF123FEB} = {DDFFEC3A-0FFB-4CF6-BB2E-30C09AFCDB1F}
|
||||
{3F28B003-6318-4E21-A9B6-6C0DBD0BDBFD} = {DDFFEC3A-0FFB-4CF6-BB2E-30C09AFCDB1F}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {8ECBE2FD-796C-4D37-B27C-27AB2EE0618B}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,14 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
namespace Iot.Device.Bh1750fvi
|
||||
{
|
||||
internal enum Command : byte
|
||||
{
|
||||
PowerDown = 0b_0000_0000,
|
||||
PowerOn = 0b_0000_0001,
|
||||
Reset = 0b_0000_0111,
|
||||
MeasurementTimeHigh = 0b_0100_0000,
|
||||
MeasurementTimeLow = 0b_0110_0000,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
namespace Iot.Device.Bh1750fvi
|
||||
{
|
||||
/// <summary>
|
||||
/// BH1750FVI I2C Address
|
||||
/// </summary>
|
||||
public enum I2cAddress : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// ADD Pin connect to high power level
|
||||
/// </summary>
|
||||
AddPinHigh = 0x5C,
|
||||
|
||||
/// <summary>
|
||||
/// ADD Pin connect to low power level
|
||||
/// </summary>
|
||||
AddPinLow = 0x23
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
namespace Iot.Device.Bh1750fvi
|
||||
{
|
||||
/// <summary>
|
||||
/// The measuring mode of BH1750FVI
|
||||
/// </summary>
|
||||
public enum MeasuringMode : byte
|
||||
{
|
||||
// Details in the datasheet P5
|
||||
|
||||
/// <summary>
|
||||
/// Start measurement at 1lx resolution
|
||||
/// Measurement Time is typically 120ms.
|
||||
/// </summary>
|
||||
ContinuouslyHighResolutionMode = 0b_0001_0000,
|
||||
|
||||
/// <summary>
|
||||
/// Start measurement at 0.5lx resolution
|
||||
/// Measurement Time is typically 120ms.
|
||||
/// </summary>
|
||||
ContinuouslyHighResolutionMode2 = 0b_0001_0001,
|
||||
|
||||
/// <summary>
|
||||
/// Start measurement at 4lx resolution
|
||||
/// Measurement Time is typically 16ms.
|
||||
/// </summary>
|
||||
ContinuouslyLowResolutionMode = 0b_0001_0011,
|
||||
|
||||
/// <summary>
|
||||
/// Start measurement at 1lx resolution once
|
||||
/// Measurement Time is typically 120ms.
|
||||
/// It is automatically set to Power Down mode after measurement.
|
||||
/// </summary>
|
||||
OneTimeHighResolutionMode = 0b_0010_0000,
|
||||
|
||||
/// <summary>
|
||||
/// Start measurement at 0.5lx resolution once
|
||||
/// Measurement Time is typically 120ms.
|
||||
/// It is automatically set to Power Down mode after measurement.
|
||||
/// </summary>
|
||||
OneTimeHighResolutionMode2 = 0b_0010_0001,
|
||||
|
||||
/// <summary>
|
||||
/// Start measurement at 4lx resolution once
|
||||
/// Measurement Time is typically 16ms.
|
||||
/// It is automatically set to Power Down mode after measurement.
|
||||
/// </summary>
|
||||
OneTimeLowResolutionMode = 0b_0010_0011
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("Iot.Device.Bh1750fvi")]
|
||||
[assembly: AssemblyCompany("nanoFramework Contributors")]
|
||||
[assembly: AssemblyCopyright("Copyright(c).NET Foundation and Contributors")]
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# BH1750FVI - Ambient Light Sensor
|
||||
BH1750FVI is an digital Ambient Light Sensor IC for I2C bus interface. This IC is the most suitable to obtain the ambient light data for adjusting LCD and Keypad backlight power of Mobile phone. It is possible to detect wide range at High resolution.
|
||||
|
||||
## Sensor Image
|
||||
![](sensor.jpg)
|
||||
|
||||
## Usage
|
||||
```C#
|
||||
I2cConnectionSettings settings = new I2cConnectionSettings(busId: 1, (int)I2cAddress.AddPinLow);
|
||||
I2cDevice device = I2cDevice.Create(settings);
|
||||
|
||||
using (Bh1750fvi sensor = new Bh1750fvi(device))
|
||||
{
|
||||
// read illuminance(Lux)
|
||||
double illuminance = sensor.Illuminance;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## References
|
||||
https://cdn.datasheetspdf.com/pdf-down/B/H/1/BH1750FVI_Rohm.pdf
|
|
@ -0,0 +1 @@
|
|||
light
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="nanoFramework.CoreLibrary" version="1.10.4-preview.11" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.System.Device.I2c" version="1.0.1-preview.33" targetFramework="netnanoframework10" />
|
||||
<package id="Nerdbank.GitVersioning" version="3.4.194" developmentDependency="true" targetFramework="netnanoframework10" />
|
||||
<package id="UnitsNet.nanoFramework.Illuminance" version="4.92.1" targetFramework="netnanoframework10" />
|
||||
</packages>
|
Двоичный файл не отображается.
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 94 KiB |
|
@ -0,0 +1,57 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<NanoFrameworkProjectSystemPath>$(MSBuildToolsPath)..\..\..\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectTypeGuids>{11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<ProjectGuid>{15CE15B2-AE83-4670-90A2-E36C3A9EFB03}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<RootNamespace>Iot.Device.Bh1750fvi.Samples</RootNamespace>
|
||||
<AssemblyName>Iot.Device.Bh1750fvi.Samples</AssemblyName>
|
||||
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
|
||||
<DocumentationFile>bin\$(Configuration)\Iot.Device.Bh1750fvi.Samples.xml</DocumentationFile>
|
||||
<LangVersion>9.0</LangVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
|
||||
<ItemGroup>
|
||||
<Reference Include="mscorlib">
|
||||
<HintPath>..\packages\nanoFramework.CoreLibrary.1.10.4-preview.11\lib\mscorlib.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Device.I2c">
|
||||
<HintPath>..\packages\nanoFramework.System.Device.I2c.1.0.1-preview.33\lib\System.Device.I2c.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnitsNet.Illuminance, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\packages\UnitsNet.nanoFramework.Illuminance.4.92.1\lib\UnitsNet.Illuminance.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<!-- INSERT FILE REFERENCES HERE -->
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="*.cs" />
|
||||
<None Include="*.md" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Bh1750fvi.nfproj" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
|
||||
<!-- INSERT IMPORTS HERE -->
|
||||
<ProjectExtensions>
|
||||
<ProjectCapabilities>
|
||||
<ProjectConfigurationsDeclaredAsItems />
|
||||
</ProjectCapabilities>
|
||||
</ProjectExtensions>
|
||||
<!-- INSERT NBGV IMPORT HERE -->
|
||||
</Project>
|
|
@ -0,0 +1,17 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using System.Device.I2c;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using Iot.Device.Bh1750fvi;
|
||||
|
||||
I2cConnectionSettings settings = new(busId: 1, (int)I2cAddress.AddPinLow);
|
||||
using I2cDevice device = I2cDevice.Create(settings);
|
||||
using Bh1750fvi sensor = new Bh1750fvi(device);
|
||||
while (true)
|
||||
{
|
||||
Debug.WriteLine($"Illuminance: {sensor.Illuminance}Lux");
|
||||
Thread.Sleep(1000);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("Iot.Device.Bh1750fvi.Samples")]
|
||||
[assembly: AssemblyCompany("nanoFramework Contributors")]
|
||||
[assembly: AssemblyCopyright("Copyright(c).NET Foundation and Contributors")]
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
# BH1750FVI - Samples
|
||||
|
||||
## Hardware Required
|
||||
* BH1750FVI
|
||||
* Male/Female Jumper Wires
|
||||
|
||||
## Circuit
|
||||
![](BH1750FVI_Circuit_bb.png)
|
||||
|
||||
* SCL - SCL
|
||||
* SDA - SDA
|
||||
* VCC - 5V
|
||||
* GND - GND
|
||||
* ADDR - GND
|
||||
|
||||
## Code
|
||||
```C#
|
||||
I2cConnectionSettings settings = new I2cConnectionSettings(busId: 1, (int)I2cAddress.AddPinLow);
|
||||
I2cDevice device = I2cDevice.Create(settings);
|
||||
|
||||
using (Bh1750fvi sensor = new Bh1750fvi(device))
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Console.WriteLine($"Illuminance: {sensor.Illuminance}Lux");
|
||||
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Result
|
||||
![](RunningResult.jpg)
|
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 47 KiB |
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="nanoFramework.CoreLibrary" version="1.10.4-preview.11" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.System.Device.I2c" version="1.0.1-preview.33" targetFramework="netnanoframework10" />
|
||||
<package id="UnitsNet.nanoFramework.Illuminance" version="4.92.1" targetFramework="netnanoframework10" />
|
||||
</packages>
|
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 62 KiB |
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
|
||||
"version": "1.0",
|
||||
"assemblyVersion": {
|
||||
"precision": "minor"
|
||||
},
|
||||
"semVer1NumericIdentifierPadding": 3,
|
||||
"nuGetPackageVersion": {
|
||||
"semVer": 2.0
|
||||
},
|
||||
"publicReleaseRefSpec": [
|
||||
"^refs/heads/develop$",
|
||||
"^refs/heads/main$",
|
||||
"^refs/heads/v\\d+(?:\\.\\d+)?$"
|
||||
],
|
||||
"cloudBuild": {
|
||||
"setAllVariables": true
|
||||
}
|
||||
}
|
|
@ -30,7 +30,7 @@
|
|||
<file src="bin\Release\Iot.Device.Bh1750fvi.pe" target="lib\Iot.Device.Bh1750fvi.pe" />
|
||||
<file src="bin\Release\Iot.Device.Bh1750fvi.xml" target="lib\Iot.Device.Bh1750fvi.xml" />
|
||||
<file src="readme.md" target="" />
|
||||
<file src="..\assets\nf-logo.png" target="images" />
|
||||
<file src="..\LICENSE.md" target="" />
|
||||
<file src="..\..\assets\nf-logo.png" target="images" />
|
||||
<file src="..\..\LICENSE.md" target="" />
|
||||
</files>
|
||||
</package>
|
||||
|
|
Загрузка…
Ссылка в новой задаче