test
Dependencies: MINI8I8O5A000 mbed EEPROM_P4 IICLCD_LOWCOST
Diff: main.cpp
- Revision:
- 2:82dbbbff7518
- Parent:
- 1:d9ab13cdf377
- Child:
- 3:e658376f6e27
--- a/main.cpp Mon Oct 12 05:09:46 2015 +0000 +++ b/main.cpp Tue Oct 13 08:50:26 2015 +0000 @@ -1,18 +1,33 @@ float firmware_version = 1.00; #include "mbed.h" + + +//#include "USBSerial.h" +//SBSerial pc; + + + +//#define USBSerialOption + +#ifdef USBSerialOption +#include "USBSerial.h" +USBSerial pc; +not work?? +#else + +Serial pc(USBTX, USBRX); + +#endif + + + #include "LiquidCrystal_I2C.h" #include "mini8i8o5a.h" #define EEPROMBUFFERSIZE 16 #include "eepromlib.h" -#ifdef USBSerial -#include "USBSerial.h" -USBSerial pc; -#else -Serial pc(USBTX, USBRX); -#endif DigitalOut myled(LED1); @@ -54,20 +69,32 @@ { int i,j; - while(pc.readable()) + +#ifdef USBSerialOption + while (pc.available()) +#else + while(pc.readable()) +#endif { - myled = 0; - inchar =pc.getc(); - wait(0.1); - myled = 1; + - if ( rx_pointer==0) //first incoming character + inchar =pc.getc(); + + + myled = 0; + + + + + + if ( rx_pointer==0) //first incoming character clear old buffer { for (i=0;i<RXBUFFERSIZE;i++) rx_buffer[i]=0; //clear old buffer - com_timer.reset(); - com_timer.start(); + // com_timer.reset(); + // com_timer.start(); } + rx_buffer[rx_pointer]=inchar; //keep char in buffer... rx_pointer++; @@ -78,12 +105,14 @@ //rx_pointer=200; //rx_buffer[rx_pointer]=0; rx_pointer=0;//Error buffer overflow - pc.printf("ERR:buffer overflow\n",firmware_version); + pc.printf("ERR:buffer overflow\n"); } + + if ((inchar=='\r')|(inchar=='\n')) { - remote_control=1; + rx_buffer[rx_pointer-1]=0;//mark end of string, remove terminate char i=0; @@ -110,7 +139,7 @@ } rx_buffer_ARG[j]=0; //end of string ++++ - pc.printf("rxbuffer: %s",rx_buffer); //test direct echo + //pc.printf("rxbuffer: %s",rx_buffer); //test direct echo if (strcmp(rx_buffer,"*IDN?")==0) { @@ -147,7 +176,36 @@ } else if ( (rx_buffer[0]=='a') & (rx_buffer[1]==('0'+boardaddress)) & (rx_buffer[2]=='2')) // Write Output "aX2" { - pc.printf("OK%d\n",22); + //writer + unsigned char b3,b2,b1; + unsigned int outdata=0; + + if (rx_buffer[3]!=0) + { + outdata=rx_buffer[3]-'0'; + } + if (rx_buffer[4]!=0) + { + outdata=outdata*10+rx_buffer[4]-'0'; + } + if (rx_buffer[5]!=0) + { + outdata=outdata*10+rx_buffer[5]-'0'; + } + + if bitchk(outdata,0) OUT0=ON; else OUT0=OFF; + if bitchk(outdata,1) OUT1=ON; else OUT1=OFF; + if bitchk(outdata,2) OUT2=ON; else OUT2=OFF; + if bitchk(outdata,3) OUT3=ON; else OUT3=OFF; + + if bitchk(outdata,4) OUT4=ON; else OUT4=OFF; + if bitchk(outdata,5) OUT5=ON; else OUT5=OFF; + if bitchk(outdata,6) OUT6=ON; else OUT6=OFF; + if bitchk(outdata,7) OUT7=ON; else OUT7=OFF; + + + + pc.printf("OK%d\n",outdata); } else if ( (rx_buffer[0]=='a') & (rx_buffer[1]==('0'+boardaddress)) & (rx_buffer[2]=='3')) // Write Output "aX2" { @@ -155,15 +213,19 @@ } else {//unknow / handle comand - pc.printf( "UNKNOWN %s=>%s,%s\n",rx_buffer,rx_buffer_CMD,rx_buffer_ARG); - } - + //pc.printf( "UNKNOWN %s=>%s,%s\n",rx_buffer,rx_buffer_CMD,rx_buffer_ARG); + pc.printf( "UNKNOWN %s=>%s,%s\n",rx_buffer); + } rx_pointer=0;//Reset at the end com_timer.stop(); - } + break;//exit while + } //end foud "terminal of command// + - } - + + } //end while data read aviable + myled = 1; + } @@ -185,8 +247,12 @@ sprintf (str, "SerailDIO v:%.2f ",1.00) ; LCDI2C4Bit_printIn(str); - - pc.baud(9600); // set what you want here depending on your terminal program speed +#ifdef USBSerialOption + +#else + pc.baud(9600); // set what you want here depending on your terminal program speed +#endif + //pc.printf( "RST\n"); com_timer.start(); @@ -195,10 +261,16 @@ wait(1); + while(0) + { + serial_pc_rx_services(); + } + + pc.attach(&serial_pc_rx_services); // while(1) { - serial_pc_rx_services(); + LiquidCrystal_I2CsetCursor(0,0); sprintf (str, " I:%d O:%d ",255,255); LCDI2C4Bit_printIn(str);