asdf

Dependencies:   NokiaLCD XMIT_IR mbed

Fork of 4180_mP_WirelessPong_revC by Curtis Mulady

Revision:
17:f92e4a384637
Parent:
16:bc0e213ba52d
Child:
18:98839f78fc01
--- a/main.cpp	Sat Oct 06 12:52:35 2012 +0000
+++ b/main.cpp	Sat Oct 06 13:40:39 2012 +0000
@@ -49,6 +49,7 @@
 Thread* threadptr_irstuff;
 char packet_buff[10];
 Mail<char,64> rx_data_mailbox;
+Mutex data_update_mutex;
 
 
 
@@ -93,6 +94,17 @@
 
         //Start flash LED
         led2 = 0.02;
+        data_update_mutex.lock();
+        char irdatbuff[4];
+        for(int i=0; i<4; i++) irdatbuff[i] = irdatIN[i];
+        data_update_mutex.unlock();
+
+        if(irdatbuff[0]!=0xA5 && irdatbuff[0]!=0x00) {
+            lcd.locate(0,7);
+            lcd.printf("Big Problem!  0x%02X",irdatbuff[0]);
+            while(1);
+        }
+
 
         //Write debug text to screen
         lcd.locate(0,1);
@@ -104,7 +116,7 @@
         lcd.locate(0,4);
         lcd.printf("IR_OUT=0x%02X,0x%02X", irdatOUT[0],irdatOUT[1]);
         lcd.locate(0,5);
-        lcd.printf("IR_IN= 0x%02X,0x%02X", irdatIN[0],irdatIN[1]);
+        lcd.printf("IR_IN= 0x%02X,0x%02X", irdatbuff[0],irdatbuff[1]);
         lcd.locate(0,6);
         lcd.printf("Error= 0x%02X", error_code);
 
@@ -120,34 +132,21 @@
     while(true) {
 
         //If data available - Print data directly to USB port (for debug)
-        /*osEvent evt = rx_data_mailbox.get();
-        while(evt.status == osEventMail) {
-            char* mail = (char*)evt.value.p;
-            //if((*mail)==0x02) pc.printf("\n");
-            //pc.printf("0x%02X.",*mail);
-            error_code = CheckPacket(*mail,packet_buff,irdatIN,4);
-            pc.printf("    ERROR=0x%02X.\n",error_code);
-
-            rx_data_mailbox.free(mail);
-            evt = rx_data_mailbox.get();
-        }*/
-
-        /*osEvent evt = ir_tx.ir_data_mailbox.get();
-        while(evt.status == osEventMail) {
-            char* mail = (char*)evt.value.p;
-            //if((*mail)==0x02) pc.printf("\n");
-            //pc.printf("0x%02X.",*mail);
-            //error_code = CheckPacket(*mail,packet_buff,irdatIN,4);
-            //pc.printf("    ERROR=0x%02X.\n",error_code);
-
-            ir_tx.ir_data_mailbox.free(mail);
-            evt = ir_tx.ir_data_mailbox.get();
-        }*/
 
         char result;
-        result = ir_tx.ReadPacket(irdatIN,4);
+        char temp_buff[4];
+        
+        //buffer data into temp register
+        result = ir_tx.ReadPacket(temp_buff,4);
+
         if(result == 0x1) {
             pc.printf("\n");
+            //update data - mutex
+            data_update_mutex.lock();
+            for(int i=0; i<4; i++) {
+                irdatIN[i] = temp_buff[i];
+            }
+            data_update_mutex.unlock();
             for(int i=0; i<4; i++) {
                 pc.printf("0x%02X.",irdatIN[i]);
             }