Remarks

Tsl2591
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Light.Tsl2591

Code Example

Tsl2591 sensor;

public override Task Initialize()
{
    Console.WriteLine("Initialize...");

    // configure our sensor on the I2C Bus
    var i2c = Device.CreateI2cBus();
    sensor = new Tsl2591(i2c);

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Tsl2591.CreateObserver(
        handler: result => Console.WriteLine($"Observer: filter satisifed: {result.New.VisibleLight?.Lux:N2}Lux, old: {result.Old?.VisibleLight?.Lux:N2}Lux"),
        // only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
        filter: result => {
            if (result.Old is { } old) { //c# 8 pattern match syntax. checks for !null and assigns var.
                // returns true if > 100lux change
                return ( (result.New.VisibleLight.Value - old.VisibleLight.Value).Abs().Lux > 100 ); 
            }
            return false;
        });
    sensor.Subscribe(consumer);

    // classical .NET events can also be used:
    sensor.Updated += (sender, result) => {
        Console.WriteLine($"  Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
        Console.WriteLine($"  Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
        Console.WriteLine($"  Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
        Console.WriteLine($"  Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    var result = await sensor.Read();
    Console.WriteLine("Initial Readings:");
    Console.WriteLine($"  Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
    Console.WriteLine($"  Infrared Light: {result.Infrared?.Lux:N2}Lux");
    Console.WriteLine($"  Visible Light: {result.VisibleLight?.Lux:N2}Lux");
    Console.WriteLine($"  Integrated Light: {result.Integrated?.Lux:N2}Lux");

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

Sample project(s) available on GitHub

Characteristic Locus
Inheritance System.Object ObservableBase<System.ValueTuple<System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>>> SensorBase<System.ValueTuple<System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>>> SamplingSensorBase<System.ValueTuple<System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>>> ByteCommsSensorBase<System.ValueTuple<System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>>> > Tsl2591
Implements IDisposable ILightSensor IDisposable
Inherited Members ByteCommsSensorBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.Peripheral ByteCommsSensorBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.ReadBuffer ByteCommsSensorBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.WriteBuffer ByteCommsSensorBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.Init(Int32, Int32) ByteCommsSensorBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.Dispose(Boolean) ByteCommsSensorBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.Dispose() SamplingSensorBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.StartUpdating(Nullable<TimeSpan>) SamplingSensorBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.StopUpdating() SensorBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.Updated SensorBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.samplingLock SensorBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.SamplingTokenSource SensorBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.Conditions SensorBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.IsSampling SensorBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.UpdateInterval SensorBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.ReadSensor() SensorBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.RaiseEventsAndNotify(IChangeResult<>) SensorBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.Read() ObservableBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.observers ObservableBase<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>>>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>>>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Sensors.Light
Assembly Tsl2591.dll

Syntax

public class Tsl2591 : ByteCommsSensorBase<(Illuminance? FullSpectrum, Illuminance? Infrared, Illuminance? VisibleLight, Illuminance? Integrated)>, IDisposable, ILightSensor, IDisposable

Constructors

Tsl2591(II2cBus, Byte, Int32)

Declaration
public Tsl2591(II2cBus bus, byte address = null, int updateIntervalMs = 1000)

Parameters

Type Name Description
II2cBus bus
System.Byte address
System.Int32 updateIntervalMs

Properties

DeviceID

Declaration
public int DeviceID { get; }

Property Value

Type Description
System.Int32

FullSpectrumLuminosity

Full spectrum luminosity (visible and infrared light combined).

Declaration
public Illuminance? FullSpectrumLuminosity { get; }

Property Value

Type Description
System.Nullable<Illuminance>

Gain

Gain of the sensor.

Declaration
public Tsl2591.GainFactor Gain { get; set; }

Property Value

Type Description
Tsl2591.GainFactor

Illuminance

Visible lux.

Declaration
public Illuminance? Illuminance { get; }

Property Value

Type Description
System.Nullable<Illuminance>

InfraredLuminosity

Infrared light luminosity.

Declaration
public Illuminance? InfraredLuminosity { get; }

Property Value

Type Description
System.Nullable<Illuminance>

IntegrationTime

Integration time for the sensor.

Declaration
public Tsl2591.IntegrationTimes IntegrationTime { get; set; }

Property Value

Type Description
Tsl2591.IntegrationTimes

PackageID

Declaration
public int PackageID { get; }

Property Value

Type Description
System.Int32

VisibleLightLuminosity

Visible light luminosity.

Declaration
public Illuminance? VisibleLightLuminosity { get; }

Property Value

Type Description
System.Nullable<Illuminance>

Methods

PowerOff()

Declaration
public void PowerOff()

PowerOn()

Declaration
public void PowerOn()

RaiseEventsAndNotify(IChangeResult<(Nullable<Illuminance> FullSpectrum, Nullable<Illuminance> Infrared, Nullable<Illuminance> VisibleLight, Nullable<Illuminance> Integrated)>)

Declaration
protected override void RaiseEventsAndNotify(IChangeResult<(Illuminance? FullSpectrum, Illuminance? Infrared, Illuminance? VisibleLight, Illuminance? Integrated)> changeResult)

Parameters

Type Name Description
IChangeResult<System.ValueTuple<System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>>> changeResult

ReadSensor()

Declaration
protected override Task<(Illuminance? FullSpectrum, Illuminance? Infrared, Illuminance? VisibleLight, Illuminance? Integrated)> ReadSensor()

Returns

Type Description
Task<System.ValueTuple<System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>>>

Overrides

Meadow.Foundation.SensorBase<System.ValueTuple<System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>, System.Nullable<Illuminance>>>.ReadSensor()

Events

FullSpectrumUpdated

Declaration
public event EventHandler<IChangeResult<Illuminance>> FullSpectrumUpdated

Event Type

Type Description
EventHandler<IChangeResult<Illuminance>>

InfraredUpdated

Declaration
public event EventHandler<IChangeResult<Illuminance>> InfraredUpdated

Event Type

Type Description
EventHandler<IChangeResult<Illuminance>>

LuminosityUpdated

Declaration
public event EventHandler<IChangeResult<Illuminance>> LuminosityUpdated

Event Type

Type Description
EventHandler<IChangeResult<Illuminance>>

VisibleLightUpdated

Declaration
public event EventHandler<IChangeResult<Illuminance>> VisibleLightUpdated

Event Type

Type Description
EventHandler<IChangeResult<Illuminance>>