AND / Mbed 2 deprecated POCBreath_V2_circular_commercial

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
christodoulos
Date:
Fri May 01 11:54:57 2020 +0000
Parent:
5:646a7e58989e
Commit message:
POC Breath using circular commercial sensors

Changed in this revision

flow.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/flow.h	Thu Jan 23 15:24:41 2020 +0000
+++ b/flow.h	Fri May 01 11:54:57 2020 +0000
@@ -50,7 +50,7 @@
         if (flag==1)
         {
           FPressure=P1-fp;
-          finalflow=(0.24*sqrt(FPressure)); //flow in litter per second
+          finalflow=(0.1724*sqrt(FPressure))+0.1637; //flow in litter per second, recalibrated at Imperial
             if(isnan(finalflow)==true){
                 return 0;
                 }
@@ -120,38 +120,130 @@
 
 ///////////////////// 8-CHANNEL SENSOR LOOP /////////////////////////
 
-int c2612()
+int c2612S0()
 {
     float sen5;
+    float v5;
+    float res5;
+    float r5;
+    
     while(1){
-        sen5=1000*((5/sensor5*3.3)-1);
+        v5=3.3*sensor5;
+        res5=5/v5;
+        r5=res5-1;
+        sen5=1000*r5;
+        return (int)sen5;
+    }
+}
+
+int c2612S1()
+{
+    float sen5;
+    float v5;
+    float res5;
+    float r5;
+    
+    while(1){
+        v5=(3.3*sensor5);
+        res5=5/v5;
+        r5=res5-1;
+        sen5=1000*r5;
         return (int)sen5;
     }
 }
 
-int c2610()
+int c2610S0()
 {
     float sen6;
+    float v6;
+    float res6;
+    float r6;
+    
     while(1){
-        sen6=1000*((5/sensor6*3.3)-1);
+        v6=3.3*sensor6;
+        res6=5/v6;
+        r6=res6-1;
+        sen6=1000*r6;
+        return (int)sen6;
+    }
+}
+
+int c2610S1()
+{
+    float sen6;
+    float v6;
+    float res6;
+    float r6;
+    
+    while(1){
+        v6=(3.3*sensor6);
+        res6=5/v6;
+        r6=res6-1;
+        sen6=1000*r6;
         return (int)sen6;
     }
 }
 
-int c2620()
+int c2620S0()
 {
     float sen7;
+    float v7;
+    float res7;
+    float r7;
+    
     while(1){
-        sen7=1000*((5/sensor7*3.3)-1);
+        v7=3.3*sensor7;
+        res7=5/v7;
+        r7=res7-1;
+        sen7=1000*r7;
         return (int)sen7;
     }
 }
 
-int c2602()
+int c2620S1()
+{
+    float sen7;
+    float v7;
+    float res7;
+    float r7;
+    
+    while(1){
+        v7=(3.3*sensor7);
+        res7=5/v7;
+        r7=res7-1;
+        sen7=1000*r7;
+        return (int)sen7;
+    }
+}
+
+int c2602S0()
 {
     float sen8;
+    float v8;
+    float res8;
+    float r8;
+    
     while(1){
-        sen8=1000*((5/sensor8*3.3)-1);
+        v8=3.3*sensor8;
+        res8=5/v8;
+        r8=res8-1;
+        sen8=1000*r8;
+        return (int)sen8;
+    }
+}
+
+int c2602S1()
+{
+    float sen8;
+    float v8;
+    float res8;
+    float r8;
+    
+    while(1){
+        v8=(3.3*sensor8);
+        res8=5/v8;
+        r8=res8-1;
+        sen8=1000*r8;
         return (int)sen8;
     }
 }
--- a/main.cpp	Thu Jan 23 15:24:41 2020 +0000
+++ b/main.cpp	Fri May 01 11:54:57 2020 +0000
@@ -30,10 +30,12 @@
     wait(0.1);
     ttl.printf("$$");//enter command mode
     wait(0.5);
-    ttl.printf("SN,myBoard\r");//set new name
+    ttl.printf("SN,POC Breath\r");//set new name
     wait(0.5);
     ttl.printf("SS,C0\r");//set transparent uart
     wait(0.5);
+    ttl.printf("&,6146DB234067\r");//Assign mac
+    wait(0.5);
     ttl.printf("---\r");//enter data mode
     wait(0.5);
 
@@ -82,13 +84,14 @@
     int flage=0;            //FLAG for keep taking samples from CO2 profile when it's too early to finish plateau
 
     int fin=0;
-    sol=1;
+    wait(1);
+    sol=1;//sol off 1
 
     while(1) {
-
-        led=0.2f;      //an LED is fully turned on at the beginning, the brightness will be reduced when the plateau is detected.
+        
+        //led=0.4f;      //an LED is fully turned on at the beginning, the brightness will be reduced when the plateau is detected.
         //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor
-        ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor
+        ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor
         wait(0.01);
         if (bf==0) {    //finding base flow before breath
             for(i=0; i<4; i++) {
@@ -96,7 +99,8 @@
                 sf+=bfArray[i];
             }
             fv=sf/4;
-            fv=fv+0.5;
+            //fv=fv+0.2;
+            fv=0.4;
             //ttl.printf("set\n");
             bf=1;
         }
@@ -104,7 +108,7 @@
         //Starts calculations when it detects breathing into the device:
 
         if ((flow()>fv) and (measurement_started ==0)) {
-            stream.start(); // PROGRAM COMES HERES DIRECTLY, CHCK WHY FLOW GOES ABOVE FV
+            stream.start(); 
             measurement_started = 1;
         }
 
@@ -116,7 +120,7 @@
             //I have also included printing the values inside the loops so we don't loose any data during calculatins.
             for(m=0; m<9; m++) {
                 //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor
-                ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor
+                ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor
                 myArray[m]=carbon();
                 wait(0.1);
             }
@@ -124,7 +128,7 @@
                 //While "flags" is enabled, keeps calculating the standard deviation.
                 for(int m=0; m<9; m++) {
                     //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor
-                    ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor
+                    ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor
                     sum+=myArray[m];
                     wait(0.1);
 
@@ -132,7 +136,7 @@
                 avg=sum/9;
                 for(int m=0; m<9; m++) {
                     //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor
-                    ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor
+                    ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor
                     difSum+=(myArray[m]-avg)*(myArray[m]-avg); //Find sum of difference between value X and mean
                     wait(0.1);
                 }
@@ -145,7 +149,7 @@
 
                     for(int m=0; m<8; m++) {
                         //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor
-                        ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor
+                        ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor
                         myArray[m]=myArray[m+1];  //Shift all CO2 values to the left by 1 value
                         wait(0.1);
 
@@ -156,10 +160,11 @@
                 //If sigma for the new set is still small, a newer set will be generated and replaced
                 //Otherwise, it's accepted and will turn on the solenoid:
                 else {
-                    //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor
-                    ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), 0.00,s1(),s2(),s3(),s4(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor, CHANGED CO2 TO 0
-                    sol=0;      //Solenoid is ON
-                    //led=0.8f;  //The brightness is reduced to half during the plateau
+                    sol=0;      //Solenoid is ON 0
+                    //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), 100.00,s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor
+                    ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), 0.00,s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor, CHANGED CO2 TO 0
+                    
+                    //led=0.4f;  //The brightness is reduced to half during the plateau
                     wait(0.1);
                     flags=1;    //breakes the while loop
                 }
@@ -172,21 +177,21 @@
 
             for(m=0; m<9; m++) {
                 //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor
-                ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor
+                ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor
                 myArray[m]=carbon();
                 wait(0.1);
             }
             while(flage==0) {
                 for(int m=0; m<9; m++) {
                     //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor
-                    ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor
+                    ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor
                     sum2+=myArray[m];
                     wait(0.1);
                 }
                 avg2=sum2/9;
                 for(int m=0; m<9; m++) {
                     //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor
-                    ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor
+                    ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor
                     difSum2+=(myArray[m]-avg2)*(myArray[m]-avg2);
                     wait(0.1);
                 }
@@ -196,49 +201,56 @@
                     // here we defined the end threshold to be 0.05, it can be changed later based on experiment results
                     for(int m=0; m<8; m++) {
                         //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor
-                        ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor, CHANGEC CO2 TO 0
+                        ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor, CHANGEC CO2 TO 0
                         myArray[m]=myArray[m+1];
                         wait(0.1);
 
                     }
                     myArray[8]=carbon();
                 } else {
-                    //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor
-                    ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), 0.00,s1(),s2(),s3(),s4(),c2612(),c2610(),c2620(),c2602(),stream.read()); //commercial sensor
+                    sol=1;  //Solenoid is OFF 1
+                    //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(), 100.00,s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor
+                    ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), 0.00,s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor
                     wait(0.1);
-                    sol=1;  //Solenoid is OFF
+                    
                     flage=1;    //breakes the loop
                 }
             }
