Skip to content

Commit 4ed9093

Browse files
authored
Merge pull request #6 from microbuilder/master
Updated class to use `.magnetic` property
2 parents 74ad039 + 6a16eba commit 4ed9093

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
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.magnetic()
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: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ def reset(self):
265265
return self._status_last
266266

267267

268+
@property
268269
def read_data(self):
269270
"""
270271
Reads a single X/Y/Z sample from the magnetometer.
@@ -277,19 +278,20 @@ def read_data(self):
277278
self._status_last, m_x, m_y, m_z = struct.unpack(">Bhhh", data)
278279

279280
# Return the raw int values if requested
280-
return m_x, m_y, m_z
281+
return (m_x, m_y, m_z)
281282

282283

284+
@property
283285
def magnetic(self):
284286
"""
285287
The processed magnetometer sensor values.
286288
A 3-tuple of X, Y, Z axis values in microteslas that are signed floats.
287289
"""
288-
m_x, m_y, m_z = self.read_data()
290+
x, y, z = self.read_data
289291

290292
# Convert the raw integer values to uT based on gain and resolution
291-
m_x *= _LSB_LOOKUP[self._gain_current][self._res_current][0]
292-
m_y *= _LSB_LOOKUP[self._gain_current][self._res_current][0]
293-
m_z *= _LSB_LOOKUP[self._gain_current][self._res_current][1]
293+
x *= _LSB_LOOKUP[self._gain_current][self._res_current][0]
294+
y *= _LSB_LOOKUP[self._gain_current][self._res_current][0]
295+
z *= _LSB_LOOKUP[self._gain_current][self._res_current][1]
294296

295-
return m_x, m_y, m_z
297+
return x, y, z

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.magnetic()
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)