Class AnalogInputPortBase
Provides a base implementation for much of the common tasks of implementing IAnalogInputPort
Assembly: Meadow.Contracts.dll
View Source
public abstract class AnalogInputPortBase : AnalogPortBase, IAnalogInputPort, IAnalogPort, IPort<IAnalogChannelInfo>, IDisposable, IObservable<IChangeResult<Voltage>>
Inheritance: System.Object
-> Meadow.Hardware.PortBase<C>
Derived:
Meadow.Hardware.AnalogInputPort
Implements:
Meadow.Hardware.IAnalogInputPort, System.IDisposable
, System.IObservable<Meadow.IChangeResult<Meadow.Units.Voltage>>
Properties
BufferSyncRoot
Gets the internal synchronization object for the analog buffer
View Source
protected object BufferSyncRoot { get; }
VoltageSampleBuffer
Gets the sample buffer. Make sure to call StartUpdating() before use.
View Source
public Voltage[] VoltageSampleBuffer { get; }
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.
View Source
public TimeSpan UpdateInterval { get; protected set; }
SampleCount
Number of samples to take per reading. If > 1
then the port will
take multiple readings and These are automatically averaged to
reduce noise, a process known as oversampling.
View Source
public int SampleCount { get; protected set; }
SampleInterval
Duration in between samples when oversampling.
View Source
public TimeSpan SampleInterval { get; protected set; }
ReferenceVoltage
The reference voltage being used for the ADC comparison
View Source
public Voltage ReferenceVoltage { get; protected set; }
Voltage
Gets the average value of the values in the buffer. Use in conjunction with StartUpdating() for long-running analog sampling. For occasional sampling, use Read().
View Source
public virtual Voltage Voltage { get; }
Observers
A collection of state observers
View Source
protected List<IObserver<IChangeResult<Voltage>>> Observers { get; }
Methods
ConvertReadingToVoltage(int)
Converts a raw 32-bit reading to a scaled value in volts
View Source
protected double ConvertReadingToVoltage(int rawReading)
Returns
System.Double
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rawReading | The raw reading to convert |
Read()
Convenience method to get the current voltage. For frequent reads, use StartUpdating() and StopUpdating() in conjunction with the SampleBuffer.
View Source
public abstract Task<Voltage> Read()
Returns
System.Threading.Tasks.Task<Meadow.Units.Voltage>
StartUpdating(TimeSpan?)
Starts continuously sampling the analog port.
This method also starts raising Changed
events and IObservable
subscribers getting notified. Use the readIntervalDuration
parameter
to specify how often events and notifications are raised/sent.
View Source
public abstract void StartUpdating(TimeSpan? updateInterval)
Parameters
Type | Name |
---|---|
System.Nullable<System.TimeSpan> | updateInterval |
StopUpdating()
Stops sampling the analog port.
View Source
public abstract void StopUpdating()
RaiseChangedAndNotify(IChangeResult<Voltage>)
Raises the Changed event and notifies the observers with the specified change result.
View Source
protected void RaiseChangedAndNotify(IChangeResult<Voltage> changeResult)
Parameters
Type | Name | Description |
---|---|---|
Meadow.IChangeResult<UNIT> | changeResult | The change result to be passed to the event and observers. |
Subscribe(IObserver<IChangeResult<Voltage>>)
Subscribes an observer to receive notifications of voltage change.
View Source
public IDisposable Subscribe(IObserver<IChangeResult<Voltage>> observer)
Returns
System.IDisposable
: An IDisposable object that can be used to unsubscribe from the observer.
Parameters
Type | Name | Description |
---|---|---|
System.IObserver<Meadow.IChangeResult<Meadow.Units.Voltage>> | observer | The observer to subscribe. |
Events
Updated
Raised when the value of the reading changes.
View Source
public event EventHandler<IChangeResult<Voltage>> Updated
Event Type
System.EventHandler<Meadow.IChangeResult<Meadow.Units.Voltage>>
Implements
- Meadow.Hardware.IAnalogInputPort
- Meadow.Hardware.IAnalogPort
- Meadow.Hardware.IPort<C>
System.IDisposable
System.IObservable<Meadow.IChangeResult<Meadow.Units.Voltage>>