final product
Dependencies: FRDM_MMA8451Q mbed
Fork of mbed_Pedometer_pressup by
main.cpp@4:a8d5a55a89da, 2016-06-16 (annotated)
- Committer:
- eddytomhall
- Date:
- Thu Jun 16 15:50:48 2016 +0000
- Revision:
- 4:a8d5a55a89da
- Parent:
- 2:b6569bd9af81
- Child:
- 5:d497f1566d19
Adding comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
muyiq | 0:0cccdf8e396f | 1 | #include "mbed.h" |
eddytomhall | 4:a8d5a55a89da | 2 | #include "MMA8451Q.h" //allow use of accelerometer |
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 | 1:bf4ad12efb64 | 73 | |
muyiq | 0:0cccdf8e396f | 74 | void dev_recv() |
muyiq | 0:0cccdf8e396f | 75 | { |
muyiq | 0:0cccdf8e396f | 76 | char c; |
eddytomhall | 1:bf4ad12efb64 | 77 | |
eddytomhall | 4:a8d5a55a89da | 78 | |
eddytomhall | 1:bf4ad12efb64 | 79 | |
muyiq | 0:0cccdf8e396f | 80 | led1 = !led1; |
muyiq | 0:0cccdf8e396f | 81 | if(bufferPnt==0) { |
muyiq | 0:0cccdf8e396f | 82 | memset(buffer,0,BUFF_SIZE); |
muyiq | 0:0cccdf8e396f | 83 | } |
muyiq | 0:0cccdf8e396f | 84 | while(dev.readable()) { |
muyiq | 0:0cccdf8e396f | 85 | c = (char)dev.getc(); |
muyiq | 0:0cccdf8e396f | 86 | #ifdef DEBUG |
eddytomhall | 1:bf4ad12efb64 | 87 | pc.putc(c); |
muyiq | 0:0cccdf8e396f | 88 | #endif |
muyiq | 0:0cccdf8e396f | 89 | buffer[bufferPnt]=c; |
muyiq | 0:0cccdf8e396f | 90 | bufferPnt++; |
muyiq | 0:0cccdf8e396f | 91 | if (bufferPnt>1000) { |
muyiq | 0:0cccdf8e396f | 92 | ready=1; |
muyiq | 0:0cccdf8e396f | 93 | } |
eddytomhall | 1:bf4ad12efb64 | 94 | // if ((c==0x0a)||(c==0x0d)){ |
muyiq | 0:0cccdf8e396f | 95 | // ready=1; |
muyiq | 0:0cccdf8e396f | 96 | // }else |
muyiq | 0:0cccdf8e396f | 97 | if (c==0x0a) { |
muyiq | 0:0cccdf8e396f | 98 | if (bufferPnt>1) { |
muyiq | 0:0cccdf8e396f | 99 | if (buffer[bufferPnt -2]==0x0d) { |
muyiq | 0:0cccdf8e396f | 100 | ready=1; |
muyiq | 0:0cccdf8e396f | 101 | break; |
muyiq | 0:0cccdf8e396f | 102 | } |
muyiq | 0:0cccdf8e396f | 103 | } |
muyiq | 0:0cccdf8e396f | 104 | } |
muyiq | 0:0cccdf8e396f | 105 | if (!dev.readable()) { |
muyiq | 0:0cccdf8e396f | 106 | wait_us(10); |
muyiq | 0:0cccdf8e396f | 107 | } |
muyiq | 0:0cccdf8e396f | 108 | } |
muyiq | 0:0cccdf8e396f | 109 | } |
eddytomhall | 1:bf4ad12efb64 | 110 | |
muyiq | 0:0cccdf8e396f | 111 | void pc_recv() |
muyiq | 0:0cccdf8e396f | 112 | { |
muyiq | 0:0cccdf8e396f | 113 | char c; |
muyiq | 0:0cccdf8e396f | 114 | led4 = !led4; |
muyiq | 0:0cccdf8e396f | 115 | while(pc.readable()) { |
muyiq | 0:0cccdf8e396f | 116 | c=(char)pc.getc(); |
muyiq | 0:0cccdf8e396f | 117 | dev.putc(c); |
muyiq | 0:0cccdf8e396f | 118 | pc.putc(c); |
muyiq | 0:0cccdf8e396f | 119 | if(c==13) { |
muyiq | 0:0cccdf8e396f | 120 | dev.putc(10); |
muyiq | 0:0cccdf8e396f | 121 | pc.putc(10); |
eddytomhall | 1:bf4ad12efb64 | 122 | } |
eddytomhall | 1:bf4ad12efb64 | 123 | |
muyiq | 0:0cccdf8e396f | 124 | } |
muyiq | 0:0cccdf8e396f | 125 | } |
eddytomhall | 1:bf4ad12efb64 | 126 | |
muyiq | 0:0cccdf8e396f | 127 | char * OKResponse(char *test, const char *pattern) |
muyiq | 0:0cccdf8e396f | 128 | { |
muyiq | 0:0cccdf8e396f | 129 | char *p= strstr(test,pattern); |
muyiq | 0:0cccdf8e396f | 130 | if (p==NULL) { |
muyiq | 0:0cccdf8e396f | 131 | // DBG("Test=<%s> Patter=<%s> NULL [p=%s]",test,pattern,p); |
muyiq | 0:0cccdf8e396f | 132 | return NULL; |
muyiq | 0:0cccdf8e396f | 133 | } else { |
muyiq | 0:0cccdf8e396f | 134 | // DBG("YAY Test=<%s> Patter=<%s> [p=%s]",test,pattern,p); |
muyiq | 0:0cccdf8e396f | 135 | } |
muyiq | 0:0cccdf8e396f | 136 | return p; |
muyiq | 0:0cccdf8e396f | 137 | } |
muyiq | 0:0cccdf8e396f | 138 | int main() |
muyiq | 0:0cccdf8e396f | 139 | { |
eddytomhall | 1:bf4ad12efb64 | 140 | MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); |
eddytomhall | 4:a8d5a55a89da | 141 | |
muyiq | 0:0cccdf8e396f | 142 | buffer=(char *)calloc(BUFF_SIZE,1); |
muyiq | 0:0cccdf8e396f | 143 | reset=0; |
eddytomhall | 1:bf4ad12efb64 | 144 | int zcount; |
eddytomhall | 1:bf4ad12efb64 | 145 | int xcount; |
eddytomhall | 4:a8d5a55a89da | 146 | zcount=0; // initial conditions of values |
eddytomhall | 1:bf4ad12efb64 | 147 | xcount=0; |
eddytomhall | 1:bf4ad12efb64 | 148 | float a; |
eddytomhall | 1:bf4ad12efb64 | 149 | float b; |
eddytomhall | 1:bf4ad12efb64 | 150 | b=1.0; |
eddytomhall | 1:bf4ad12efb64 | 151 | a=1.0; |
eddytomhall | 1:bf4ad12efb64 | 152 | float x; |
eddytomhall | 1:bf4ad12efb64 | 153 | float z; |
muyiq | 0:0cccdf8e396f | 154 | pc.baud(115200); |
muyiq | 0:0cccdf8e396f | 155 | dev.baud(115200); |
muyiq | 0:0cccdf8e396f | 156 | pc.attach(&pc_recv, Serial::RxIrq); |
muyiq | 0:0cccdf8e396f | 157 | dev.attach(&dev_recv, Serial::RxIrq); |
muyiq | 0:0cccdf8e396f | 158 | pc.printf("Start up\n\r"); |
eddytomhall | 1:bf4ad12efb64 | 159 | wait(3.0); |
muyiq | 0:0cccdf8e396f | 160 | reset=1; |
muyiq | 0:0cccdf8e396f | 161 | char * resp=NULL; |
muyiq | 0:0cccdf8e396f | 162 | pc.printf("Here \n\r"); |
muyiq | 0:0cccdf8e396f | 163 | while(1) { |
muyiq | 0:0cccdf8e396f | 164 | if (ready) { |
muyiq | 0:0cccdf8e396f | 165 | ready=0; |
muyiq | 0:0cccdf8e396f | 166 | bufferPnt=0; |
muyiq | 0:0cccdf8e396f | 167 | INFO("[%d],##%s##",state,buffer); |
muyiq | 0:0cccdf8e396f | 168 | switch (state) { |
eddytomhall | 4:a8d5a55a89da | 169 | case 0: { //sets up microcontroller as client |
muyiq | 0:0cccdf8e396f | 170 | resp=OKResponse(buffer,"WIFI GOT IP"); |
muyiq | 0:0cccdf8e396f | 171 | if (resp!=NULL) { |
muyiq | 0:0cccdf8e396f | 172 | wait(1); |
muyiq | 0:0cccdf8e396f | 173 | dev.printf("AT\r\n"); |
muyiq | 0:0cccdf8e396f | 174 | state++; |
muyiq | 0:0cccdf8e396f | 175 | } |
muyiq | 0:0cccdf8e396f | 176 | break; |
muyiq | 0:0cccdf8e396f | 177 | } |
muyiq | 0:0cccdf8e396f | 178 | case 1: |
muyiq | 0:0cccdf8e396f | 179 | case 2: { |
muyiq | 0:0cccdf8e396f | 180 | resp=OKResponse(buffer,"OK"); |
muyiq | 0:0cccdf8e396f | 181 | if (resp!=NULL) { |
muyiq | 0:0cccdf8e396f | 182 | dev.printf("AT\r\n"); |
muyiq | 0:0cccdf8e396f | 183 | state++; |
muyiq | 0:0cccdf8e396f | 184 | } |
muyiq | 0:0cccdf8e396f | 185 | break; |
muyiq | 0:0cccdf8e396f | 186 | } |
muyiq | 0:0cccdf8e396f | 187 | case 3: { |
muyiq | 0:0cccdf8e396f | 188 | resp=OKResponse(buffer,"OK"); |
muyiq | 0:0cccdf8e396f | 189 | if (resp!=NULL) { |
muyiq | 0:0cccdf8e396f | 190 | dev.printf("AT+RST\r\n"); |
muyiq | 0:0cccdf8e396f | 191 | state++; |
muyiq | 0:0cccdf8e396f | 192 | } |
eddytomhall | 1:bf4ad12efb64 | 193 | |
muyiq | 0:0cccdf8e396f | 194 | break; |
muyiq | 0:0cccdf8e396f | 195 | } |
muyiq | 0:0cccdf8e396f | 196 | case 4: { |
muyiq | 0:0cccdf8e396f | 197 | resp=OKResponse(buffer,"WIFI GOT IP"); |
muyiq | 0:0cccdf8e396f | 198 | if (resp!=NULL) { |
muyiq | 0:0cccdf8e396f | 199 | dev.printf("AT+CWMODE=1\r\n"); |
muyiq | 0:0cccdf8e396f | 200 | state++; |
muyiq | 0:0cccdf8e396f | 201 | } |
eddytomhall | 1:bf4ad12efb64 | 202 | |
muyiq | 0:0cccdf8e396f | 203 | break; |
muyiq | 0:0cccdf8e396f | 204 | } |
muyiq | 0:0cccdf8e396f | 205 | case 5: { |
muyiq | 0:0cccdf8e396f | 206 | resp=OKResponse(buffer,"OK"); |
muyiq | 0:0cccdf8e396f | 207 | if (resp!=NULL) { |
eddytomhall | 1:bf4ad12efb64 | 208 | |
eddytomhall | 1:bf4ad12efb64 | 209 | dev.printf("AT+CWJAP=\"BTHub3-WXWX\",\"fdd6f7c682\"\r\n"); |
muyiq | 0:0cccdf8e396f | 210 | state++; |
muyiq | 0:0cccdf8e396f | 211 | } |
eddytomhall | 1:bf4ad12efb64 | 212 | |
muyiq | 0:0cccdf8e396f | 213 | break; |
muyiq | 0:0cccdf8e396f | 214 | } |
muyiq | 0:0cccdf8e396f | 215 | case 6: { |
muyiq | 0:0cccdf8e396f | 216 | resp=OKResponse(buffer,"OK"); |
muyiq | 0:0cccdf8e396f | 217 | if (resp!=NULL) { |
muyiq | 0:0cccdf8e396f | 218 | wait(1); |
muyiq | 0:0cccdf8e396f | 219 | dev.printf("AT+CIFSR\r\n"); |
muyiq | 0:0cccdf8e396f | 220 | state++; |
muyiq | 0:0cccdf8e396f | 221 | } |
eddytomhall | 1:bf4ad12efb64 | 222 | |
muyiq | 0:0cccdf8e396f | 223 | break; |
muyiq | 0:0cccdf8e396f | 224 | } |
muyiq | 0:0cccdf8e396f | 225 | case 7: { |
muyiq | 0:0cccdf8e396f | 226 | resp=OKResponse(buffer,"+CIFSR:STAIP,"); |
muyiq | 0:0cccdf8e396f | 227 | if (resp!=NULL) { |
muyiq | 0:0cccdf8e396f | 228 | char *strt = strtok(buffer,"\""); |
muyiq | 0:0cccdf8e396f | 229 | strcpy(ipAddress,strtok(NULL,"\"")); |
muyiq | 0:0cccdf8e396f | 230 | strtok(NULL,"\""); |
eddytomhall | 1:bf4ad12efb64 | 231 | strcpy(macAddress,strtok(NULL,"\"")); |
muyiq | 0:0cccdf8e396f | 232 | INFO("mac Address = %s", macAddress); |
muyiq | 0:0cccdf8e396f | 233 | INFO("IP Address = %s", ipAddress); |
eddytomhall | 1:bf4ad12efb64 | 234 | dev.printf("AT+CIPMUX=1\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 8: { |
muyiq | 0:0cccdf8e396f | 241 | resp=OKResponse(buffer,"OK"); |
muyiq | 0:0cccdf8e396f | 242 | if (resp!=NULL) { |
eddytomhall | 1:bf4ad12efb64 | 243 | |
eddytomhall | 1:bf4ad12efb64 | 244 | INFO("Ready 8"); |
eddytomhall | 1:bf4ad12efb64 | 245 | dev.printf("AT+CIPSTART=4,\"TCP\",\"192.168.1.91\",8080\r\n"); |
eddytomhall | 1:bf4ad12efb64 | 246 | state++; |
eddytomhall | 1:bf4ad12efb64 | 247 | wait(0.1); |
eddytomhall | 1:bf4ad12efb64 | 248 | |
muyiq | 0:0cccdf8e396f | 249 | } |
eddytomhall | 1:bf4ad12efb64 | 250 | |
eddytomhall | 1:bf4ad12efb64 | 251 | break; |
eddytomhall | 1:bf4ad12efb64 | 252 | } |
muyiq | 0:0cccdf8e396f | 253 | case 9: { |
eddytomhall | 1:bf4ad12efb64 | 254 | |
muyiq | 0:0cccdf8e396f | 255 | resp=OKResponse(buffer,"OK"); |
muyiq | 0:0cccdf8e396f | 256 | if (resp!=NULL) { |
eddytomhall | 1:bf4ad12efb64 | 257 | |
eddytomhall | 1:bf4ad12efb64 | 258 | INFO("Ready 9"); |
eddytomhall | 1:bf4ad12efb64 | 259 | state++; |
eddytomhall | 1:bf4ad12efb64 | 260 | zcount=0; |
eddytomhall | 1:bf4ad12efb64 | 261 | a=1.0; |
eddytomhall | 1:bf4ad12efb64 | 262 | |
muyiq | 0:0cccdf8e396f | 263 | } |
eddytomhall | 1:bf4ad12efb64 | 264 | |
eddytomhall | 1:bf4ad12efb64 | 265 | } |
eddytomhall | 1:bf4ad12efb64 | 266 | case 10: { |
eddytomhall | 1:bf4ad12efb64 | 267 | |
eddytomhall | 2:b6569bd9af81 | 268 | resp=OKResponse(buffer,"OK"); |
eddytomhall | 2:b6569bd9af81 | 269 | if (resp!=NULL) { |
eddytomhall | 2:b6569bd9af81 | 270 | INFO("Ready 10"); |
eddytomhall | 2:b6569bd9af81 | 271 | dev.printf("AT+CIPSEND=4,9\r\n"); |
eddytomhall | 2:b6569bd9af81 | 272 | wait(0.1); |
eddytomhall | 2:b6569bd9af81 | 273 | |
eddytomhall | 2:b6569bd9af81 | 274 | } |
eddytomhall | 2:b6569bd9af81 | 275 | wait(0.1); |
eddytomhall | 2:b6569bd9af81 | 276 | // while (OKResponse(buffer,">")!=NULL){ |
eddytomhall | 2:b6569bd9af81 | 277 | // printf(".\r\n"); |
eddytomhall | 2:b6569bd9af81 | 278 | // wait(1); |
eddytomhall | 2:b6569bd9af81 | 279 | // }; |
eddytomhall | 2:b6569bd9af81 | 280 | |
eddytomhall | 2:b6569bd9af81 | 281 | INFO("SENDING"); |
eddytomhall | 2:b6569bd9af81 | 282 | |
eddytomhall | 2:b6569bd9af81 | 283 | wait(0.2); |
eddytomhall | 4:a8d5a55a89da | 284 | dev.printf("PEDOMETER"); //send greeting to server |
eddytomhall | 2:b6569bd9af81 | 285 | |
eddytomhall | 1:bf4ad12efb64 | 286 | while (true) { |
eddytomhall | 4:a8d5a55a89da | 287 | z = (acc.getAccX()); //changes it from measureing Z driection for press ups to X for running |
eddytomhall | 2:b6569bd9af81 | 288 | x = (acc.getAccZ()); |
eddytomhall | 1:bf4ad12efb64 | 289 | |
eddytomhall | 1:bf4ad12efb64 | 290 | if (a==1.0) { |
eddytomhall | 1:bf4ad12efb64 | 291 | |
eddytomhall | 1:bf4ad12efb64 | 292 | if (z<0.0) { |
eddytomhall | 1:bf4ad12efb64 | 293 | a=0.0; |
eddytomhall | 1:bf4ad12efb64 | 294 | zcount++; |
eddytomhall | 1:bf4ad12efb64 | 295 | pc.printf(".......zc=%02u\r\n",zcount); |
eddytomhall | 1:bf4ad12efb64 | 296 | |
eddytomhall | 1:bf4ad12efb64 | 297 | resp=OKResponse(buffer,"OK"); |
eddytomhall | 1:bf4ad12efb64 | 298 | if (resp!=NULL) { |
eddytomhall | 1:bf4ad12efb64 | 299 | INFO("Ready 10"); |
eddytomhall | 2:b6569bd9af81 | 300 | dev.printf("AT+CIPSEND=4,4\r\n"); |
eddytomhall | 1:bf4ad12efb64 | 301 | wait(0.1); |
eddytomhall | 1:bf4ad12efb64 | 302 | |
eddytomhall | 1:bf4ad12efb64 | 303 | } |
eddytomhall | 1:bf4ad12efb64 | 304 | wait(0.1); |
eddytomhall | 1:bf4ad12efb64 | 305 | // while (OKResponse(buffer,">")!=NULL){ |
eddytomhall | 1:bf4ad12efb64 | 306 | // printf(".\r\n"); |
eddytomhall | 1:bf4ad12efb64 | 307 | // wait(1); |
eddytomhall | 1:bf4ad12efb64 | 308 | // }; |
eddytomhall | 1:bf4ad12efb64 | 309 | |
eddytomhall | 1:bf4ad12efb64 | 310 | INFO("SENDING"); |
eddytomhall | 1:bf4ad12efb64 | 311 | |
eddytomhall | 1:bf4ad12efb64 | 312 | wait(0.2); |
eddytomhall | 1:bf4ad12efb64 | 313 | dev.printf("%02u\r\n",zcount); |
eddytomhall | 1:bf4ad12efb64 | 314 | |
eddytomhall | 1:bf4ad12efb64 | 315 | |
eddytomhall | 1:bf4ad12efb64 | 316 | |
eddytomhall | 1:bf4ad12efb64 | 317 | |
eddytomhall | 1:bf4ad12efb64 | 318 | } |
eddytomhall | 1:bf4ad12efb64 | 319 | |
eddytomhall | 1:bf4ad12efb64 | 320 | } |
eddytomhall | 1:bf4ad12efb64 | 321 | if (z>0) { |
eddytomhall | 4:a8d5a55a89da | 322 | a=1.0; //prevents multiple signals for singal dip below zero |
eddytomhall | 1:bf4ad12efb64 | 323 | } |
muyiq | 0:0cccdf8e396f | 324 | } |
eddytomhall | 1:bf4ad12efb64 | 325 | if (a==0) { |
eddytomhall | 1:bf4ad12efb64 | 326 | if (z<0) { |
eddytomhall | 1:bf4ad12efb64 | 327 | a=0.0; |
eddytomhall | 1:bf4ad12efb64 | 328 | } |
eddytomhall | 1:bf4ad12efb64 | 329 | if (z>0) { |
eddytomhall | 1:bf4ad12efb64 | 330 | a=1.0; |
eddytomhall | 1:bf4ad12efb64 | 331 | } |
muyiq | 0:0cccdf8e396f | 332 | } |
eddytomhall | 1:bf4ad12efb64 | 333 | if (b==1) { |
eddytomhall | 1:bf4ad12efb64 | 334 | if (x<0) { |
eddytomhall | 1:bf4ad12efb64 | 335 | b=0.0; |
eddytomhall | 1:bf4ad12efb64 | 336 | xcount=xcount+1; |
eddytomhall | 1:bf4ad12efb64 | 337 | //printf("Xcount: %u \n\r",xcount); |
eddytomhall | 1:bf4ad12efb64 | 338 | |
eddytomhall | 1:bf4ad12efb64 | 339 | } |
eddytomhall | 1:bf4ad12efb64 | 340 | if (x>0) { |
eddytomhall | 1:bf4ad12efb64 | 341 | b=1.0; |
eddytomhall | 1:bf4ad12efb64 | 342 | } |
eddytomhall | 1:bf4ad12efb64 | 343 | } |
eddytomhall | 2:b6569bd9af81 | 344 | |
eddytomhall | 1:bf4ad12efb64 | 345 | if (b==0) { |
eddytomhall | 1:bf4ad12efb64 | 346 | if (x<0) { |
eddytomhall | 1:bf4ad12efb64 | 347 | b=0.0; |
eddytomhall | 1:bf4ad12efb64 | 348 | } |
eddytomhall | 1:bf4ad12efb64 | 349 | if (x>0) { |
eddytomhall | 1:bf4ad12efb64 | 350 | b=1.0; |
eddytomhall | 1:bf4ad12efb64 | 351 | } |
eddytomhall | 1:bf4ad12efb64 | 352 | } |
eddytomhall | 1:bf4ad12efb64 | 353 | |
muyiq | 0:0cccdf8e396f | 354 | } |
eddytomhall | 1:bf4ad12efb64 | 355 | break; |
muyiq | 0:0cccdf8e396f | 356 | } |
muyiq | 0:0cccdf8e396f | 357 | } |
muyiq | 0:0cccdf8e396f | 358 | //__WFI(); // DELETED AS IT KILLS THE KL25 RESPONSIVITY |
muyiq | 0:0cccdf8e396f | 359 | } |
eddytomhall | 1:bf4ad12efb64 | 360 | |
eddytomhall | 1:bf4ad12efb64 | 361 | } |