This commit is contained in:
Laurent Ellerbach 2021-05-24 11:37:00 +02:00 коммит произвёл GitHub
Родитель 059963afe2
Коммит e9320b9e32
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
18 изменённых файлов: 637 добавлений и 0 удалений

164
devices/Hts221/Hts221.cs Normal file
Просмотреть файл

@ -0,0 +1,164 @@
// 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.Hts221
{
/// <summary>
/// HTS221 - Capacitive digital sensor for relative humidity and temperature
/// </summary>
[Interface("HTS221 - Capacitive digital sensor for relative humidity and temperature")]
public class Hts221 : IDisposable
{
private const byte ReadMask = 0x80;
private I2cDevice _i2c;
/// <summary>
/// Hts221 - Temperature and humidity sensor
/// </summary>
public Hts221(I2cDevice i2cDevice)
{
_i2c = i2cDevice ?? throw new ArgumentNullException(nameof(i2cDevice));
// Highest resolution for both temperature and humidity sensor:
// 0.007 DegreesCelsius and 0.03 percentage of relative humidity respectively
byte resolution = 0b0011_1111;
WriteByte(Register.ResolutionMode, resolution);
byte control1orig = Read(Register.Control1);
// 7 - PD - power down control - 1 means active
// 6-3 - reserved - keep original
// 2 - BDU - block data update - 1 is recommended by datasheet and means that output registers
// won't be updated until both LSB and MSB are read
// 0-1 - output data rate - 11 means 12.5Hz
byte control1 = (byte)(0b1000_0111 | (control1orig & 0b0111_1000));
WriteByte(Register.Control1, control1);
}
/// <summary>
/// Temperature
/// </summary>
[Telemetry]
public Temperature Temperature => Temperature.FromDegreesCelsius(GetActualTemperature(ReadInt16(Register.Temperature)));
/// <summary>
/// Relative humidity
/// </summary>
[Telemetry]
public RelativeHumidity Humidity => GetActualHumidity(ReadInt16(Register.Humidity));
private static float Lerp(float x, float x0, float x1, float y0, float y1)
{
float xrange = x1 - x0;
float yrange = y1 - y0;
return y0 + (x - x0) * yrange / xrange;
}
private void WriteByte(Register register, byte data)
{
SpanByte buff = new byte[2]
{
(byte)register,
data
};
_i2c.Write(buff);
}
private short ReadInt16(Register register)
{
SpanByte val = new byte[2];
Read(register, val);
return BinaryPrimitives.ReadInt16LittleEndian(val);
}
private void Read(Register register, SpanByte buffer)
{
_i2c.WriteByte((byte)((byte)register | ReadMask));
_i2c.Read(buffer);
}
private byte Read(Register register)
{
_i2c.WriteByte((byte)((byte)register | ReadMask));
return _i2c.ReadByte();
}
private float GetActualTemperature(short temperatureRaw)
{
// datasheet does not specify if calibration points are not changing
// since this is almost no-op and max output data rate is 12.5Hz let's do it every time
// Original code:
// (short t0raw, short t1raw) = GetTemperatureCalibrationPointsRaw();
// (ushort t0x8C, ushort t1x8C) = GetTemperatureCalibrationPointsCelsius();
// return Lerp(temperatureRaw, t0raw, t1raw, t0x8C / 8.0f, t1x8C / 8.0f);
var raw = GetTemperatureCalibrationPointsRaw();
var x8C = GetTemperatureCalibrationPointsCelsius();
return Lerp(temperatureRaw, raw.S1, raw.S2, x8C.U1 / 8.0f, x8C.U2 / 8.0f);
}
private RelativeHumidity GetActualHumidity(short humidityRaw)
{
// datasheet does not specify if calibration points are not changing
// since this is almost no-op and max output data rate is 12.5Hz let's do it every time
// Original code:
// (short h0raw, short h1raw) = GetHumidityCalibrationPointsRaw();
// (byte h0x2rH, byte h1x2rH) = GetHumidityCalibrationPointsRH();
// return RelativeHumidity.FromPercent(Lerp(humidityRaw, h0raw, h1raw, h0x2rH / 2.0f, h1x2rH / 2.0f));
var raw = GetHumidityCalibrationPointsRaw();
var x2rH = GetHumidityCalibrationPointsRH();
return RelativeHumidity.FromPercent(Lerp(humidityRaw, raw.S1, raw.S2, x2rH.B1 / 2.0f, x2rH.B2 / 2.0f));
}
// Original code: private (ushort T0x8, ushort T1x8) GetTemperatureCalibrationPointsCelsius()
private TuppleUshortUshort GetTemperatureCalibrationPointsCelsius()
{
SpanByte t0t1Lsb = new byte[2];
Read(Register.Temperature0LsbDegCx8, t0t1Lsb);
byte t0t1Msb = Read(Register.Temperature0And1MsbDegCx8);
ushort t0 = (ushort)(t0t1Lsb[0] | ((t0t1Msb & 0b11) << 8));
ushort t1 = (ushort)(t0t1Lsb[1] | ((t0t1Msb & 0b1100) << 6));
return new TuppleUshortUshort(t0, t1);
}
// Original code: private (short T0, short T1) GetTemperatureCalibrationPointsRaw()
private TuppleShortShort GetTemperatureCalibrationPointsRaw()
{
SpanByte t0t1 = new byte[4];
Read(Register.Temperature0Raw, t0t1);
short t0 = BinaryPrimitives.ReadInt16LittleEndian(t0t1.Slice(0, 2));
short t1 = BinaryPrimitives.ReadInt16LittleEndian(t0t1.Slice(2, 2));
return new TuppleShortShort(t0, t1);
}
// Original code: private (byte H0, byte H1) GetHumidityCalibrationPointsRH()
private TuppleByteByte GetHumidityCalibrationPointsRH()
{
SpanByte h0h1 = new byte[2];
Read(Register.Humidity0rHx2, h0h1);
return new TuppleByteByte(h0h1[0], h0h1[1]);
}
// Original code: private (short H0, short H1) GetHumidityCalibrationPointsRaw()
private TuppleShortShort GetHumidityCalibrationPointsRaw()
{
// space in addressing between both registers therefore do 2 reads
short h0 = ReadInt16(Register.Humidity0Raw);
short h1 = ReadInt16(Register.Humidity1Raw);
return new TuppleShortShort(h0, h1);
}
/// <inheritdoc/>
public void Dispose()
{
_i2c?.Dispose();
_i2c = null!;
}
}
}

