Skip to main content

Interface IObservableAnalogInputPort

Contract for ports that implement an observable, sampling analog input channel.

Assembly: Meadow.Contracts.dll
View Source
Declaration
public interface IObservableAnalogInputPort : IAnalogInputPort, IAnalogPort, IPort<IAnalogChannelInfo>, IDisposable, IObservable<IChangeResult<Voltage>>

Properties

VoltageSampleBuffer

Gets the sample buffer.

View Source
Declaration
Voltage[] VoltageSampleBuffer { get; }

Voltage

Gets the average value of the values in the buffer. Use in conjunction with StartSampling() for long-running analog sampling. For occasional sampling, use Read().

View Source
Declaration
Voltage Voltage { get; }

UpdateInterval

A System.TimeSpan that specifies how long to wait between readings. This value influences how often Updated events are raised and IObservable consumers are notified.

View Source
Declaration
TimeSpan UpdateInterval { get; }

SampleCount

Number of samples to take per reading. If > 0, then the port will take multiple readings and automatically average them to reduce noise, a process known as oversampling.

View Source
Declaration
int SampleCount { get; }

SampleInterval

Duration between samples when oversampling.

View Source
Declaration
TimeSpan SampleInterval { get; }

Methods

StartUpdating(TimeSpan?)

Starts continuously sampling the analog port.

This method also starts raising Updated events and notifying IObservable subscribers. Use the updateInterval parameter to specify how often events and notifications are raised.

View Source
Declaration
void StartUpdating(TimeSpan? updateInterval = null)
Parameters
TypeNameDescription
System.Nullable<System.TimeSpan>updateIntervalThe interval between readings.

StopUpdating()

Stops sampling the analog port.

View Source
Declaration
void StopUpdating()

CreateObserver(Action<IChangeResult<Voltage>>, Predicate<IChangeResult<Voltage>>?)

Creates an observer for monitoring changes in the analog input voltage.

View Source
Declaration
public static FilterableChangeObserver<Voltage> CreateObserver(Action<IChangeResult<Voltage>> handler, Predicate<IChangeResult<Voltage>>? filter = null)
Returns

Meadow.FilterableChangeObserver<UNIT>: The created observer.

Parameters
TypeNameDescription
System.Action<Meadow.IChangeResult<Meadow.Units.Voltage>>handlerThe handler to be called when a change occurs.
System.Predicate<Meadow.IChangeResult<Meadow.Units.Voltage>>filterAn optional filter predicate for filtering changes.

Events

Updated

Raised when the value of the reading changes.

View Source
Declaration
event EventHandler<IChangeResult<Voltage>> Updated
Event Type

System.EventHandler<Meadow.IChangeResult<Meadow.Units.Voltage>>