Skip to content

Commit b1c016b

Browse files
authored
Merge pull request #11 from adafruit/black-update
Black reformatting with Python 3 target.
2 parents 3944d29 + 5aebd78 commit b1c016b

File tree

6 files changed

+209
-152
lines changed

6 files changed

+209
-152
lines changed

adafruit_lsm6ds.py

+84-58
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@
5454
from adafruit_register.i2c_struct import ROUnaryStruct, Struct
5555
from adafruit_register.i2c_bits import RWBits
5656
from adafruit_register.i2c_bit import RWBit
57+
5758
__version__ = "0.0.0-auto.0"
5859
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM6DSOX.git"
5960

6061

61-
_LSM6DS_DEFAULT_ADDRESS = const(0x6a)
62+
_LSM6DS_DEFAULT_ADDRESS = const(0x6A)
6263

6364
_LSM6DS_CHIP_ID = const(0x6C)
6465
_ISM330DHCT_CHIP_ID = const(0x6B)
@@ -95,6 +96,7 @@
9596

9697
_MILLI_G_TO_ACCEL = 0.00980665
9798

99+
98100
class CV:
99101
"""struct helper"""
100102

@@ -115,62 +117,74 @@ def is_valid(cls, value):
115117
"Returns true if the given value is a member of the CV"
116118
return value in cls.string
117119

120+
118121
class AccelRange(CV):
119122
"""Options for ``accelerometer_range``"""
120-
pass #pylint: disable=unnecessary-pass
121123

122-
AccelRange.add_values((
123-
('RANGE_2G', 0, 2, 0.061),
124-
('RANGE_16G', 1, 16, 0.488),
125-
('RANGE_4G', 2, 4, 0.122),
126-
('RANGE_8G', 3, 8, 0.244)
127-
))
124+
125+
AccelRange.add_values(
126+
(
127+
("RANGE_2G", 0, 2, 0.061),
128+
("RANGE_16G", 1, 16, 0.488),
129+
("RANGE_4G", 2, 4, 0.122),
130+
("RANGE_8G", 3, 8, 0.244),
131+
)
132+
)
133+
128134

129135
class GyroRange(CV):
130136
"""Options for ``gyro_data_range``"""
131-
pass #pylint: disable=unnecessary-pass
132137

133-
GyroRange.add_values((
134-
('RANGE_125_DPS', 125, 125, 4.375),
135-
('RANGE_250_DPS', 0, 250, 8.75),
136-
('RANGE_500_DPS', 1, 500, 17.50),
137-
('RANGE_1000_DPS', 2, 1000, 35.0),
138-
('RANGE_2000_DPS', 3, 2000, 70.0),
139-
('RANGE_4000_DPS', 4000, 4000, 140.0)
140-
))
138+
139+
GyroRange.add_values(
140+
(
141+
("RANGE_125_DPS", 125, 125, 4.375),
142+
("RANGE_250_DPS", 0, 250, 8.75),
143+
("RANGE_500_DPS", 1, 500, 17.50),
144+
("RANGE_1000_DPS", 2, 1000, 35.0),
145+
("RANGE_2000_DPS", 3, 2000, 70.0),
146+
("RANGE_4000_DPS", 4000, 4000, 140.0),
147+
)
148+
)
149+
141150

