Skip to content

Commit 176b817

Browse files
committed
Black reformatting with Python 3 target.
1 parent 3944d29 commit 176b817

File tree

6 files changed

+217
-152
lines changed

6 files changed

+217
-152
lines changed

adafruit_lsm6ds.py

+92-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,82 @@ 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+
pass # pylint: disable=unnecessary-pass
125+
126+
127+
AccelRange.add_values(
128+
(
129+
("RANGE_2G", 0, 2, 0.061),
130+
("RANGE_16G", 1, 16, 0.488),
131+
("RANGE_4G", 2, 4, 0.122),
132+
("RANGE_8G", 3, 8, 0.244),
133+
)
134+
)
135+
128136

129137
class GyroRange(CV):
130138
"""Options for ``gyro_data_range``"""
131-
pass #pylint: disable=unnecessary-pass
132139

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-
))
140+
pass # pylint: disable=unnecessary-pass
141+
142+
143+
GyroRange.add_values(
144+
(
145+
("RANGE_125_DPS", 125, 125, 4.375),
146+
("RANGE_250_DPS", 0, 250, 8.75),
147+
("RANGE_500_DPS", 1, 500, 17.50),
148+
("RANGE_1000_DPS", 2, 1000, 35.0),
149+
("RANGE_2000_DPS", 3, 2000, 70.0),
150+
("RANGE_4000_DPS", 4000, 4000, 140.0),
151+
)
152+
)
153+
141154

142155
class Rate(CV):
143156
"""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-
))
157+
158+
pass # pylint: disable=unnecessary-pass
159+
160+
161+
Rate.add_values(
162+
(
163+
("RATE_SHUTDOWN", 0, 0, None),
164+
("RATE_12_5_HZ", 1, 12.5, None),
165+
("RATE_26_HZ", 2, 26.0, None),
166+
("RATE_52_HZ", 3, 52.0, None),
167+
("RATE_104_HZ", 4, 104.0, None),
168+
("RATE_208_HZ", 5, 208.0, None),
169+
("RATE_416_HZ", 6, 416.0, None),
170+
("RATE_833_HZ", 7, 833.0, None),
171+
("RATE_1_66K_HZ", 8, 1066.0, None),
172+
("RATE_3_33K_HZ", 9, 3033.0, None),
173+
("RATE_6_66K_HZ", 10, 6066.0, None),
174+
("RATE_1_6_HZ", 11, 1.6, None),
175+
)
176+
)
177+
160178

161179
class AccelHPF(CV):
162180
"""Options for the accelerometer high pass filter"""
163-
pass #pylint: disable=unnecessary-pass
164181

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-
))
182+
pass # pylint: disable=unnecessary-pass
183+
184+
185+
AccelHPF.add_values(
186+
(
187+
("SLOPE", 0, 0, None),
188+
("HPF_DIV100", 1, 0, None),
189+
("HPF_DIV9", 2, 0, None),
190+
("HPF_DIV400", 3, 0, None),
191+
)
192+
)
171193

172194

173-
class LSM6DS: #pylint: disable=too-many-instance-attributes
195+
class LSM6DS: # pylint: disable=too-many-instance-attributes
174196

175197
"""Driver for the LSM6DSOX 6-axis accelerometer and gyroscope.
176198
@@ -179,11 +201,11 @@ class LSM6DS: #pylint: disable=too-many-instance-attributes
179201
180202
"""
181203

182-
#ROUnaryStructs:
204+
# ROUnaryStructs:
183205
_chip_id = ROUnaryStruct(_LSM6DS_WHOAMI, "<b")
184206
_temperature = ROUnaryStruct(_LSM6DS_OUT_TEMP_L, "<h")
185207

186-
#RWBits:
208+
# RWBits:
187209
_ois_ctrl_from_ui = RWBit(_LSM6DS_FUNC_CFG_ACCESS, 0)
188210
_shub_reg_access = RWBit(_LSM6DS_FUNC_CFG_ACCESS, 6)
189211
_func_cfg_access = RWBit(_LSM6DS_FUNC_CFG_ACCESS, 7)
@@ -245,16 +267,18 @@ def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
245267
if self.CHIP_ID is None:
246268
raise AttributeError("LSM6DS Parent Class cannot be directly instantiated")
247269
if self._chip_id != self.CHIP_ID:
248-
raise RuntimeError("Failed to find %s - check your wiring!"%self.__class__.__name__)
270+
raise RuntimeError(
271+
"Failed to find %s - check your wiring!" % self.__class__.__name__
272+
)
249273
self.reset()
250274

251275
self._bdu = True
252276

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
277+
self.accelerometer_data_rate = Rate.RATE_104_HZ # pylint: disable=no-member
278+
self.gyro_data_rate = Rate.RATE_104_HZ # pylint: disable=no-member
255279

256-
self.accelerometer_range = AccelRange.RANGE_4G #pylint: disable=no-member
257-
self.gyro_range = GyroRange.RANGE_250_DPS #pylint: disable=no-member
280+
self.accelerometer_range = AccelRange.RANGE_4G # pylint: disable=no-member
281+
self.gyro_range = GyroRange.RANGE_250_DPS # pylint: disable=no-member
258282

259283
def reset(self):
260284
"Resets the sensor's configuration into an initial state"
@@ -273,7 +297,7 @@ def acceleration(self):
273297
y = self._scale_xl_data(raw_accel_data[1])
274298
z = self._scale_xl_data(raw_accel_data[2])
275299

276-
return(x, y, z)
300+
return (x, y, z)
277301

278302
@property
279303
def gyro(self):
@@ -286,7 +310,11 @@ def gyro(self):
286310
return (x, y, z)
287311

288312
def _scale_xl_data(self, raw_measurement):
289-
return raw_measurement * AccelRange.lsb[self._cached_accel_range] * _MILLI_G_TO_ACCEL
313+
return (
314+
raw_measurement
315+
* AccelRange.lsb[self._cached_accel_range]
316+
* _MILLI_G_TO_ACCEL
317+
)
290318

291319
def _scale_gyro_data(self, raw_measurement):
292320
return raw_measurement * GyroRange.lsb[self._cached_gyro_range] / 1000
@@ -297,14 +325,14 @@ def accelerometer_range(self):
297325
Note that larger ranges will be less accurate. Must be an `AccelRange`"""
298326
return self._cached_accel_range
299327

