Basic tank-style drive robot control firmware for Freescale FRDM-K64F. Controls motors on a Dual-Full-H-Bridge with EN, like DBH-1x series, from Bluetooth serial commands
Diff: ASerial.h
- Revision:
- 4:7620d21baef3
- Parent:
- 3:502f90649834
--- a/ASerial.h Thu Aug 13 17:50:28 2015 +0000 +++ b/ASerial.h Sun Aug 16 22:46:25 2015 +0000 @@ -13,7 +13,7 @@ #define EOLN "\r\n" // singleton serial command byte buffer -#define CMDBUFLEN 16 +#define CMDBUFLEN 64 int cbuf[CMDBUFLEN]; static int bufIn=0; static int bufOut=0; @@ -27,9 +27,9 @@ // decrements before bufIn, one hopes that the glitch will not be problematic. // indication of char in the buffer remains correce, and one hopes that by the next // time they check, both counts are accurate. - if (bufIn > 1001*CMDBUFLEN) { - bufOut -= 1000*CMDBUFLEN; - bufIn -= 1000*CMDBUFLEN; + if (bufIn > 401*CMDBUFLEN) { + bufOut -= 400*CMDBUFLEN; + bufIn -= 400*CMDBUFLEN; } } @@ -70,12 +70,13 @@ if(bufOut < bufIn) { int c = cbuf[bufOut % CMDBUFLEN]; bufOut++; - DiagSerial.printf("\r\n\t%d got %d(%c)\r\n",bufOut-1,c,c); + //DiagSerial.printf("\r\n\t%d got %d(%c)\r\n",bufOut-1,c,c); int n = bufIn-bufOut; if ((n > CMDBUFLEN-3) && (n < 800*CMDBUFLEN)) { - _serial->printf("\t\r\tCommand Buffer Overflow Warning!\r\n"); + DiagSerial.printf("\t\r\tCommand Buffer Overflow RESET!\r\n"); + bufIn=bufOut=0; } return(c); } else { return(-1); }