a

Dependencies:   HMC6352 PID mbed

Committer:
akudohune
Date:
Fri Apr 19 09:13:32 2013 +0000
Revision:
0:8215f0743d86
to yusuke

Who changed what in which revision?

UserRevisionLine numberNew contents of line
akudohune 0:8215f0743d86 1
akudohune 0:8215f0743d86 2 #include "mbed.h"
akudohune 0:8215f0743d86 3 #include "uart1.h"
akudohune 0:8215f0743d86 4 #include "HMC6352.h"
akudohune 0:8215f0743d86 5
akudohune 0:8215f0743d86 6 extern Serial device2;
akudohune 0:8215f0743d86 7 extern HMC6352 compass;
akudohune 0:8215f0743d86 8
akudohune 0:8215f0743d86 9 extern uint8_t state;
akudohune 0:8215f0743d86 10
akudohune 0:8215f0743d86 11 float ultrasonicVal[4];
akudohune 0:8215f0743d86 12 uint8_t direction;
akudohune 0:8215f0743d86 13 uint8_t Distance;
akudohune 0:8215f0743d86 14 uint8_t IR_found;
akudohune 0:8215f0743d86 15 uint8_t xbee;
akudohune 0:8215f0743d86 16
akudohune 0:8215f0743d86 17 void dev_rx()
akudohune 0:8215f0743d86 18 {
akudohune 0:8215f0743d86 19 static uint8_t count;
akudohune 0:8215f0743d86 20 static uint8_t RecData[RECEIVE_DATA_NUM];
akudohune 0:8215f0743d86 21
akudohune 0:8215f0743d86 22 RecData[count] = device2.getc();
akudohune 0:8215f0743d86 23
akudohune 0:8215f0743d86 24 if(RecData[KEY] == KEYCODE){
akudohune 0:8215f0743d86 25 count++;
akudohune 0:8215f0743d86 26 }else{
akudohune 0:8215f0743d86 27 count = 0;
akudohune 0:8215f0743d86 28 }
akudohune 0:8215f0743d86 29 if(count >= RECEIVE_DATA_NUM){
akudohune 0:8215f0743d86 30 if(RecData[CHECK] == CHECKCODE){
akudohune 0:8215f0743d86 31 //mbedleds = 1;
akudohune 0:8215f0743d86 32 direction = RecData[DIRECTION];
akudohune 0:8215f0743d86 33 Distance = RecData[DISTANCE];
akudohune 0:8215f0743d86 34 ultrasonicVal[0] = (RecData[SONIC1_1] + (RecData[SONIC1_2] << 8)) / 10.0;
akudohune 0:8215f0743d86 35 ultrasonicVal[1] = (RecData[SONIC2_1] + (RecData[SONIC2_2] << 8)) / 10.0;
akudohune 0:8215f0743d86 36 ultrasonicVal[2] = (RecData[SONIC3_1] + (RecData[SONIC3_2] << 8)) / 10.0;
akudohune 0:8215f0743d86 37 ultrasonicVal[3] = (RecData[SONIC4_1] + (RecData[SONIC4_2] << 8)) / 10.0;
akudohune 0:8215f0743d86 38 xbee = RecData[XBEE];
akudohune 0:8215f0743d86 39 IR_found = xbee;
akudohune 0:8215f0743d86 40 }
akudohune 0:8215f0743d86 41 count = 0;
akudohune 0:8215f0743d86 42 }
akudohune 0:8215f0743d86 43 }
akudohune 0:8215f0743d86 44
akudohune 0:8215f0743d86 45 void dev_tx()
akudohune 0:8215f0743d86 46 {
akudohune 0:8215f0743d86 47 static uint8_t count2;
akudohune 0:8215f0743d86 48 static uint8_t SendData[SEND_DATA_NUM];
akudohune 0:8215f0743d86 49
akudohune 0:8215f0743d86 50 //mbedleds = 2;
akudohune 0:8215f0743d86 51
akudohune 0:8215f0743d86 52 if(count2 >= SEND_DATA_NUM){
akudohune 0:8215f0743d86 53 SendData[KEY2] = KEYCODE2;
akudohune 0:8215f0743d86 54 SendData[DATA1] = ((int)(compass.sample())) >> 8 ;
akudohune 0:8215f0743d86 55 SendData[DATA2] = (int)(compass.sample());
akudohune 0:8215f0743d86 56 SendData[DATA3] = state;
akudohune 0:8215f0743d86 57 SendData[DATA4] = 1;
akudohune 0:8215f0743d86 58 SendData[CHECK2] = CHECKCODE2;
akudohune 0:8215f0743d86 59
akudohune 0:8215f0743d86 60 count2 = 0;
akudohune 0:8215f0743d86 61
akudohune 0:8215f0743d86 62 }
akudohune 0:8215f0743d86 63 device2.putc(SendData[count2]);
akudohune 0:8215f0743d86 64
akudohune 0:8215f0743d86 65 count2++;
akudohune 0:8215f0743d86 66 }