右側のほうのセンサLPC1114FN28 fumiya版

Dependencies:   IRM2121_2 Ping mbed HMC6352 Watchdog

Fork of CatPot_SensorRight by CatPot 2015-2016

Files at this revision

API Documentation at this revision

Comitter:
ryuna
Date:
Wed Mar 11 01:03:39 2015 +0000
Parent:
15:3d27e435e014
Commit message:
without multiserial;

Changed in this revision

MultiSerial.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
usart.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 3d27e435e014 -r 83721dac1049 MultiSerial.lib
--- a/MultiSerial.lib	Tue Mar 10 13:22:22 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/teams/B/code/MultiSerial/#f2f3c3d6a6be
diff -r 3d27e435e014 -r 83721dac1049 main.cpp
--- a/main.cpp	Tue Mar 10 13:22:22 2015 +0000
+++ b/main.cpp	Wed Mar 11 01:03:39 2015 +0000
@@ -7,7 +7,6 @@
  
 #include "mbed.h"
  
-#include "MultiSerial.h"
 #include "IRM2121.h"
 #include "Ping.h"
 #include "HMC6352.h"
@@ -15,9 +14,7 @@
  
 #define PING_COUNT 5 //5回に1回にPing処理
 
-#define ADDRESS 0xAA//
-#define DATA_NUM 9
- 
+
  
 IRM2121 Ir[12] = {p5,p6,p7,p8,  p11,p12,    p15,p16,p17,p18,p19,p20};
 
@@ -29,9 +26,14 @@
 DigitalOut Led[4] = {LED1, LED2, LED3, LED4};
  
 HMC6352 hmc6352(p28,p27);
-MultiSerial Mbed(p13, p14);
+Serial Mbed(p13, p14);
 Serial pc(USBTX,USBRX);
  
+extern void micon_tx();
+uint8_t PingData[4] = {0};
+uint8_t IrData[3] = {0};
+uint8_t CompassData[2] = {0};
+    
 
 void IrSort(unsigned int input[], uint8_t output[]){
     
@@ -93,17 +95,13 @@
     uint8_t PingCk = 0;
     
     /*Data*/
-    unsigned int PingData[4] = {0};
+
     unsigned int IrBase[12] = {0};
-    uint8_t IrData[3] = {0};
-    uint8_t CompassData[2] = {0};
-    
+
     /*Serial*/
-    uint8_t tx_data[DATA_NUM]={0};
-    Mbed.write_data(tx_data, ADDRESS);
-    Mbed.start_write();
- 
     CompassDef = (hmc6352.sample() / 10);
+    Mbed.attach(&micon_tx,Serial::TxIrq);//送信空き割り込み設定
+    Mbed.putc(1);          
     while(1) {
         
         g.Service();
@@ -146,6 +144,7 @@
             CompassData[0] = Compass;
             CompassData[1] = 0;
         }
+        /*
         if(PingCk == 2){
             
             Ping1.Send();    
@@ -176,23 +175,28 @@
             
             PingCk = 0;
         }
-        
-        //ex.
-        tx_data[0] = IrData[0];
-        tx_data[1] = IrData[1];
-        tx_data[2] = IrData[2];
-        tx_data[3] = PingData[0];
-        tx_data[4] = PingData[1];
-        tx_data[5] = PingData[2];
-        tx_data[6] = PingData[3];
-        tx_data[7] = CompassData[0];
-        tx_data[8] = CompassData[1];        
-        
+        */
+        Ping1.Send();
+        Ping2.Send();
+        Ping3.Send();
+        Ping4.Send();    
+        wait_ms(30);
+        PingData[0] = Ping1.Read_cm();
+        PingData[1] = Ping2.Read_cm();
+        PingData[2] = Ping3.Read_cm();
+        PingData[3] = Ping4.Read_cm();
+        if(PingData[0]>0xFF) PingData[0]=0xFF;
+        if(PingData[1]>0xFF) PingData[1]=0xFF;
+        if(PingData[2]>0xFF) PingData[2]=0xFF;
+        if(PingData[3]>0xFF) PingData[3]=0xFF;
+            
         
         
         Led[0] = 0;//周回の終わり
         
         wait_ms(1);
+        
+    //pc.printf("%d %d %d %d \n", PingData[0],PingData[1],PingData[2],PingData[3]);
         //pc.printf("%d\t %d\t %d\t %d\t %d\t %d\t\n",tx_data[3],tx_data[4],tx_data[5],tx_data[6],tx_data[7],tx_data[8]);
         
         
diff -r 3d27e435e014 -r 83721dac1049 usart.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/usart.cpp	Wed Mar 11 01:03:39 2015 +0000
@@ -0,0 +1,64 @@
+#include "mbed.h"
+
+#define KEYCODE 0xAA
+#define TX_CHECKCODE (tx_data[1]^tx_data[2]^tx_data[3]^tx_data[4]^tx_data[5]^tx_data[6]^tx_data[7]^tx_data[8]^tx_data[9])
+#define RX_CHECKCODE (rx_data[1]^rx_data[2]^rx_data[3]^rx_data[4]^rx_data[5]^rx_data[6]^rx_data[7]^rx_data[8]^rx_data[9])
+#define DATA_NUM 11
+#define CHECK (DATA_NUM - 1)
+
+
+extern Serial Mbed;
+extern Serial pc;
+extern uint8_t PingData[4];
+extern uint8_t IrData[3];
+extern uint8_t CompassData[2];
+/*
+void micon_rx(){
+    
+    static uint8_t rx;
+    static uint8_t rx_data[DATA_NUM];
+    
+    rx_data[rx] = sensor.getc();
+    
+    if(rx_data[0] == KEYCODE){
+        rx++;
+    }
+    
+    if(rx >= DATA_NUM){
+        if(rx_data[CHECK] == RX_CHECKCODE){
+             pc.printf("%d %d %d %d %d\n", rx_data[1], rx_data[2], rx_data[3], rx_data[4], rx_data[5]);
+        }  
+     rx = 0;   
+    }
+
+}
+*/
+void micon_tx(){
+    
+    static uint8_t tx;
+    static uint8_t tx_data[DATA_NUM];
+    
+    if(tx >= DATA_NUM){
+        
+        tx_data[0] = KEYCODE;
+        tx_data[1] = IrData[0];
+        tx_data[2] = IrData[1];
+        tx_data[3] = IrData[2];
+        tx_data[4] = PingData[0];
+        tx_data[5] = PingData[1];
+        tx_data[6] = PingData[2];
+        tx_data[7] = PingData[3];
+        tx_data[8] = CompassData[0];
+        tx_data[9] = CompassData[1];
+        tx_data[10] = TX_CHECKCODE;
+        
+        tx = 0;
+        
+    //pc.printf("%d %d %d %d\n",PingData[0],PingData[1],PingData[2],PingData[3]);
+    }
+    
+    
+    Mbed.putc(tx_data[tx]);
+    tx++;
+    //wait(0.1);
+}
\ No newline at end of file