Remarks

Mma7660fc
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Mma7660fc

Code Example

Mma7660fc sensor;

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

    // create the sensor driver
    sensor = new Mma7660fc(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += (sender, result) => {
        Resolver.Log.Info($"Accel: [X:{result.New.X.MetersPerSecondSquared:N2}," +
            $"Y:{result.New.Y.MetersPerSecondSquared:N2}," +
            $"Z:{result.New.Z.MetersPerSecondSquared:N2} (m/s^2)]" +
            $" Direction: {sensor.Direction}" +
            $" Orientation: {sensor.Orientation}");
    };

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Mma7660fc.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer: [x] changed by threshold; new [x]: X:{result.New.X:N2}, old: X:{result.Old?.X:N2}"),
        // only notify if there's a greater than 0.5G change in the Z direction
        filter: result => {
            if (result.Old is { } old) { //c# 8 pattern match syntax. checks for !null and assigns var.
                return ((result.New - old).Z > new Acceleration(0.5, AU.Gravity));
            }
            return false;
        });
    sensor.Subscribe(consumer);

    return Task.CompletedTask;
}

public async override Task Run()
{
    //==== one-off read
    var result = await sensor.Read();
    Resolver.Log.Info("Initial Readings:");
    Resolver.Log.Info($"Accel: [X:{result.X.MetersPerSecondSquared:N2}," +
        $"Y:{result.Y.MetersPerSecondSquared:N2}," +
        $"Z:{result.Z.MetersPerSecondSquared:N2} (m/s^2)]");

    sensor.StartUpdating(TimeSpan.FromMilliseconds(1000));
}

Sample project(s) available on GitHub

Characteristic Locus
Inheritance System.Object ObservableBase<Acceleration3D> SamplingSensorBase<Acceleration3D> PollingSensorBase<Acceleration3D> ByteCommsSensorBase<Acceleration3D> > Mma7660fc
Implements ISamplingSensor<Acceleration3D> ISamplingSensor<Acceleration3D> IDisposable IAccelerometer
Inherited Members ByteCommsSensorBase<Acceleration3D>.Peripheral ByteCommsSensorBase<Acceleration3D>.ReadBuffer ByteCommsSensorBase<Acceleration3D>.WriteBuffer ByteCommsSensorBase<Acceleration3D>.Init(Int32, Int32) ByteCommsSensorBase<Acceleration3D>.Dispose(Boolean) ByteCommsSensorBase<Acceleration3D>.Dispose() PollingSensorBase<Acceleration3D>.StartUpdating(Nullable<TimeSpan>) PollingSensorBase<Acceleration3D>.StopUpdating() SamplingSensorBase<Acceleration3D>.samplingLock SamplingSensorBase<Acceleration3D>.Updated SamplingSensorBase<Acceleration3D>.SamplingTokenSource SamplingSensorBase<Acceleration3D>.Conditions SamplingSensorBase<Acceleration3D>.IsSampling SamplingSensorBase<Acceleration3D>.UpdateInterval SamplingSensorBase<Acceleration3D>.RaiseEventsAndNotify(IChangeResult<>) SamplingSensorBase<Acceleration3D>.Read() ObservableBase<Acceleration3D>.observers ObservableBase<Acceleration3D>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<Acceleration3D>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<Acceleration3D>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Sensors.Motion
Assembly Mma7660fc.dll

Syntax

public class Mma7660fc : ByteCommsSensorBase<Acceleration3D>, ISamplingSensor<Acceleration3D>, ISamplingSensor<Acceleration3D>, IDisposable, IAccelerometer

Constructors

Mma7660fc(II2cBus, Mma7660fc.Addresses)

Create a new instance of the Mma7660fc communicating over the I2C interface.

Declaration
public Mma7660fc(II2cBus i2cBus, Mma7660fc.Addresses address = default(Mma7660fc.Addresses))

Parameters

Type Name Description
II2cBus i2cBus

I2C bus

Mma7660fc.Addresses address

Address of the I2C sensor

Mma7660fc(II2cBus, Byte)

Create a new instance of the Mma7660fc communicating over the I2C interface.

Declaration
public Mma7660fc(II2cBus i2cBus, byte address)

Parameters

Type Name Description
II2cBus i2cBus

I2C bus

System.Byte address

Address of the I2C sensor

Properties

Acceleration3D

Current Acceleration3d value

Declaration
public Acceleration3D? Acceleration3D { get; }

Property Value

Type Description
System.Nullable<Acceleration3D>

Direction

Get the current direction value

Declaration
public Mma7660fc.DirectionType Direction { get; set; }

Property Value

Type Description
Mma7660fc.DirectionType

Orientation

Get the current orientation

Declaration
public Mma7660fc.OrientationType Orientation { get; set; }

Property Value

Type Description
Mma7660fc.OrientationType

Methods

RaiseEventsAndNotify(IChangeResult<Acceleration3D>)

Raise event and notify subscribers

Declaration
protected override void RaiseEventsAndNotify(IChangeResult<Acceleration3D> changeResult)

Parameters

Type Name Description
IChangeResult<Acceleration3D> changeResult

Acceleration3d data

ReadSensor()

Read sensor data from registers

Declaration
protected override Task<Acceleration3D> ReadSensor()

Returns

Type Description
Task<Acceleration3D>

Overrides

Meadow.Foundation.SamplingSensorBase<Acceleration3D>.ReadSensor()

SetSampleRate(Mma7660fc.SampleRate)

Set sample rate in samples per second

Declaration
public void SetSampleRate(Mma7660fc.SampleRate rate)

Parameters

Type Name Description
Mma7660fc.SampleRate rate

sample rate

Events

Acceleration3DUpdated

Raised when new acceleration data is processed

Declaration
public event EventHandler<IChangeResult<Acceleration3D>> Acceleration3DUpdated

Event Type

Type Description
EventHandler<IChangeResult<Acceleration3D>>