Skip to content

Commit 74ad039

Browse files
author
Kevin Townsend
committed
Separated raw and processed data
1 parent 5f1f459 commit 74ad039

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Usage Example
6666
SENSOR = adafruit_mlx90393.MLX90393(I2C_BUS, gain=adafruit_mlx90393.GAIN_1X)
6767
6868
while True:
69-
MX, MY, MZ = SENSOR.read_data(raw=False)
69+
MX, MY, MZ = SENSOR.magnetic()
7070
print("[{}]".format(time.monotonic()))
7171
print("X: {} uT".format(MX))
7272
print("Y: {} uT".format(MY))

adafruit_mlx90393.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def _transceive(self, payload, rxlen=0, delay=0.01):
171171
except OSError:
172172
pass
173173
# Track status byte
174-
_status_last = data[0]
174+
self._status_last = data[0]
175175
# Unpack data (status byte, big-endian 16-bit register value)
176176
if self._debug:
177177
print("\t[{}]".format(time.monotonic()))
@@ -261,11 +261,11 @@ def reset(self):
261261
if self._debug:
262262
print("Resetting sensor")
263263
time.sleep(2)
264-
_status_last = self._transceive(bytes([_CMD_RT]))
265-
return _status_last
264+
self._status_last = self._transceive(bytes([_CMD_RT]))
265+
return self._status_last
266266

267267

268-
def read_data(self, raw=False):
268+
def read_data(self):
269269
"""
270270
Reads a single X/Y/Z sample from the magnetometer.
271271
"""
@@ -276,9 +276,16 @@ def read_data(self, raw=False):
276276
data = self._transceive(bytes([_CMD_RM | _CMD_AXIS_ALL]), 6)
277277
self._status_last, m_x, m_y, m_z = struct.unpack(">Bhhh", data)
278278

279-
if raw:
280-
# Return the raw int values if requested
281-
return m_x, m_y, m_z
279+
# Return the raw int values if requested
280+
return m_x, m_y, m_z
281+
282+
283+
def magnetic(self):
284+
"""
285+
The processed magnetometer sensor values.
286+
A 3-tuple of X, Y, Z axis values in microteslas that are signed floats.
287+
"""
288+
m_x, m_y, m_z = self.read_data()
282289

283290
# Convert the raw integer values to uT based on gain and resolution
284291
m_x *= _LSB_LOOKUP[self._gain_current][self._res_current][0]

examples/adafruit_mlx90393_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
SENSOR = adafruit_mlx90393.MLX90393(I2C_BUS, gain=adafruit_mlx90393.GAIN_1X)
99

1010
while True:
11-
MX, MY, MZ = SENSOR.read_data(raw=False)
11+
MX, MY, MZ = SENSOR.magnetic()
1212
print("[{}]".format(time.monotonic()))
1313
print("X: {} uT".format(MX))
1414
print("Y: {} uT".format(MY))

0 commit comments

Comments
 (0)