123

Dependencies:   mbed

Fork of Boboobooo by Clark Lin

Committer:
backman
Date:
Wed Jun 04 12:56:52 2014 +0000
Revision:
2:c51647d3c14d
Parent:
1:82bc25a7b68b
Child:
3:c5f2281b3ed2
two cam

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 1:82bc25a7b68b 6
backman 2:c51647d3c14d 7 BX_camera::BX_camera(void){
backman 1:82bc25a7b68b 8
backman 2:c51647d3c14d 9 line_CamR = new FastAnalogIn(PTD5);
backman 2:c51647d3c14d 10 line_CamL= new FastAnalogIn(PTD6,0);
backman 2:c51647d3c14d 11 cam_clk=new DigitalOut(PTE1);
backman 2:c51647d3c14d 12 si=new DigitalOut(PTD7);
backman 1:82bc25a7b68b 13
backman 2:c51647d3c14d 14
backman 1:82bc25a7b68b 15
backman 1:82bc25a7b68b 16
backman 1:82bc25a7b68b 17 }
backman 1:82bc25a7b68b 18
backman 1:82bc25a7b68b 19
backman 2:c51647d3c14d 20 void BX_camera::read(void){
backman 1:82bc25a7b68b 21
backman 2:c51647d3c14d 22 w_f_vL=0x0000;
backman 2:c51647d3c14d 23 b_f_vL=0xffff;
backman 2:c51647d3c14d 24
backman 2:c51647d3c14d 25 w_f_vR=0x0000;
backman 2:c51647d3c14d 26 b_f_vR=0xffff;
backman 1:82bc25a7b68b 27
backman 1:82bc25a7b68b 28
backman 1:82bc25a7b68b 29
backman 2:c51647d3c14d 30
backman 1:82bc25a7b68b 31 *si=1;
backman 2:c51647d3c14d 32 *cam_clk=1;
backman 1:82bc25a7b68b 33
backman 1:82bc25a7b68b 34 wait_us(30); // tune here
backman 1:82bc25a7b68b 35 *si=0;
backman 1:82bc25a7b68b 36 *cam_clk=0;
backman 1:82bc25a7b68b 37
backman 1:82bc25a7b68b 38
backman 1:82bc25a7b68b 39
backman 2:c51647d3c14d 40 line_CamR->enable();
backman 2:c51647d3c14d 41 line_CamL->enable();
backman 1:82bc25a7b68b 42
backman 1:82bc25a7b68b 43
backman 2:c51647d3c14d 44 //input 128 //both
backman 1:82bc25a7b68b 45
backman 1:82bc25a7b68b 46 for(int i=0;i<128;i++){
backman 2:c51647d3c14d 47 *cam_clk=1;
backman 2:c51647d3c14d 48 wait_us(5);
backman 1:82bc25a7b68b 49
backman 1:82bc25a7b68b 50
backman 2:c51647d3c14d 51 line_imageR[i]=line_CamR->read_u16();
backman 2:c51647d3c14d 52 line_imageL[i]=line_CamL->read_u16();
backman 1:82bc25a7b68b 53
backman 1:82bc25a7b68b 54 // big small
backman 2:c51647d3c14d 55 if(line_imageR[i] > w_f_vR)
backman 2:c51647d3c14d 56 w_f_vR=line_imageR[i];
backman 2:c51647d3c14d 57 else if(line_imageR[i] < b_f_vR )
backman 2:c51647d3c14d 58 b_f_vR = line_imageR[i];
backman 2:c51647d3c14d 59
backman 2:c51647d3c14d 60
backman 2:c51647d3c14d 61 if(line_imageL[i] > w_f_vL)
backman 2:c51647d3c14d 62 w_f_vL=line_imageL[i];
backman 2:c51647d3c14d 63 else if(line_imageL[i] < b_f_vL )
backman 2:c51647d3c14d 64 b_f_vL = line_imageL[i];
backman 1:82bc25a7b68b 65
backman 1:82bc25a7b68b 66
backman 1:82bc25a7b68b 67
backman 1:82bc25a7b68b 68
backman 1:82bc25a7b68b 69 *cam_clk=0;
backman 1:82bc25a7b68b 70 wait_us(5);
backman 1:82bc25a7b68b 71
backman 1:82bc25a7b68b 72
backman 1:82bc25a7b68b 73 }
backman 1:82bc25a7b68b 74
backman 1:82bc25a7b68b 75
backman 2:c51647d3c14d 76 line_CamR->enable();
backman 2:c51647d3c14d 77 line_CamL->enable();
backman 1:82bc25a7b68b 78
backman 1:82bc25a7b68b 79
backman 2:c51647d3c14d 80 //filter L R //may change
backman 1:82bc25a7b68b 81
backman 1:82bc25a7b68b 82 for(int i=0;i<128;i++){
backman 1:82bc25a7b68b 83
backman 1:82bc25a7b68b 84
backman 2:c51647d3c14d 85 if( (line_imageR[i]-b_f_vR) < (w_f_vR - line_imageR[i] ) )
backman 2:c51647d3c14d 86 sign_line_imageR[i]=' ';
backman 2:c51647d3c14d 87 else
backman 2:c51647d3c14d 88 sign_line_imageR[i]='O';
backman 2:c51647d3c14d 89
backman 2:c51647d3c14d 90
backman 2:c51647d3c14d 91 if( (line_imageL[i]-b_f_vL) < (w_f_vL - line_imageL[i] ) )
backman 2:c51647d3c14d 92 sign_line_imageL[i]=' ';
backman 1:82bc25a7b68b 93 else
backman 2:c51647d3c14d 94 sign_line_imageL[i]='O';
backman 2:c51647d3c14d 95
backman 1:82bc25a7b68b 96
backman 2:c51647d3c14d 97
backman 2:c51647d3c14d 98
backman 2:c51647d3c14d 99
backman 2:c51647d3c14d 100 if(i==0){
backman 2:c51647d3c14d 101 sign_line_imageR[i]='X';
backman 2:c51647d3c14d 102 sign_line_imageL[i]='X';
backman 2:c51647d3c14d 103 }
backman 2:c51647d3c14d 104
backman 1:82bc25a7b68b 105
backman 1:82bc25a7b68b 106 }
backman 1:82bc25a7b68b 107
backman 1:82bc25a7b68b 108
backman 1:82bc25a7b68b 109
backman 1:82bc25a7b68b 110 }