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:
- 36:709c6fae0b2e
- Parent:
- 35:69e2bc347f0c
- Child:
- 37:1b459e0ef847
--- a/main.cpp Tue Sep 07 09:10:41 2021 +0000
+++ b/main.cpp Wed Sep 08 09:39:42 2021 +0000
@@ -1,6 +1,5 @@
#include "mbed.h"
#include "SDFileSystem.h"
-//#include <time.h>
#include <errno.h>
/*
@@ -88,6 +87,7 @@
char filename1[16]= {};
char filename2[16]= {};
int ret = 0,init=1;
+//uint8_t *bufferIndex = NULL;
/*
void timer(){
@@ -96,12 +96,13 @@
void sub(){
static short tx=0,ty=0,tz=0;
+ static short tx2=0,ty2=0,tz2=0;
static long scr = 0;
+ static long scr2 = 0;
static long ax,ay,az,as;
static long ax2,ay2,az2,as2;
+ //char tmpbuffer[32] = {};
//static int cnt;
- //static char *bufferIndex;
- //static unsigned int storeSize;
read3axes331(&tx,&ty,&tz);
//キャリブレーションの補正
@@ -118,7 +119,7 @@
az+= tz;
as+= scr;
//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("%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);
//Total Max G
@@ -133,33 +134,28 @@
}
}
- //MAX G per 50cycle
+ //MAX G per cycle
if(tmp_max < scr){
tmp_max = scr;
}
- //sprintf(stracc1,"%d,%d,%2.2f,%2.2f,%2.2f,%2.2f\r\n",timecount,time(NULL),(float)tx*0.005,(float)ty*0.005,(float)tz*0.005,(float)scr*0.005);
- //sprintf(stracc1,"%d,%d,%d\r\n",timecount,time(NULL),scr);
- //sprintf(stracc1,"%d,%d\r\n",timecount,time(NULL));
- //pc.printf("h3lis331dl:%s",stracc1);
-
- //50回平均(/s)
- if (newcount == 50) {
- float asc = (float)as / 50.0f;
- pc.printf("avarage x:%3.2f,y:%3.2f,z:%3.2f,scaler=%3.2f,max:%3.2f\r\n",
- (float)ax/50.0f*0.005,(float)ay/50.0f*0.005,(float)az/50.0f*0.005,(float)as/50.0f*0.005, (float)tmp_max*0.005);
- sprintf(stracc1,"%d,%d,%3.2f,%3.2f\r\n",timecount,time(NULL),asc*0.005,(float)tmp_max*0.005);
+ //平均(/s)
+ if (newcount == 500) {
+ float asc = (float)as / 500.0f;
+ //pc.printf("avarage(new) x:%2.2f,y:%2.2f,z:%2.2f,scaler=%2.2f,max:%2.2f\r\n",
+ //(float)ax/1000.0f*0.005,(float)ay/1000.0f*0.005,(float)az/1000.0f*0.005,(float)as/1000.0f*0.005, (float)tmp_max*0.005);
+ sprintf(stracc1,"%d,%d,%2.2f,%2.2f\r\n",timecount,time(NULL),asc*0.005,(float)tmp_max*0.005);
- if(strlen(buffer1)+strlen(stracc1) > DATA_SIZE) {
- pc.printf("try write fp1\r\n");
+ if((strlen(buffer1)+strlen(stracc1)) > DATA_SIZE) {
+ pc.printf("try write fp1:%d,%d\r\n",strlen(buffer1),strlen(stracc1));
//ret = fprintf(fp1,"%s",buffer1);
ret = fwrite(buffer1,sizeof(char),strlen(buffer1),fp1);
- //if(ret <= 0){
if(ret < strlen(buffer1)){
pc.printf("fp1 write failed:%d. errno:%d. Reboot!!!\r\n",ret,errno);
NVIC_SystemReset();
}
memset(buffer1,0,sizeof(buffer1));
+ //bufferIndex = buffer1;
sprintf(buffer1,"%s",stracc1);
} else {
sprintf(buffer1,"%s%s",buffer1,stracc1);
@@ -172,26 +168,27 @@
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;
- if(tmp_max2 < scr){
- tmp_max2 = scr;
+ read3axes(&tx2,&ty2,&tz2);
+ scr2 = int_sqrt( tx2*tx2 + ty2*ty2 + tz2*tz2);
+ ax2+= tx2;
+ ay2+= ty2;
+ az2+= tz2;
+ as2+= scr2;
+ if(tmp_max2 < scr2){
+ tmp_max2 = scr2;
}
- //pc.printf("%d,%d,old x:%d y:%d,z:%d scaler = %d\r\n",timecount,time(NULL),tx,ty,tz,scr);
+ //pc.printf("old %d,%d,x:%2.2f y:%2.2f,z:%2.2f scaler = %2.2f \r\n",timecount,time(NULL),(float)tx2*0.005,(float)ty2*0.005,(float)tz2*0.005,(float)scr2*0.005);
+ //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(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(oldcount == 5000){
+ float asc2 = (float)as2 / 500.0f;
+ //pc.printf("avarage(old) x:%2.2f,y:%2.2f,z:%2.2f,scaler=%2.2f,max:%2.2f\r\n",
+ //(float)ax2/100.0f*0.005,(float)ay2/100.0f*0.005,(float)az2/100.0f*0.005,(float)as2/100.0f*0.005, (float)tmp_max2*0.005);
+ sprintf(stracc2,"%d,%d,%2.2f,%2.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");
+ if( (strlen(buffer2)+ strlen(stracc2)) > DATA_SIZE) {
+ pc.printf("try write fp2:%d,%d\r\n",strlen(buffer2),strlen(stracc2));
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);
@@ -214,12 +211,16 @@
//Create New File
set_time(NULL);
timecount = 0;
- fclose(fp1);
- free(fp1);
- fp1 = NULL;
- fclose(fp2);
- free(fp2);
- fp2 = NULL;
+ if(fp1){
+ fclose(fp1);
+ //free(fp1);
+ fp1 = NULL;
+ }
+ if(fp2){
+ fclose(fp2);
+ //free(fp2);
+ fp2 = NULL;
+ }
lognum1++;
lognum2++;
sprintf(filename1,"/sd/new_%d",lognum1);
@@ -240,6 +241,7 @@
int main()
{
+ i2c.frequency(400000);
short retry = 0;
sprintf(filename1,"/sd/new_%d",lognum1);
sprintf(filename2,"/sd/old_%d",lognum2);
@@ -260,8 +262,8 @@
pc.printf("fp2(%s) open failed errno:%d\r\n",filename2,errno);
//NVIC_SystemReset();
}
+ retry++;
wait_ms(100);
- retry++;
}
//Read Max G
@@ -278,13 +280,15 @@
wait_ms(100);
}
//interrupt.attach_us(&timer,20000);//20ms
+ //bufferIndex = buffer1;
while(1)
{
timecount++;
oldcount++;
newcount++;
sub();
- wait_ms(20);
+ //wait_ms(20);
+ //wait_ms(1);
}
}
/*********** porting **************/