kl25z version
Fork of ESP8266_MDM by
Simple code setup to talk to the wifi esp8266 using a kl25z has extra bits in it to read the value of the touch panel back to the wifi
Revision 3:2b5f88cf893d, committed 2016-06-10
- Comitter:
- cstevens
- Date:
- Fri Jun 10 09:54:48 2016 +0000
- Parent:
- 2:6c150720937c
- Commit message:
- kl25z sending tsi sensor values after setup
Changed in this revision
TSI.lib | 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 |
diff -r 6c150720937c -r 2b5f88cf893d TSI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TSI.lib Fri Jun 10 09:54:48 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/TSI/#1a60ef257879
diff -r 6c150720937c -r 2b5f88cf893d main.cpp --- a/main.cpp Wed Jun 08 11:06:45 2016 +0000 +++ b/main.cpp Fri Jun 10 09:54:48 2016 +0000 @@ -1,5 +1,5 @@ #include "mbed.h" - +#include "TSISensor.h" #define DEBUG #define INFOMESSAGES #define WARNMESSAGES @@ -31,13 +31,18 @@ #define INFO(x, ...) #endif -#define BUFF_SIZE 2048 -RawSerial pc(USBTX, USBRX); +#define BUFF_SIZE 1024 +// PIN DEFS NOW FOR OLD FIRMWARE VERSION OF THE KL25Z +Serial pc(USBTX, USBRX); //RawSerial dev(D1, D0); -RawSerial dev(p28, p27); //tx,rx +Serial dev(PTD3,PTD2); //tx,rx DigitalOut led1(LED1); -DigitalOut led4(LED4); -DigitalOut reset(p26,1); +DigitalOut led4(LED3); // CHANGE TO LED 3 +DigitalOut reset(PTA13,1); + + + PwmOut led(LED_GREEN); + TSISensor tsi; volatile int state=0; volatile int ready=0; @@ -58,16 +63,16 @@ while(dev.readable()) { c = (char)dev.getc(); #ifdef DEBUG - // pc.putc(c); + pc.putc(c); #endif buffer[bufferPnt]=c; bufferPnt++; - if (bufferPnt>1024) { + if (bufferPnt>1000) { ready=1; } - if ((c==0x0a)||(c==0x0d)){ - ready=1; - }else + // if ((c==0x0a)||(c==0x0d)){ + // ready=1; + // }else if (c==0x0a) { if (bufferPnt>1) { if (buffer[bufferPnt -2]==0x0d) { @@ -77,7 +82,7 @@ } } if (!dev.readable()) { - wait_us(100); + wait_us(10); } } } @@ -90,6 +95,10 @@ c=(char)pc.getc(); dev.putc(c); pc.putc(c); + if(c==13) { + dev.putc(10); + pc.putc(10); + } } } @@ -107,9 +116,10 @@ } int main() { + float touch; buffer=(char *)calloc(BUFF_SIZE,1); reset=0; - + int counter=0; pc.baud(115200); dev.baud(115200); pc.attach(&pc_recv, Serial::RxIrq); @@ -123,7 +133,7 @@ if (ready) { ready=0; bufferPnt=0; - INFO("[%d]",state); + INFO("[%d],##%s##",state,buffer); switch (state) { case 0: { resp=OKResponse(buffer,"WIFI GOT IP"); @@ -200,15 +210,49 @@ resp=OKResponse(buffer,"OK"); if (resp!=NULL) { INFO("Ready"); + dev.printf("AT+CIPSTART=4,\"TCP\",\"192.168.1.3\",8080\r\n"); state++; } break; + } + case 9: { + resp=OKResponse(buffer,"OK"); + if (resp!=NULL) { + INFO("Ready"); + state++; + dev.printf("AT+CIPSEND=4,10\r\n"); + } + + break; + } + case 10: { + resp=OKResponse(buffer,">"); + if (resp!=NULL) { + INFO("SENDING"); + state++; + touch=tsi.readPercentage(); + dev.printf("TSI=%1.2f\n\r",touch); + pc.printf(" ############ tsi=%1.2f\n\r",touch); + //INFO("sensor=%1.2f",float)tsi.readPercentage()); + } + case 11: { + resp=OKResponse(buffer,"SEND OK"); + if (resp!=NULL) { + INFO("SEND OK"); + state=9; + //wait(2); + } + wait(1); + state=9; + } + + break; } } } - __WFI(); + //__WFI(); // DELETED AS IT KILLS THE KL25 RESPONSIVITY } } \ No newline at end of file