ryo seki
/
serialSend5
a
Diff: uart1.cpp
- Revision:
- 1:ed00e9c4ba6e
- Parent:
- 0:62ac378df546
--- a/uart1.cpp Fri Apr 19 09:14:08 2013 +0000 +++ b/uart1.cpp Tue Apr 30 09:06:57 2013 +0000 @@ -3,39 +3,43 @@ #include "uart1.h" extern Serial device; -extern BusOut mbedleds; +extern BusOut mbedleds; +//extern Serial pc; extern int direction; extern int Distance; extern int IR_found; +extern int AveDistance; extern uint16_t ultrasonicVal[4]; -extern int xbee; -int data[4]; +uint8_t xbee; +uint8_t data[4]; + +extern uint8_t data2[5]; void dev_rx() { - static uint8_t count2; + static uint8_t count2 = 0; static uint8_t RecData[RECEIVE_DATA_NUM]; + + RecData[count2] = device.getc(); - //mbedleds = 2; + if(RecData[KEY2] == KEYCODE2){ - if(RecData[KEY2] == KEYCODE2){ count2++; }else{ count2 = 0; } if(count2 >= RECEIVE_DATA_NUM){ if(RecData[CHECK2] == CHECKCODE2){ - mbedleds = 1; + //pc.printf("a"); + //mbedleds = 15; data[0] = RecData[DATA1]; data[1] = RecData[DATA2]; data[2] = RecData[DATA3]; data[3] = RecData[DATA4]; - if(data[0] == 25){ - mbedleds = 15; - } + //pc.printf("%d\n",data[2]); } count2 = 0; } @@ -43,17 +47,14 @@ void dev_tx() { - - static uint8_t count; + static uint8_t count = 0; static uint8_t SendData0[SEND_DATA_NUM]; - //mbedleds = 1; - xbee = IR_found; - if(count >= SEND_DATA_NUM){ + xbee = data2[0]; SendData0[KEY] = KEYCODE; SendData0[DIRECTIONN] = direction; - SendData0[DISTANCE] = Distance; + SendData0[DISTANCE] = AveDistance; SendData0[SONIC1_1] = ultrasonicVal[0]; SendData0[SONIC1_2] = (ultrasonicVal[0] >> 8); SendData0[SONIC2_1] = ultrasonicVal[1]; @@ -62,11 +63,13 @@ SendData0[SONIC3_2] = (ultrasonicVal[2] >> 8); SendData0[SONIC4_1] = ultrasonicVal[3]; SendData0[SONIC4_2] = (ultrasonicVal[3] >> 8); + SendData0[IR_FOUND] = IR_found; SendData0[XBEE] = xbee; SendData0[CHECK] = CHECKCODE; + //pc.printf("%d\t%d\t%d\t%d\n",SendData0[DIRECTIONN],SendData0[DISTANCE],SendData0[IR_FOUND],SendData0[CHECK]); + count = 0; - } device.putc(SendData0[count]);