Просмотреть файл

@ -0,0 +1,70 @@
<?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>{A0C1C89B-1D57-4764-BC9F-98204E84221B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<FileAlignment>512</FileAlignment>
<RootNamespace>Iot.Device.Hts221</RootNamespace>
<AssemblyName>Iot.Device.Hts221</AssemblyName>
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
<DocumentationFile>bin\$(Configuration)\Iot.Device.Hts221.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.RelativeHumidity, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>packages\UnitsNet.nanoFramework.RelativeHumidity.4.92.1\lib\UnitsNet.RelativeHumidity.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="UnitsNet.Temperature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>packages\UnitsNet.nanoFramework.Temperature.4.92.1\lib\UnitsNet.Temperature.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<Compile Include="TuppleShortShort.cs" />
<Compile Include="TuppleUshortUshort.cs" />
<Compile Include="TuppleByteByte.cs" />
<Compile Include="Register.cs" />
<Compile Include="Hts221.cs" />
<None Include="README.md" />
</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\BinaryPrimitives\BinaryPrimitives.projitems" Label="Shared" />
<Import Project="..\..\src\System.Device.Model\System.Device.Model.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,39 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>nanoFramework.Iot.Device.Hts221</id>
<version>$version$</version>
<title>nanoFramework.Iot.Device.Hts221</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.Hts221 for .NET nanoFramework C# projects.</description>
<summary>Iot.Device.Hts221 assembly for .NET nanoFramework C# projects</summary>
<tags>nanoFramework C# csharp netmf netnf Iot.Device.Hts221</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.RelativeHumidity" version="4.92.1" />
<dependency id="UnitsNet.nanoFramework.Temperature" version="4.92.1" />
</dependencies>
</metadata>
<files>
<file src="bin\Release\Iot.Device.Hts221.dll" target="lib\Iot.Device.Hts221.dll" />
<file src="bin\Release\Iot.Device.Hts221.pdb" target="lib\Iot.Device.Hts221.pdb" />
<file src="bin\Release\Iot.Device.Hts221.pdbx" target="lib\Iot.Device.Hts221.pdbx" />
<file src="bin\Release\Iot.Device.Hts221.pe" target="lib\Iot.Device.Hts221.pe" />
<file src="bin\Release\Iot.Device.Hts221.xml" target="lib\Iot.Device.Hts221.xml" />
<file src="readme.md" target="" />
<file src="..\..\assets\nf-logo.png" target="images" />
<file src="..\..\LICENSE.md" target="" />
</files>
</package>

52
devices/Hts221/Hts221.sln Normal file
Просмотреть файл

@ -0,0 +1,52 @@
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}") = "Hts221", "Hts221.nfproj", "{A0C1C89B-1D57-4764-BC9F-98204E84221B}"
EndProject
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Hts221.Samples", "samples\Hts221.Samples.nfproj", "{C4CECB13-E6B2-4B40-8B0F-080D816F0B58}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared Projects", "Shared Projects", "{4DF66B44-AFCA-4606-98BD-1534E233C937}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "BinaryPrimitives", "..\..\src\BinaryPrimitives\BinaryPrimitives.shproj", "{3F28B003-6318-4E21-A9B6-6C0DBD0BDBFD}"
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}") = "Iot.Device.Common", "..\..\src\Iot.Device.Common\Iot.Device.Common.shproj", "{B439A23D-A742-4D1E-B182-7EC4C84DE211}"
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
..\..\src\Iot.Device.Common\Iot.Device.Common.projitems*{b439a23d-a742-4d1e-b182-7ec4c84de211}*SharedItemsImports = 13
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A0C1C89B-1D57-4764-BC9F-98204E84221B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A0C1C89B-1D57-4764-BC9F-98204E84221B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A0C1C89B-1D57-4764-BC9F-98204E84221B}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{A0C1C89B-1D57-4764-BC9F-98204E84221B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A0C1C89B-1D57-4764-BC9F-98204E84221B}.Release|Any CPU.Build.0 = Release|Any CPU
{A0C1C89B-1D57-4764-BC9F-98204E84221B}.Release|Any CPU.Deploy.0 = Release|Any CPU
{C4CECB13-E6B2-4B40-8B0F-080D816F0B58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C4CECB13-E6B2-4B40-8B0F-080D816F0B58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C4CECB13-E6B2-4B40-8B0F-080D816F0B58}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{C4CECB13-E6B2-4B40-8B0F-080D816F0B58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C4CECB13-E6B2-4B40-8B0F-080D816F0B58}.Release|Any CPU.Build.0 = Release|Any CPU
{C4CECB13-E6B2-4B40-8B0F-080D816F0B58}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{3F28B003-6318-4E21-A9B6-6C0DBD0BDBFD} = {4DF66B44-AFCA-4606-98BD-1534E233C937}
{23325B14-3651-4879-9697-9846FF123FEB} = {4DF66B44-AFCA-4606-98BD-1534E233C937}
{B439A23D-A742-4D1E-B182-7EC4C84DE211} = {4DF66B44-AFCA-4606-98BD-1534E233C937}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4A2A74B7-2BF8-4586-BEF2-5AED6DDD35FD}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,10 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Iot.Device.Hts221")]
[assembly: AssemblyCompany("nanoFramework Contributors")]
[assembly: AssemblyCopyright("Copyright(c).NET Foundation and Contributors")]
[assembly: ComVisible(false)]

