ryo seki
/
serialSend5
a
Diff: uart1.cpp
- Revision:
- 0:62ac378df546
- Child:
- 1:ed00e9c4ba6e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uart1.cpp Fri Apr 19 09:14:08 2013 +0000 @@ -0,0 +1,74 @@ + +#include "mbed.h" +#include "uart1.h" + +extern Serial device; +extern BusOut mbedleds; +extern int direction; +extern int Distance; +extern int IR_found; +extern uint16_t ultrasonicVal[4]; +extern int xbee; + +int data[4]; + +void dev_rx() +{ + static uint8_t count2; + static uint8_t RecData[RECEIVE_DATA_NUM]; + + RecData[count2] = device.getc(); + + //mbedleds = 2; + + if(RecData[KEY2] == KEYCODE2){ + count2++; + }else{ + count2 = 0; + } + if(count2 >= RECEIVE_DATA_NUM){ + if(RecData[CHECK2] == CHECKCODE2){ + mbedleds = 1; + data[0] = RecData[DATA1]; + data[1] = RecData[DATA2]; + data[2] = RecData[DATA3]; + data[3] = RecData[DATA4]; + if(data[0] == 25){ + mbedleds = 15; + } + } + count2 = 0; + } +} + +void dev_tx() +{ + + static uint8_t count; + static uint8_t SendData0[SEND_DATA_NUM]; + + //mbedleds = 1; + xbee = IR_found; + + if(count >= SEND_DATA_NUM){ + SendData0[KEY] = KEYCODE; + SendData0[DIRECTIONN] = direction; + SendData0[DISTANCE] = Distance; + SendData0[SONIC1_1] = ultrasonicVal[0]; + SendData0[SONIC1_2] = (ultrasonicVal[0] >> 8); + SendData0[SONIC2_1] = ultrasonicVal[1]; + SendData0[SONIC2_2] = (ultrasonicVal[1] >> 8); + SendData0[SONIC3_1] = ultrasonicVal[2]; + SendData0[SONIC3_2] = (ultrasonicVal[2] >> 8); + SendData0[SONIC4_1] = ultrasonicVal[3]; + SendData0[SONIC4_2] = (ultrasonicVal[3] >> 8); + SendData0[XBEE] = xbee; + SendData0[CHECK] = CHECKCODE; + + count = 0; + + } + device.putc(SendData0[count]); + + count++; +} \ No newline at end of file