Skip to content

Commit 039c91a

Browse files
committed
clean up - black
1 parent a3319a1 commit 039c91a

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

adafruit_lsm6ds/__init__.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ class LSM6DS: # pylint: disable=too-many-instance-attributes
186186
_raw_temp_data = Struct(_LSM6DS_OUT_TEMP_L, "<h")
187187
_emb_func_en_a = Struct(_LSM6DS_EMB_FUNC_EN_A, "<b")
188188
_emb_func_en_b = Struct(_LSM6DS_EMB_FUNC_EN_B, "<b")
189-
_mlc0_src = Struct(_LSM6DS_MLC0_SRC, "<b")
190-
# _all_int = Struct(_LSM6DS_ALL_INT_SRC, "<bbbbbbbb")
189+
_mlc0_src = Struct(_LSM6DS_MLC0_SRC, "<bbbbbbbb")
191190
# RWBits:
192191
_accel_range = RWBits(2, _LSM6DS_CTRL1_XL, 2)
193192
_accel_data_rate = RWBits(4, _LSM6DS_CTRL1_XL, 4)
@@ -241,7 +240,6 @@ def __init__(
241240
self.accelerometer_range = AccelRange.RANGE_4G # pylint: disable=no-member
242241
self.gyro_range = GyroRange.RANGE_250_DPS # pylint: disable=no-member
243242
# Load and configure MLC if UCF file is provided
244-
print(ucf)
245243
if ucf is not None:
246244
self.load_mlc(ucf)
247245

@@ -406,17 +404,15 @@ def temperature(self) -> float:
406404

407405
return temp * 0.0625
408406

409-
def set_embedded_functions(self, enable, emb_ab=None):
410-
"""DocString Here"""
407+
def _set_embedded_functions(self, enable, emb_ab=None):
408+
"""Enable/disable embedded functions - returns prior settings when disabled"""
411409
self._mem_bank = 1
412410
if enable:
413411
self._emb_func_en_a = emb_ab[0]
414412
self._emb_func_en_b = emb_ab[1]
415413
else:
416414
emb_a = self._emb_func_en_a
417415
emb_b = self._emb_func_en_b
418-
print(emb_a)
419-
print(emb_b)
420416
self._emb_func_en_a = (emb_a[0] & 0xC7,)
421417
self._emb_func_en_b = (emb_b[0] & 0xE6,)
422418
emb_ab = (emb_a, emb_b)
@@ -425,20 +421,20 @@ def set_embedded_functions(self, enable, emb_ab=None):
425421
return emb_ab
426422

427423
def load_mlc(self, ucf):
428-
"""DOCString Here"""
424+
"""Load MLC configuration file into sensor"""
429425
buf = bytearray(2)
430426
with self.i2c_device as i2c:
431427
# Load MLC config from file
432428
with open(ucf, "r") as ucf_file:
433429
for line in ucf_file:
434430
if line.startswith("Ac"):
435431
command = [int(v, 16) for v in line.strip().split(" ")[1:3]]
436-
print(line)
437432
buf[0] = command[0]
438433
buf[1] = command[1]
439434
i2c.write(buf)
440435

441-
emb_ab = self.set_embedded_functions(False)
436+
# Disable embudded function -- save current settings
437+
emb_ab = self._set_embedded_functions(False)
442438

443439
# Disable I3C interface
444440
self._i3c_disable = 1
@@ -449,19 +445,19 @@ def load_mlc(self, ucf):
449445
# Route signals on interrupt pin 1
450446
self._mem_bank = 1
451447
self._route_int1 &= 1
452-
self._mem_bank = 1
448+
self._mem_bank = 0
453449

454450
# Configure interrupt pin mode
455451
self._tap_latch = 1
456452
self._tap_clear = 1
457453

458-
self.set_embedded_functions(True, emb_ab)
454+
# Enabble Embedded Functions using previously stored settings
455+
self._set_embedded_functions(True, emb_ab)
459456

460457
def read_mlc_output(self):
461-
"""DOCString here"""
458+
"""Read MLC results"""
462459
buf = None
463460
if self._mlc_status:
464-
# junk = self._all_int
465461
self._mem_bank = 1
466462
buf = self._mlc0_src
467463
self._mem_bank = 0

examples/lsm6ds_lsm6dsox_mlc_test.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# NOTE: The pre-trained models (UCF files) for the examples can be found here:
88
# https://github.com/STMicroelectronics/STMems_Machine_Learning_Core/tree/master/application_examples/lsm6dsox
99

10+
import time
1011
import board
1112
from adafruit_lsm6ds.lsm6dsox import LSM6DSOX
1213
from adafruit_lsm6ds import Rate, AccelRange, GyroRange
@@ -23,15 +24,36 @@
2324
lsm.accelerometer_range = AccelRange.RANGE_4G
2425
lsm.accelerometer_data_rate = Rate.RATE_26_HZ
2526
lsm.gyro_data_rate = Rate.RATE_26_HZ
27+
28+
2629
# Head gestures example
2730
# UCF_FILE = "lsm6dsox_head_gestures.ucf"
2831
# UCF_LABELS = {0:"Nod", 1:"Shake", 2:"Stationary", 3:"Swing", 4:"Walk"}
2932
# NOTE: Selected data rate and scale must match the MLC data rate and scale.
30-
# lsm = LSM6DSOX(i2c, gyro_odr=26, accel_odr=26, gyro_scale=250, accel_scale=2, ucf=UCF_FILE)
33+
# lsm = LSM6DSOX(i2c, ucf=UCF_FILE)
34+
# lsm.gyro_range = GyroRange.RANGE_250_DPS
35+
# lsm.accelerometer_range = AccelRange.RANGE_2G
36+
# lsm.accelerometer_data_rate = Rate.RATE_26_HZ
37+
# lsm.gyro_data_rate = Rate.RATE_26_HZ
38+
39+
# 6 DOF Position example
40+
# UCF_FILE = "lsm6dsox_six_d_position.ucf"
41+
# UCF_LABELS = {0:"None", 1:"X-UP", 2:"X-DOWN", 3:"Y-UP", 4:"Y-DOWN", 5:"Z-UP", 6:"Z-DOWN"}
42+
# NOTE: Selected data rate and scale must match the MLC data rate and scale.
43+
# lsm = LSM6DSOX(i2c, ucf=UCF_FILE)
44+
# lsm.gyro_range = GyroRange.RANGE_250_DPS
45+
# lsm.accelerometer_range = AccelRange.RANGE_2G
46+
# lsm.accelerometer_data_rate = Rate.RATE_26_HZ
47+
# lsm.gyro_data_rate = Rate.RATE_26_HZ
48+
3149

3250
print("MLC configured...")
3351

3452
while True:
3553
buf = lsm.read_mlc_output()
3654
if buf is not None:
3755
print(UCF_LABELS[buf[0]])
56+
# delay to allow interrupt flag to clear
57+
# interrupt stays high for one sample interval
58+
# (38.4 ms @ 26 Hz ot 19.2 ms @ 52Hz)
59+
time.sleep(0.05)

examples/lsm6ds_lsm6dsox_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import board
66
from adafruit_lsm6ds.lsm6dsox import LSM6DSOX
77

8-
i2c = board.STEMMA_I2C() # uses board.SCL and board.SDA
8+
i2c = board.I2C() # uses board.SCL and board.SDA
99
sensor = LSM6DSOX(i2c)
1010

1111
while True:

0 commit comments

Comments
 (0)