123

Dependencies:   mbed

Fork of Boboobooo by Clark Lin

Committer:
physicsgood
Date:
Mon Jul 07 08:16:46 2014 +0000
Revision:
6:b046d6ff3745
Parent:
5:e32b091aa1fb
Child:
7:f04bde0ca846
QQQQQQQ

Who changed what in which revision?

UserRevisionLine numberNew contents of line
backman 1:82bc25a7b68b 1 #include "mbed.h"
backman 1:82bc25a7b68b 2 #include "camera_api.h"
backman 1:82bc25a7b68b 3
backman 1:82bc25a7b68b 4 #define clk 2 //ms
backman 1:82bc25a7b68b 5
backman 2:c51647d3c14d 6 BX_camera::BX_camera(void){
backman 1:82bc25a7b68b 7
backman 2:c51647d3c14d 8 line_CamR = new FastAnalogIn(PTD5);
backman 2:c51647d3c14d 9 line_CamL= new FastAnalogIn(PTD6,0);
backman 2:c51647d3c14d 10 cam_clk=new DigitalOut(PTE1);
backman 2:c51647d3c14d 11 si=new DigitalOut(PTD7);
backman 4:05b21dbca0c7 12
backman 1:82bc25a7b68b 13 }
backman 1:82bc25a7b68b 14
backman 3:c5f2281b3ed2 15 int BX_camera::black_centerR(void){
backman 4:05b21dbca0c7 16
physicsgood 6:b046d6ff3745 17 int black_R_left = 0;
physicsgood 6:b046d6ff3745 18 for(int i = 120; i >=8; i--){
physicsgood 6:b046d6ff3745 19 if(sign_line_imageR[i] == 'O' && sign_line_imageR[i-1] == ' ' && sign_line_imageR[i-2] == ' '){
physicsgood 6:b046d6ff3745 20 return i;
physicsgood 6:b046d6ff3745 21 }
physicsgood 6:b046d6ff3745 22 }
physicsgood 6:b046d6ff3745 23 return black_R_left;
backman 3:c5f2281b3ed2 24
backman 3:c5f2281b3ed2 25
physicsgood 6:b046d6ff3745 26
backman 3:c5f2281b3ed2 27
physicsgood 6:b046d6ff3745 28 }
backman 3:c5f2281b3ed2 29
backman 3:c5f2281b3ed2 30
backman 3:c5f2281b3ed2 31
backman 3:c5f2281b3ed2 32
backman 3:c5f2281b3ed2 33 int BX_camera::black_centerL(void){
backman 3:c5f2281b3ed2 34
physicsgood 6:b046d6ff3745 35 int black_L_right = 128;
physicsgood 6:b046d6ff3745 36 for(int i = 8; i <121 ; i++){
physicsgood 6:b046d6ff3745 37 if(sign_line_imageL[i] == 'O' && sign_line_imageL[i+1] == ' ' && sign_line_imageL[i+2] == ' '){
physicsgood 6:b046d6ff3745 38 return i;
physicsgood 6:b046d6ff3745 39 }
physicsgood 6:b046d6ff3745 40 }
physicsgood 6:b046d6ff3745 41 return black_L_right;
backman 3:c5f2281b3ed2 42
backman 3:c5f2281b3ed2 43
physicsgood 6:b046d6ff3745 44
physicsgood 6:b046d6ff3745 45
physicsgood 6:b046d6ff3745 46
physicsgood 6:b046d6ff3745 47
backman 3:c5f2281b3ed2 48
backman 3:c5f2281b3ed2 49 }
backman 3:c5f2281b3ed2 50
backman 4:05b21dbca0c7 51
backman 1:82bc25a7b68b 52
backman 2:c51647d3c14d 53 void BX_camera::read(void){
backman 1:82bc25a7b68b 54
backman 2:c51647d3c14d 55 w_f_vL=0x0000;
backman 2:c51647d3c14d 56 b_f_vL=0xffff;
backman 2:c51647d3c14d 57
backman 2:c51647d3c14d 58 w_f_vR=0x0000;
backman 2:c51647d3c14d 59 b_f_vR=0xffff;
backman 1:82bc25a7b68b 60
backman 1:82bc25a7b68b 61
backman 1:82bc25a7b68b 62
backman 2:c51647d3c14d 63
backman 1:82bc25a7b68b 64 *si=1;
backman 2:c51647d3c14d 65 *cam_clk=1;
backman 1:82bc25a7b68b 66
backman 1:82bc25a7b68b 67 wait_us(30); // tune here
backman 1:82bc25a7b68b 68 *si=0;
backman 1:82bc25a7b68b 69 *cam_clk=0;
backman 1:82bc25a7b68b 70
backman 1:82bc25a7b68b 71
backman 1:82bc25a7b68b 72
backman 2:c51647d3c14d 73 line_CamR->enable();
backman 2:c51647d3c14d 74 line_CamL->enable();
backman 1:82bc25a7b68b 75
backman 1:82bc25a7b68b 76
backman 2:c51647d3c14d 77 //input 128 //both
backman 1:82bc25a7b68b 78
backman 1:82bc25a7b68b 79 for(int i=0;i<128;i++){
backman 2:c51647d3c14d 80 *cam_clk=1;
backman 2:c51647d3c14d 81 wait_us(5);
backman 1:82bc25a7b68b 82
backman 1:82bc25a7b68b 83
backman 2:c51647d3c14d 84 line_imageR[i]=line_CamR->read_u16();
backman 2:c51647d3c14d 85 line_imageL[i]=line_CamL->read_u16();
backman 1:82bc25a7b68b 86
backman 1:82bc25a7b68b 87 // big small
backman 2:c51647d3c14d 88 if(line_imageR[i] > w_f_vR)
backman 2:c51647d3c14d 89 w_f_vR=line_imageR[i];
backman 2:c51647d3c14d 90 else if(line_imageR[i] < b_f_vR )
backman 2:c51647d3c14d 91 b_f_vR = line_imageR[i];
backman 2:c51647d3c14d 92
backman 2:c51647d3c14d 93
backman 2:c51647d3c14d 94 if(line_imageL[i] > w_f_vL)
backman 2:c51647d3c14d 95 w_f_vL=line_imageL[i];
backman 2:c51647d3c14d 96 else if(line_imageL[i] < b_f_vL )
backman 2:c51647d3c14d 97 b_f_vL = line_imageL[i];
backman 1:82bc25a7b68b 98
backman 1:82bc25a7b68b 99
backman 1:82bc25a7b68b 100
backman 1:82bc25a7b68b 101
backman 1:82bc25a7b68b 102 *cam_clk=0;
backman 1:82bc25a7b68b 103 wait_us(5);
backman 1:82bc25a7b68b 104
backman 1:82bc25a7b68b 105
backman 1:82bc25a7b68b 106 }
backman 1:82bc25a7b68b 107
backman 1:82bc25a7b68b 108
backman 2:c51647d3c14d 109 line_CamR->enable();
backman 2:c51647d3c14d 110 line_CamL->enable();
backman 1:82bc25a7b68b 111
backman 1:82bc25a7b68b 112
backman 2:c51647d3c14d 113 //filter L R //may change
backman 1:82bc25a7b68b 114
backman 1:82bc25a7b68b 115 for(int i=0;i<128;i++){
backman 1:82bc25a7b68b 116
backman 1:82bc25a7b68b 117
backman 2:c51647d3c14d 118 if( (line_imageR[i]-b_f_vR) < (w_f_vR - line_imageR[i] ) )
backman 2:c51647d3c14d 119 sign_line_imageR[i]=' ';
backman 2:c51647d3c14d 120 else
backman 2:c51647d3c14d 121 sign_line_imageR[i]='O';
backman 2:c51647d3c14d 122
backman 2:c51647d3c14d 123
backman 2:c51647d3c14d 124 if( (line_imageL[i]-b_f_vL) < (w_f_vL - line_imageL[i] ) )
backman 2:c51647d3c14d 125 sign_line_imageL[i]=' ';
backman 1:82bc25a7b68b 126 else
backman 2:c51647d3c14d 127 sign_line_imageL[i]='O';
backman 2:c51647d3c14d 128
backman 1:82bc25a7b68b 129
backman 2:c51647d3c14d 130
backman 2:c51647d3c14d 131
backman 2:c51647d3c14d 132
backman 2:c51647d3c14d 133 if(i==0){
backman 2:c51647d3c14d 134 sign_line_imageR[i]='X';
backman 2:c51647d3c14d 135 sign_line_imageL[i]='X';
backman 2:c51647d3c14d 136 }
backman 2:c51647d3c14d 137
backman 1:82bc25a7b68b 138
backman 1:82bc25a7b68b 139 }
backman 1:82bc25a7b68b 140
backman 1:82bc25a7b68b 141
backman 1:82bc25a7b68b 142
backman 1:82bc25a7b68b 143 }