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.
Committer:
spastor
Date:
Mon Dec 08 22:27:34 2014 +0000
Revision:
0:cea6b92069b7
Initial commit.-

Who changed what in which revision?

UserRevisionLine numberNew contents of line
spastor 0:cea6b92069b7 1 #include "mbed.h"
spastor 0:cea6b92069b7 2 #include "H3LIS331DL.h"
spastor 0:cea6b92069b7 3
spastor 0:cea6b92069b7 4 H3LIS331DL h3lis(p28, p27);
spastor 0:cea6b92069b7 5
spastor 0:cea6b92069b7 6 Serial pc(USBTX, USBRX); // tx, rx
spastor 0:cea6b92069b7 7
spastor 0:cea6b92069b7 8 char* tag[] = {"Z+","Z-","Y+","Y-","X+","X-"};
spastor 0:cea6b92069b7 9 int16_t dataBuf[6][3] = {0};
spastor 0:cea6b92069b7 10
spastor 0:cea6b92069b7 11 void getAdjParameter()
spastor 0:cea6b92069b7 12 {
spastor 0:cea6b92069b7 13 AxesRaw_t data;
spastor 0:cea6b92069b7 14 int32_t sum[3] = {0};
spastor 0:cea6b92069b7 15
spastor 0:cea6b92069b7 16 pc.printf("Start ...\n");
spastor 0:cea6b92069b7 17 wait(3);
spastor 0:cea6b92069b7 18 for(int timer = 0; timer < 6; timer++){
spastor 0:cea6b92069b7 19 pc.printf("please turn ");
spastor 0:cea6b92069b7 20 pc.printf("%s", tag[timer]);
spastor 0:cea6b92069b7 21 pc.printf(" up\n");
spastor 0:cea6b92069b7 22 wait(3);
spastor 0:cea6b92069b7 23 for(int i = 0; i < 5; i++){
spastor 0:cea6b92069b7 24 pc.printf("start will be in ");
spastor 0:cea6b92069b7 25 pc.printf("%i", 5 - i);
spastor 0:cea6b92069b7 26 pc.printf(" seconds\n");
spastor 0:cea6b92069b7 27 wait(1);
spastor 0:cea6b92069b7 28 }
spastor 0:cea6b92069b7 29 pc.printf("calculating ... ");
spastor 0:cea6b92069b7 30 for(int i = 0 ; i < 100; i++){
spastor 0:cea6b92069b7 31 status_t response = h3lis.getAccAxesRaw(&data);
spastor 0:cea6b92069b7 32 if(MEMS_SUCCESS == response){
spastor 0:cea6b92069b7 33 sum[0] += data.AXIS_X;
spastor 0:cea6b92069b7 34 sum[1] += data.AXIS_Y;
spastor 0:cea6b92069b7 35 sum[2] += data.AXIS_Z;
spastor 0:cea6b92069b7 36 }
spastor 0:cea6b92069b7 37 wait_ms(20);
spastor 0:cea6b92069b7 38 }
spastor 0:cea6b92069b7 39 dataBuf[timer][0] = sum[0]/100;
spastor 0:cea6b92069b7 40 dataBuf[timer][1] = sum[1]/100;
spastor 0:cea6b92069b7 41 dataBuf[timer][2] = sum[2]/100;
spastor 0:cea6b92069b7 42 sum[0] = sum[1] = sum[2] = 0;
spastor 0:cea6b92069b7 43 pc.printf("calculate success\n");
spastor 0:cea6b92069b7 44 wait(1);
spastor 0:cea6b92069b7 45 }
spastor 0:cea6b92069b7 46 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;
spastor 0:cea6b92069b7 47 pc.printf("adjust value of X axis is %d\n", axis_x);
spastor 0:cea6b92069b7 48
spastor 0:cea6b92069b7 49 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;
spastor 0:cea6b92069b7 50 pc.printf("adjust value of Y axis is %d\n", axis_y);
spastor 0:cea6b92069b7 51
spastor 0:cea6b92069b7 52 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;
spastor 0:cea6b92069b7 53 pc.printf("adjust value of Z axis is %d\n", axis_z);
spastor 0:cea6b92069b7 54
spastor 0:cea6b92069b7 55 pc.printf("note: these data can be used in H3LISDL_Demo sketch");
spastor 0:cea6b92069b7 56 }
spastor 0:cea6b92069b7 57
spastor 0:cea6b92069b7 58 int main() {
spastor 0:cea6b92069b7 59 h3lis.init();
spastor 0:cea6b92069b7 60
spastor 0:cea6b92069b7 61 getAdjParameter();
spastor 0:cea6b92069b7 62 while(1) {
spastor 0:cea6b92069b7 63 wait(1);
spastor 0:cea6b92069b7 64 }
spastor 0:cea6b92069b7 65 }