sensor

Dependencies:   HMC6352 mbed

Fork of program_SensorBlock by Fumiya Fujisawa

Committer:
ryuna
Date:
Mon Feb 24 07:05:48 2014 +0000
Revision:
3:7de2c50339bd
Parent:
1:3ecb80796a7f
Child:
6:97015325107b
program version.2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ryuna 1:3ecb80796a7f 1 #include "mbed.h"
ryuna 1:3ecb80796a7f 2
ryuna 1:3ecb80796a7f 3 #define KEYCODE 0xAA
ryuna 1:3ecb80796a7f 4 #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]^tx_data[10])
ryuna 1:3ecb80796a7f 5 #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]^rx_data[10])
ryuna 3:7de2c50339bd 6 #define DATA_NUM 14
ryuna 1:3ecb80796a7f 7 #define CHECK (DATA_NUM - 1)
ryuna 1:3ecb80796a7f 8 #define ALL_IR 10
ryuna 1:3ecb80796a7f 9 #define ALL_PING 4
ryuna 1:3ecb80796a7f 10 #define ALL_LINE 4
ryuna 1:3ecb80796a7f 11
ryuna 1:3ecb80796a7f 12
ryuna 1:3ecb80796a7f 13
ryuna 1:3ecb80796a7f 14 extern Serial sensor;
ryuna 1:3ecb80796a7f 15 extern Serial pc;
ryuna 1:3ecb80796a7f 16 extern unsigned int value_ping[ALL_PING];
ryuna 1:3ecb80796a7f 17 extern unsigned int value_ir[ALL_IR];
ryuna 1:3ecb80796a7f 18 extern unsigned int value_ir_min;
ryuna 1:3ecb80796a7f 19 extern unsigned int ir_min_num;
ryuna 1:3ecb80796a7f 20 extern unsigned int value_line[ALL_LINE];
ryuna 3:7de2c50339bd 21 extern unsigned int value_compass[2];
ryuna 1:3ecb80796a7f 22 void micon_rx(){
ryuna 1:3ecb80796a7f 23
ryuna 1:3ecb80796a7f 24 static uint8_t rx;
ryuna 1:3ecb80796a7f 25 static uint8_t rx_data[DATA_NUM];
ryuna 1:3ecb80796a7f 26
ryuna 1:3ecb80796a7f 27 rx_data[rx] = sensor.getc();
ryuna 1:3ecb80796a7f 28
ryuna 1:3ecb80796a7f 29 if(rx_data[0] == KEYCODE){
ryuna 1:3ecb80796a7f 30 rx++;
ryuna 1:3ecb80796a7f 31 }
ryuna 1:3ecb80796a7f 32
ryuna 1:3ecb80796a7f 33 if(rx >= DATA_NUM){
ryuna 1:3ecb80796a7f 34 if(rx_data[CHECK] == RX_CHECKCODE){
ryuna 1:3ecb80796a7f 35 pc.printf("%d %d %d %d %d\n", rx_data[1], rx_data[2], rx_data[3], rx_data[4], rx_data[5]);
ryuna 1:3ecb80796a7f 36 }
ryuna 1:3ecb80796a7f 37 rx = 0;
ryuna 1:3ecb80796a7f 38 }
ryuna 1:3ecb80796a7f 39
ryuna 1:3ecb80796a7f 40 }
ryuna 1:3ecb80796a7f 41
ryuna 1:3ecb80796a7f 42 void micon_tx(){
ryuna 1:3ecb80796a7f 43
ryuna 1:3ecb80796a7f 44 static uint8_t tx;
ryuna 1:3ecb80796a7f 45 static uint8_t tx_data[DATA_NUM];
ryuna 1:3ecb80796a7f 46
ryuna 1:3ecb80796a7f 47 if(tx >= DATA_NUM){
ryuna 1:3ecb80796a7f 48 tx_data[0] = KEYCODE;
ryuna 1:3ecb80796a7f 49 tx_data[1] = value_ir_min;
ryuna 1:3ecb80796a7f 50 tx_data[2] = ir_min_num;
ryuna 1:3ecb80796a7f 51 tx_data[3] = value_ping[0];
ryuna 1:3ecb80796a7f 52 tx_data[4] = value_ping[1];
ryuna 1:3ecb80796a7f 53 tx_data[5] = value_ping[2];
ryuna 1:3ecb80796a7f 54 tx_data[6] = value_ping[3];
ryuna 1:3ecb80796a7f 55 tx_data[7] = value_line[0];
ryuna 1:3ecb80796a7f 56 tx_data[8] = value_line[1];
ryuna 1:3ecb80796a7f 57 tx_data[9] = value_line[2];
ryuna 1:3ecb80796a7f 58 tx_data[10] = value_line[3];
ryuna 3:7de2c50339bd 59 tx_data[11] = value_compass[0];
ryuna 3:7de2c50339bd 60 tx_data[12] = value_compass[1];
ryuna 3:7de2c50339bd 61 tx_data[13] = TX_CHECKCODE;
ryuna 1:3ecb80796a7f 62
ryuna 1:3ecb80796a7f 63 tx = 0;
ryuna 1:3ecb80796a7f 64 }
ryuna 1:3ecb80796a7f 65
ryuna 1:3ecb80796a7f 66
ryuna 1:3ecb80796a7f 67 sensor.putc(tx_data[tx]);
ryuna 1:3ecb80796a7f 68 //pc.printf("%d\n", tx_data[tx]);
ryuna 1:3ecb80796a7f 69 tx++;
ryuna 1:3ecb80796a7f 70 //wait(0.1);
ryuna 1:3ecb80796a7f 71 }