sensor

Dependencies:   HMC6352 mbed

Fork of program_SensorBlock by Fumiya Fujisawa

Committer:
com3
Date:
Sat Mar 08 13:16:25 2014 +0000
Revision:
6:97015325107b
Parent:
3:7de2c50339bd
sensors

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
com3 6:97015325107b 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])
com3 6:97015325107b 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])
com3 6:97015325107b 6 #define DATA_NUM 12
ryuna 1:3ecb80796a7f 7 #define CHECK (DATA_NUM - 1)
com3 6:97015325107b 8 #define ALL_IR 12
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];
com3 6:97015325107b 22 /*
ryuna 1:3ecb80796a7f 23 void micon_rx(){
ryuna 1:3ecb80796a7f 24
ryuna 1:3ecb80796a7f 25 static uint8_t rx;
ryuna 1:3ecb80796a7f 26 static uint8_t rx_data[DATA_NUM];
ryuna 1:3ecb80796a7f 27
ryuna 1:3ecb80796a7f 28 rx_data[rx] = sensor.getc();
ryuna 1:3ecb80796a7f 29
ryuna 1:3ecb80796a7f 30 if(rx_data[0] == KEYCODE){
ryuna 1:3ecb80796a7f 31 rx++;
ryuna 1:3ecb80796a7f 32 }
ryuna 1:3ecb80796a7f 33
ryuna 1:3ecb80796a7f 34 if(rx >= DATA_NUM){
ryuna 1:3ecb80796a7f 35 if(rx_data[CHECK] == RX_CHECKCODE){
ryuna 1:3ecb80796a7f 36 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 37 }
ryuna 1:3ecb80796a7f 38 rx = 0;
ryuna 1:3ecb80796a7f 39 }
ryuna 1:3ecb80796a7f 40
ryuna 1:3ecb80796a7f 41 }
com3 6:97015325107b 42 */
ryuna 1:3ecb80796a7f 43
ryuna 1:3ecb80796a7f 44 void micon_tx(){
ryuna 1:3ecb80796a7f 45
ryuna 1:3ecb80796a7f 46 static uint8_t tx;
ryuna 1:3ecb80796a7f 47 static uint8_t tx_data[DATA_NUM];
ryuna 1:3ecb80796a7f 48
ryuna 1:3ecb80796a7f 49 if(tx >= DATA_NUM){
ryuna 1:3ecb80796a7f 50 tx_data[0] = KEYCODE;
ryuna 1:3ecb80796a7f 51 tx_data[1] = value_ir_min;
ryuna 1:3ecb80796a7f 52 tx_data[2] = ir_min_num;
ryuna 1:3ecb80796a7f 53 tx_data[3] = value_ping[0];
ryuna 1:3ecb80796a7f 54 tx_data[4] = value_ping[1];
ryuna 1:3ecb80796a7f 55 tx_data[5] = value_ping[2];
ryuna 1:3ecb80796a7f 56 tx_data[6] = value_ping[3];
com3 6:97015325107b 57 /* tx_data[7] = value_line[0];
ryuna 1:3ecb80796a7f 58 tx_data[8] = value_line[1];
ryuna 1:3ecb80796a7f 59 tx_data[9] = value_line[2];
ryuna 1:3ecb80796a7f 60 tx_data[10] = value_line[3];
com3 6:97015325107b 61 */
com3 6:97015325107b 62 tx_data[7] = value_compass[0];
com3 6:97015325107b 63 tx_data[8] = value_compass[1];
com3 6:97015325107b 64 tx_data[9] = value_ir[10];
com3 6:97015325107b 65 tx_data[10] = value_ir[11];
com3 6:97015325107b 66 tx_data[11] = TX_CHECKCODE;
ryuna 1:3ecb80796a7f 67
ryuna 1:3ecb80796a7f 68 tx = 0;
ryuna 1:3ecb80796a7f 69 }
ryuna 1:3ecb80796a7f 70
ryuna 1:3ecb80796a7f 71
ryuna 1:3ecb80796a7f 72 sensor.putc(tx_data[tx]);
ryuna 1:3ecb80796a7f 73 //pc.printf("%d\n", tx_data[tx]);
ryuna 1:3ecb80796a7f 74 tx++;
ryuna 1:3ecb80796a7f 75 //wait(0.1);
ryuna 1:3ecb80796a7f 76 }