@@ -149,24 +149,24 @@ def accel_range(self):
149
149
- ACCELRANGE_8G
150
150
- ACCELRANGE_16G
151
151
"""
152
- reg = self ._read_u8 (_XGTYPE , LSM9DS1_REGISTER_CTRL_REG6_XL )
152
+ reg = self ._read_u8 (_XGTYPE , _LSM9DS1_REGISTER_CTRL_REG6_XL )
153
153
return (reg & 0b00011000 ) & 0xFF
154
154
155
155
@accel_range .setter
156
156
def accel_range (self , val ):
157
157
assert val in (ACCELRANGE_2G , ACCELRANGE_4G , ACCELRANGE_8G ,
158
158
ACCELRANGE_16G )
159
- reg = self ._read_u8 (_XGTYPE , LSM9DS1_REGISTER_CTRL_REG6_XL )
159
+ reg = self ._read_u8 (_XGTYPE , _LSM9DS1_REGISTER_CTRL_REG6_XL )
160
160
reg = (reg & ~ (0b00011000 )) & 0xFF
161
161
reg |= val
162
162
self ._write_u8 (_XGTYPE , _LSM9DS1_REGISTER_CTRL_REG6_XL , reg )
163
- if val == _LSM9DS1_ACCELRANGE_2G :
163
+ if val == ACCELRANGE_2G :
164
164
self ._accel_mg_lsb = _LSM9DS1_ACCEL_MG_LSB_2G
165
- elif val == _LSM9DS1_ACCELRANGE_4G :
165
+ elif val == ACCELRANGE_4G :
166
166
self ._accel_mg_lsb = _LSM9DS1_ACCEL_MG_LSB_4G
167
- elif val == _LSM9DS1_ACCELRANGE_8G :
167
+ elif val == ACCELRANGE_8G :
168
168
self ._accel_mg_lsb = _LSM9DS1_ACCEL_MG_LSB_8G
169
- elif val == _LSM9DS1_ACCELRANGE_16G :
169
+ elif val == ACCELRANGE_16G :
170
170
self ._accel_mg_lsb = _LSM9DS1_ACCEL_MG_LSB_16G
171
171
172
172
@property
@@ -188,13 +188,13 @@ def mag_gain(self, val):
188
188
reg = (reg & ~ (0b01100000 )) & 0xFF
189
189
reg |= val
190
190
self ._write_u8 (_MAGTYPE , _LSM9DS1_REGISTER_CTRL_REG2_M , reg )
191
- if val == _LSM9DS1_MAGGAIN_4GAUSS :
191
+ if val == MAGGAIN_4GAUSS :
192
192
self ._mag_mgauss_lsb = _LSM9DS1_MAG_MGAUSS_4GAUSS
193
- elif val == _LSM9DS1_MAGGAIN_8GAUSS :
193
+ elif val == MAGGAIN_8GAUSS :
194
194
self ._mag_mgauss_lsb = _LSM9DS1_MAG_MGAUSS_8GAUSS
195
- elif val == _LSM9DS1_MAGGAIN_12GAUSS :
195
+ elif val == MAGGAIN_12GAUSS :
196
196
self ._mag_mgauss_lsb = _LSM9DS1_MAG_MGAUSS_12GAUSS
197
- elif val == _LSM9DS1_MAGGAIN_16GAUSS :
197
+ elif val == MAGGAIN_16GAUSS :
198
198
self ._mag_mgauss_lsb = _LSM9DS1_MAG_MGAUSS_16GAUSS
199
199
200
200
@property
@@ -214,11 +214,11 @@ def gyro_scale(self, val):
214
214
reg = (reg & ~ (0b00110000 )) & 0xFF
215
215
reg |= val
216
216
self ._write_u8 (_XGTYPE , _LSM9DS1_REGISTER_CTRL_REG1_G , reg )
217
- if val == _LSM9DS1_GYROSCALE_245DPS :
217
+ if val == GYROSCALE_245DPS :
218
218
self ._gyro_dps_digit = _LSM9DS1_GYRO_DPS_DIGIT_245DPS
219
- elif val == _LSM9DS1_GYROSCALE_500DPS :
219
+ elif val == GYROSCALE_500DPS :
220
220
self ._gyro_dps_digit = _LSM9DS1_GYRO_DPS_DIGIT_500DPS
221
- elif val == _LSM9DS1_GYROSCALE_2000DPS :
221
+ elif val == GYROSCALE_2000DPS :
222
222
self ._gyro_dps_digit = _LSM9DS1_GYRO_DPS_DIGIT_2000DPS
223
223
224
224
def read_accel_raw (self ):
@@ -228,7 +228,7 @@ def read_accel_raw(self):
228
228
accelerometer property!
229
229
"""
230
230
# Read the accelerometer
231
- self ._read_bytes (_XGTYPE , 0x80 | LSM9DS1_REGISTER_OUT_X_L_XL , 6 ,
231
+ self ._read_bytes (_XGTYPE , 0x80 | _LSM9DS1_REGISTER_OUT_X_L_XL , 6 ,
232
232
self ._BUFFER )
233
233
xlo = self ._BUFFER [0 ];
234
234
xhi = self ._BUFFER [1 ];
@@ -315,7 +315,7 @@ def read_temp_raw(self):
315
315
want to use the temperature property!
316
316
"""
317
317
# Read temp sensor
318
- self ._read_bytes (_XGTYPE , 0x80 | LSM9DS1_REGISTER_TEMP_OUT_L , 2 ,
318
+ self ._read_bytes (_XGTYPE , 0x80 | _LSM9DS1_REGISTER_TEMP_OUT_L , 2 ,
319
319
self ._BUFFER )
320
320
temp = (self ._BUFFER [1 ] << 8 ) | self ._BUFFER [0 ]
321
321
return temp
@@ -362,31 +362,31 @@ def _read_u8(self, sensor_type, address):
362
362
device = self ._mag_device
363
363
else :
364
364
device = self ._xg_device
365
- with device :
365
+ with device as i2c :
366
366
self ._BUFFER [0 ] = address & 0xFF
367
- device .write (self ._BUFFER , end = 1 )
368
- device .readinto (self ._BUFFER , end = 1 )
367
+ i2c .write (self ._BUFFER , end = 1 , stop = False )
368
+ i2c .readinto (self ._BUFFER , end = 1 )
369
369
return self ._BUFFER [0 ]
370
370
371
371
def _read_bytes (self , sensor_type , address , count , buffer ):
372
372
if sensor_type == _MAGTYPE :
373
373
device = self ._mag_device
374
374
else :
375
375
device = self ._xg_device
376
- with device :
376
+ with device as i2c :
377
377
self ._BUFFER [0 ] = address & 0xFF
378
- device .write (self ._BUFFER , end = 1 )
379
- device .readinto (self ._BUFFER , end = count )
378
+ i2c .write (self ._BUFFER , end = 1 , stop = False )
379
+ i2c .readinto (self ._BUFFER , end = count )
380
380
381
381
def _write_u8 (self , sensor_type , address , val ):
382
382
if sensor_type == _MAGTYPE :
383
383
device = self ._mag_device
384
384
else :
385
385
device = self ._xg_device
386
- with device :
386
+ with device as i2c :
387
387
self ._BUFFER [0 ] = address & 0xFF
388
388
self ._BUFFER [1 ] = val & 0xFF
389
- device .write (self ._BUFFER , end = 2 )
389
+ i2c .write (self ._BUFFER , end = 2 )
390
390
391
391
392
392
class LSM9DS1_SPI (LSM9DS1 ):
@@ -401,31 +401,31 @@ def _read_u8(self, sensor_type, address):
401
401
device = self ._mag_device
402
402
else :
403
403
device = self ._xg_device
404
- with device :
405
- device .configure (baudrate = 200000 , phase = 0 , polarity = 0 )
404
+ with device as spi :
405
+ spi .configure (baudrate = 200000 , phase = 0 , polarity = 0 )
406
406
self ._BUFFER [0 ] = (address | 0x80 ) & 0xFF
407
- device .write (self ._BUFFER , end = 1 )
408
- device .readinto (self ._BUFFER , end = 1 )
407
+ spi .write (self ._BUFFER , end = 1 )
408
+ spi .readinto (self ._BUFFER , end = 1 )
409
409
return self ._BUFFER [0 ]
410
410
411
411
def _read_bytes (self , sensor_type , address , count , buffer ):
412
412
if sensor_type == _MAGTYPE :
413
413
device = self ._mag_device
414
414
else :
415
415
device = self ._xg_device
416
- with device :
417
- device .configure (baudrate = 200000 , phase = 0 , polarity = 0 )
416
+ with device as spi :
417
+ spi .configure (baudrate = 200000 , phase = 0 , polarity = 0 )
418
418
self ._BUFFER [0 ] = (address | 0x80 ) & 0xFF
419
- device .write (self ._BUFFER , end = 1 )
420
- device .readinto (self ._BUFFER , end = count )
419
+ spi .write (self ._BUFFER , end = 1 )
420
+ spi .readinto (self ._BUFFER , end = count )
421
421
422
422
def _write_u8 (self , sensor_type , address , val ):
423
423
if sensor_type == _MAGTYPE :
424
424
device = self ._mag_device
425
425
else :
426
426
device = self ._xg_device
427
- with device :
428
- device .configure (baudrate = 200000 , phase = 0 , polarity = 0 )
427
+ with device as spi :
428
+ spi .configure (baudrate = 200000 , phase = 0 , polarity = 0 )
429
429
self ._BUFFER [0 ] = (address & 0x7F ) & 0xFF
430
430
self ._BUFFER [1 ] = val & 0xFF
431
- device .write (self ._BUFFER , end = 2 )
431
+ spi .write (self ._BUFFER , end = 2 )
0 commit comments