123

Dependencies:   mbed

Fork of Boboobooo by Clark Lin

Committer:
even
Date:
Thu Jul 10 10:22:14 2014 +0000
Revision:
12:a3cee7619b77
Parent:
11:9b4788de75fe
lots of weird things

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
even 11:9b4788de75fe 17 int black_R = 10;
even 11:9b4788de75fe 18 for(int i = 118; i >=10; 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 }
even 7:f04bde0ca846 23 return black_R;
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 int BX_camera::black_centerL(void){
backman 3:c5f2281b3ed2 31
even 11:9b4788de75fe 32 int black_L = 118;
even 11:9b4788de75fe 33 for(int i = 10; i <118 ; i++){
physicsgood 6:b046d6ff3745 34 if(sign_line_imageL[i] == 'O' && sign_line_imageL[i+1] == ' ' && sign_line_imageL[i+2] == ' '){
physicsgood 6:b046d6ff3745 35 return i;
physicsgood 6:b046d6ff3745 36 }
physicsgood 6:b046d6ff3745 37 }
even 7:f04bde0ca846 38 return black_L;
backman 3:c5f2281b3ed2 39
backman 3:c5f2281b3ed2 40
physicsgood 6:b046d6ff3745 41
physicsgood 6:b046d6ff3745 42
physicsgood 6:b046d6ff3745 43
physicsgood 6:b046d6ff3745 44
backman 3:c5f2281b3ed2 45
backman 3:c5f2281b3ed2 46 }
backman 3:c5f2281b3ed2 47
backman 4:05b21dbca0c7 48
backman 1:82bc25a7b68b 49
backman 2:c51647d3c14d 50 void BX_camera::read(void){
backman 1:82bc25a7b68b 51
backman 2:c51647d3c14d 52 w_f_vL=0x0000;
backman 2:c51647d3c14d 53 b_f_vL=0xffff;
backman 2:c51647d3c14d 54
backman 2:c51647d3c14d 55 w_f_vR=0x0000;
backman 2:c51647d3c14d 56 b_f_vR=0xffff;
backman 1:82bc25a7b68b 57
backman 1:82bc25a7b68b 58
backman 1:82bc25a7b68b 59
backman 2:c51647d3c14d 60
backman 1:82bc25a7b68b 61 *si=1;
backman 2:c51647d3c14d 62 *cam_clk=1;
backman 1:82bc25a7b68b 63
backman 1:82bc25a7b68b 64 wait_us(30); // tune here
backman 1:82bc25a7b68b 65 *si=0;
backman 1:82bc25a7b68b 66 *cam_clk=0;
backman 1:82bc25a7b68b 67
backman 1:82bc25a7b68b 68
backman 1:82bc25a7b68b 69
backman 2:c51647d3c14d 70 line_CamR->enable();
backman 2:c51647d3c14d 71 line_CamL->enable();
backman 1:82bc25a7b68b 72
backman 1:82bc25a7b68b 73
backman 2:c51647d3c14d 74 //input 128 //both
backman 1:82bc25a7b68b 75
even 9:a891053657f3 76 for(int i=127;i>=0;i--){
backman 2:c51647d3c14d 77 *cam_clk=1;
backman 2:c51647d3c14d 78 wait_us(5);
backman 1:82bc25a7b68b 79
backman 1:82bc25a7b68b 80
backman 2:c51647d3c14d 81 line_imageR[i]=line_CamR->read_u16();
backman 2:c51647d3c14d 82 line_imageL[i]=line_CamL->read_u16();
backman 1:82bc25a7b68b 83
backman 1:82bc25a7b68b 84 // big small
backman 2:c51647d3c14d 85 if(line_imageR[i] > w_f_vR)
backman 2:c51647d3c14d 86 w_f_vR=line_imageR[i];
backman 2:c51647d3c14d 87 else if(line_imageR[i] < b_f_vR )
backman 2:c51647d3c14d 88 b_f_vR = line_imageR[i];
backman 2:c51647d3c14d 89
backman 2:c51647d3c14d 90
backman 2:c51647d3c14d 91 if(line_imageL[i] > w_f_vL)
backman 2:c51647d3c14d 92 w_f_vL=line_imageL[i];
backman 2:c51647d3c14d 93 else if(line_imageL[i] < b_f_vL )
backman 2:c51647d3c14d 94 b_f_vL = line_imageL[i];
backman 1:82bc25a7b68b 95
backman 1:82bc25a7b68b 96
backman 1:82bc25a7b68b 97
backman 1:82bc25a7b68b 98
backman 1:82bc25a7b68b 99 *cam_clk=0;
backman 1:82bc25a7b68b 100 wait_us(5);
backman 1:82bc25a7b68b 101
backman 1:82bc25a7b68b 102
backman 1:82bc25a7b68b 103 }
backman 1:82bc25a7b68b 104
backman 1:82bc25a7b68b 105
backman 2:c51647d3c14d 106 line_CamR->enable();
backman 2:c51647d3c14d 107 line_CamL->enable();
backman 1:82bc25a7b68b 108
backman 1:82bc25a7b68b 109
backman 2:c51647d3c14d 110 //filter L R //may change
backman 1:82bc25a7b68b 111
backman 1:82bc25a7b68b 112 for(int i=0;i<128;i++){
backman 1:82bc25a7b68b 113
backman 1:82bc25a7b68b 114
backman 2:c51647d3c14d 115 if( (line_imageR[i]-b_f_vR) < (w_f_vR - line_imageR[i] ) )
backman 2:c51647d3c14d 116 sign_line_imageR[i]=' ';
backman 2:c51647d3c14d 117 else
backman 2:c51647d3c14d 118 sign_line_imageR[i]='O';
backman 2:c51647d3c14d 119
backman 2:c51647d3c14d 120
backman 2:c51647d3c14d 121 if( (line_imageL[i]-b_f_vL) < (w_f_vL - line_imageL[i] ) )
backman 2:c51647d3c14d 122 sign_line_imageL[i]=' ';
backman 1:82bc25a7b68b 123 else
backman 2:c51647d3c14d 124 sign_line_imageL[i]='O';
backman 2:c51647d3c14d 125
backman 1:82bc25a7b68b 126
backman 2:c51647d3c14d 127
backman 2:c51647d3c14d 128
backman 2:c51647d3c14d 129
backman 2:c51647d3c14d 130 if(i==0){
backman 2:c51647d3c14d 131 sign_line_imageR[i]='X';
backman 2:c51647d3c14d 132 sign_line_imageL[i]='X';
backman 2:c51647d3c14d 133 }
backman 2:c51647d3c14d 134
backman 1:82bc25a7b68b 135
backman 1:82bc25a7b68b 136 }
backman 1:82bc25a7b68b 137
backman 1:82bc25a7b68b 138
backman 1:82bc25a7b68b 139
backman 1:82bc25a7b68b 140 }