revised examples
This commit is contained in:
parent
1a29e35097
commit
b86e97662a
@ -1,14 +1,14 @@
|
||||
/*
|
||||
* SCLICK SCLICK
|
||||
* _________ __________
|
||||
* | | | | |
|
||||
* | | | | |
|
||||
* ----- ------------------ | ------
|
||||
* |
|
||||
* TIME_LIMIT TIME_LIMIT|
|
||||
* >---------< >----------<|
|
||||
* LATENCY WINDOW |
|
||||
* >----------<>----------< | => DCLICK INT
|
||||
* SCLICK SCLICK
|
||||
* __________ ___________
|
||||
* | | | | |
|
||||
* | | | | |
|
||||
* ----- -------------------- | ------
|
||||
* |
|
||||
* TIME_LIMIT TIME_LIMIT |
|
||||
* >---------< >--------< | ==> DCLICK_INT
|
||||
* LATENCY WINDOW >----|---<
|
||||
* >----------<>----------< LATENCY
|
||||
* */
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
@ -54,18 +54,20 @@ int main() {
|
||||
lis.cfg.filter.mode = LIS3DH_FILTER_MODE_NORMAL;
|
||||
lis.cfg.filter.cutoff = LIS3DH_FILTER_CUTOFF_8;
|
||||
lis.cfg.filter.click = 1; /* enable filtering for CLICK function */
|
||||
|
||||
lis.cfg.click.xd = 1; /* enable X axis double click */
|
||||
lis.cfg.click.yd = 1; /* enable Y axis double click */
|
||||
lis.cfg.click.zd = 1; /* enable Z axis double click */
|
||||
|
||||
lis.cfg.pin1.click = 1; /* enable click int src through pin1 */
|
||||
lis.cfg.int1.latch = 1; /* latch interrupt until INT1_SRC is read */
|
||||
|
||||
/* 1 LSb = 16 mg @ FS_2G
|
||||
* so a 0.072g 'shock' is 72/16 = 4.5
|
||||
* However, the device can have up to +- 40mg read error
|
||||
* 0.112g => 112/16 = 15
|
||||
* so a 0.3g 'shock' is 300/16 = 18.75
|
||||
* However, the device can have up to +- 40mg read error, so add 40mg
|
||||
* 0.34g => 340/16 ~= 21
|
||||
*/
|
||||
lis.cfg.click_ths = 15; /* pretty sensitive */
|
||||
lis.cfg.click_ths = 21; /* pretty sensitive */
|
||||
|
||||
/* Duration time is measured in N/ODR where:
|
||||
* --- N = The content of the intX_dur integer
|
||||
@ -88,6 +90,11 @@ int main() {
|
||||
/* error handling */
|
||||
}
|
||||
|
||||
/* read CLICK_SRC to clear previous interrupts, if any */
|
||||
if (lis3dh_read_click(&lis)) {
|
||||
/* error handling */
|
||||
}
|
||||
|
||||
for(;;) {
|
||||
|
||||
/* poll interrupt on INT1 pin */
|
||||
@ -100,10 +107,10 @@ int main() {
|
||||
/* error handling */
|
||||
}
|
||||
|
||||
/* only print data if DCLICK=1 in CLICK_SRC */
|
||||
/* only print if DCLICK=1 */
|
||||
if (LIS3DH_CLICK_DCLICK(lis.src.click)) {
|
||||
/* print data gathered from CLICK_SRC */
|
||||
printf("Click: X=%d, Y=%d, Z=%d, Sign=%d, S_en=%d, D_en=%d\n",
|
||||
printf("Click: X=%d, Y=%d, Z=%d, Sign=%d, S_CLICK=%d, D_CLICK=%d\n",
|
||||
LIS3DH_CLICK_SRC_X(lis.src.click),
|
||||
LIS3DH_CLICK_SRC_Y(lis.src.click),
|
||||
LIS3DH_CLICK_SRC_Z(lis.src.click),
|
||||
@ -111,6 +118,10 @@ int main() {
|
||||
LIS3DH_CLICK_SCLICK(lis.src.click),
|
||||
LIS3DH_CLICK_DCLICK(lis.src.click));
|
||||
}
|
||||
|
||||
/* sleep for 5 ms because gpio sysfs is slow at clearing interrupts */
|
||||
/* not necessary with "real" IRQ */
|
||||
usleep(5000);
|
||||
}
|
||||
|
||||
/* unregister interrupt */
|
||||
|
@ -45,7 +45,7 @@ int main() {
|
||||
|
||||
/* 1 LSb = 16 mg @ FS_2G
|
||||
* 0.3g threshold = 300/16 = 18.75
|
||||
* add read error, +40mg => 240/16 = 21.25 ~= 21
|
||||
* add read error, +40mg => 340/16 = 21.25 ~= 21
|
||||
* if you for some reason don't want to use the HP filter,
|
||||
* just add 1g to the threshold calculation.
|
||||
*/
|
||||
@ -72,15 +72,13 @@ int main() {
|
||||
lis.cfg.int1.aoi = 0; /* set to 1 for AND mode */
|
||||
lis.cfg.int1.en_6d = 0;
|
||||
|
||||
|
||||
/* latch interrupt. might not work. */
|
||||
/* latch interrupt */
|
||||
lis.cfg.int1.latch = 1;
|
||||
|
||||
/* set up a HP filter to ignore constant earth acceleration */
|
||||
lis.cfg.filter.mode = LIS3DH_FILTER_MODE_NORMAL_REF;
|
||||
lis.cfg.filter.cutoff = LIS3DH_FILTER_CUTOFF_8;
|
||||
lis.cfg.filter.ia1 = 1; /* enable filter for INT1 generator */
|
||||
|
||||
|
||||
/* write device config */
|
||||
if (lis3dh_configure(&lis)) {
|
||||
@ -111,13 +109,17 @@ int main() {
|
||||
|
||||
/* print received interrupt .. */
|
||||
printf("IA=%d ZH=%d ZL=%d YH=%d YL=%d XH=%d XL=%d\n",
|
||||
!!(lis.src.int1 & 0x40),
|
||||
LIS3DH_INT_SRC_IA(lis.src.int1),
|
||||
LIS3DH_INT_SRC_Z_HIGH(lis.src.int1),
|
||||
LIS3DH_INT_SRC_Z_LOW(lis.src.int1),
|
||||
LIS3DH_INT_SRC_Y_HIGH(lis.src.int1),
|
||||
LIS3DH_INT_SRC_Y_LOW(lis.src.int1),
|
||||
LIS3DH_INT_SRC_X_HIGH(lis.src.int1),
|
||||
LIS3DH_INT_SRC_X_LOW(lis.src.int1));
|
||||
|
||||
/* sleep for 5 ms because gpio sysfs is slow at clearing interrupts */
|
||||
/* not necessary with "real" IRQ */
|
||||
usleep(5000);
|
||||
}
|
||||
|
||||
/* unregister interrupt */
|
||||
|
6
main.c
6
main.c
@ -118,13 +118,17 @@ int main() {
|
||||
|
||||
/* print received interrupt .. */
|
||||
printf("IA=%d ZH=%d ZL=%d YH=%d YL=%d XH=%d XL=%d\n",
|
||||
!!(lis.src.int1 & 0x40),
|
||||
LIS3DH_INT_SRC_IA(lis.src.int1),
|
||||
LIS3DH_INT_SRC_Z_HIGH(lis.src.int1),
|
||||
LIS3DH_INT_SRC_Z_LOW(lis.src.int1),
|
||||
LIS3DH_INT_SRC_Y_HIGH(lis.src.int1),
|
||||
LIS3DH_INT_SRC_Y_LOW(lis.src.int1),
|
||||
LIS3DH_INT_SRC_X_HIGH(lis.src.int1),
|
||||
LIS3DH_INT_SRC_X_LOW(lis.src.int1));
|
||||
|
||||
/* sleep for 5 ms because gpio sysfs is slow at clearing interrupts */
|
||||
/* not necessary with "real" IRQ */
|
||||
usleep(5000);
|
||||
}
|
||||
|
||||
/* unregister interrupt */
|
||||
|
Loading…
Reference in New Issue
Block a user