Skip to main content

Meadow.Foundation.Sensors.Light.AnalogSolarIntensityGauge

AnalogSolarIntensityGauge
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.Light.AnalogSolarIntensityGauge

Code Example

AnalogSolarIntensityGauge solarGauge;

public override Task Initialize()
{
Resolver.Log.Info("Initialize...");

solarGauge = new AnalogSolarIntensityGauge(Device.Pins.A02, updateInterval: TimeSpan.FromSeconds(1));

//==== classic .NET Event
solarGauge.Updated += (s, result) => Resolver.Log.Info($"SolarIntensityUpdated: {result.New * 100:n2}%");

//==== Filterable observer
var observer = AnalogSolarIntensityGauge.CreateObserver(
handler: result => Resolver.Log.Info($"Observer filter satisfied, new intensity: {result.New * 100:n2}%"),
filter: result =>
{
if (result.Old is { } old)
{
return (Math.Abs(result.New - old) > 0.05); // only notify if change is > 5%
}
return false;
});
solarGauge.Subscribe(observer);

return Task.CompletedTask;
}

public override async Task Run()
{
var result = await solarGauge.Read();
Resolver.Log.Info($"Solar Intensity: {result * 100:n2}%");

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

Sample project(s) available on GitHub

Class AnalogSolarIntensityGauge

Driver to measure solar panel input

Assembly: AnalogSolarIntensityGauge.dll
View Source
Declaration
public class AnalogSolarIntensityGauge : SamplingSensorBase<float>, IObservable<IChangeResult<float>>, ISamplingSensor<float>, ISamplingSensor, ISolarIntensityGauge, ISensor<float>, ISensor, IDisposable

Inheritance: System.Object -> Meadow.Foundation.ObservableBase<UNIT>

Implements:
System.IObservable<Meadow.IChangeResult<System.Single>>, Meadow.Peripherals.Sensors.ISamplingSensor<System.Single>, Meadow.Peripherals.Sensors.ISamplingSensor, Meadow.Peripherals.Sensors.Light.ISolarIntensityGauge, Meadow.Peripherals.Sensors.ISensor<System.Single>, Meadow.Peripherals.Sensors.ISensor, System.IDisposable

Properties

MinVoltageReference

Minimum voltage reference

View Source
Declaration
public Voltage MinVoltageReference { get; protected set; }

MaxVoltageReference

Maximum voltage reference

View Source
Declaration
public Voltage MaxVoltageReference { get; protected set; }

SolarIntensity

Gets percentage of solar intensity, from 0 to 1.0, with 1.0 being the MaxVoltageReference, and 0 being the MinVoltageReference.

View Source
Declaration
public float? SolarIntensity { get; protected set; }

IsDisposed

Is the object disposed

View Source
Declaration
public bool IsDisposed { get; }

Methods

Initialize()

Initialize the sensor

View Source
Declaration
protected void Initialize()

ReadSensor()

Reads data from the sensor

View Source
Declaration
protected override Task<float> ReadSensor()
Returns

System.Threading.Tasks.Task<System.Single>: The latest sensor reading### StartUpdating(TimeSpan?) Starts continuously sampling the sensor

This method also starts raising SolarIntensityUpdated events and IObservable subscribers getting notified. Use the readIntervalDuration parameter to specify how often events and notifications are raised/sent.

View Source
Declaration
public override void StartUpdating(TimeSpan? updateInterval)
Parameters
TypeNameDescription
System.Nullable<System.TimeSpan>updateIntervalA TimeSpan that specifies how long to
 wait between readings. This value influences how often `*Updated`
events are raised and `IObservable` consumers are notified. |

StopUpdating()

Stops sampling the solar intensity

View Source
Declaration
public override void StopUpdating()

ConvertVoltageToIntensity(Voltage)

Converts a voltage reading to a solar intensity percentage, taking into account the minimum and maximum expected values.

View Source
Declaration
protected float ConvertVoltageToIntensity(Voltage voltage)
Returns

System.Single: 0.0 - 1.0

Parameters
TypeName
Meadow.Units.Voltagevoltage

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

View Source
Declaration
public void Dispose()

Dispose(bool)

Dispose of the object

View Source
Declaration
protected virtual void Dispose(bool disposing)
Parameters
TypeNameDescription
System.BooleandisposingIs disposing

Implements

  • System.IObservable<Meadow.IChangeResult<System.Single>>
  • Meadow.Peripherals.Sensors.ISamplingSensor<System.Single>
  • Meadow.Peripherals.Sensors.ISamplingSensor
  • Meadow.Peripherals.Sensors.Light.ISolarIntensityGauge
  • Meadow.Peripherals.Sensors.ISensor<System.Single>
  • Meadow.Peripherals.Sensors.ISensor
  • System.IDisposable