142151
class Rate(CV):
143152
"""Options for ``accelerometer_data_rate`` and ``gyro_data_rate``"""
144-
pass #pylint: disable=unnecessary-pass
145-
146-
Rate.add_values((
147-
('RATE_SHUTDOWN', 0, 0, None),
148-
('RATE_12_5_HZ', 1, 12.5, None),
149-
('RATE_26_HZ', 2, 26.0, None),
150-
('RATE_52_HZ', 3, 52.0, None),
151-
('RATE_104_HZ', 4, 104.0, None),
152-
('RATE_208_HZ', 5, 208.0, None),
153-
('RATE_416_HZ', 6, 416.0, None),
154-
('RATE_833_HZ', 7, 833.0, None),
155-
('RATE_1_66K_HZ', 8, 1066.0, None),
156-
('RATE_3_33K_HZ', 9, 3033.0, None),
157-
('RATE_6_66K_HZ', 10, 6066.0, None),
158-
('RATE_1_6_HZ', 11, 1.6, None)
159-
))
153+
154+
155+
Rate.add_values(
156+
(
157+
("RATE_SHUTDOWN", 0, 0, None),
158+
("RATE_12_5_HZ", 1, 12.5, None),
159+
("RATE_26_HZ", 2, 26.0, None),
160+
("RATE_52_HZ", 3, 52.0, None),
161+
("RATE_104_HZ", 4, 104.0, None),
162+
("RATE_208_HZ", 5, 208.0, None),
163+
("RATE_416_HZ", 6, 416.0, None),
164+
("RATE_833_HZ", 7, 833.0, None),
165+
("RATE_1_66K_HZ", 8, 1066.0, None),
166+
("RATE_3_33K_HZ", 9, 3033.0, None),
167+
("RATE_6_66K_HZ", 10, 6066.0, None),
168+
("RATE_1_6_HZ", 11, 1.6, None),
169+
)
170+
)
171+
160172

161173
class AccelHPF(CV):
162174
"""Options for the accelerometer high pass filter"""
163-
pass #pylint: disable=unnecessary-pass
164175

165-
AccelHPF.add_values((
166-
('SLOPE', 0, 0, None),
167-
('HPF_DIV100', 1, 0, None),
168-
('HPF_DIV9', 2, 0, None),
169-
('HPF_DIV400', 3, 0, None),
170-
))
171176

177+
AccelHPF.add_values(
178+
(
179+
("SLOPE", 0, 0, None),
180+
("HPF_DIV100", 1, 0, None),
181+
("HPF_DIV9", 2, 0, None),
182+
("HPF_DIV400", 3, 0, None),
183+
)
184+
)
172185

173-
class LSM6DS: #pylint: disable=too-many-instance-attributes
186+
187+
class LSM6DS: # pylint: disable=too-many-instance-attributes
174188

175189
"""Driver for the LSM6DSOX 6-axis accelerometer and gyroscope.
176190
@@ -179,11 +193,11 @@ class LSM6DS: #pylint: disable=too-many-instance-attributes
179193
180194
"""
181195

182-
#ROUnaryStructs:
196+
# ROUnaryStructs:
183197
_chip_id = ROUnaryStruct(_LSM6DS_WHOAMI, "<b")
184198
_temperature = ROUnaryStruct(_LSM6DS_OUT_TEMP_L, "<h")
185199

186-
#RWBits:
200+
# RWBits:
187201
_ois_ctrl_from_ui = RWBit(_LSM6DS_FUNC_CFG_ACCESS, 0)
188202
_shub_reg_access = RWBit(_LSM6DS_FUNC_CFG_ACCESS, 6)
189203
_func_cfg_access = RWBit(_LSM6DS_FUNC_CFG_ACCESS, 7)
@@ -245,16 +259,18 @@ def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
245259
if self.CHIP_ID is None:
246260
raise AttributeError("LSM6DS Parent Class cannot be directly instantiated")
247261
if self._chip_id != self.CHIP_ID:
248-
raise RuntimeError("Failed to find %s - check your wiring!"%self.__class__.__name__)
262+
raise RuntimeError(
263+
"Failed to find %s - check your wiring!" % self.__class__.__name__
264+
)
249265
self.reset()
250266

251267
self._bdu = True
252268

253-
self.accelerometer_data_rate = Rate.RATE_104_HZ #pylint: disable=no-member
254-
self.gyro_data_rate = Rate.RATE_104_HZ #pylint: disable=no-member
269+
self.accelerometer_data_rate = Rate.RATE_104_HZ # pylint: disable=no-member
270+
self.gyro_data_rate = Rate.RATE_104_HZ # pylint: disable=no-member
255271

256-
self.accelerometer_range = AccelRange.RANGE_4G #pylint: disable=no-member
257-
self.gyro_range = GyroRange.RANGE_250_DPS #pylint: disable=no-member
272+
self.accelerometer_range = AccelRange.RANGE_4G # pylint: disable=no-member
273+
self.gyro_range = GyroRange.RANGE_250_DPS # pylint: disable=no-member
258274