17
devices/Hts221/README.md Normal file
Просмотреть файл

@ -0,0 +1,17 @@
# HTS221 - Capacitive digital sensor for relative humidity and temperature
Some of the applications mentioned by the datasheet:
- Air conditioning, heating and ventilation
- Air humidifiers
- Refrigerators
- Wearable devices
- Smart home automation
- Industrial automation
- Respiratory equipment
- Asset and goods tracking
See [samples](samples/README.md) for information about usage.
## References
- https://www.st.com/resource/en/datasheet/hts221.pdf

Просмотреть файл

@ -0,0 +1,38 @@
// 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.Hts221
{
internal enum Register : byte
{
WhoAmI = 0x0F, // WHO_AM_I
ResolutionMode = 0x10, // AV_CONF
Control1 = 0x20, // CTRL_REG1
Control2 = 0x21, // CTRL_REG2
Control3 = 0x22, // CTRL_REG3
Status = 0x27, // STATUS_REG
Humidity = 0x28, // 16-bit, HUMIDITY_OUT_L (0x28), HUMIDITY_OUT_H (0x29)
Temperature = 0x2A, // 16-bit, TEMP_OUT_L (0x2A), TEMP_OUT_H (0x2B)
// Calibration registers
// Humidity actual value scaled by 2, point 0 and 1
Humidity0rHx2 = 0x30, // UInt8, H0_rH_x2
Humidity1rHx2 = 0x31, // UInt8, H1_rH_x2
// Temperature actual value scaled by 8, point 0 and 1 (10 bit values)
// 8 least significant bits
Temperature0LsbDegCx8 = 0x32, // UInt8, T0_degC_x8
Temperature1LsbDegCx8 = 0x33, // UInt8, T1_degC_x8
// 2 most significant bits for both points: 0bXXXXAABB (AA=T1.9-8; BB=T0.9-8; X - reserved)
Temperature0And1MsbDegCx8 = 0x35, // 2x UInt2, T1/T0 msb
// Humidity raw value, point 0 and 1
Humidity0Raw = 0x36, // Int16, H0_T0_OUT
Humidity1Raw = 0x3A, // Int16, H1_T0_OUT
// Temperature raw value, point 0 and 1
Temperature0Raw = 0x3C, // Int16, T0_OUT
Temperature1Raw = 0x3E, // Int16, T1_OUT
}
}

