@@ -4,7 +4,7 @@ The [LIS3DH](http://www.st.com/st-web-ui/static/active/en/resource/technical/doc
4
4
5
5
The LPS25H can interface over I² ; C or SPI. This class addresses only I² ; C for the time being.
6
6
7
- ** To add this library to your project, add** ` #require "LIS3DH.class.nut:1.2 .0" ` ** to the top of your device code**
7
+ ** To add this library to your project, add** ` #require "LIS3DH.class.nut:1.3 .0" ` ** to the top of your device code**
8
8
9
9
## Class Usage
10
10
@@ -20,7 +20,7 @@ The class’ constructor takes one required parameter (a configured imp I²C
20
20
  ; <br >
21
21
22
22
``` squirrel
23
- #require "LIS3DH.class.nut:1.2 .0"
23
+ #require "LIS3DH.class.nut:1.3 .0"
24
24
25
25
i2c <- hardware.i2c89;
26
26
i2c.configure(CLOCK_SPEED_400_KHZ);
@@ -127,6 +127,70 @@ The *getRange()* method returns the currently-set measurement range of the senso
127
127
server.log(format("Current Sensor Range is +/- %dG", accel.getRange()));
128
128
```
129
129
130
+ ### configureFifoInterrupt(* state[ , fifomode] [ , watermark ] * )
131
+
132
+ This method configures an interrupt when the FIFO buffer reaches the set watermark:
133
+
134
+ | Parameter | Type | Default Value | Description |
135
+ | --------- | ---- | ------------- | ----------- |
136
+ | * state* | Boolean | N/A | ` true ` to enable, ` false ` to disable |
137
+ | * fifomode* | bitfield | * FIFO_STREAM_MODE* | See table below |
138
+ | * watermark* | Integer | 28 | Number of buffer slots filled to generate<br > interrupt (buffer has 32 slots) |
139
+
140
+ This example sets the FIFO buffer to Stream Mode and reads the data from
141
+ the buffer whenever the watermark is reached:
142
+
143
+ ``` squirrel
144
+ // Function to read from FIFO buffer
145
+ function readBuffer() {
146
+
147
+ if (wakePin.read() == 0) return;
148
+
149
+ // Read buffer
150
+ local stats = accel.getFifoStats();
151
+ for (local i = 0; i < stats.unread; ++i) {
152
+ local data = accel.getAccel();
153
+ server.log(format("Accel (x,y,z): [%d, %d, %d]", data.x, data.y, data.z));
154
+ }
155
+
156
+ // Check if we are now overrun
157
+ local stats = accel.getFifoStats();
158
+ if (stats.overrun) {
159
+ server.error("Accelerometer buffer overrun")
160
+
161
+ // Set FIFO mode to bypass to clear the buffer and then return to stream mode
162
+ accel.configureFifoInterrupt(true, accel.FIFO_BYPASS_MODE);
163
+ accel.configureFifoInterrupt(true, accel.FIFO_STREAM_MODE, 30);
164
+ }
165
+
166
+ }
167
+
168
+ i2c <- hardware.i2cAB;
169
+ i2c.configure(CLOCK_SPEED_400_KHZ);
170
+ accel <- LIS3DH(i2c);
171
+
172
+ // Configure interrupt pin
173
+ wakePin <- hardware.pinW;
174
+ wakePin.configure(DIGITAL_IN_PULLDOWN, readBuffer);
175
+
176
+ // Configure accelerometer
177
+ accel.init();
178
+ accel.setDataRate(100);
179
+
180
+ // Configure the FIFO buffer in Stream Mode and set interrupt generator to
181
+ // generate an interrupt when there are 30 entries in the buffer
182
+ accel.configureFifoInterrupt(true, accel.FIFO_STREAM_MODE, 30);
183
+ ```
184
+
185
+ #### FIFO modes
186
+
187
+ | Mode | Description |
188
+ | ---- | ----------- |
189
+ | * FIFO_BYPASS_MODE* | Disables the FIFO buffer (only the first address is used for each channel) |
190
+ | * FIFO_FIFO_MODE* | When full, the FIFO buffer stops collecting data from the input channels |
191
+ | * FIFO_STREAM_MODE* | When full, the FIFO buffer discards the older data as the new arrive |
192
+ | * FIFO_STREAM_TO_FIFO_MODE* | When full, the FIFO buffer discards the older data as the new arrive.<br > Once trigger event occurs, the FIFO buffer starts operating in FIFO mode. |
193
+
130
194
### configureInertialInterrupt(* state[ , threshold] [ , duration ] [ , options] * )
131
195
132
196
This method configures the inertial interrupt generator:
@@ -353,6 +417,17 @@ switch(hardware.wakereason()) {
353
417
}
354
418
```
355
419
420
+ ### getFifoStats()
421
+
422
+ This method returns information about the state of the FIFO buffer in a squirrel table:
423
+
424
+ | Value | Type | Description |
425
+ | --- | --- | --- | --- |
426
+ | * watermark* | Boolean | ` true ` if watermark has been set |
427
+ | * overrun* | Boolean | ` true ` if data has been overwritten without being read |
428
+ | * empty* | Boolean | ` true ` if buffer is empty |
429
+ | * unread* | Integer | Number of unread slots in buffer |
430
+
356
431
### configureHighPassFilter(* filters[ , cutoff] [ , mode ] * )
357
432
358
433
This method configures the high-pass filter.
0 commit comments