![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Export for Dan
Diff: main.cpp
- Revision:
- 1:66e3217ec4ec
- Parent:
- 0:4b4c18724370
- Child:
- 2:d6cadd28a68e
--- a/main.cpp Thu Oct 22 23:08:05 2015 +0000 +++ b/main.cpp Tue Oct 27 17:39:06 2015 +0000 @@ -3,7 +3,7 @@ #include "mbed.h" #include "MODSERIAL.h" -#define MESSAGE_BUFFER_SIZE 32 +#define MESSAGE_BUFFER_SIZE 100 DigitalOut led1(LED1); DigitalOut led2(LED2); @@ -14,34 +14,42 @@ char messageBufferIncoming[MESSAGE_BUFFER_SIZE]; char messageBufferOutgoing[MESSAGE_BUFFER_SIZE]; +int count = 0; +int i = 0; bool messageReceived; + void messageReceive(MODSERIAL_IRQ_INFO *q) { + // Get the pointer to MODSERIAL object that invoked this callback. MODSERIAL *sys = q->serial; - sys->move(messageBufferIncoming, MESSAGE_BUFFER_SIZE); - messageReceived = true; + char c = sys->rxGetLastChar(); // Where local pc variable is a pointer to the global MODSERIAL pc object. + //add char c to messageBufferIncoming + if(i <=MESSAGE_BUFFER_SIZE){ + messageBufferIncoming[i] = c; + i++; + // led3 = !led3; + } + count++; + if (count == 8){ + //led4 = !led4; + // + if (!strncmp(messageBufferIncoming, "AA", sizeof("AA")-1)) led2 = !led2; + //else if (!strncmp(messageBufferIncoming, "BB", sizeof("BB")-1)) led3 = !led3; + memset(messageBufferIncoming, '\0', sizeof(messageBufferIncoming)); + i = 0; + messageReceived = true; + count = 0; + } return; } -void messageProcess(void) { +void messageProcess(void) { led1 = !led1; - - if (!strncmp(messageBufferIncoming, "LED1:1", sizeof("LED1:1")-1)) led1 = !led1; - else if (!strncmp(messageBufferIncoming, "LED1:0", sizeof("LED1:0")-1)) led1 = 0; - else if (!strncmp(messageBufferIncoming, "LED1:2", sizeof("LED1:2")-1)) led1 = !led1; - - else if (!strncmp(messageBufferIncoming, "LED2:1", sizeof("LED2:1")-1)) led2 = 1; - else if (!strncmp(messageBufferIncoming, "LED2:0", sizeof("LED2:0")-1)) led2 = 0; - else if (!strncmp(messageBufferIncoming, "LED2:2", sizeof("LED2:2")-1)) led2 = !led2; - - else if (!strncmp(messageBufferIncoming, "LED3:1", sizeof("LED3:1")-1)) led3 = 1; - else if (!strncmp(messageBufferIncoming, "LED3:0", sizeof("LED3:0")-1)) led3 = 0; - else if (!strncmp(messageBufferIncoming, "LED3:2", sizeof("LED3:2")-1)) led3 = !led3; - - else if (!strncmp(messageBufferIncoming, "LED4:1", sizeof("LED4:1")-1)) led4 = 1; - else if (!strncmp(messageBufferIncoming, "LED4:0", sizeof("LED4:0")-1)) led4 = 0; - else if (!strncmp(messageBufferIncoming, "LED4:2", sizeof("LED4:2")-1)) led4 = !led4; - + // if (!strncmp(messageBufferIncoming, "AA", sizeof("AA")-1)) led2 = !led2; //it's comparing the last character enetered + //else if (!strncmp(messageBufferIncoming, "BB", sizeof("BB")-1)) led3 = !led3; + //else led4 = !led4; + //else if (!strncmp(messageBufferIncoming, "CC33FF00", sizeof("CC33FF00")-1)) led4 = !led4; + //else if (!strncmp(messageBufferIncoming, "DD22FF00", sizeof("DD22FF00")-1)) led4 = !led4; messageReceived = false; } @@ -49,10 +57,11 @@ int main() { messageReceived = false; + memset(messageBufferIncoming, '\0', sizeof(messageBufferIncoming)); messageSystem.baud(9600); - messageSystem.attach(&messageReceive, MODSERIAL::RxAutoDetect); - messageSystem.autoDetectChar('f'); - + messageSystem.attach(&messageReceive, MODSERIAL::RxIrq); + //messageSystem.autoDetectChar('f'); + // Fix Mbed library bug, see http://mbed.org/forum/bugs-suggestions/topic/1498 LPC_GPIOINT->IO2IntClr = (1UL << 5) | (1UL << 4) | (1UL << 3) | (1UL << 2); \ @@ -62,6 +71,7 @@ // messageSystem.putc(messageSystem.getc()); //} // Process incoming messages. + if (messageReceived) { // led1 = !led1;