@@ -230,17 +230,13 @@ class LIS331:
230
230
_data_rate_lpf_bits = RWBits (2 , _LIS331_REG_CTRL1 , 3 )
231
231
_range_bits = RWBits (2 , _LIS331_REG_CTRL4 , 4 )
232
232
_raw_acceleration = ROByteArray ((_LIS331_REG_OUT_X_L | 0x80 ), "<hhh" , 6 )
233
- _reference_value = UnaryStruct (_LIS331_REG_REFERENCE , "<b" )
234
- _zero_hpf_reference = ROUnaryStruct (_LIS331_REG_HP_FILTER_RESET , "<b" )
235
233
234
+ _reference_value = UnaryStruct (_LIS331_REG_REFERENCE , "<b" )
235
+ _zero_hpf = ROUnaryStruct (_LIS331_REG_HP_FILTER_RESET , "<b" )
236
236
_hpf_mode_bits = RWBit (_LIS331_REG_CTRL2 , 5 )
237
237
_hpf_enable_bit = RWBit (_LIS331_REG_CTRL2 , 4 )
238
238
_hpf_cutoff = RWBits (2 , _LIS331_REG_CTRL2 , 0 )
239
239
240
- CHIP_ID = None
241
- # Adafruit_BusIO_Register reference_reg = Adafruit_BusIO_Register(
242
- # i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LIS331_REG_REFERENCE);
243
- # reference_reg.write(reference);
244
240
def __init__ (self , i2c_bus , address = _LIS331_DEFAULT_ADDRESS ):
245
241
if (not isinstance (self , LIS331HH )) and (not isinstance (self , H3LIS331 )):
246
242
raise RuntimeError (
@@ -307,6 +303,7 @@ def zero_hpf(self):
307
303
will set all measurements to zero immediately, avoiding the normal settling time seen when
308
304
using the high-pass filter without a ``hpf_reference``
309
305
"""
306
+ self ._zero_hpf # pylint: disable=pointless-statement
310
307
311
308
def enable_hpf (
312
309
self , enabled = True , cutoff = RateDivisor .ODR_DIV_50 , use_reference = False
@@ -332,25 +329,19 @@ def enable_hpf(
332
329
@property
333
330
def data_rate (self ):
334
331
"""Select the rate at which the accelerometer takes measurements. Must be a `Rate`"""
335
- # because both the power mode[pm] and data rate[dr] bits determine the data rate
336
- # we'll report the whole bunch
337
332
return self ._cached_data_rate
338
333
339
334
@data_rate .setter
340
335
def data_rate (self , new_rate_bits ):
341
336
if not Rate .is_valid (new_rate_bits ):
342
337
raise AttributeError ("data_rate must be a `Rate`" )
343
- # like `data_rate` we'll receive the whole group of pm/dr bits to determine what to be set
344
- # print("(entry)new_rate_bits", bin(new_rate_bits))
338
+
339
+ # to determine what to be set we'll receive the whole group of pm/dr bits
340
+ # to make sure we don't overwrite the filter
345
341
new_mode , adjusted_rate_bits = self ._mode_and_rate (new_rate_bits )
346
- # print("new mode:", bin(new_mode), "adjusted_rate_bits:", bin(adjusted_rate_bits))
347
342
if new_mode == Mode .NORMAL : # pylint: disable=no-member
348
- # print("Mode is NORMAL")
349
- # print("setting self._mode_and_odr_bits to new_rate_bits", bin(new_rate_bits))
350
343
self ._mode_and_odr_bits = new_rate_bits
351
344
else :
352
- # print("Mode is ", Mode.string[new_mode], "and not NORMAL")
353
- # print("setting self._power_mode_bits to new_mode", bin(new_mode))
354
345
self ._power_mode_bits = new_mode
355
346
356
347
self ._cached_data_rate = new_mode << 2 | new_rate_bits
@@ -365,10 +356,10 @@ def mode(self):
365
356
def _mode_and_rate (self , data_rate = None ):
366
357
if data_rate is None :
367
358
data_rate = self ._cached_data_rate
368
- # pylint: disable=no-member
359
+
369
360
pm_value = (data_rate & 0x1C ) >> 2
370
361
dr_value = data_rate & 0x3
371
- if pm_value is Mode .LOW_POWER :
362
+ if pm_value is Mode .LOW_POWER : # pylint: disable=no-member
372
363
dr_value = 0
373
364
return (pm_value , dr_value )
374
365
@@ -402,9 +393,9 @@ def acceleration(self):
402
393
403
394
def _scale_acceleration (self , value ):
404
395
# The measurements are 12 bits left justified to preserve the sign bit
396
+ # so we'll shift them back to get the real value
405
397
right_justified = value >> 4
406
398
lsb_value = self ._range_class .lsb [self ._cached_accel_range ]
407
- # print("v:", value, "cr:", self._cached_accel_range, "l:", lsb_value)
408
399
return right_justified * lsb_value
409
400
410
401
0 commit comments