Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed SDFileSystem_
Diff: main.cpp
- Revision:
- 19:2475d32bd93f
- Parent:
- 18:2a42f4052139
- Child:
- 20:db6a609232d2
--- a/main.cpp Fri Sep 03 07:16:27 2021 +0000 +++ b/main.cpp Fri Sep 03 08:54:23 2021 +0000 @@ -69,11 +69,11 @@ int update=0; char buffer1[512] = {}; char buffer2[512] = {}; -char stracc1[32] = {}, stracc2[32] = {}; +char stracc1[64] = {}, stracc2[32] = {}; int lognum1 = 0, lognum2 = 0; char filename1[32]= {}; char filename2[32]= {}; -int ret = 0; +int ret = 0,init=1; //int timer_flag = 0; /* @@ -106,8 +106,8 @@ //az+= tz; //as+= scr; //cnt++; - //pc.printf("new x:%f y:%f,z:%f scaler = %f \r\n",(float)tx*0.005,(float)ty*0.005,(float)tz*0.005,(float)scr); - pc.printf("new x:%d y:%d,z:%d scaler = %d \r\n",tx,ty,tz,scr); + pc.printf("new x:%2.2f y:%2.2f,z:%2.2f scaler = %2.2f \r\n",(float)tx*0.005,(float)ty*0.005,(float)tz*0.005,(float)scr*0.005); + //pc.printf("new x:%d y:%d,z:%d scaler = %d \r\n",tx,ty,tz,scr); if ( max_g < scr) { max_g = scr; @@ -118,7 +118,7 @@ writeEEPROMByte(0, max_g); } - sprintf(stracc1,"%d,%f\r\n",timecount,scr); + sprintf(stracc1,"%d,x:%2.2f,y:%2.2f,z:%2.2f scr:%2.2f\r\n",timecount,(float)tx*0.005,(float)ty*0.005,(float)tz*0.005,(float)scr*0.005); //pc.printf("h3lis331dl:%s",stracc1); if(strlen(buffer1)+strlen(stracc1) > 512) { //pc.printf("buffer over. write file2\r\n"); @@ -129,6 +129,7 @@ NVIC_SystemReset(); } + memset(buffer1,0,sizeof(buffer1)); sprintf(buffer1,"%s",stracc1); @@ -158,7 +159,7 @@ } oldcount = 0; } - + if(time(NULL) > 86400){ //Create New File set_time(NULL); @@ -194,24 +195,22 @@ sprintf(filename1,"/sd/new_%d",lognum1); sprintf(filename2,"/sd/old_%d",lognum2); - while(fp1 || fp2){ - fp1 = fopen(filename1,"a"); - if(!fp1) { - pc.printf("fp1(%s) open failed\r\n",filename1); - //NVIC_SystemReset(); - } - fp2 = fopen(filename2,"a"); - if(!fp2) { - pc.printf("fp2(%s) open failed\r\n",filename2); - //NVIC_SystemReset(); - } + fp1 = fopen(filename1,"a"); + if(!fp1) { + pc.printf("fp1(%s) open failed\r\n",filename1); + //NVIC_SystemReset(); + } + fp2 = fopen(filename2,"a"); + if(!fp2) { + pc.printf("fp2(%s) open failed\r\n",filename2); + //NVIC_SystemReset(); } - while(ret) { - ret = initLIS3DH(); - ret = initLIS331(); - pc.printf(" init acc sensor %d\r\n",ret); - wait_ms(100); + while(init) { + init = initLIS331(); + initLIS3DH(); + pc.printf(" init acc sensor %d\r\n",ret); + wait_ms(100); } //interrupt.attach_us(&timer,20000);//20ms while(1)