259275
def reset(self):
260276
"Resets the sensor's configuration into an initial state"
@@ -273,7 +289,7 @@ def acceleration(self):
273289
y = self._scale_xl_data(raw_accel_data[1])
274290
z = self._scale_xl_data(raw_accel_data[2])
275291

276-
return(x, y, z)
292+
return (x, y, z)
277293

278294
@property
279295
def gyro(self):
@@ -286,7 +302,11 @@ def gyro(self):
286302
return (x, y, z)
287303

288304
def _scale_xl_data(self, raw_measurement):
289-
return raw_measurement * AccelRange.lsb[self._cached_accel_range] * _MILLI_G_TO_ACCEL
305+
return (
306+
raw_measurement
307+
* AccelRange.lsb[self._cached_accel_range]
308+
* _MILLI_G_TO_ACCEL
309+
)
290310

291311
def _scale_gyro_data(self, raw_measurement):
292312
return raw_measurement * GyroRange.lsb[self._cached_gyro_range] / 1000
@@ -297,14 +317,14 @@ def accelerometer_range(self):
297317
Note that larger ranges will be less accurate. Must be an `AccelRange`"""
298318
return self._cached_accel_range
299319

300-
#pylint: disable=no-member
320+
# pylint: disable=no-member
301321
@accelerometer_range.setter
302322
def accelerometer_range(self, value):
303323
if not AccelRange.is_valid(value):
304324
raise AttributeError("range must be an `AccelRange`")
305325
self._accel_range = value
306326
self._cached_accel_range = value
307-
sleep(.2) # needed to let new range settle
327+
sleep(0.2) # needed to let new range settle
308328

309329
@property
310330
def gyro_range(self):
@@ -332,9 +352,9 @@ def gyro_range(self, value):
332352
self._gyro_range = value
333353

334354
self._cached_gyro_range = value
335-
sleep(.2) # needed to let new range settle
355+
sleep(0.2) # needed to let new range settle
336356

337-
#pylint: enable=no-member
357+
# pylint: enable=no-member
338358

339359
@property
340360
def accelerometer_data_rate(self):
@@ -350,7 +370,6 @@ def accelerometer_data_rate(self, value):
350370
self._accel_data_rate = value
351371
# sleep(.2) # needed to let new range settle
352372

353-
354373
@property
355374
def gyro_data_rate(self):
356375
"""Select the rate at which the gyro takes measurements. Must be a `Rate`"""
@@ -387,38 +406,45 @@ def high_pass_filter(self, value):
387406
self._pass_filter = value
388407

389408

390-
class LSM6DSOX(LSM6DS): #pylint: disable=too-many-instance-attributes
409+
class LSM6DSOX(LSM6DS): # pylint: disable=too-many-instance-attributes
391410

392411
"""Driver for the LSM6DSOX 6-axis accelerometer and gyroscope.
393412
394413
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DSOX is connected to.
395414
:param address: The I2C slave address of the sensor
396415
397416
"""
417+
398418
CHIP_ID = _LSM6DS_CHIP_ID
419+
399420
def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
400421
super().__init__(i2c_bus, address)
401422
self._i3c_disable = True
402423

403-
class LSM6DS33(LSM6DS): #pylint: disable=too-many-instance-attributes
424+
425+
class LSM6DS33(LSM6DS): # pylint: disable=too-many-instance-attributes
404426

405427
"""Driver for the LSM6DS33 6-axis accelerometer and gyroscope.
406428
407429
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DS33 is connected to.
408430
:param address: The I2C slave address of the sensor
409431
410432
"""
433+
411434
CHIP_ID = _LSM6DS33_CHIP_ID
412435

413-
class ISM330DHCT(LSM6DS): #pylint: disable=too-many-instance-attributes
436+
437+
class ISM330DHCT(LSM6DS): # pylint: disable=too-many-instance-attributes
414438

415439
"""Driver for the LSM6DS33 6-axis accelerometer and gyroscope.
416440
417441
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DS33 is connected to.
418442
:param address: The I2C slave address of the sensor
419443
420444
"""
445+
421446
CHIP_ID = _ISM330DHCT_CHIP_ID
447+
422448
def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
423449
super().__init__(i2c_bus, address)
424450

0 commit comments

Comments
 (0)