300-
#pylint: disable=no-member
328+
# pylint: disable=no-member
301329
@accelerometer_range.setter
302330
def accelerometer_range(self, value):
303331
if not AccelRange.is_valid(value):
304332
raise AttributeError("range must be an `AccelRange`")
305333
self._accel_range = value
306334
self._cached_accel_range = value
307-
sleep(.2) # needed to let new range settle
335+
sleep(0.2) # needed to let new range settle
308336

309337
@property
310338
def gyro_range(self):
@@ -332,9 +360,9 @@ def gyro_range(self, value):
332360
self._gyro_range = value
333361

334362
self._cached_gyro_range = value
335-
sleep(.2) # needed to let new range settle
363+
sleep(0.2) # needed to let new range settle
336364

337-
#pylint: enable=no-member
365+
# pylint: enable=no-member
338366

339367
@property
340368
def accelerometer_data_rate(self):
@@ -350,7 +378,6 @@ def accelerometer_data_rate(self, value):
350378
self._accel_data_rate = value
351379
# sleep(.2) # needed to let new range settle
352380

353-
354381
@property
355382
def gyro_data_rate(self):
356383
"""Select the rate at which the gyro takes measurements. Must be a `Rate`"""
@@ -387,38 +414,45 @@ def high_pass_filter(self, value):
387414
self._pass_filter = value
388415

389416

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

392419
"""Driver for the LSM6DSOX 6-axis accelerometer and gyroscope.
393420
394421
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DSOX is connected to.
395422
:param address: The I2C slave address of the sensor
396423
397424
"""
425+
398426
CHIP_ID = _LSM6DS_CHIP_ID
427+
399428
def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
400429
super().__init__(i2c_bus, address)
401430
self._i3c_disable = True
402431

403-
class LSM6DS33(LSM6DS): #pylint: disable=too-many-instance-attributes
432+
433+
class LSM6DS33(LSM6DS): # pylint: disable=too-many-instance-attributes
404434

405435
"""Driver for the LSM6DS33 6-axis accelerometer and gyroscope.
406436
407437
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DS33 is connected to.
408438
:param address: The I2C slave address of the sensor
409439
410440
"""
441+
411442
CHIP_ID = _LSM6DS33_CHIP_ID
412443

413-
class ISM330DHCT(LSM6DS): #pylint: disable=too-many-instance-attributes
444+
445+
class ISM330DHCT(LSM6DS): # pylint: disable=too-many-instance-attributes
414446

415447
"""Driver for the LSM6DS33 6-axis accelerometer and gyroscope.
416448
417449
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DS33 is connected to.
418450
:param address: The I2C slave address of the sensor
419451
420452
"""
453+
421454
CHIP_ID = _ISM330DHCT_CHIP_ID
455+
422456
def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
423457
super().__init__(i2c_bus, address)
424458

0 commit comments

Comments
 (0)