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:
- 35:69e2bc347f0c
- Parent:
- 34:6bffe97ae35d
- Child:
- 36:709c6fae0b2e
--- a/main.cpp Tue Sep 07 07:39:23 2021 +0000
+++ b/main.cpp Tue Sep 07 09:10:41 2021 +0000
@@ -77,9 +77,9 @@
unsigned long timecount = 0;
short oldcount = 0;
short newcount = 0;
-//uint8_t maxacc = 0;
long max_g=0;
long tmp_max=0;
+long tmp_max2=0;
short update=0;
char buffer1[DATA_SIZE] = {};
char buffer2[DATA_SIZE] = {};
@@ -98,7 +98,7 @@
static short tx=0,ty=0,tz=0;
static long scr = 0;
static long ax,ay,az,as;
- //static long ax1,ay2,az2,as2;
+ static long ax2,ay2,az2,as2;
//static int cnt;
//static char *bufferIndex;
//static unsigned int storeSize;
@@ -117,7 +117,7 @@
ay+= ty;
az+= tz;
as+= scr;
- newcount++;
+ //newcount++;
pc.printf("%d,%d,x:%2.2f y:%2.2f,z:%2.2f scaler = %2.2f \r\n",timecount,time(NULL),(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);
@@ -161,7 +161,7 @@
}
memset(buffer1,0,sizeof(buffer1));
sprintf(buffer1,"%s",stracc1);
- } else {
+ } else {
sprintf(buffer1,"%s%s",buffer1,stracc1);
}
@@ -170,36 +170,44 @@
tmp_max = 0;
}
- if(oldcount == 10){
+ if( (oldcount % 10) == 0){
//LIS3DH
read3axes(&tx,&ty,&tz);
scr = int_sqrt( tx*tx + ty*ty + tz*tz);
- //ax2+= tx;
- //ay2+= ty;
- //az2+= tz;
- //as2+= scr;
- //oldcount++;
+ ax2+= tx;
+ ay2+= ty;
+ az2+= tz;
+ as2+= scr;
+ if(tmp_max2 < scr){
+ tmp_max2 = scr;
+ }
//pc.printf("%d,%d,old x:%d y:%d,z:%d scaler = %d\r\n",timecount,time(NULL),tx,ty,tz,scr);
//sprintf(stracc2,"%d,%d,%d\r\n",timecount,time(NULL),scr);
//pc.printf("lis3dh:%s",stracc2);
-
- if(strlen(buffer2)+ strlen(stracc2)> 512) {
- //pc.printf("try write fp2\r\n");
- //ret = fprintf(fp2,"%s",buffer2);
- ret = fwrite(buffer2,sizeof(char),strlen(buffer2),fp2);
- //if(ret <= 0){
- if(strlen(buffer2)){
- pc.printf("fp2 write failed:%d. errno:%d. Reboot!!!\r\n",ret,errno);
- NVIC_SystemReset();
+ if(oldcount == 50){
+ float asc2 = (float)as2 / 50.0f;
+ //pc.printf("avarage x:%3.2f,y:%3.2f,z:%3.2f,scaler=%3.2f,max:%3.2f\r\n",
+ //(float)ax2/50.0f*0.005,(float)ay2/50.0f*0.005,(float)az2/50.0f*0.005,(float)as2/50.0f*0.005, (float)tmp_max*0.005);
+ sprintf(stracc2,"%d,%d,%3.2f,%3.2f\r\n",timecount,time(NULL),asc2*0.005,(float)tmp_max2*0.005);
+
+ if(strlen(buffer2)+ strlen(stracc2)> DATA_SIZE) {
+ pc.printf("try write fp2\r\n");
+ ret = fwrite(buffer2,sizeof(char),strlen(buffer2),fp2);
+ if(ret < strlen(buffer2)){
+ pc.printf("fp2 write failed:%d. errno:%d. Reboot!!!\r\n",ret,errno);
+ NVIC_SystemReset();
+ }
+
+ memset(buffer2,0,sizeof(buffer2));
+ sprintf(buffer2,"%s",stracc2);
+ } else {
+ sprintf(buffer2,"%s%s",buffer2,stracc2);
}
-
- memset(buffer2,0,sizeof(buffer2));
- sprintf(buffer2,"%s",stracc2);
- } else {
- sprintf(buffer2,"%s%s",buffer2,stracc2);
+
+ oldcount = 0;
+ as2=ax2=ay2=az2=0;
+ tmp_max2 = 0;
}
-
- oldcount = 0;
}
if(time(NULL) > 86400){
@@ -272,10 +280,10 @@
//interrupt.attach_us(&timer,20000);//20ms
while(1)
{
+ timecount++;
+ oldcount++;
+ newcount++;
sub();
- timecount++;
- //oldcount++;
- //newcount++;
wait_ms(20);
}
}