Running for Fitness Unit

Dependencies:   FRDM_MMA8451Q mbed

Fork of MBED_wifi_setup by Costa

Files at this revision

API Documentation at this revision

Comitter:
eddytomhall
Date:
Fri Jun 17 10:17:45 2016 +0000
Parent:
5:d497f1566d19
Commit message:
for pressup

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Jun 16 15:55:40 2016 +0000
+++ b/main.cpp	Fri Jun 17 10:17:45 2016 +0000
@@ -1,5 +1,5 @@
 #include "mbed.h"
-#include "MMA8451Q.h"       //allow use of accelerometer
+#include "MMA8451Q.h"
 
 #define DEBUG
 #define INFOMESSAGES
@@ -70,6 +70,23 @@
 char macAddress[32];
 char *buffer;
 unsigned int bufferPnt=0;
+int zcount;
+int xcount;
+char resp;
+
+float a;
+float b;
+char * OKResponse(char *test, const char *pattern)
+{
+    char *p= strstr(test,pattern);
+    if (p==NULL) {
+        //   DBG("Test=<%s> Patter=<%s> NULL [p=%s]",test,pattern,p);
+        return NULL;
+    } else {
+        //  DBG("YAY Test=<%s> Patter=<%s>  [p=%s]",test,pattern,p);
+    }
+    return p;
+}
 
 void dev_recv()
 {
@@ -107,6 +124,28 @@
         }
     }
 }
+void sendinfo()
+{
+    pc.printf(".......zc=%02u\r\n",zcount);
+
+    // resp=OKResponse(buffer,"OK");
+//   if (resp!=NULL) {
+    INFO("Ready 10");
+    dev.printf("AT+CIPSEND=4,4\r\n");
+    wait(0.1);
+
+
+    wait(0.1);
+//  while (OKResponse(buffer,">")!=NULL){
+//   printf(".\r\n");
+//  wait(1);
+//  };
+
+    INFO("SENDING");
+
+    wait(0.2);
+    dev.printf("%02u\r\n",zcount);
+}
 
 void pc_recv()
 {
@@ -124,31 +163,17 @@
     }
 }
 
-char * OKResponse(char *test, const char *pattern)
-{
-    char *p= strstr(test,pattern);
-    if (p==NULL) {
-        //   DBG("Test=<%s> Patter=<%s> NULL [p=%s]",test,pattern,p);
-        return NULL;
-    } else {
-        //  DBG("YAY Test=<%s> Patter=<%s>  [p=%s]",test,pattern,p);
-    }
-    return p;
-}
+
 int main()
 {
     MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
 
     buffer=(char *)calloc(BUFF_SIZE,1);
     reset=0;
-    int zcount;
-    int xcount;
+    b=1.0;
+    a=1.0;
     zcount=0;               // initial conditions of values
     xcount=0;
-    float a;
-    float b;
-    b=1.0;
-    a=1.0;
     float x;
     float z;
     pc.baud(115200);
@@ -265,97 +290,85 @@
                 }
                 case 10: {
 
-resp=OKResponse(buffer,"OK");
-                                if (resp!=NULL) {
-                                    INFO("Ready 10");
-                                    dev.printf("AT+CIPSEND=4,9\r\n");
-                                    wait(0.1);
+                    resp=OKResponse(buffer,"OK");
+                    if (resp!=NULL) {
+                        INFO("Ready 10");
+                        dev.printf("AT+CIPSEND=4,9\r\n");
+                        wait(0.1);
+
+                    }
+                    wait(0.1);
+                    //  while (OKResponse(buffer,">")!=NULL){
+                    //   printf(".\r\n");
+                    //  wait(1);
+                    //  };
+
+                    INFO("SENDING");
+
+                    wait(0.2);
+                    dev.printf("PEDOMETER\r\n");
+                    state++;      //send greeting to server
+                    break;
+                    case 11: {
+                        while (true) {
+
+                            z = (acc.getAccX());  //changes it from measureing Z driection for press ups to X for running
+                            x = (acc.getAccZ());
+
+                            if (a==1.0) {
+                               
+                                if (z<0.0) {
+                                    a=0.0;
+                                    
+                                    zcount++;
+
+                                    sendinfo();
+
+
 
                                 }
-                                wait(0.1);
-                             //  while (OKResponse(buffer,">")!=NULL){
-                             //   printf(".\r\n");
-                              //  wait(1);
-                              //  };
-                                
-                                    INFO("SENDING");
 
-                                    wait(0.2);
-                                    dev.printf("PEDOMETER\r\n");        //send greeting to server
 
-                    while (true) {
-                        z = (acc.getAccX());  //changes it from measureing Z driection for press ups to X for running
-                        x = (acc.getAccZ());
-
-                        if (a==1.0) {
-
-                            if (z<0.0) {
-                                a=0.0;
-                                zcount++;
-                                pc.printf(".......zc=%02u\r\n",zcount);
-
-                                resp=OKResponse(buffer,"OK");
-                                if (resp!=NULL) {
-                                    INFO("Ready 10");
-                                    dev.printf("AT+CIPSEND=4,4\r\n");
-                                    wait(0.1);
+                                if (z>0) {
+                                    a=1.0;      //prevents multiple signals for singal dip below zero
+                                }
+                            }
+                            if (a==0) {
+                                if (z<0) {
+                                    a=0.0;
+                                }
+                                if (z>0) {
+                                    a=1.0;
+                                }
+                            }
+                            if (b==1) {
+                                if (x<0) {
+                                    b=0.0;
+                                    xcount=xcount+1;
+                                    //printf("Xcount: %u \n\r",xcount);
 
                                 }
-                                wait(0.1);
-                             //  while (OKResponse(buffer,">")!=NULL){
-                             //   printf(".\r\n");
-                              //  wait(1);
-                              //  };
-                                
-                                    INFO("SENDING");
+                                if (x>0) {
+                                    b=1.0;
+                                }
+                            }
 
-                                    wait(0.2);
-                                    dev.printf("%02u\r\n",zcount);
-
-                                
-
-
+                            if (b==0) {
+                                if (x<0) {
+                                    b=0.0;
+                                }
+                                if (x>0) {
+                                    b=1.0;
+                                }
                             }
 
                         }
-                        if (z>0) {
-                            a=1.0;      //prevents multiple signals for singal dip below zero
-                        }
+                        break;
                     }
-                    if (a==0) {
-                        if (z<0) {
-                            a=0.0;
-                        }
-                        if (z>0) {
-                            a=1.0;
-                        }
-                    }
-                    if (b==1) {
-                        if (x<0) {
-                            b=0.0;
-                            xcount=xcount+1;
-                            //printf("Xcount: %u \n\r",xcount);
+                }
+                //__WFI(); // DELETED AS IT KILLS THE KL25 RESPONSIVITY
+            }
 
-                        }
-                        if (x>0) {
-                            b=1.0;
-                        }
-                    }
-
-                    if (b==0) {
-                        if (x<0) {
-                            b=0.0;
-                        }
-                        if (x>0) {
-                            b=1.0;
-                        }
-                    }
-
-                }
-                break;
-            }
         }
-        //__WFI(); // DELETED AS IT KILLS THE KL25 RESPONSIVITY
     }
-
 }