final product
Dependencies: FRDM_MMA8451Q mbed
Fork of mbed_Pedometer_pressup by
main.cpp@6:c02bbe512cdc, 2016-06-17 (annotated)
- Committer:
- eddytomhall
- Date:
- Fri Jun 17 10:17:45 2016 +0000
- Revision:
- 6:c02bbe512cdc
- Parent:
- 5:d497f1566d19
- Child:
- 7:65643a8602ed
for pressup
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
muyiq | 0:0cccdf8e396f | 1 | #include "mbed.h" |
eddytomhall | 6:c02bbe512cdc | 2 | #include "MMA8451Q.h" |
eddytomhall | 4:a8d5a55a89da | 3 | |
muyiq | 0:0cccdf8e396f | 4 | #define DEBUG |
muyiq | 0:0cccdf8e396f | 5 | #define INFOMESSAGES |
muyiq | 0:0cccdf8e396f | 6 | #define WARNMESSAGES |
muyiq | 0:0cccdf8e396f | 7 | #define ERRMESSAGES |
eddytomhall | 1:bf4ad12efb64 | 8 | |
muyiq | 0:0cccdf8e396f | 9 | #define FUNCNAME "MAIN" |
eddytomhall | 1:bf4ad12efb64 | 10 | |
eddytomhall | 1:bf4ad12efb64 | 11 | |
eddytomhall | 1:bf4ad12efb64 | 12 | |
eddytomhall | 1:bf4ad12efb64 | 13 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
eddytomhall | 1:bf4ad12efb64 | 14 | PinName const SDA = PTE25; |
eddytomhall | 1:bf4ad12efb64 | 15 | PinName const SCL = PTE24; |
eddytomhall | 1:bf4ad12efb64 | 16 | #elif defined (TARGET_KL05Z) |
eddytomhall | 1:bf4ad12efb64 | 17 | PinName const SDA = PTB4; |
eddytomhall | 1:bf4ad12efb64 | 18 | PinName const SCL = PTB3; |
eddytomhall | 1:bf4ad12efb64 | 19 | #elif defined (TARGET_K20D50M) |
eddytomhall | 1:bf4ad12efb64 | 20 | PinName const SDA = PTB1; |
eddytomhall | 1:bf4ad12efb64 | 21 | PinName const SCL = PTB0; |
eddytomhall | 1:bf4ad12efb64 | 22 | #else |
eddytomhall | 1:bf4ad12efb64 | 23 | #error TARGET NOT DEFINED |
eddytomhall | 1:bf4ad12efb64 | 24 | #endif |
eddytomhall | 1:bf4ad12efb64 | 25 | |
eddytomhall | 1:bf4ad12efb64 | 26 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
eddytomhall | 1:bf4ad12efb64 | 27 | |
eddytomhall | 1:bf4ad12efb64 | 28 | |
muyiq | 0:0cccdf8e396f | 29 | #ifdef NoDEBUG |
muyiq | 0:0cccdf8e396f | 30 | #define DBG(x, ...) pc.printf(" ["FUNCNAME" : DBG] "x" <line %d>\r\n", ##__VA_ARGS__,__LINE__); |
muyiq | 0:0cccdf8e396f | 31 | #else |
muyiq | 0:0cccdf8e396f | 32 | #define DBG(x, ...) |
muyiq | 0:0cccdf8e396f | 33 | #endif |
eddytomhall | 1:bf4ad12efb64 | 34 | |
muyiq | 0:0cccdf8e396f | 35 | #ifdef ERRMESSAGES |
muyiq | 0:0cccdf8e396f | 36 | #define ERR(x, ...) pc.printf(" ["FUNCNAME" : ERR] "x"\r\n", ##__VA_ARGS__); |
muyiq | 0:0cccdf8e396f | 37 | #else |
muyiq | 0:0cccdf8e396f | 38 | #define ERR(x, ...) |
muyiq | 0:0cccdf8e396f | 39 | #endif |
eddytomhall | 1:bf4ad12efb64 | 40 | |
muyiq | 0:0cccdf8e396f | 41 | #ifdef WARNMESSAGES |
muyiq | 0:0cccdf8e396f | 42 | #define WARN(x, ...) printf("["FUNCNAME" : WARN] "x"\r\n", ##__VA_ARGS__); |
muyiq | 0:0cccdf8e396f | 43 | #else |
muyiq | 0:0cccdf8e396f | 44 | #define WARN(x, ...) |
muyiq | 0:0cccdf8e396f | 45 | #endif |
eddytomhall | 1:bf4ad12efb64 | 46 | |
muyiq | 0:0cccdf8e396f | 47 | #ifdef INFOMESSAGES |
eddytomhall | 1:bf4ad12efb64 | 48 | #define INFO(x, ...) pc.printf("["FUNCNAME" : INFO] "x"\r\n",##__VA_ARGS__); |
muyiq | 0:0cccdf8e396f | 49 | #else |
muyiq | 0:0cccdf8e396f | 50 | #define INFO(x, ...) |
muyiq | 0:0cccdf8e396f | 51 | #endif |
eddytomhall | 1:bf4ad12efb64 | 52 | |
muyiq | 0:0cccdf8e396f | 53 | #define BUFF_SIZE 1024 |
muyiq | 0:0cccdf8e396f | 54 | // PIN DEFS NOW FOR OLD FIRMWARE VERSION OF THE KL25Z |
muyiq | 0:0cccdf8e396f | 55 | Serial pc(USBTX, USBRX); |
muyiq | 0:0cccdf8e396f | 56 | //RawSerial dev(D1, D0); |
eddytomhall | 1:bf4ad12efb64 | 57 | Serial dev(PTE22,PTE23); //tx,rx |
muyiq | 0:0cccdf8e396f | 58 | DigitalOut led1(LED1); |
muyiq | 0:0cccdf8e396f | 59 | DigitalOut led4(LED3); // CHANGE TO LED 3 |
eddytomhall | 1:bf4ad12efb64 | 60 | DigitalOut reset(PTB0,1); |
eddytomhall | 1:bf4ad12efb64 | 61 | |
eddytomhall | 1:bf4ad12efb64 | 62 | |
eddytomhall | 1:bf4ad12efb64 | 63 | |
eddytomhall | 1:bf4ad12efb64 | 64 | PwmOut led(LED_GREEN); |
muyiq | 0:0cccdf8e396f | 65 | // TSISensor tsi; |
muyiq | 0:0cccdf8e396f | 66 | volatile int state=0; |
muyiq | 0:0cccdf8e396f | 67 | volatile int ready=0; |
eddytomhall | 1:bf4ad12efb64 | 68 | int glue=0; |
muyiq | 0:0cccdf8e396f | 69 | char ipAddress[20]; |
muyiq | 0:0cccdf8e396f | 70 | char macAddress[32]; |
muyiq | 0:0cccdf8e396f | 71 | char *buffer; |
muyiq | 0:0cccdf8e396f | 72 | unsigned int bufferPnt=0; |
eddytomhall | 6:c02bbe512cdc | 73 | int zcount; |
eddytomhall | 6:c02bbe512cdc | 74 | int xcount; |
eddytomhall | 6:c02bbe512cdc | 75 | char resp; |
eddytomhall | 6:c02bbe512cdc | 76 | |
eddytomhall | 6:c02bbe512cdc | 77 | float a; |
eddytomhall | 6:c02bbe512cdc | 78 | float b; |
eddytomhall | 6:c02bbe512cdc | 79 | char * OKResponse(char *test, const char *pattern) |
eddytomhall | 6:c02bbe512cdc | 80 | { |
eddytomhall | 6:c02bbe512cdc | 81 | char *p= strstr(test,pattern); |
eddytomhall | 6:c02bbe512cdc | 82 | if (p==NULL) { |
eddytomhall | 6:c02bbe512cdc | 83 | // DBG("Test=<%s> Patter=<%s> NULL [p=%s]",test,pattern,p); |
eddytomhall | 6:c02bbe512cdc | 84 | return NULL; |
eddytomhall | 6:c02bbe512cdc | 85 | } else { |
eddytomhall | 6:c02bbe512cdc | 86 | // DBG("YAY Test=<%s> Patter=<%s> [p=%s]",test,pattern,p); |
eddytomhall | 6:c02bbe512cdc | 87 | } |
eddytomhall | 6:c02bbe512cdc | 88 | return p; |
eddytomhall | 6:c02bbe512cdc | 89 | } |
eddytomhall | 1:bf4ad12efb64 | 90 | |
muyiq | 0:0cccdf8e396f | 91 | void dev_recv() |
muyiq | 0:0cccdf8e396f | 92 | { |
muyiq | 0:0cccdf8e396f | 93 | char c; |
eddytomhall | 1:bf4ad12efb64 | 94 | |
eddytomhall | 4:a8d5a55a89da | 95 | |
eddytomhall | 1:bf4ad12efb64 | 96 | |
muyiq | 0:0cccdf8e396f | 97 | led1 = !led1; |
muyiq | 0:0cccdf8e396f | 98 | if(bufferPnt==0) { |
muyiq | 0:0cccdf8e396f | 99 | memset(buffer,0,BUFF_SIZE); |
muyiq | 0:0cccdf8e396f | 100 | } |
muyiq | 0:0cccdf8e396f | 101 | while(dev.readable()) { |
muyiq | 0:0cccdf8e396f | 102 | c = (char)dev.getc(); |
muyiq | 0:0cccdf8e396f | 103 | #ifdef DEBUG |
eddytomhall | 1:bf4ad12efb64 | 104 | pc.putc(c); |
muyiq | 0:0cccdf8e396f | 105 | #endif |
muyiq | 0:0cccdf8e396f | 106 | buffer[bufferPnt]=c; |
muyiq | 0:0cccdf8e396f | 107 | bufferPnt++; |
muyiq | 0:0cccdf8e396f | 108 | if (bufferPnt>1000) { |
muyiq | 0:0cccdf8e396f | 109 | ready=1; |
muyiq | 0:0cccdf8e396f | 110 | } |
eddytomhall | 1:bf4ad12efb64 | 111 | // if ((c==0x0a)||(c==0x0d)){ |
muyiq | 0:0cccdf8e396f | 112 | // ready=1; |
muyiq | 0:0cccdf8e396f | 113 | // }else |
muyiq | 0:0cccdf8e396f | 114 | if (c==0x0a) { |
muyiq | 0:0cccdf8e396f | 115 | if (bufferPnt>1) { |
muyiq | 0:0cccdf8e396f | 116 | if (buffer[bufferPnt -2]==0x0d) { |
muyiq | 0:0cccdf8e396f | 117 | ready=1; |
muyiq | 0:0cccdf8e396f | 118 | break; |
muyiq | 0:0cccdf8e396f | 119 | } |
muyiq | 0:0cccdf8e396f | 120 | } |
muyiq | 0:0cccdf8e396f | 121 | } |
muyiq | 0:0cccdf8e396f | 122 | if (!dev.readable()) { |
muyiq | 0:0cccdf8e396f | 123 | wait_us(10); |
muyiq | 0:0cccdf8e396f | 124 | } |
muyiq | 0:0cccdf8e396f | 125 | } |
muyiq | 0:0cccdf8e396f | 126 | } |
eddytomhall | 6:c02bbe512cdc | 127 | void sendinfo() |
eddytomhall | 6:c02bbe512cdc | 128 | { |
eddytomhall | 6:c02bbe512cdc | 129 | pc.printf(".......zc=%02u\r\n",zcount); |
eddytomhall | 6:c02bbe512cdc | 130 | |
eddytomhall | 6:c02bbe512cdc | 131 | // resp=OKResponse(buffer,"OK"); |
eddytomhall | 6:c02bbe512cdc | 132 | // if (resp!=NULL) { |
eddytomhall | 6:c02bbe512cdc | 133 | INFO("Ready 10"); |
eddytomhall | 6:c02bbe512cdc | 134 | dev.printf("AT+CIPSEND=4,4\r\n"); |
eddytomhall | 6:c02bbe512cdc | 135 | wait(0.1); |
eddytomhall | 6:c02bbe512cdc | 136 | |
eddytomhall | 6:c02bbe512cdc | 137 | |
eddytomhall | 6:c02bbe512cdc | 138 | wait(0.1); |
eddytomhall | 6:c02bbe512cdc | 139 | // while (OKResponse(buffer,">")!=NULL){ |
eddytomhall | 6:c02bbe512cdc | 140 | // printf(".\r\n"); |
eddytomhall | 6:c02bbe512cdc | 141 | // wait(1); |
eddytomhall | 6:c02bbe512cdc | 142 | // }; |
eddytomhall | 6:c02bbe512cdc | 143 | |
eddytomhall | 6:c02bbe512cdc | 144 | INFO("SENDING"); |
eddytomhall | 6:c02bbe512cdc | 145 | |
eddytomhall | 6:c02bbe512cdc | 146 | wait(0.2); |
eddytomhall | 6:c02bbe512cdc | 147 | dev.printf("%02u\r\n",zcount); |
eddytomhall | 6:c02bbe512cdc | 148 | } |
eddytomhall | 1:bf4ad12efb64 | 149 | |
muyiq | 0:0cccdf8e396f | 150 | void pc_recv() |
muyiq | 0:0cccdf8e396f | 151 | { |
muyiq | 0:0cccdf8e396f | 152 | char c; |
muyiq | 0:0cccdf8e396f | 153 | led4 = !led4; |
muyiq | 0:0cccdf8e396f | 154 | while(pc.readable()) { |
muyiq | 0:0cccdf8e396f | 155 | c=(char)pc.getc(); |
muyiq | 0:0cccdf8e396f | 156 | dev.putc(c); |
muyiq | 0:0cccdf8e396f | 157 | pc.putc(c); |
muyiq | 0:0cccdf8e396f | 158 | if(c==13) { |
muyiq | 0:0cccdf8e396f | 159 | dev.putc(10); |
muyiq | 0:0cccdf8e396f | 160 | pc.putc(10); |
eddytomhall | 1:bf4ad12efb64 | 161 | } |
eddytomhall | 1:bf4ad12efb64 | 162 | |
muyiq | 0:0cccdf8e396f | 163 | } |
muyiq | 0:0cccdf8e396f | 164 | } |
eddytomhall | 1:bf4ad12efb64 | 165 | |
eddytomhall | 6:c02bbe512cdc | 166 | |
muyiq | 0:0cccdf8e396f | 167 | int main() |
muyiq | 0:0cccdf8e396f | 168 | { |
eddytomhall | 1:bf4ad12efb64 | 169 | MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); |
eddytomhall | 4:a8d5a55a89da | 170 | |
muyiq | 0:0cccdf8e396f | 171 | buffer=(char *)calloc(BUFF_SIZE,1); |
muyiq | 0:0cccdf8e396f | 172 | reset=0; |
eddytomhall | 6:c02bbe512cdc | 173 | b=1.0; |
eddytomhall | 6:c02bbe512cdc | 174 | a=1.0; |
eddytomhall | 4:a8d5a55a89da | 175 | zcount=0; // initial conditions of values |
eddytomhall | 1:bf4ad12efb64 | 176 | xcount=0; |
eddytomhall | 1:bf4ad12efb64 | 177 | float x; |
eddytomhall | 1:bf4ad12efb64 | 178 | float z; |
muyiq | 0:0cccdf8e396f | 179 | pc.baud(115200); |
muyiq | 0:0cccdf8e396f | 180 | dev.baud(115200); |
muyiq | 0:0cccdf8e396f | 181 | pc.attach(&pc_recv, Serial::RxIrq); |
muyiq | 0:0cccdf8e396f | 182 | dev.attach(&dev_recv, Serial::RxIrq); |
muyiq | 0:0cccdf8e396f | 183 | pc.printf("Start up\n\r"); |
eddytomhall | 1:bf4ad12efb64 | 184 | wait(3.0); |
muyiq | 0:0cccdf8e396f | 185 | reset=1; |
muyiq | 0:0cccdf8e396f | 186 | char * resp=NULL; |
muyiq | 0:0cccdf8e396f | 187 | pc.printf("Here \n\r"); |
muyiq | 0:0cccdf8e396f | 188 | while(1) { |
muyiq | 0:0cccdf8e396f | 189 | if (ready) { |
muyiq | 0:0cccdf8e396f | 190 | ready=0; |
muyiq | 0:0cccdf8e396f | 191 | bufferPnt=0; |
muyiq | 0:0cccdf8e396f | 192 | INFO("[%d],##%s##",state,buffer); |
muyiq | 0:0cccdf8e396f | 193 | switch (state) { |
eddytomhall | 4:a8d5a55a89da | 194 | case 0: { //sets up microcontroller as client |
muyiq | 0:0cccdf8e396f | 195 | resp=OKResponse(buffer,"WIFI GOT IP"); |
muyiq | 0:0cccdf8e396f | 196 | if (resp!=NULL) { |
muyiq | 0:0cccdf8e396f | 197 | wait(1); |
muyiq | 0:0cccdf8e396f | 198 | dev.printf("AT\r\n"); |
muyiq | 0:0cccdf8e396f | 199 | state++; |
muyiq | 0:0cccdf8e396f | 200 | } |
muyiq | 0:0cccdf8e396f | 201 | break; |
muyiq | 0:0cccdf8e396f | 202 | } |
muyiq | 0:0cccdf8e396f | 203 | case 1: |
muyiq | 0:0cccdf8e396f | 204 | case 2: { |
muyiq | 0:0cccdf8e396f | 205 | resp=OKResponse(buffer,"OK"); |
muyiq | 0:0cccdf8e396f | 206 | if (resp!=NULL) { |
muyiq | 0:0cccdf8e396f | 207 | dev.printf("AT\r\n"); |
muyiq | 0:0cccdf8e396f | 208 | state++; |
muyiq | 0:0cccdf8e396f | 209 | } |
muyiq | 0:0cccdf8e396f | 210 | break; |
muyiq | 0:0cccdf8e396f | 211 | } |
muyiq | 0:0cccdf8e396f | 212 | case 3: { |
muyiq | 0:0cccdf8e396f | 213 | resp=OKResponse(buffer,"OK"); |
muyiq | 0:0cccdf8e396f | 214 | if (resp!=NULL) { |
muyiq | 0:0cccdf8e396f | 215 | dev.printf("AT+RST\r\n"); |
muyiq | 0:0cccdf8e396f | 216 | state++; |
muyiq | 0:0cccdf8e396f | 217 | } |
eddytomhall | 1:bf4ad12efb64 | 218 | |
muyiq | 0:0cccdf8e396f | 219 | break; |
muyiq | 0:0cccdf8e396f | 220 | } |
muyiq | 0:0cccdf8e396f | 221 | case 4: { |
muyiq | 0:0cccdf8e396f | 222 | resp=OKResponse(buffer,"WIFI GOT IP"); |
muyiq | 0:0cccdf8e396f | 223 | if (resp!=NULL) { |
muyiq | 0:0cccdf8e396f | 224 | dev.printf("AT+CWMODE=1\r\n"); |
muyiq | 0:0cccdf8e396f | 225 | state++; |
muyiq | 0:0cccdf8e396f | 226 | } |
eddytomhall | 1:bf4ad12efb64 | 227 | |
muyiq | 0:0cccdf8e396f | 228 | break; |
muyiq | 0:0cccdf8e396f | 229 | } |
muyiq | 0:0cccdf8e396f | 230 | case 5: { |
muyiq | 0:0cccdf8e396f | 231 | resp=OKResponse(buffer,"OK"); |
muyiq | 0:0cccdf8e396f | 232 | if (resp!=NULL) { |
eddytomhall | 1:bf4ad12efb64 | 233 | |
eddytomhall | 1:bf4ad12efb64 | 234 | dev.printf("AT+CWJAP=\"BTHub3-WXWX\",\"fdd6f7c682\"\r\n"); |
muyiq | 0:0cccdf8e396f | 235 | state++; |
muyiq | 0:0cccdf8e396f | 236 | } |
eddytomhall | 1:bf4ad12efb64 | 237 | |
muyiq | 0:0cccdf8e396f | 238 | break; |
muyiq | 0:0cccdf8e396f | 239 | } |
muyiq | 0:0cccdf8e396f | 240 | case 6: { |
muyiq | 0:0cccdf8e396f | 241 | resp=OKResponse(buffer,"OK"); |
muyiq | 0:0cccdf8e396f | 242 | if (resp!=NULL) { |
muyiq | 0:0cccdf8e396f | 243 | wait(1); |
muyiq | 0:0cccdf8e396f | 244 | dev.printf("AT+CIFSR\r\n"); |
muyiq | 0:0cccdf8e396f | 245 | state++; |
muyiq | 0:0cccdf8e396f | 246 | } |
eddytomhall | 1:bf4ad12efb64 | 247 | |
muyiq | 0:0cccdf8e396f | 248 | break; |
muyiq | 0:0cccdf8e396f | 249 | } |
muyiq | 0:0cccdf8e396f | 250 | case 7: { |
muyiq | 0:0cccdf8e396f | 251 | resp=OKResponse(buffer,"+CIFSR:STAIP,"); |
muyiq | 0:0cccdf8e396f | 252 | if (resp!=NULL) { |
muyiq | 0:0cccdf8e396f | 253 | char *strt = strtok(buffer,"\""); |
muyiq | 0:0cccdf8e396f | 254 | strcpy(ipAddress,strtok(NULL,"\"")); |
muyiq | 0:0cccdf8e396f | 255 | strtok(NULL,"\""); |
eddytomhall | 1:bf4ad12efb64 | 256 | strcpy(macAddress,strtok(NULL,"\"")); |
muyiq | 0:0cccdf8e396f | 257 | INFO("mac Address = %s", macAddress); |
muyiq | 0:0cccdf8e396f | 258 | INFO("IP Address = %s", ipAddress); |
eddytomhall | 1:bf4ad12efb64 | 259 | dev.printf("AT+CIPMUX=1\r\n"); |
muyiq | 0:0cccdf8e396f | 260 | state++; |
muyiq | 0:0cccdf8e396f | 261 | } |
eddytomhall | 1:bf4ad12efb64 | 262 | |
muyiq | 0:0cccdf8e396f | 263 | break; |
muyiq | 0:0cccdf8e396f | 264 | } |
muyiq | 0:0cccdf8e396f | 265 | case 8: { |
muyiq | 0:0cccdf8e396f | 266 | resp=OKResponse(buffer,"OK"); |
muyiq | 0:0cccdf8e396f | 267 | if (resp!=NULL) { |
eddytomhall | 1:bf4ad12efb64 | 268 | |
eddytomhall | 1:bf4ad12efb64 | 269 | INFO("Ready 8"); |
eddytomhall | 1:bf4ad12efb64 | 270 | dev.printf("AT+CIPSTART=4,\"TCP\",\"192.168.1.91\",8080\r\n"); |
eddytomhall | 1:bf4ad12efb64 | 271 | state++; |
eddytomhall | 1:bf4ad12efb64 | 272 | wait(0.1); |
eddytomhall | 1:bf4ad12efb64 | 273 | |
muyiq | 0:0cccdf8e396f | 274 | } |
eddytomhall | 1:bf4ad12efb64 | 275 | |
eddytomhall | 1:bf4ad12efb64 | 276 | break; |
eddytomhall | 1:bf4ad12efb64 | 277 | } |
muyiq | 0:0cccdf8e396f | 278 | case 9: { |
eddytomhall | 1:bf4ad12efb64 | 279 | |
muyiq | 0:0cccdf8e396f | 280 | resp=OKResponse(buffer,"OK"); |
muyiq | 0:0cccdf8e396f | 281 | if (resp!=NULL) { |
eddytomhall | 1:bf4ad12efb64 | 282 | |
eddytomhall | 1:bf4ad12efb64 | 283 | INFO("Ready 9"); |
eddytomhall | 1:bf4ad12efb64 | 284 | state++; |
eddytomhall | 1:bf4ad12efb64 | 285 | zcount=0; |
eddytomhall | 1:bf4ad12efb64 | 286 | a=1.0; |
eddytomhall | 1:bf4ad12efb64 | 287 | |
muyiq | 0:0cccdf8e396f | 288 | } |
eddytomhall | 1:bf4ad12efb64 | 289 | |
eddytomhall | 1:bf4ad12efb64 | 290 | } |
eddytomhall | 1:bf4ad12efb64 | 291 | case 10: { |
eddytomhall | 1:bf4ad12efb64 | 292 | |
eddytomhall | 6:c02bbe512cdc | 293 | resp=OKResponse(buffer,"OK"); |
eddytomhall | 6:c02bbe512cdc | 294 | if (resp!=NULL) { |
eddytomhall | 6:c02bbe512cdc | 295 | INFO("Ready 10"); |
eddytomhall | 6:c02bbe512cdc | 296 | dev.printf("AT+CIPSEND=4,9\r\n"); |
eddytomhall | 6:c02bbe512cdc | 297 | wait(0.1); |
eddytomhall | 6:c02bbe512cdc | 298 | |
eddytomhall | 6:c02bbe512cdc | 299 | } |
eddytomhall | 6:c02bbe512cdc | 300 | wait(0.1); |
eddytomhall | 6:c02bbe512cdc | 301 | // while (OKResponse(buffer,">")!=NULL){ |
eddytomhall | 6:c02bbe512cdc | 302 | // printf(".\r\n"); |
eddytomhall | 6:c02bbe512cdc | 303 | // wait(1); |
eddytomhall | 6:c02bbe512cdc | 304 | // }; |
eddytomhall | 6:c02bbe512cdc | 305 | |
eddytomhall | 6:c02bbe512cdc | 306 | INFO("SENDING"); |
eddytomhall | 6:c02bbe512cdc | 307 | |
eddytomhall | 6:c02bbe512cdc | 308 | wait(0.2); |
eddytomhall | 6:c02bbe512cdc | 309 | dev.printf("PEDOMETER\r\n"); |
eddytomhall | 6:c02bbe512cdc | 310 | state++; //send greeting to server |
eddytomhall | 6:c02bbe512cdc | 311 | break; |
eddytomhall | 6:c02bbe512cdc | 312 | case 11: { |
eddytomhall | 6:c02bbe512cdc | 313 | while (true) { |
eddytomhall | 6:c02bbe512cdc | 314 | |
eddytomhall | 6:c02bbe512cdc | 315 | z = (acc.getAccX()); //changes it from measureing Z driection for press ups to X for running |
eddytomhall | 6:c02bbe512cdc | 316 | x = (acc.getAccZ()); |
eddytomhall | 6:c02bbe512cdc | 317 | |
eddytomhall | 6:c02bbe512cdc | 318 | if (a==1.0) { |
eddytomhall | 6:c02bbe512cdc | 319 | |
eddytomhall | 6:c02bbe512cdc | 320 | if (z<0.0) { |
eddytomhall | 6:c02bbe512cdc | 321 | a=0.0; |
eddytomhall | 6:c02bbe512cdc | 322 | |
eddytomhall | 6:c02bbe512cdc | 323 | zcount++; |
eddytomhall | 6:c02bbe512cdc | 324 | |
eddytomhall | 6:c02bbe512cdc | 325 | sendinfo(); |
eddytomhall | 6:c02bbe512cdc | 326 | |
eddytomhall | 6:c02bbe512cdc | 327 | |
eddytomhall | 2:b6569bd9af81 | 328 | |
eddytomhall | 2:b6569bd9af81 | 329 | } |
eddytomhall | 2:b6569bd9af81 | 330 | |
eddytomhall | 2:b6569bd9af81 | 331 | |
eddytomhall | 6:c02bbe512cdc | 332 | if (z>0) { |
eddytomhall | 6:c02bbe512cdc | 333 | a=1.0; //prevents multiple signals for singal dip below zero |
eddytomhall | 6:c02bbe512cdc | 334 | } |
eddytomhall | 6:c02bbe512cdc | 335 | } |
eddytomhall | 6:c02bbe512cdc | 336 | if (a==0) { |
eddytomhall | 6:c02bbe512cdc | 337 | if (z<0) { |
eddytomhall | 6:c02bbe512cdc | 338 | a=0.0; |
eddytomhall | 6:c02bbe512cdc | 339 | } |
eddytomhall | 6:c02bbe512cdc | 340 | if (z>0) { |
eddytomhall | 6:c02bbe512cdc | 341 | a=1.0; |
eddytomhall | 6:c02bbe512cdc | 342 | } |
eddytomhall | 6:c02bbe512cdc | 343 | } |
eddytomhall | 6:c02bbe512cdc | 344 | if (b==1) { |
eddytomhall | 6:c02bbe512cdc | 345 | if (x<0) { |
eddytomhall | 6:c02bbe512cdc | 346 | b=0.0; |
eddytomhall | 6:c02bbe512cdc | 347 | xcount=xcount+1; |
eddytomhall | 6:c02bbe512cdc | 348 | //printf("Xcount: %u \n\r",xcount); |
eddytomhall | 1:bf4ad12efb64 | 349 | |
eddytomhall | 1:bf4ad12efb64 | 350 | } |
eddytomhall | 6:c02bbe512cdc | 351 | if (x>0) { |
eddytomhall | 6:c02bbe512cdc | 352 | b=1.0; |
eddytomhall | 6:c02bbe512cdc | 353 | } |
eddytomhall | 6:c02bbe512cdc | 354 | } |
eddytomhall | 1:bf4ad12efb64 | 355 | |
eddytomhall | 6:c02bbe512cdc | 356 | if (b==0) { |
eddytomhall | 6:c02bbe512cdc | 357 | if (x<0) { |
eddytomhall | 6:c02bbe512cdc | 358 | b=0.0; |
eddytomhall | 6:c02bbe512cdc | 359 | } |
eddytomhall | 6:c02bbe512cdc | 360 | if (x>0) { |
eddytomhall | 6:c02bbe512cdc | 361 | b=1.0; |
eddytomhall | 6:c02bbe512cdc | 362 | } |
eddytomhall | 1:bf4ad12efb64 | 363 | } |
eddytomhall | 1:bf4ad12efb64 | 364 | |
eddytomhall | 1:bf4ad12efb64 | 365 | } |
eddytomhall | 6:c02bbe512cdc | 366 | break; |
muyiq | 0:0cccdf8e396f | 367 | } |
eddytomhall | 6:c02bbe512cdc | 368 | } |
eddytomhall | 6:c02bbe512cdc | 369 | //__WFI(); // DELETED AS IT KILLS THE KL25 RESPONSIVITY |
eddytomhall | 6:c02bbe512cdc | 370 | } |
eddytomhall | 1:bf4ad12efb64 | 371 | |
muyiq | 0:0cccdf8e396f | 372 | } |
muyiq | 0:0cccdf8e396f | 373 | } |
eddytomhall | 1:bf4ad12efb64 | 374 | } |