-            solend =0;  //end of this section
-            led=0.20f;  //LED is back to full brightness
+
+            //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(),carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor
+            ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor            solend =0;  //end of this section
+            //led=0.4f;  //LED is back to full brightness
             bf=0;       //reset the detecting base flow flag
             fin=1;      //enables the next section flag
 
 
+
         }
 
-        if((carbon()<1.0) && (fin ==1)) {  //CHECK IF CO2 SHOULD BE 1 OR 0.75
-            //User has to wait for the CO2 level to drop less than 1% before testing again.
-            //Once it is less than 1%, all the flags and parameters used in calculations are reset
-            stream.stop();
-            stream.reset();
-            measurement_started =0;
-            solstart=0;
-            sum=0;
-            var=0.0;
-            sigma=0.0;
-            difSum=0;
-            sum2=0;
-            var2=0.0;
-            sigma2=0.0;
-            difSum2=0;
-            avg2=0;
-            avg=0;
-            flags=0;
-            flage=0;
-            fin=0;
-        }
+        if(carbon()<2.00 && fin ==1) {
+                //User has to wait for the CO2 level to drop less than 1% before testing again.
+                //Once it is less than 1%, all the flags and parameters used in calculations are reset
+
+                //ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",getTemp(),flow(),carbon(),s1(),s2(),s3(),s4(),s5(),s6(),s7(),s8(),stream.read()); //chemical sensor
+                ttl.printf("tt%.2f,ff%.2f,cc%.2f,sa%i,sb%i,sc%i,sd%i,se%i,sf%i,sg%i,sh%i,ti%.2f\n",0.00,flow(), carbon(),s1(),s2(),s3(),s4(),c2612S1(),c2610S1(),c2620S1(),c2602S1(),stream.read()); //commercial sensor            solend =0;  //end of this section
+                stream.reset();
+                stream.stop();
+                measurement_started =0;
+                solstart=0;
+                sum=0;
+                var=0.0;
+                sigma=0.0;
+                difSum=0;
+                sum2=0;
+                var2=0.0;
+                sigma2=0.0;
+                difSum2=0;
+                avg2=0;
+                avg=0;
+                flags=0;
+                flage=0;
+                fin=0;
+            }
 
     }
 }
\ No newline at end of file