$ gcc -o gsensor_sample_demo gsensor_sample_demo.c gsensor_sample_demo.c: In function ‘main’: gsensor_sample_demo.c:34:3: warning: implicit declaration of function ‘exit’ [-Wimplicit-function-declaration] 34 | exit(-1); | ^~~~ gsensor_sample_demo.c:34:3: warning: incompatible implicit declaration of built-in function ‘exit’ gsensor_sample_demo.c:4:1: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’ 3 | #include <fcntl.h> +++ |+#include <stdlib.h> 4 | gsensor_sample_demo.c:41:3: warning: implicit declaration of function ‘close’; did you mean ‘pclose’? [-Wimplicit-function-declaration] 41 | close(gsensor_fd); | ^~~~~ | pclose gsensor_sample_demo.c:42:3: warning: incompatible implicit declaration of built-in function ‘exit’ 42 | exit(-1); | ^~~~ gsensor_sample_demo.c:42:3: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’ gsensor_sample_demo.c:53:4: warning: incompatible implicit declaration of built-in function ‘exit’ 53 | exit(-1); | ^~~~ gsensor_sample_demo.c:53:4: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’ gsensor_sample_demo.c:57:3: warning: implicit declaration of function ‘sleep’ [-Wimplicit-function-declaration] 57 | sleep(1); | ^~~~~
Run
Rotate the board while running, you can see the changes in gsensor data
1 2 3 4 5 6 7 8 9 10 11 12
$ ./gsensor_sample_demo gsensor node open success!!! gsensor start sueecss !!! start to get gsensor data ... gsensor_data -- x:-2112,y:16,z:16448 gsensor_data -- x:-2128,y:176,z:16128 gsensor_data -- x:-1632,y:2784,z:15968 gsensor_data -- x:7440,y:-3760,z:14608 gsensor_data -- x:-512,y:-7280,z:12128 gsensor_data -- x:-14384,y:-2336,z:11280 gsensor_data -- x:9952,y:-5264,z:15216 gsensor_data -- x:-6432,y:3760,z:24896