Characteristic | Locus |
---|---|
Inheritance | System.Object ObservableBase<UNIT> > SamplingSensorBase<UNIT> > PollingSensorBase<UNIT> > AnalogSamplingBase > AnalogWaterLevel > AnalogJoystick > AnalogLightSensor > AnalogTemperature |
Implements | ISamplingSensor<UNIT> |
Inherited Members | ObservableBase<UNIT>.observers ObservableBase<UNIT>.NotifyObservers(IChangeResult<UNIT>) ObservableBase<UNIT>.Subscribe(IObserver<IChangeResult<UNIT>>) ObservableBase<UNIT>.CreateObserver(Action<IChangeResult<UNIT>>, Nullable<Predicate<IChangeResult<UNIT>>>) |
Namespace | Meadow.Foundation |
Assembly | Meadow.Foundation.dll |
Syntax
public abstract class SamplingSensorBase<UNIT> : ObservableBase<UNIT>, ISamplingSensor<UNIT> where UNIT : struct
Type Parameters
Name | Description |
---|---|
UNIT |
Fields
samplingLock
Lock for sampling
Declaration
protected object samplingLock
Field Value
Type | Description |
---|---|
System.Object |
Properties
Conditions
The last read conditions
Declaration
public UNIT Conditions { get; protected set; }
Property Value
Type | Description |
---|---|
UNIT |
IsSampling
Gets a value indicating whether the sensor is currently in a sampling loop. Call StartSampling() to spin up the sampling process.
Declaration
public bool IsSampling { get; protected set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
SamplingTokenSource
Sampling cancellation token source
Declaration
protected CancellationTokenSource? SamplingTokenSource { get; set; }
Property Value
Type | Description |
---|---|
System.Nullable<CancellationTokenSource> |
UpdateInterval
A TimeSpan
that specifies how long to
wait between readings. This value influences how often *Updated
events are raised and IObservable
consumers are notified.
Declaration
public virtual TimeSpan UpdateInterval { get; protected set; }
Property Value
Type | Description |
---|---|
TimeSpan |
Methods
RaiseEventsAndNotify(IChangeResult<UNIT>)
Notify observers
Declaration
protected virtual void RaiseEventsAndNotify(IChangeResult<UNIT> changeResult)
Parameters
Type | Name | Description |
---|---|---|
IChangeResult<UNIT> | changeResult | provides new and old values |
Read()
Convenience method to get the current sensor readings. For frequent reads, use StartSampling() and StopSampling() in conjunction with the SampleBuffer.
Declaration
public virtual Task<UNIT> Read()
Returns
Type | Description |
---|---|
Task<UNIT> |
ReadSensor()
Read value from sensor
Declaration
protected abstract Task<UNIT> ReadSensor()
Returns
Type | Description |
---|---|
Task<UNIT> | unitized value |
StartUpdating(Nullable<TimeSpan>)
Starts updating the sensor on the updateInterval frequency specified
Declaration
public abstract void StartUpdating(TimeSpan? updateInterval = null)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<TimeSpan> | updateInterval | A TimeSpan that specifies how long to wait between readings |
StopUpdating()
Stops sampling the sensor
Declaration
public abstract void StopUpdating()
Events
Updated
Event handler for updated values
Declaration
public event EventHandler<IChangeResult<UNIT>> Updated
Event Type
Type | Description |
---|---|
EventHandler<IChangeResult<UNIT>> |