F

Dependencies:   mbed Sht31 MAX44009

Revision:
11:3a63d6f65ff5
Parent:
10:a9db57e6456e
Child:
12:5a140bcc456f
--- a/main.cpp	Fri Apr 24 16:08:58 2020 +0000
+++ b/main.cpp	Fri Apr 24 18:09:32 2020 +0000
@@ -29,11 +29,18 @@
     public : float t;
              float h;
     };
+class myData{
+    public :    int timestamp;
+                unsigned short light;
+                unsigned short noise;
+               
+    };  
     
 RGB RGBdata[10];
 TandH THdata[10];
 float luxdata[10];
-
+myData sleepData[1000];
+int sleepDataPos=0;
 int counter = 10; //to tackle with 0 mod 10 problem, use 10 instead;
 int sendCounter=0; // for sending in auto/ instant measure
 int _30Scounter=0;
@@ -45,7 +52,7 @@
 bool wrote=false;
 DigitalOut led(LED1);
 char    signal[1];
-LocalFileSystem local("local"); //Create the local filesystem under the name "local"
+//LocalFileSystem local("local"); //Create the local filesystem under the name "local"
 
  void letsee() {
             led=!led;
@@ -227,16 +234,16 @@
                     luxavg = ((luxavg*(counter) + luxdata[counter]))/(counter+1);
             }
             
-        //pc.printf("test");
-       // pc.printf("Shine Like:%s,%d,%d,%d,%d,%3.2f,%3.2f%,%0.001f\n",signal,(int)(RGBavg.C+0.5), (int)(RGBavg.R+0.5), (int)(RGBavg.G+0.5), (int)(RGBavg.B+0.5),THavg.t, THavg.h,luxavg);
+        
             BLE_Can_receive = 0;
             counter++;
-            if (counter == 10 &&_30Scounter==3){
+            if (counter == 10 &&_30Scounter==2){
                 _30Scounter=0;
-                FILE *fp = fopen("/local/out.txt", "a");   
-               fprintf(fp, "[%d,%d,%d,%d,%d,%d,%d,%0.001f,%0.001f],\n",seconds,(int)(RGBavg.C+0.5),
-                        (int)(RGBavg.R+0.5), (int)(RGBavg.G+0.5), (int)(RGBavg.B+0.5),(int)THavg.t,(int) THavg.h,luxavg,second);   
-                fclose(fp); 
+               // pc.printf("%u,%u\n",(unsigned short)(luxavg*1000),(unsigned short)(second*1000));
+                sleepData[sleepDataPos].timestamp=(int)seconds;
+                sleepData[sleepDataPos].light=(unsigned short)(luxavg*1000);
+                sleepData[sleepDataPos].noise=(unsigned short)(second*1000);
+                sleepDataPos++;
                 allfilled = true; 
             }
             else 
@@ -247,14 +254,11 @@
             BLE_Can_receive = 1;
         if (wrote){
            if (signal[0]=='s'){
-                FILE *fp = fopen("/local/out.txt", "r"); 
-                char str[45];   
-                 while(!feof(fp))
-                    if(fgets(str,40,fp)!=NULL) {
-                        pc.printf("%s\n",str);
-                        //wait_ms(300);
-                    }
-                 fclose(fp);
+               for (int i=0;i <sleepDataPos;i++){
+                float tempL=sleepData[i].light/1000.0f;
+                float tempN=sleepData[i].noise/1000.0f;
+                pc.printf("[%d,%f,%f]\n",sleepData[i].timestamp,tempL,tempN);
+                }
                 wrote=false;
             }
             else