Skip to content

Commit c777f98

Browse files
committed
Review findings
1 parent 0c5c8f4 commit c777f98

File tree

6 files changed

+22
-89
lines changed

6 files changed

+22
-89
lines changed

src/Iot.Device.Bindings/CompatibilitySuppressions.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
<Right>lib/net6.0/Iot.Device.Bindings.dll</Right>
5151
<IsBaselineSuppression>true</IsBaselineSuppression>
5252
</Suppression>
53+
<Suppression>
54+
<DiagnosticId>CP0002</DiagnosticId>
55+
<Target>M:Iot.Device.Bmp180.Bmm150.CalibrateMagnetometer(System.Int32)</Target>
56+
<Left>lib/net6.0/Iot.Device.Bindings.dll</Left>
57+
<Right>lib/net6.0/Iot.Device.Bindings.dll</Right>
58+
<IsBaselineSuppression>true</IsBaselineSuppression>
59+
</Suppression>
5360
<Suppression>
5461
<DiagnosticId>CP0002</DiagnosticId>
5562
<Target>M:Iot.Device.Bmp180.Bmm150.GetDeviceInfo</Target>
@@ -211,6 +218,13 @@
211218
<Right>lib/netstandard2.0/Iot.Device.Bindings.dll</Right>
212219
<IsBaselineSuppression>true</IsBaselineSuppression>
213220
</Suppression>
221+
<Suppression>
222+
<DiagnosticId>CP0002</DiagnosticId>
223+
<Target>M:Iot.Device.Bmp180.Bmm150.CalibrateMagnetometer(System.Int32)</Target>
224+
<Left>lib/netstandard2.0/Iot.Device.Bindings.dll</Left>
225+
<Right>lib/netstandard2.0/Iot.Device.Bindings.dll</Right>
226+
<IsBaselineSuppression>true</IsBaselineSuppression>
227+
</Suppression>
214228
<Suppression>
215229
<DiagnosticId>CP0002</DiagnosticId>
216230
<Target>M:Iot.Device.Bmp180.Bmm150.GetDeviceInfo</Target>

src/devices/Arduino/ArduinoBoard.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public ArduinoBoard(Stream serialPortStream, bool usesHardwareFlowControl)
7979
/// <remarks>
8080
/// The device is initialized when the first command is sent. The constructor always succeeds.
8181
/// </remarks>
82+
/// <remarks>
83+
/// The stream must have a blocking read operation, or the connection might fail. Some serial port drivers incorrectly
84+
/// return immediately when no data is available and the <code>ReadTimeout</code> is set to infinite (the default). In such a case, set the
85+
/// ReadTimeout to a large value (such as <code>Int.Max - 10</code>), which will simulate a blocking call.
86+
/// </remarks>
8287
/// <param name="serialPortStream">A stream to an Arduino/Firmata device</param>
8388
public ArduinoBoard(Stream serialPortStream)
8489
: this(serialPortStream, false)
@@ -96,6 +101,7 @@ public ArduinoBoard(string portName, int baudRate)
96101
{
97102
_dataStream = null;
98103
_serialPort = new SerialPort(portName, baudRate);
104+
// Set the timeout to a long time, but not infinite. See the note for the constructor above.
99105
_serialPort.ReadTimeout = int.MaxValue - 10;
100106
StreamUsesHardwareFlowControl = false; // Would need to configure the serial port externally for this to work
101107
_logger = this.GetCurrentClassLogger();

src/devices/Bmm150/Bmm150.cs

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -133,91 +133,6 @@ private void Initialize()
133133
WriteRegister(Bmp180Register.OP_MODE_ADDR, 0x00);
134134
}
135135

