Meadow.Foundation.Sensors.Distance.Me007ys
Me007ys | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Me007ys me007ys;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
me007ys = new Me007ys(Device, Device.PlatformOS.GetSerialPortName("COM1"));
var consumer = Me007ys.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Observer: Distance changed by threshold; new distance: {result.New.Centimeters:N1}cm, old: {result.Old?.Centimeters:N1}cm");
},
filter: result =>
{
if (result.Old is { } old)
{
return Math.Abs((result.New - old).Centimeters) > 5.0;
}
return false;
}
);
me007ys.Subscribe(consumer);
me007ys.Updated += Me007y_DistanceUpdated;
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("Run...");
var distance = await me007ys.Read();
Resolver.Log.Info($"Initial distance is: {distance.Centimeters:N1}cm / {distance.Inches:N1}in");
me007ys.StartUpdating(TimeSpan.FromSeconds(2));
}
private void Me007y_DistanceUpdated(object sender, IChangeResult<Length> e)
{
Resolver.Log.Info($"Distance: {e.New.Centimeters:N1}cm / {e.New.Inches:N1}in");
}
Sample project(s) available on GitHub
Class Me007ys
Represents the ME007YS serial distance sensor
Assembly: Me007ys.dll
View Source
public class Me007ys : PollingSensorBase<Length>, IObservable<IChangeResult<Length>>, IRangeFinder, ISamplingSensor<Length>, ISensor<Length>, ISensor, ISamplingSensor, ISleepAwarePeripheral, IDisposable
Inheritance: System.Object
-> Meadow.Foundation.ObservableBase<UNIT>
Implements:
System.IObservable<Meadow.IChangeResult<Meadow.Units.Length>>
, Meadow.Peripherals.Sensors.Distance.IRangeFinder
, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Length>
, Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Length>
, Meadow.Peripherals.Sensors.ISensor
, Meadow.Peripherals.Sensors.ISamplingSensor
, Meadow.ISleepAwarePeripheral
, System.IDisposable
Properties
Distance
Distance from sensor to object
View Source
public Length? Distance { get; }
OutOfRangeValue
Value returned when the sensor cannot determine the distance
View Source
public Length OutOfRangeValue { get; }
SensorReadTimeOut
The maximum time to wait for a sensor reading
View Source
public TimeSpan SensorReadTimeOut { get; set; }
Methods
MeasureDistance()
Start a distance measurement
View Source
public void MeasureDistance()
Read()
Convenience method to get the current sensor reading
View Source
public override Task<Length> Read()
Returns
System.Threading.Tasks.Task<Meadow.Units.Length>
ReadSensor()
Read the distance from the sensor
View Source
protected override Task<Length> ReadSensor()
Returns
System.Threading.Tasks.Task<Meadow.Units.Length>
StartUpdating(TimeSpan?)
Start updating distances
View Source
public override void StartUpdating(TimeSpan? updateInterval)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.TimeSpan> | updateInterval | The interval used to notify external subscribers |
StopUpdating()
Stop sampling
View Source
public override void StopUpdating()
BeforeSleep(CancellationToken)
Called before the platform goes into Sleep state
View Source
public Task BeforeSleep(CancellationToken cancellationToken)
Returns
System.Threading.Tasks.Task
Parameters
Type | Name |
---|---|
System.Threading.CancellationToken | cancellationToken |
AfterWake(CancellationToken)
Called after the platform returns to Wake state
View Source
public Task AfterWake(CancellationToken cancellationToken)
Returns
System.Threading.Tasks.Task
Parameters
Type | Name |
---|---|
System.Threading.CancellationToken | cancellationToken |
Dispose(bool)
Dispose of the object
View Source
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing | Is disposing |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
View Source
public void Dispose()
Implements
System.IObservable<Meadow.IChangeResult<Meadow.Units.Length>>
Meadow.Peripherals.Sensors.Distance.IRangeFinder
Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Length>
Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Length>
Meadow.Peripherals.Sensors.ISensor
Meadow.Peripherals.Sensors.ISamplingSensor
Meadow.ISleepAwarePeripheral
System.IDisposable