52
52
import ustruct as struct
53
53
from micropython import const
54
54
from adafruit_bus_device .i2c_device import I2CDevice
55
+ from adafruit_register .i2c_struct import UnaryStruct
56
+ from adafruit_register .i2c_bit import RWBit
57
+ from adafruit_register .i2c_bits import RWBits
58
+
55
59
56
60
__version__ = "0.0.0-auto.0"
57
61
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM303_Accel.git"
92
96
_REG_ACCEL_TIME_LIMIT_A = const (0x3B )
93
97
_REG_ACCEL_TIME_LATENCY_A = const (0x3C )
94
98
_REG_ACCEL_TIME_WINDOW_A = const (0x3D )
95
-
99
+ _REG_ACCEL_ACT_THS_A = const (0x3E )
100
+ _REG_ACCEL_ACT_DUR_A = const (0x3F )
101
+ _REG_ACCEL_WHO_AM_I = const (0x0F )
96
102
97
103
# Conversion constants
98
104
_LSM303ACCEL_MG_LSB = 16704.0
@@ -105,10 +111,23 @@ class LSM303_Accel:
105
111
# Class-level buffer for reading and writing data with the sensor.
106
112
# This reduces memory allocations but means the code is not re-entrant or
107
113
# thread safe!
114
+ _chip_id = UnaryStruct (_REG_ACCEL_WHO_AM_I , "B" )
115
+ _int2_int1_enable = RWBit (_REG_ACCEL_CTRL_REG6_A , 6 , 1 )
116
+ _int2_int2_enable = RWBit (_REG_ACCEL_CTRL_REG6_A , 5 , 1 )
117
+
118
+ _int2_activity_enable = RWBit (_REG_ACCEL_CTRL_REG6_A , 3 , 1 )
119
+ _int_pin_active_low = RWBit (_REG_ACCEL_CTRL_REG6_A , 1 , 1 )
120
+
121
+ _act_threshold = UnaryStruct (_REG_ACCEL_ACT_THS_A , "B" )
122
+ _act_duration = UnaryStruct (_REG_ACCEL_ACT_DUR_A , "B" )
123
+
124
+ _data_rate = RWBits (4 , _REG_ACCEL_CTRL_REG1_A , 4 , 1 )
125
+
108
126
_BUFFER = bytearray (6 )
109
127
110
128
def __init__ (self , i2c ):
111
129
self ._accel_device = I2CDevice (i2c , _ADDRESS_ACCEL )
130
+ self .i2c_device = self ._accel_device
112
131
self ._write_u8 (self ._accel_device , _REG_ACCEL_CTRL_REG1_A , 0x27 ) # Enable the accelerometer
113
132
114
133
@property
0 commit comments