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
Revision 3:e319c8becf06, committed 2019-06-19
- Comitter:
- mehrnaz
- Date:
- Wed Jun 19 10:01:39 2019 +0000
- Parent:
- 2:af7522079ec4
- Commit message:
- handheld latest version2
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r af7522079ec4 -r e319c8becf06 main.cpp
--- a/main.cpp Tue Apr 16 09:19:53 2019 +0000
+++ b/main.cpp Wed Jun 19 10:01:39 2019 +0000
@@ -3,9 +3,12 @@
#include "co2.h"
#include "time.h"
-//Serial ble(A4,A5);
+Serial ble(A4,A5);
AnalogIn flowIn(A3);
AnalogIn temp(A2);
+AnalogIn neg(D3);
+AnalogIn pos(D4);
+
Timer t;
Thread co2Thread;
Thread flowThread;
@@ -13,23 +16,11 @@
float flowVal;
+
-//void gettime()
-//{
-// while(1)
-// {
-// if ((flowVal>0.7) and (measurement_started ==0))
-// {
-// start = clock();
-// }
-// if((flowVal<0.7) and (measurement_started == 1))
-// {
-// end = clock();
-// }
-// }
-//}
+
void flow()
@@ -37,7 +28,6 @@
while(1) {
flowVal=(sqrt(((flowIn*3.3)*1.5)*125-62.5))*0.24; //Logic level 3.3
-// printf("Flow: %f", flowVal);
}
}
@@ -63,7 +53,7 @@
int main()
{
- // ble.baud(9600);
+ ble.baud(9600);
float mc,ac;
int k,u,b;
int flagg=0;
@@ -79,13 +69,16 @@
float co2Array[80];
float flowArray[40];
+ float bfArray[4];
long double var=0.0;
float sigma=0.0;
float sum=0;
double sum2=0;
double finalsum;
+
int difSum=0;
float avg=0;
+
//int peravg=0;
unsigned long long sqSum=0;
int cflag=0;
@@ -104,52 +97,150 @@
//int measurement_started = 0;
int maxflag=0;
float fv=0;
-
+ int bf=0;
+ float sf=0;
int i = 0;
int j=0;
+ int o=0;
+ int ready=0;
+ int ch = 0;
+
+ int msg1 = 0;
+ int msg2 = 0;
+int positive = 0;
+int negative =0;
+float pos2;
+float neg2;
+int symyes =0;
+int symno =0;
+float symy;
+float symn;
+
+
+
///*******
+ble.printf("First, please indicate if you feel good or not.\n");
+
while(1) {
- //printf(" CO2: %d, Flow: %f, \n", carbon(), flowVal ); //COOL TERM
+ // ble.printf(" CO2: %d, Flow: %f, \n", carbon(), flowVal ); //COOL TERM
+ pos2=pos*3.3;
+ neg2=neg*3.3;
+ if (bf==0)
+ {
+ for(o=0; o<4; o++)
+ {
+ bfArray[o]=flowVal;
+ sf+=bfArray[j];
+ }
+ fv=sf/4;
+ // printf("first fv: %f \n", fv);
+ fv=fv+0.2;
+ //printf("sec fv: %f \n", fv);
+
+
+ bf=1;
+ }
- //for(j=0; j<10; j++)
-// {
-// flowArray[j]=flowVal;
-// }
-
+ if((carbon()<10000) and (ready ==1))
+ {
+ ble.printf("Now you can breathe into device. \n");
+ ble.printf("First, please indicate if you feel good or not.\n");
+ ready=0;
+ }
+ if(msg1==0)
+ {
+ if(neg2>2)
+ {
+ negative=1;
+ ble.printf("Did you have experienced any symptoms today?\n");
+ if(neg2<1)
+ {
+ msg2=1;
+ msg1=1;
+ }
+ msg2=1;
+ msg1=1;
+ }
+ if(pos2>2)
+ {
+ positive = 1;
+ ble.printf("Did you have experienced any symptoms today?\n");
+ if(pos2<1)
+ {
+ msg2=1;
+ msg1=1;
+ }
+ msg2=1;
+ msg1=1;
+ }
+
+ }
+ if((msg1==1) and (msg2==1))
+ {
+ symy=pos*3.3;
+ symn=neg*3.3;
+ if(symy>2)
+ {
+ symyes=1;
+ ble.printf("*BEEP*\n");
+ ble.printf("Now please breath into the device.\n");
+ msg2=0;
+ }
+ if(symn>2)
+ {
+ symno=1;
+ ble.printf("*BEEP*\n");
+ ble.printf("Now please breath into the device.\n");
+ msg2=0;
+ }
+ }
- if ((flowVal>0.8) and (measurement_started ==0)) {
+
+ if ((flowVal>fv) and (measurement_started ==0)) {
// time(&start_t);
- measurement_started = 1;
+
- printf("Balloon is blowing \n");
- printf("Calculating... \n");
+ ble.printf("Please keep exhaling for: \n");
+ ble.printf("4 seconds...\n");
+ measurement_started = 1;
}
- if (measurement_started == 1) {
-
- for(j=0; j<40; j++) {
+ if (measurement_started == 1)
+ {
+ for(j=0; j<10; j++) {
+ flowArray[j]=flowVal;
+ co2Array[j]=carbon();
+ wait(0.1);
+ }
+ ble.printf("3 seconds... \n");
+ for(j=10; j<20; j++) {
flowArray[j]=flowVal;
co2Array[j]=carbon();
- //printf("co2array[%d] %f \n",k,co2Array[k]);
-
-
-
+ wait(0.1);
+ }
+ ble.printf("2 seconds...\n");
+ for(j=20; j<30; j++) {
+ flowArray[j]=flowVal;
+ co2Array[j]=carbon();
wait(0.1);
-
-
}
-
+ ble.printf("1 second... \n");
+ for(j=30; j<40; j++) {
+ flowArray[j]=flowVal;
+ co2Array[j]=carbon();
+ wait(0.1);
+ }
+ ble.printf("*BEEP* *BEEP* Done!\n");
for(j=40; j<80; j++) {
co2Array[j]=carbon();
- //printf("co2array[%d] %f \n",k,co2Array[k]);
wait(0.1);
}
-
+ ble.printf("Calculating results... \n");
for(j=0; j<80; j++) {
if(co2Array[j]<10000) {
co2Array[j]=carbon();
@@ -174,14 +265,14 @@
if (flowArray[j] > maximum) {
maximum = flowArray[j];
- // printf("Max: %f",maximum);
+ // ble.printf("Max: %f",maximum);
}
}
maxflag=0;
measurement_started =1;
}
- if((flowVal<0.8) and (measurement_started == 1)) {
+ if((flowVal<fv) and (measurement_started == 1)) {
// time(&end_t);
//T = difftime(end_t, start_t);
@@ -193,45 +284,90 @@
//cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
// T=cpu_time_used;
- // printf("t=%f \n", T);
+ // ble.printf("t=%f \n", T);
// T=0;
- printf("********* \n");
- printf("Your breath results: \n");
-
- printf("Maximum Flow: %3.2f Litres/Second \n",maximum);
-
- for(j=0; j<39; j++) {
+ for(j=0; j<39; j++) {
flowsum[j]=((flowArray[j]+flowArray[j+1])*0.1)/2;
- //printf("flowsum %f \n",flowsum[j]);
+ //ble.printf("flowsum %f \n",flowsum[j]);
finalsum+=flowsum[j];
}
-
- printf("Lung Capacity: %3.2f Litres \n",finalsum);
-
+
+ //mkdir("/sd/mydir", 0777);
+//FILE *fp = fopen("/sd/mydir/sdtest.xls", "w");
+// if(fp == NULL) {
+// error("Could not open file for write\n");
+// }
+ ble.printf("********* \n");
+ // fprintf(fp, "*********");
+
+ ble.printf("Your breath results: \n");
+ // fprintf(fp, "Your breath results:");
+ ble.printf("********* \n");
+ // fprintf(fp, "*********");
+ if (positive==1)
+ {
+ ble.printf("Patient felt healthy,");
+ // fprintf(fp, "Patient felt healthy.");
+ positive=0;
+ }
+ if (negative==1)
+ {
+ ble.printf("Patient felt unhealthy,");
+ // fprintf(fp, "Patient felt unhealthy.");
+ negative=0;
+ }
+ if (symyes == 1)
+ {
+ ble.printf(" and had experienced symptoms. ");
+ symyes =0;
+ }
+ if (symno ==1)
+ {
+ ble.printf(" and hadn't experienced any symptoms. ");
+ symno=0;
+ }
if (finalsum<0.9) {
- printf("Breath Score: 1 \n");
+ ble.printf("Breath Score: 1 \n");
+ //fprintf(fp, "Breath Score: 1");
}
if((finalsum>1) and (finalsum<1.9)) {
- printf("Breath Score: 2 \n");
+ ble.printf("Breath Score: 2 \n");
+ // fprintf(fp, "Breath Score: 2");
}
if((finalsum>2) and (finalsum<2.9)) {
- printf("Breath Score: 3 \n");
+ ble.printf("Breath Score: 3 \n");
+ // fprintf(fp, "Breath Score: 3");
}
if((finalsum>3) and (finalsum<3.9)) {
- printf("Breath Score: 4 \n");
+ ble.printf("Breath Score: 4 \n");
+ // fprintf(fp, "Breath Score: 4");
}
if((finalsum>4) and (finalsum<5)) {
- printf("Breath Score: 5 \n");
+ ble.printf("Breath Score: 5 \n");
+ // fprintf(fp, "Breath Score: 5");
}
+
+ // ble.printf("Maximum Flow: %3.2f Litres/Second \n",maximum);
+ // fprintf(fp, "Maximum Flow: %3.2f Litres/Second \n",maximum);
+
+ // ble.printf("Lung Capacity: %3.2f Litres \n",finalsum);
+ // fprintf(fp, "Lung Capacity: %3.2f Litres \n",finalsum);
+
+
+
finalsum=0;
+ fv=0;
cflag=1;
+ // ble.printf("********* \n");
+ // fprintf(fp, "*********");
+
}
if(cflag==1) {
for(j=0; j<80; j++) {
- //printf("co2[%d]: %f \n",j,co2Array[j]);
+ //ble.printf("co2[%d]: %f \n",j,co2Array[j]);
sum+=co2Array[j];
}
maximumco2 = co2Array[0];
@@ -241,22 +377,49 @@
if (co2Array[j] > maximumco2) {
maximumco2 = co2Array[j];
- // printf("Max: %f",maximum);
+ // ble.printf("Max: %f",maximum);
}
}
mc=maximumco2/10000;
- printf("Maximum CO2: %3.2f percent \n",mc);
- // printf("co2 sum: %f \n",sum);
+ // ble.printf("Maximum CO2: %3.2f percent \n",mc);
+ // fprintf(fp, "Maximum CO2: %3.2f percent \n",mc);
+ // ble.printf("co2 sum: %f \n",sum);
avg=sum/80;
+ //s1av=s1sum/40;
+// s2av=s2sum/40;
+// s3av=s3sum/40;
+// s4av=s4sum/40;
+// s5av=s5sum/40;
+// s6av=s6sum/40;
+// s7av=s7sum/40;
+// s8av=s8sum/40;
+ // ble.printf("%f,%f,%f,%f,%f,%f,%f,%f \n", s1av,s2av,s3av,s4av,s5av,s6av,s7av,s8av);
ac=avg/10000;
- printf("CO2 Average: %3.2f percent \n", ac);
- printf("********* \n");
- printf("Nice Job! You can try again. \n");
+ // ble.printf("CO2 Average: %3.2f percent \n", ac);
+ // fprintf(fp, "CO2 Average: %3.2f percent \n", ac);
+ ble.printf("********* \n");
+ // fprintf(fp, "*********");
+ ble.printf("Nice Job! Please wait for the next try. \n");
+ //fclose(fp);
+
+
+ // led = 0;
+
+ // s1av=0;
+// s2av=0;
+// s3av=0;
+// s4av=0;
+// s5av=0;s6av=0;
+// s7av=0;s8av=0;
+ ready=1;
ac=0;
mc=0;
sum=0;
cflag=0;
+ bf=0;
+ch = 0;
+msg1=0;