Syntax
public class Lis3mdl : PollingSensorBase<MagneticField3D>, IObservable<IChangeResult<MagneticField3D>>, IMagnetometer, ISamplingSensor<MagneticField3D>, ISensor<MagneticField3D>, II2cPeripheral
Constructors
Lis3mdl(II2cBus, byte, FullScale, OutputDataRate)
Create a new instance of an Lis3mdl 3D magnetometer sensor.
Declaration
public Lis3mdl(II2cBus i2cBus, byte address = 28, Lis3mdl.FullScale fullScale = FullScale.PlusMinus4Gauss, Lis3mdl.OutputDataRate outputDataRate = OutputDataRate.Odr10Hz)
Parameters
Type | Name | Description |
---|---|---|
II2cBus | i2cBus | The I2C bus connected to the sensor |
byte | address | The I2C address |
Lis3mdl.FullScale | fullScale | default Lis3mdl.FullScale enumeration value to use during initialization. |
Lis3mdl.OutputDataRate | outputDataRate | The output data rate |
Fields
i2cComms
I2C Communication bus used to communicate with the peripheral
Declaration
protected readonly II2cCommunications i2cComms
Field Value
Type | Description |
---|---|
II2cCommunications |
Properties
DefaultI2cAddress
The default I2C address for the peripheral
Declaration
public byte DefaultI2cAddress { get; }
Property Value
Type | Description |
---|---|
byte |
MagneticField3D
Current Magnetic Field 3D
Declaration
public MagneticField3D? MagneticField3D { get; }
Property Value
Type | Description |
---|---|
MagneticField3D? |
Methods
GetBlockDataUpdate()
Gets the status of the Block Data Update (BDU) feature.
Declaration
public bool GetBlockDataUpdate()
Returns
Type | Description |
---|---|
bool | true if BDU is enabled, false otherwise. |
GetFastRead()
Gets the status of the Fast Read feature.
Declaration
public bool GetFastRead()
Returns
Type | Description |
---|---|
bool | true if Fast Read is enabled, false otherwise. |
GetFullScale()
Gets the full scale range of the magnetometer.
Declaration
public Lis3mdl.FullScale GetFullScale()
Returns
Type | Description |
---|---|
Lis3mdl.FullScale | The full scale range as a Lis3mdl.FullScale enum. |
GetOperatingMode()
Gets the operating mode of the magnetometer.
Declaration
public Lis3mdl.OperatingMode GetOperatingMode()
Returns
Type | Description |
---|---|
Lis3mdl.OperatingMode | The operating mode as a Lis3mdl.OperatingMode enum. |
GetOutputDataRate()
Gets the output data rate (ODR) of the magnetometer.
Declaration
public Lis3mdl.OutputDataRate GetOutputDataRate()
Returns
Type | Description |
---|---|
Lis3mdl.OutputDataRate | The output data rate as a Lis3mdl.OutputDataRate enum. |
GetTemperatureSensorEnable()
Gets the status of the temperature sensor feature.
Declaration
public bool GetTemperatureSensorEnable()
Returns
Type | Description |
---|---|
bool | true if temperature sensor is enabled, false otherwise. |
RaiseEventsAndNotify(IChangeResult<MagneticField3D>)
Raise events for subscribers and notify of value changes
Declaration
protected override void RaiseEventsAndNotify(IChangeResult<MagneticField3D> changeResult)
Parameters
Type | Name | Description |
---|---|---|
IChangeResult<MagneticField3D> | changeResult | The updated sensor data |
Overrides
ReadSensor()
Reads data from the sensor
Declaration
protected override Task<MagneticField3D> ReadSensor()
Returns
Type | Description |
---|---|
Task<MagneticField3D> | The latest sensor reading |
Overrides
SetBlockDataUpdate(bool)
Sets the status of the Block Data Update (BDU) feature.
Declaration
public void SetBlockDataUpdate(bool enable)
Parameters
Type | Name | Description |
---|---|---|
bool | enable | true to enable BDU, false to disable it. |
SetFastRead(bool)
Sets the status of the Fast Read feature.
Declaration
public void SetFastRead(bool enable)
Parameters
Type | Name | Description |
---|---|---|
bool | enable | true to enable Fast Read, false to disable it. |
SetFullScale(FullScale)
Sets the full scale range of the magnetometer.
Declaration
public void SetFullScale(Lis3mdl.FullScale scale)
Parameters
Type | Name | Description |
---|---|---|
Lis3mdl.FullScale | scale | The desired full scale range as a Lis3mdl.FullScale enum. |
SetOperatingMode(OperatingMode)
Sets the operating mode of the magnetometer.
Declaration
public void SetOperatingMode(Lis3mdl.OperatingMode mode)
Parameters
Type | Name | Description |
---|---|---|
Lis3mdl.OperatingMode | mode | The desired operating mode as a Lis3mdl.OperatingMode enum. |
SetOutputDataRate(OutputDataRate)
Sets the output data rate (ODR) of the magnetometer.
Declaration
public void SetOutputDataRate(Lis3mdl.OutputDataRate odr)
Parameters
Type | Name | Description |
---|---|---|
Lis3mdl.OutputDataRate | odr | The desired output data rate as a Lis3mdl.OutputDataRate enum. |
SetTemperatureSensorEnable(bool)
Sets the status of the temperature sensor feature.
Declaration
public void SetTemperatureSensorEnable(bool enable)
Parameters
Type | Name | Description |
---|---|---|
bool | enable | true to enable the temperature sensor, false to disable it. |
Events
MagneticField3DUpdated
Event raised when magnetic field changes
Declaration
public event EventHandler<IChangeResult<MagneticField3D>> MagneticField3DUpdated
Event Type
Type | Description |
---|---|
EventHandler<IChangeResult<MagneticField3D>> |