Remarks

CTempHum15
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation.mikroBUS.Sensors.Atmospheric.CTempHum15

Code Example

CTempHum15 cTempHum15;

public MeadowApp()
{
    Console.WriteLine("Initializing...");

    cTempHum15 = new CTempHum15(Device.CreateI2cBus());

    var consumer = CTempHum15.CreateObserver(
        handler: result =>
        {
            Console.WriteLine($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C");
        },
        filter: result =>
        {
            //c# 8 pattern match syntax. checks for !null and assigns var.
            if (result.Old is { } old)
            {
                return (
                (result.New.Temperature.Value - old.Temperature.Value).Abs().Celsius > 0.5
                &&
                (result.New.Humidity.Value.Percent - old.Humidity.Value.Percent) > 0.05
                );
            }
            return false;
        }
    );
    cTempHum15.Subscribe(consumer);

    cTempHum15.Updated += (sender, result) =>
    {
        Console.WriteLine($"  Temperature: {result.New.Temperature?.Celsius:N2}C");
        Console.WriteLine($"  Relative Humidity: {result.New.Humidity:N2}%");
    };

    ReadConditions().Wait();

    cTempHum15.StartUpdating(TimeSpan.FromSeconds(1));
}

async Task ReadConditions()
{
    var conditions = await cTempHum15.Read();
    Console.WriteLine("Initial Readings:");
    Console.WriteLine($"  Temperature: {conditions.Temperature?.Celsius:N2}C");
    Console.WriteLine($"  Relative Humidity: {conditions.Humidity?.Percent:N2}%");
}

Sample project(s) available on GitHub

Characteristic Locus
Inheritance object ObservableBase<(Temperature? Temperature, RelativeHumidity? Humidity)> SamplingSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)> PollingSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)> ByteCommsSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)> Sht4x > CTempHum15
Implements IObservable<IChangeResult<(Temperature? Temperature, RelativeHumidity? Humidity)>> ISamplingSensor<(Temperature? Temperature, RelativeHumidity? Humidity)> ISensor<(Temperature? Temperature, RelativeHumidity? Humidity)> IDisposable ITemperatureSensor ISamplingSensor<Temperature> ISensor<Temperature> IHumiditySensor ISamplingSensor<RelativeHumidity> ISensor<RelativeHumidity> II2cPeripheral
Inherited Members Sht4x.ReadPrecision Sht4x.TemperatureUpdated Sht4x.HumidityUpdated Sht4x.Temperature Sht4x.Humidity Sht4x.DefaultI2cAddress Sht4x.RaiseEventsAndNotify(IChangeResult<(Temperature? Temperature, RelativeHumidity? Humidity)>) Sht4x.GetDelayForPrecision(Sht4x.Precision) Sht4x.ReadSensor() ByteCommsSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.BusComms ByteCommsSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.ReadBuffer ByteCommsSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.WriteBuffer ByteCommsSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.Init(int, int) ByteCommsSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.Dispose(bool) ByteCommsSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.Dispose() PollingSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.StartUpdating(TimeSpan?) PollingSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.StopUpdating() SamplingSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.samplingLock SamplingSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.Updated SamplingSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.SamplingTokenSource SamplingSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.Conditions SamplingSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.IsSampling SamplingSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.UpdateInterval SamplingSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.ReadSensor() SamplingSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.RaiseEventsAndNotify(IChangeResult<(Temperature? Temperature, RelativeHumidity? Humidity)>) SamplingSensorBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.Read() ObservableBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.observers ObservableBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.NotifyObservers(IChangeResult<(Temperature? Temperature, RelativeHumidity? Humidity)>) ObservableBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.Subscribe(IObserver<IChangeResult<(Temperature? Temperature, RelativeHumidity? Humidity)>>) ObservableBase<(Temperature? Temperature, RelativeHumidity? Humidity)>.CreateObserver(Action<IChangeResult<(Temperature? Temperature, RelativeHumidity? Humidity)>>, Predicate<IChangeResult<(Temperature? Temperature, RelativeHumidity? Humidity)>>) object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString()
Namespace Meadow.Foundation.mikroBUS.Sensors.Atmospheric
Assembly CTempHum15.dll

Syntax

public class CTempHum15 : Sht4x, IObservable<IChangeResult<(Temperature? Temperature, RelativeHumidity? Humidity)>>, ISamplingSensor<(Temperature? Temperature, RelativeHumidity? Humidity)>, ISensor<(Temperature? Temperature, RelativeHumidity? Humidity)>, IDisposable, ITemperatureSensor, ISamplingSensor<Temperature>, ISensor<Temperature>, IHumiditySensor, ISamplingSensor<RelativeHumidity>, ISensor<RelativeHumidity>, II2cPeripheral

Constructors

CTempHum15(II2cBus)

Creates a CTempHum15 driver

Declaration
public CTempHum15(II2cBus i2cBus)

Parameters

Type Name Description
II2cBus i2cBus

Remarks

CTempHum15
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation.mikroBUS.Sensors.Atmospheric.CTempHum15

Code Example

CTempHum15 cTempHum15;

public MeadowApp()
{
    Console.WriteLine("Initializing...");

    cTempHum15 = new CTempHum15(Device.CreateI2cBus());

    var consumer = CTempHum15.CreateObserver(
        handler: result =>
        {
            Console.WriteLine($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C");
        },
        filter: result =>
        {
            //c# 8 pattern match syntax. checks for !null and assigns var.
            if (result.Old is { } old)
            {
                return (
                (result.New.Temperature.Value - old.Temperature.Value).Abs().Celsius > 0.5
                &&
                (result.New.Humidity.Value.Percent - old.Humidity.Value.Percent) > 0.05
                );
            }
            return false;
        }
    );
    cTempHum15.Subscribe(consumer);

    cTempHum15.Updated += (sender, result) =>
    {
        Console.WriteLine($"  Temperature: {result.New.Temperature?.Celsius:N2}C");
        Console.WriteLine($"  Relative Humidity: {result.New.Humidity:N2}%");
    };

    ReadConditions().Wait();

    cTempHum15.StartUpdating(TimeSpan.FromSeconds(1));
}

async Task ReadConditions()
{
    var conditions = await cTempHum15.Read();
    Console.WriteLine("Initial Readings:");
    Console.WriteLine($"  Temperature: {conditions.Temperature?.Celsius:N2}C");
    Console.WriteLine($"  Relative Humidity: {conditions.Humidity?.Percent:N2}%");
}

Sample project(s) available on GitHub