![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
aa
Dependencies: HMC6352 PID mbed
Diff: uart1.cpp
- Revision:
- 0:e9b97faa3e37
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uart1.cpp Mon Jun 17 00:12:40 2013 +0000 @@ -0,0 +1,108 @@ + +#include "mbed.h" +#include "uart1.h" +#include "HMC6352.h" + +//extern Serial pc; +extern Serial device2; +extern HMC6352 compass; +extern BusOut mbedleds; +extern DigitalOut led1; +extern DigitalOut led2; +extern DigitalOut led3; +extern DigitalOut led4; + +extern uint8_t state; +extern uint8_t hold_flag; + +int diff; +uint16_t ultrasonicVal[4]; +uint8_t direction; +uint8_t Distance; +uint8_t IR_found; +uint8_t xbee; +int irDistance[6] = {0,3,5,99,33,11}; + +void dev_rx() +{ + static uint8_t count = 0; + static uint8_t RecData[RECEIVE_DATA_NUM]; + static uint8_t last_data; + + RecData[count] = device2.getc(); + + if(RecData[KEY] == KEYCODE){ + count++; + }else{ + count = 0; + } + if(count >= RECEIVE_DATA_NUM){ + if(RecData[CHECK] == CHECKCODE){ + //mbedleds = 15; + + if((RecData[DIRECTION] <= 15) || (RecData[DIRECTION] == 200)){ + direction = RecData[DIRECTION]; + } + if(RecData[DISTANCE] <= 180){ + Distance = RecData[DISTANCE]; + } + + ultrasonicVal[0] = (int)((RecData[SONIC1_1] + (RecData[SONIC1_2] << 8)) / 10.0); + if(ultrasonicVal[0] == 6553)ultrasonicVal[0] = 0xFFFF; + ultrasonicVal[1] = (int)((RecData[SONIC2_1] + (RecData[SONIC2_2] << 8)) / 10.0); + if(ultrasonicVal[1] == 6553)ultrasonicVal[1] = 0xFFFF; + ultrasonicVal[2] = (int)((RecData[SONIC3_1] + (RecData[SONIC3_2] << 8)) / 10.0); + if(ultrasonicVal[2] == 6553)ultrasonicVal[2] = 0xFFFF; + ultrasonicVal[3] = (int)((RecData[SONIC4_1] + (RecData[SONIC4_2] << 8)) / 10.0); + if(ultrasonicVal[3] == 6553)ultrasonicVal[3] = 0xFFFF; + + if((RecData[IR_FOUND] == 0) || (RecData[IR_FOUND] == 1)){ + IR_found = RecData[IR_FOUND]; + } + xbee = RecData[XBEE]; + xbee = 0; + + + //pc.printf("%f\t%f\t%f\t%f\n",ultrasonicVal[0],ultrasonicVal[1],ultrasonicVal[2],ultrasonicVal[3]); + //pc.printf("%d\n",xbee); + //pc.printf("%d\n",IR_found); + + diff = last_data - Distance; + last_data = Distance; + } + count = 0; + } +} + +void dev_tx() +{ + static uint8_t count2 = 0; + static uint8_t SendData[SEND_DATA_NUM]; + + if(count2 >= SEND_DATA_NUM){ + SendData[KEY2] = KEYCODE2; + SendData[DATA1] = ((int)(compass.sample())) >> 8 ; + SendData[DATA2] = (int)(compass.sample()); + SendData[DATA3] = state; + SendData[DATA4] = 1; + SendData[DISTANCE1] = irDistance[0] >> 8; + SendData[DISTANCE1_2] = irDistance[0]; + SendData[DISTANCE2] = irDistance[1] >> 8; + SendData[DISTANCE2_2] = irDistance[1]; + SendData[DISTANCE3] = irDistance[2] >> 8; + SendData[DISTANCE3_2] = irDistance[2]; + SendData[DISTANCE4] = irDistance[3] >> 8; + SendData[DISTANCE4_2] = irDistance[3]; + SendData[DISTANCE5] = irDistance[4] >> 8; + SendData[DISTANCE5_2] = irDistance[4]; + SendData[DISTANCE6] = irDistance[5] >> 8; + SendData[DISTANCE6_2] = irDistance[5]; + SendData[CHECK2] = CHECKCODE2; + + count2 = 0; + + } + device2.putc(SendData[count2]); + + count2++; +} \ No newline at end of file