From 46b524fccdb9f9b705e0f53b126ea25ca1d115c4 Mon Sep 17 00:00:00 2001 From: lady ada Date: Sat, 2 Jan 2021 14:34:18 -0500 Subject: [PATCH 1/3] simplify xyz to just use one struct read and do the scaling in a listcomp --- adafruit_msa301.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/adafruit_msa301.py b/adafruit_msa301.py index 2471426..0560457 100644 --- a/adafruit_msa301.py +++ b/adafruit_msa301.py @@ -50,7 +50,7 @@ import struct from micropython import const -from adafruit_register.i2c_struct import ROUnaryStruct +from adafruit_register.i2c_struct import Struct, ROUnaryStruct from adafruit_register.i2c_bit import RWBit from adafruit_register.i2c_bits import RWBits, ROBits import adafruit_bus_device.i2c_device as i2cdevice @@ -230,7 +230,8 @@ def __init__(self, i2c_bus): _disable_y = RWBit(_MSA301_REG_ODR, 6) _disable_z = RWBit(_MSA301_REG_ODR, 5) - _xyz_raw = ROBits(48, _MSA301_REG_OUT_X_L, 0, 6) + #_xyz_raw = ROBits(48, _MSA301_REG_OUT_X_L, 0, 6) + _xyz_raw = Struct(_MSA301_REG_OUT_X_L, "> (8 * shift) & 0xFF - acc_bytes.append(bottom_byte) - - # unpack three LE, signed shorts - x, y, z = struct.unpack_from("> 2) / scale) * _STANDARD_GRAVITY - y_acc = ((y >> 2) / scale) * _STANDARD_GRAVITY - z_acc = ((z >> 2) / scale) * _STANDARD_GRAVITY + x, y, z = [((i >> 2) / scale) * _STANDARD_GRAVITY for i in self._xyz_raw] - return (x_acc, y_acc, z_acc) + return (x, y, z) def enable_tap_detection( self, From feb805e0202fcb7cf56d899c5430fa6a4906b1db Mon Sep 17 00:00:00 2001 From: lady ada Date: Sat, 2 Jan 2021 14:41:38 -0500 Subject: [PATCH 2/3] blacken --- adafruit_msa301.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_msa301.py b/adafruit_msa301.py index 0560457..66adc51 100644 --- a/adafruit_msa301.py +++ b/adafruit_msa301.py @@ -207,7 +207,7 @@ class TapDuration: # pylint: disable=too-few-public-methods,too-many-instance-a class MSA301: # pylint: disable=too-many-instance-attributes """Driver for the MSA301 Accelerometer. - :param ~busio.I2C i2c_bus: The I2C bus the MSA is connected to. + :param ~busio.I2C i2c_bus: The I2C bus the MSA is connected to. """ _part_id = ROUnaryStruct(_MSA301_REG_PARTID, " Date: Sat, 2 Jan 2021 14:44:07 -0500 Subject: [PATCH 3/3] lint --- adafruit_msa301.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/adafruit_msa301.py b/adafruit_msa301.py index 66adc51..2bdac2e 100644 --- a/adafruit_msa301.py +++ b/adafruit_msa301.py @@ -47,12 +47,10 @@ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MSA301.git" -import struct - from micropython import const from adafruit_register.i2c_struct import Struct, ROUnaryStruct from adafruit_register.i2c_bit import RWBit -from adafruit_register.i2c_bits import RWBits, ROBits +from adafruit_register.i2c_bits import RWBits import adafruit_bus_device.i2c_device as i2cdevice _MSA301_I2CADDR_DEFAULT = const(0x26)