Export for Dan

Dependencies:   MODSERIAL mbed

Files at this revision

API Documentation at this revision

Comitter:
atravieso
Date:
Thu Apr 14 18:57:43 2016 +0000
Parent:
0:6861a3fd2ef0
Commit message:
Serial Bridge for the Compass. Works using the MC output on the SIB.

Changed in this revision

DC-4E.cpp Show annotated file Show diff for this revision Revisions of this file
MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
--- a/DC-4E.cpp	Tue Nov 03 22:17:02 2015 +0000
+++ b/DC-4E.cpp	Thu Apr 14 18:57:43 2016 +0000
@@ -10,106 +10,29 @@
 DigitalOut led3(LED3);
 DigitalOut led4(LED4);
 
-MODSERIAL Compass (p9, p10);
-
-MODSERIAL messageSystem(p13, p14);
-
-unsigned char messageBufferIncoming[MESSAGE_BUFFER_SIZE];
-unsigned int hexBufferIncoming[MESSAGE_BUFFER_SIZE];
-unsigned char messageBufferOutgoing[MESSAGE_BUFFER_SIZE];
-unsigned int compassMessage[3];
-int count = 0;
-int i = 0;
-bool messageReceived;
+Serial Compass (p9, p10);
+Serial pc (p13, p14);
 
 
-void messageReceive(MODSERIAL_IRQ_INFO *q) {
-    // Get the pointer to MODSERIAL object that invoked this callback.
-    led1 = !led1;
-    MODSERIAL *sys = q->serial;
-    
-    //dereference rxGetLasChar() of sys object 
-    unsigned int c = sys->rxGetLastChar(); // Returns the last byte to pass through the RX interrupt handler.
+main(){
+    Compass.baud(9600);
+    pc.baud(9600);
+  
+  while(1){
+    led3 = !led3;
+    wait(0.2);
+
+    if(pc.readable()){
+      led2=!led2;
+      Compass.putc(pc.getc());
+    }
+      
+    if(Compass.readable()){
+      led1 = !led1;
+      pc.putc(Compass.getc());
+    }
     
-    //add the character that triggered the interrupt to the incoming buffers
-    //I'm adding to an in buffer and a char buffer, but using the int buffer to determine which message it is
-        //if I want to use the char buffer to determine, then I need to use strcmp instead of =
-    if(i <=MESSAGE_BUFFER_SIZE){
-        messageBufferIncoming[i] = c;
-        hexBufferIncoming[i] = c;
-        messageSystem.printf("%x", hexBufferIncoming[i]);
-        i++;
-        }     
-    count++;
-   
-  /*if (count == 3){ //send to compass and read the compasses response
-       led3 = !led3;
-            if (hexBufferIncoming[0] == 0xA4){              //Start Calibration
-                if (hexBufferIncoming[1] == 0x01){
-                    if (hexBufferIncoming[2] == 0xA0){
-                            led1 = !led1;
-                            messageSystem.printf("%c", hexBufferIncoming[0]);              
-                            messageSystem.printf("%c", hexBufferIncoming[1]);
-                            messageSystem.printf("%c", hexBufferIncoming[2]);
-                            
-                        
-                        }
-                    }
-               }
-           }
-         
-       */
-         
-             
-         memset(messageBufferIncoming, '\0', sizeof(messageBufferIncoming));
-         memset(hexBufferIncoming, '\0', sizeof(hexBufferIncoming));
-         memset(messageBufferOutgoing, '\0', sizeof(messageBufferOutgoing));
-         i = 0;
-         messageReceived = true;
-         count = 0;
-         //} //end of if count == 4
-
-
-    return;
-}
-
-void messageProcess(void) { 
-     //  led1 = !led1;
-    messageReceived = false;
-}
-
-
-
-
-
-int main() {
-
-    messageReceived = false;
-    memset(messageBufferIncoming, '\0', sizeof(messageBufferIncoming));
-    memset(hexBufferIncoming, '\0', sizeof(hexBufferIncoming));
-    memset(messageBufferOutgoing, '\0', sizeof(messageBufferOutgoing));
-    messageSystem.baud(9600);
-    Compass.attach(&messageReceive, MODSERIAL::RxIrq); //Attach a C++ type object/method pointer as the callback.
-    
-
-   
-    // Fix Mbed library bug, see http://mbed.org/forum/bugs-suggestions/topic/1498
-    LPC_GPIOINT->IO2IntClr = (1UL << 5) | (1UL << 4) | (1UL << 3) | (1UL << 2); 
- \
-    while(1) {
-        //led1 = !led1;
-        wait(.05);
-        compassMessage[0] = 0xA3;
-      //  compassMessage[1] = 0x02;
-        compassMessage[2] = 0xA1;
-        Compass.printf("%x", compassMessage[0]);
-        Compass.printf("%x", compassMessage[1]);
-        Compass.printf("%x", compassMessage[2]);
-    
-        if (messageReceived)
-        {
-        //led2 = !led2;
-        messageProcess();
-         }
-    }
-}
+  }//while(1)
+           
+}//main    
+        
\ No newline at end of file
--- a/MODSERIAL.lib	Tue Nov 03 22:17:02 2015 +0000
+++ b/MODSERIAL.lib	Thu Apr 14 18:57:43 2016 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/AjK/code/MODSERIAL/#b59e9b91374d
+https://developer.mbed.org/users/atravieso/code/MODSERIAL/#b59e9b91374d