136-
/// <summary>
137-
/// Calibrate the magnetometer.
138-
/// Please make sure you are not close to any magnetic field like magnet or phone
139-
/// Please make sure you are moving the magnetometer all over space, rotating it.
140-
/// </summary>
141-
/// <param name="numberOfMeasurements">Number of measurement for the calibration, default is 100</param>
142-
// https://platformio.org/lib/show/12697/M5_BMM150
143-
[Obsolete("Not a reliable way of calibration. Use a calibration determined with MagneticDeviationCorrection instead")]
144-
public void CalibrateMagnetometer(int numberOfMeasurements = 100)
145-
{
146-
CalibrateMagnetometer(null, numberOfMeasurements);
147-
}
148-
149-
/// <summary>
150-
/// Calibrate the magnetometer.
151-
/// Please make sure you are not close to any magnetic field like magnet or phone
152-
/// Please make sure you are moving the magnetometer all over space, rotating it.
153-
/// </summary>
154-
/// <param name="progress">A progress provider (returns a value in percent)</param>
155-
/// <param name="numberOfMeasurements">Number of measurement for the calibration, default is 100</param>
156-
// https://platformio.org/lib/show/12697/M5_BMM150
157-
[Obsolete("Not a reliable way of calibration. Use a calibration determined with MagneticDeviationCorrection instead")]
158-
public void CalibrateMagnetometer(IProgress<double>? progress, int numberOfMeasurements)
159-
{
160-
Vector3 mag_min = new Vector3() { X = 9000, Y = 9000, Z = 30000 };
161-
Vector3 mag_max = new Vector3() { X = -9000, Y = -9000, Z = -30000 };
162-
Vector3 rawMagnetometerData;
163-
if (numberOfMeasurements <= 0)
164-
{
165-
throw new ArgumentOutOfRangeException(nameof(numberOfMeasurements), "The number of measurements must be > 0");
166-
}
167-
168-
for (int i = 0; i < numberOfMeasurements; i++)
169-
{
170-
try
171-
{
172-
rawMagnetometerData = ReadMagnetometerWithoutCorrection();
173-
174-
if (rawMagnetometerData.X != 0)
175-
{
176-
mag_min.X = (rawMagnetometerData.X < mag_min.X) ? rawMagnetometerData.X : mag_min.X;
177-
mag_max.X = (rawMagnetometerData.X > mag_max.X) ? rawMagnetometerData.X : mag_max.X;
178-
}
179-
180-
if (rawMagnetometerData.Y != 0)
181-
{
182-
mag_max.Y = (rawMagnetometerData.Y > mag_max.Y) ? rawMagnetometerData.Y : mag_max.Y;
183-
mag_min.Y = (rawMagnetometerData.Y < mag_min.Y) ? rawMagnetometerData.Y : mag_min.Y;
184-
}
185-
186-
if (rawMagnetometerData.Z != 0)
187-
{
188-
mag_min.Z = (rawMagnetometerData.Z < mag_min.Z) ? rawMagnetometerData.Z : mag_min.Z;
189-
mag_max.Z = (rawMagnetometerData.Z > mag_max.Z) ? rawMagnetometerData.Z : mag_max.Z;
190-
}
191-
192-
// Wait for 100ms until next reading
193-
Wait(100);
194-
}
195-
catch
196-
{
197-
// skip this reading
198-
}
199-
200-
if (progress != null)
201-
{
202-
double percentDone = ((double)i / numberOfMeasurements) * 100.0;
203-
progress.Report(percentDone);
204-
}
205-
}
206-
207-
if (progress != null)
208-
{
209-
progress.Report(100.0);
210-
}
211-
212-
// Refresh CalibrationCompensation vector
213-
CalibrationCompensation = new Vector3()
214-
{
215-
X = (mag_max.X + mag_min.X) / 2,
216-
Y = (mag_max.Y + mag_min.Y) / 2,
217-
Z = (mag_max.Z + mag_min.Z) / 2
218-
};
219-
}
220-
221136
/// <summary>
222137
/// True if there is a data to read
223138
/// </summary>

src/devices/Bmm150/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ Documentation for the Bmm150 can be [found here](https://www.bosch-sensortec.com
99

1010
## Usage
1111

12-
You can find an example in the [sample](./samples/Program.cs) directory. Usage is straight forward. The "Calibration" provided
13-
needs conceptual review and is therefore currently not recommended. Also, when using the magnetometer in a real-world application,
14-
it is not reasonable to turn it around all axes at every startup (try that with a car!).
12+
You can find an example in the [sample](./samples/Program.cs) directory. Usage is straight forward. The previous "Calibration" method
13+
was removed, as it would need to be completely rewritten to do something useful.
1514

1615
```csharp
1716
I2cConnectionSettings mpui2CConnectionSettingmpus = new(1, Bmm150.DefaultI2cAddress);
1817

1918
using Bmm150 bmm150 = new Bmm150(I2cDevice.Create(mpui2CConnectionSettingmpus));
2019

21-
2220
while (!Console.KeyAvailable)
2321
{
2422
MagnetometerData magne;

src/devices/Bmm150/corrcalib.png

-37.3 KB
Binary file not shown.

src/devices/Bmm150/rawcalib.png

-12 KB
Binary file not shown.

0 commit comments

Comments
 (0)