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:
- 18:2a42f4052139
- Parent:
- 17:039d304c4a9c
- Child:
- 19:2475d32bd93f
--- a/main.cpp Fri Sep 03 01:54:02 2021 +0000 +++ b/main.cpp Fri Sep 03 07:16:27 2021 +0000 @@ -47,7 +47,7 @@ RawSerial pc(PA_9, PA_10,115200); //console UART //LowPowerTicker interrupt; -Ticker interrupt; +//Ticker interrupt; SPI STSPI(PB_15, PB_14, PB_13); //mosi,miso,clk DigitalOut STSPICS(PB_12); @@ -74,17 +74,20 @@ char filename1[32]= {}; char filename2[32]= {}; int ret = 0; -int timer_flag = 0; +//int timer_flag = 0; +/* void timer(){ timer_flag = 1; timecount++; oldcount++; } +*/ void sub(){ short tx=0,ty=0,tz=0; - float scr=0; + //float scr=0; + long scr = 0; //static long ax,ay,az,as; //static int cnt; @@ -95,7 +98,7 @@ tz += OFFSET_Z; //スカラー値変換 - scr = int_sqrt( tx*tx + ty*ty + tz*tz) * 0.005;// 195mg/digit + scr = int_sqrt( tx*tx + ty*ty + tz*tz);// 195mg/digit now_g = scr; //ax+= tx; @@ -103,7 +106,9 @@ //az+= tz; //as+= scr; //cnt++; - pc.printf("new x:%f y:%f,z:%f scaler = %f \r\n",tx*0.005,ty*0.005,tz*0.005,scr); + //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); + if ( max_g < scr) { max_g = scr; update=1; @@ -117,11 +122,13 @@ //pc.printf("h3lis331dl:%s",stracc1); if(strlen(buffer1)+strlen(stracc1) > 512) { //pc.printf("buffer over. write file2\r\n"); + ret = fprintf(fp1,"%s",buffer1); if(ret == 0){ pc.printf("fp1 write failed. Reboot!!!\r\n"); NVIC_SystemReset(); } + memset(buffer1,0,sizeof(buffer1)); sprintf(buffer1,"%s",stracc1); @@ -137,11 +144,13 @@ sprintf(stracc2,"%d,%d\r\n",timecount,scr); //pc.printf("lis3dh:%s",stracc2); if(strlen(buffer2)+ strlen(stracc2)> 512) { + ret = fprintf(fp2,"%s",buffer2); if(ret == 0){ pc.printf("fp2 write failed. Reboot!!!\r\n"); NVIC_SystemReset(); } + memset(buffer2,0,sizeof(buffer2)); sprintf(buffer2,"%s",stracc2); } else { @@ -172,7 +181,8 @@ } } - timer_flag = 0; + + //timer_flag = 0; } int main() @@ -184,15 +194,17 @@ sprintf(filename1,"/sd/new_%d",lognum1); sprintf(filename2,"/sd/old_%d",lognum2); - 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(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(); + } } while(ret) { @@ -201,15 +213,15 @@ pc.printf(" init acc sensor %d\r\n",ret); wait_ms(100); } - interrupt.attach_us(&timer,20000);//20ms + //interrupt.attach_us(&timer,20000);//20ms while(1) { - if(timer_flag){ + //if(timer_flag){ sub(); - //timecount++; - //oldcount++; - } - //wait_ms(20); + timecount++; + oldcount++; + //} + wait_ms(200); } }