Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Syntax
public class Tsl2591 : ByteCommsSensorBase<(Illuminance? FullSpectrum, Illuminance? Infrared, Illuminance? VisibleLight, Illuminance? Integrated)>, IObservable<IChangeResult<(Illuminance? FullSpectrum, Illuminance? Infrared, Illuminance? VisibleLight, Illuminance? Integrated)>>, ISamplingSensor<(Illuminance? FullSpectrum, Illuminance? Infrared, Illuminance? VisibleLight, Illuminance? Integrated)>, ISensor<(Illuminance? FullSpectrum, Illuminance? Infrared, Illuminance? VisibleLight, Illuminance? Integrated)>, ILightSensor, ISamplingSensor<Illuminance>, ISensor<Illuminance>, IDisposable, IPowerControllablePeripheral
Constructors
Tsl2591(II2cBus, byte)
Create a new Tsl2591 object
Declaration
public Tsl2591(II2cBus i2cBus, byte address = 41)
Parameters
Type | Name | Description |
---|---|---|
II2cBus | i2cBus | The I2C bus |
byte | address | The I2C address |
Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Properties
DeviceID
Sensor device ID
Declaration
public int DeviceID { get; }
Property Value
Type | Description |
---|---|
int |
Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
FullSpectrumLuminosity
Full spectrum luminosity (visible and infrared light combined)
Declaration
public Illuminance? FullSpectrumLuminosity { get; }
Property Value
Type | Description |
---|---|
Illuminance? |
Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Gain
Gain of the sensor
Declaration
public Tsl2591.GainFactor Gain { get; set; }
Property Value
Type | Description |
---|---|
Tsl2591.GainFactor |
Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Illuminance
Visible lux
Declaration
public Illuminance? Illuminance { get; }
Property Value
Type | Description |
---|---|
Illuminance? |
Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
InfraredLuminosity
Infrared light luminosity
Declaration
public Illuminance? InfraredLuminosity { get; }
Property Value
Type | Description |
---|---|
Illuminance? |
Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
IntegrationTime
Integration time for the sensor
Declaration
public Tsl2591.IntegrationTimes IntegrationTime { get; set; }
Property Value
Type | Description |
---|---|
Tsl2591.IntegrationTimes |
Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
PackageID
Sensor package ID
Declaration
public int PackageID { get; }
Property Value
Type | Description |
---|---|
int |
Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
VisibleLightLuminosity
Visible light luminosity
Declaration
public Illuminance? VisibleLightLuminosity { get; }
Property Value
Type | Description |
---|---|
Illuminance? |
Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Methods
PowerOff()
Power the sensor off
Declaration
public Task PowerOff()
Returns
Type | Description |
---|---|
Task |
Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
PowerOn()
Power the sensor on
Declaration
public Task PowerOn()
Returns
Type | Description |
---|---|
Task |
Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
RaiseEventsAndNotify(IChangeResult<(Illuminance? FullSpectrum, Illuminance? Infrared, Illuminance? VisibleLight, Illuminance? Integrated)>)
Raise events for subscribers and notify of value changes
Declaration
protected override void RaiseEventsAndNotify(IChangeResult<(Illuminance? FullSpectrum, Illuminance? Infrared, Illuminance? VisibleLight, Illuminance? Integrated)> changeResult)
Parameters
Type | Name | Description |
---|---|---|
IChangeResult<(Illuminance? FullSpectrum, Illuminance? Infrared, Illuminance? VisibleLight, Illuminance? Integrated)> | changeResult | The updated sensor data |
Overrides
Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
ReadSensor()
Reads data from the sensor
Declaration
protected override Task<(Illuminance? FullSpectrum, Illuminance? Infrared, Illuminance? VisibleLight, Illuminance? Integrated)> ReadSensor()
Returns
Type | Description |
---|---|
Task<(Illuminance? FullSpectrum, Illuminance? Infrared, Illuminance? VisibleLight, Illuminance? Integrated)> | The latest sensor reading |
Overrides
Meadow.Foundation.SamplingSensorBase<(Meadow.Units.Illuminance? FullSpectrum, Meadow.Units.Illuminance? Infrared, Meadow.Units.Illuminance? VisibleLight, Meadow.Units.Illuminance? Integrated)>.ReadSensor()
Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Events
FullSpectrumUpdated
Raised when Full Spectrum Illuminance value changes
Declaration
public event EventHandler<IChangeResult<Illuminance>> FullSpectrumUpdated
Event Type
Type | Description |
---|---|
EventHandler<IChangeResult<Illuminance>> |
Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
IlluminanceUpdated
Raised when Luminosity value changes
Declaration
public event EventHandler<IChangeResult<Illuminance>> IlluminanceUpdated
Event Type
Type | Description |
---|---|
EventHandler<IChangeResult<Illuminance>> |
Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
InfraredUpdated
Raised when Infrared Illuminance value changes
Declaration
public event EventHandler<IChangeResult<Illuminance>> InfraredUpdated
Event Type
Type | Description |
---|---|
EventHandler<IChangeResult<Illuminance>> |
Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
VisibleLightUpdated
Raised when Visible Light value changes
Declaration
public event EventHandler<IChangeResult<Illuminance>> VisibleLightUpdated
Event Type
Type | Description |
---|---|
EventHandler<IChangeResult<Illuminance>> |
Remarks
Tsl2591 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Tsl2591 sensor;
public override Task Initialize()
{
Resolver.Log.Info("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 => Resolver.Log.Info($"Observer: filter satisfied: {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)
{
// 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) =>
{
Resolver.Log.Info($" Full Spectrum Light: {result.New.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.New.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.New.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.New.Integrated?.Lux:N2}Lux");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Full Spectrum Light: {result.FullSpectrum?.Lux:N2}Lux");
Resolver.Log.Info($" Infrared Light: {result.Infrared?.Lux:N2}Lux");
Resolver.Log.Info($" Visible Light: {result.VisibleLight?.Lux:N2}Lux");
Resolver.Log.Info($" Integrated Light: {result.Integrated?.Lux:N2}Lux");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}