LPC824専用プログラム
Dependencies: Ping SDFileSystem mbed-src
Diff: format.cpp
- Revision:
- 12:c90a124169e6
- Parent:
- 11:a5023f22f25a
- Child:
- 13:938a2dda0626
--- a/format.cpp Tue Jan 26 15:03:56 2016 +0000 +++ b/format.cpp Sat Jan 30 08:44:10 2016 +0000 @@ -123,8 +123,8 @@ rear_dis = rear.Read_cm(); if(rear_dis>0xFE) rear_dis=0xFE; led[0]=0; - wait_us(100); - pc.printf("%d\t%d\t\r\n", front_dis, rear_dis); + wait_us(1000); + //pc.printf("%d\t%d\t\r\n", front_dis, rear_dis); //emergency(); } @@ -157,7 +157,7 @@ #ifdef IR_SENSOR uint8_t ir_notice=0;//4bit -static uint8_t const ir_key=0xA;//4bit +static uint8_t const ir_key=IR_KEY;//4bit uint8_t ir_position[2]={0};//4bit*2 void emergency(void){ @@ -171,7 +171,7 @@ order = nucleo.read(); if(order == 0xABCD){ //key/notice/long/short - packet = ((ir_key<<12)|(ir_notice<<8)|(ir_position[1]<<4)|(ir_position[0]<<0))&0xFFFF;nucleo.reply(packet); + packet = ((ir_key<<12)|(ir_notice<<8)|(ir_position[LONG_SPOT]<<4)|(ir_position[SHORT_SPOT]<<0))&0xFFFF;nucleo.reply(packet); } else{ packet = 0xFFFF;nucleo.reply(packet); @@ -186,12 +186,19 @@ uint8_t i;//ic uint8_t j;//ch - //uint8_t num_long, num_short; - //uint16_t ir_val, ir_val_long[8], ir_val_short[12]; - //uint8_t ir_posi, ir_posi_long[8], ir_posi_short[12]; + + uint8_t num_long; + uint8_t num_short; + + uint16_t ir_val_long[8]; + uint16_t ir_val_short[12]; + + uint16_t ir_val, ir_val_diff; + + uint8_t ir_posi; + uint8_t ir_posi_long[8]; + uint8_t ir_posi_short[12]; static uint8_t const ch_num[3]={8, 8, 4}; - - uint16_t ir_data[IC_NUM][IR_NUM]={0}; nucleo.format(16, 3); nucleo.frequency(1000000); @@ -204,50 +211,96 @@ supply.period(0.010);//T=10[ms] supply.write(0.9);//L...10%,H...90% - //call.fall(&emergency); + call.fall(&emergency); for(i=0; i<IC_NUM; i++) cs[i]=1; while(1) { - //num_short=0; - //num_long=0; + num_short=0; + num_long=0; + //i=1...long_data is not used. for(i=0; i<IC_NUM; i++){//IC for(j=0; j<ch_num[i]; j++){//Ch - ir_data[i][j] = read_input(i, j); - /* ir_val = read_input(i, j); ir_posi = read_position(i, j); + /* + ir_val_short[num_short] = ir_val; + ir_posi_short[num_short] = ir_posi; + num_short++; + */ if(i==0){ ir_val_long[num_long] = ir_val; ir_posi_long[num_long] = ir_posi; num_long++; + } else{ ir_val_short[num_short] = ir_val; ir_posi_short[num_short] = ir_posi; num_short++; - }*/ + } + } } - //BubbleSort(ir_val_short, ir_posi_short, 12); - //BubbleSort(ir_val_long, ir_posi_long, 8); + BubbleSort(ir_val_short, ir_posi_short, 12); + BubbleSort(ir_val_long, ir_posi_long, 8); + + ir_val_diff = ir_val_short[0]-ir_val_short[11];//After bubble + + ir_position[SHORT_SPOT] = ir_posi_short[11];//After bubble + ir_position[LONG_SPOT] = ir_posi_long[7];//After bubble + /* - ir_position[0] = ir_posi_short[0]; - ir_position[1] = ir_posi_long[0]; - ir_notice=0; + #define IR_NOTE_NONE 0x0 + #define IR_NOTE_FAR 0x1 + #define IR_NOTE_CLOSE 0x2 + #define IR_NOTE_CLOSER 0x3 */ + ir_notice = IR_NOTE_NONE;//none + if((DIS_MORE_CLOSE<=ir_val_diff)&&(1)){ + ir_notice = IR_NOTE_CLOSER;//short_data + } + else if((DIS_CLOSE<=ir_val_diff)&&(ir_val_diff<DIS_MORE_CLOSE)){ + ir_notice = IR_NOTE_CLOSE;//short_data + } + else if((DIS_FAR<=ir_val_diff)&&(ir_val_diff<DIS_CLOSE)){ + ir_notice = IR_NOTE_FAR;//long_data + } + else if((1)&&(ir_val_diff<DIS_FAR)){ + ir_notice = IR_NOTE_NONE;//none + if((ir_val_long[0]-ir_val_long[7])>700){ + ir_notice = IR_NOTE_FAR;//long_data + } + } + /* pc.printf("%Value is "); - pc.printf("%d\t", ir_data[1][0]); - pc.printf("%d\t", ir_data[1][1]); - pc.printf("%d\t", ir_data[1][2]); - pc.printf("%d\t", ir_data[1][3]); - pc.printf("%d\t", ir_data[1][4]); - pc.printf("%d\t", ir_data[1][5]); - pc.printf("%d\t", ir_data[1][6]); - pc.printf("%d\t", ir_data[1][7]); + pc.printf("state_short is %d\t", ir_position[0]); + pc.printf("state_long is %d\t", ir_position[1]); + pc.printf("Dirr_short is %d\t", ir_val_short[0]-ir_val_short[11]); + pc.printf("Dirr_short is %d\t", ir_val_long[0]-ir_val_long[7]); + pc.printf("notice is %d\t", ir_notice); + pc.printf("\r\n"); + */ + /* + pc.printf("%Value is "); + pc.printf("Dirr_short is %d\t", ir_val_short[0]-ir_val_short[11]); + pc.printf("Dirr_long is %d\t", ir_val_long[0]-ir_val_long[7]); pc.printf("\r\n"); + */ + /* + pc.printf("%Value is "); + for(i=0; i<8; i++){ + pc.printf("%d\t", ir_val_long[i]); + } + for(i=0; i<12; i++){ + pc.printf("%d\t", ir_val_short[i]); + } + + pc.printf("\r\n"); + */ + //emergency(); } }