Просмотреть файл

@ -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.
namespace Iot.Device.Hts221
{
internal class TuppleByteByte
{
public TuppleByteByte(byte b1, byte b2)
{
B1 = b1;
B2 = b2;
}
public byte B1 { get; set; }
public byte B2 { get; set; }
}
}

Просмотреть файл

@ -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.
namespace Iot.Device.Hts221
{
class TuppleShortShort
{
public TuppleShortShort(short s1, short s2)
{
S1 = s1;
S2 = s2;
}
public short S1 { get; set; }
public short S2 { get; set; }
}
}

Просмотреть файл

@ -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.
namespace Iot.Device.Hts221
{
class TuppleUshortUshort
{
public TuppleUshortUshort(ushort u1, ushort u2)
{
U1 = u1;
U2 = u2;
}
public ushort U1 { get; set; }
public ushort U2 { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,2 @@
hygrometer
thermometer

Просмотреть файл

@ -0,0 +1,8 @@
<?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.RelativeHumidity" version="4.92.1" targetFramework="netnanoframework10" />
<package id="UnitsNet.nanoFramework.Temperature" version="4.92.1" targetFramework="netnanoframework10" />
</packages>

Просмотреть файл

@ -0,0 +1,79 @@
<?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>{C4CECB13-E6B2-4B40-8B0F-080D816F0B58}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<FileAlignment>512</FileAlignment>
<RootNamespace>Iot.Device.Hts221.Samples</RootNamespace>
<AssemblyName>Iot.Device.Hts221.Samples</AssemblyName>
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
<DocumentationFile>bin\$(Configuration)\Iot.Device.Hts221.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="System.Math, Version=1.4.0.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<HintPath>..\packages\nanoFramework.System.Math.1.4.0-preview.7\lib\System.Math.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="UnitsNet.Length, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\UnitsNet.nanoFramework.Length.4.92.1\lib\UnitsNet.Length.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="UnitsNet.Pressure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\UnitsNet.nanoFramework.Pressure.4.92.1\lib\UnitsNet.Pressure.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="UnitsNet.RelativeHumidity, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\UnitsNet.nanoFramework.RelativeHumidity.4.92.1\lib\UnitsNet.RelativeHumidity.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="UnitsNet.Temperature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\UnitsNet.nanoFramework.Temperature.4.92.1\lib\UnitsNet.Temperature.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<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="..\Hts221.nfproj" />
</ItemGroup>
<Import Project="..\..\..\src\Iot.Device.Common\Iot.Device.Common.projitems" Label="Shared" />
<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,34 @@
// 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.Threading;
using System.Device.I2c;
using Iot.Device.Common;
using Iot.Device.Hts221;
using UnitsNet;
using System.Diagnostics;
// I2C address on SenseHat board
const int I2cAddress = 0x5F;
using Hts221 th = new(CreateI2cDevice());
while (true)
{
var tempValue = th.Temperature;
var humValue = th.Humidity;
Debug.WriteLine($"Temperature: {tempValue.DegreesCelsius:0.#}\u00B0C");
Debug.WriteLine($"Relative humidity: {humValue:0.#}%");
// WeatherHelper supports more calculations, such as saturated vapor pressure, actual vapor pressure and absolute humidity.
Debug.WriteLine($"Heat index: {WeatherHelper.CalculateHeatIndex(tempValue, humValue).DegreesCelsius:0.#}\u00B0C");
Debug.WriteLine($"Dew point: {WeatherHelper.CalculateDewPoint(tempValue, humValue).DegreesCelsius:0.#}\u00B0C");
Thread.Sleep(1000);
}
I2cDevice CreateI2cDevice()
{
I2cConnectionSettings settings = new(1, I2cAddress);
return I2cDevice.Create(settings);
}

Просмотреть файл

@ -0,0 +1,10 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Iot.Device.Hts221.Samples")]
[assembly: AssemblyCompany("nanoFramework Contributors")]
[assembly: AssemblyCopyright("Copyright(c).NET Foundation and Contributors")]
[assembly: ComVisible(false)]

Просмотреть файл

@ -0,0 +1,34 @@
# HTS221 - Capacitive digital sensor for relative humidity and temperature
```csharp
class Program
{
// I2C address on SenseHat board
public const int I2cAddress = 0x5F;
static void Main(string[] args)
{
using (var th = new Hts221(CreateI2cDevice()))
{
while (true)
{
var tempValue = th.Temperature;
var humValue = th.Humidity;
Console.WriteLine($"Temperature: {tempValue.Celsius:0.#}\u00B0C");
Console.WriteLine($"Relative humidity: {humValue:0.#}%");
// WeatherHelper supports more calculations, such as saturated vapor pressure, actual vapor pressure and absolute humidity.
Console.WriteLine($"Heat index: {WeatherHelper.CalculateHeatIndex(tempValue, humValue).Celsius:0.#}\u00B0C");
Console.WriteLine($"Dew point: {WeatherHelper.CalculateDewPoint(tempValue, humValue).Celsius:0.#}\u00B0C");
Thread.Sleep(1000);
}
}
}
private static I2cDevice CreateI2cDevice()
{
var settings = new I2cConnectionSettings(1, I2cAddress);
return I2cDevice.Create(settings);
}
}
```

Просмотреть файл

@ -0,0 +1,10 @@
<?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="nanoFramework.System.Math" version="1.4.0-preview.7" targetFramework="netnanoframework10" />
<package id="UnitsNet.nanoFramework.Length" version="4.92.1" targetFramework="netnanoframework10" />
<package id="UnitsNet.nanoFramework.Pressure" version="4.92.1" targetFramework="netnanoframework10" />
<package id="UnitsNet.nanoFramework.RelativeHumidity" version="4.92.1" targetFramework="netnanoframework10" />
<package id="UnitsNet.nanoFramework.Temperature" version="4.92.1" targetFramework="netnanoframework10" />
</packages>

Просмотреть файл

@ -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
}
}