AdjVal application from Seeed Studio's H3LIS331DL repository

Dependencies:   H3LIS331DL mbed

Code ported from Seeed Studio's H3LIS331DL repository.

License

The MIT License (MIT)

Copyright (c) 2013 Seeed Technology Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Files at this revision

API Documentation at this revision

Comitter:
spastor
Date:
Mon Dec 08 22:27:34 2014 +0000
Commit message:
Initial commit.-

Changed in this revision

H3LIS331DL.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r cea6b92069b7 H3LIS331DL.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/H3LIS331DL.lib	Mon Dec 08 22:27:34 2014 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/spastor/code/H3LIS331DL/#2b446bf9b93b
diff -r 000000000000 -r cea6b92069b7 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Dec 08 22:27:34 2014 +0000
@@ -0,0 +1,65 @@
+#include "mbed.h"
+#include "H3LIS331DL.h"
+
+H3LIS331DL h3lis(p28, p27);
+
+Serial pc(USBTX, USBRX); // tx, rx
+
+char* tag[] = {"Z+","Z-","Y+","Y-","X+","X-"};
+int16_t dataBuf[6][3] = {0};
+
+void getAdjParameter()
+{
+    AxesRaw_t data;
+    int32_t sum[3] = {0};
+    
+    pc.printf("Start ...\n");
+    wait(3);
+    for(int timer = 0; timer < 6; timer++){
+      pc.printf("please turn ");
+      pc.printf("%s", tag[timer]);
+      pc.printf(" up\n");
+      wait(3);
+      for(int i = 0; i < 5; i++){
+        pc.printf("start will be in ");
+        pc.printf("%i", 5 - i);
+        pc.printf(" seconds\n");
+        wait(1);
+      }
+      pc.printf("calculating ... ");
+      for(int i = 0 ; i < 100; i++){
+        status_t response = h3lis.getAccAxesRaw(&data);
+        if(MEMS_SUCCESS == response){
+          sum[0] += data.AXIS_X;
+          sum[1] += data.AXIS_Y;
+          sum[2] += data.AXIS_Z;
+        }
+        wait_ms(20);
+     }
+     dataBuf[timer][0] = sum[0]/100;
+     dataBuf[timer][1] = sum[1]/100;
+     dataBuf[timer][2] = sum[2]/100;
+     sum[0] = sum[1] = sum[2] = 0;
+     pc.printf("calculate success\n");
+     wait(1);
+   }
+   int16_t axis_x = (dataBuf[4][0] + dataBuf[5][0])*0.3 + (dataBuf[0][0]+dataBuf[1][0]+dataBuf[2][0]+dataBuf[3][0])/10;   
+   pc.printf("adjust value of X axis is %d\n", axis_x);
+   
+   int16_t axis_y = (dataBuf[2][1] + dataBuf[3][1])*0.3 + (dataBuf[0][1]+dataBuf[1][1]+dataBuf[4][1]+dataBuf[5][1])/10;
+   pc.printf("adjust value of Y axis is %d\n", axis_y);
+   
+   int16_t axis_z = (dataBuf[0][2] + dataBuf[1][2])*0.3 + (dataBuf[2][2]+dataBuf[3][2]+dataBuf[4][2]+dataBuf[5][2])/10;
+   pc.printf("adjust value of Z axis is %d\n", axis_z);
+   
+   pc.printf("note: these data can be used in H3LISDL_Demo sketch");
+}
+
+int main() {
+    h3lis.init();
+
+    getAdjParameter();
+    while(1) {
+        wait(1);
+    }
+}
diff -r 000000000000 -r cea6b92069b7 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Dec 08 22:27:34 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file