Ramiro Rubio / Mbed 2 deprecated Camara

Dependencies:   mbed

Committer:
RAMIRORUBIO
Date:
Mon Apr 18 22:20:38 2016 +0000
Revision:
0:63fef0f8da41
Child:
1:9855b1065eae
cam; ;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RAMIRORUBIO 0:63fef0f8da41 1 #include "mbed.h"
RAMIRORUBIO 0:63fef0f8da41 2 Serial pc(USBTX, USBRX); // tx, rx
RAMIRORUBIO 0:63fef0f8da41 3 Serial cam(PTC4,PTC3);
RAMIRORUBIO 0:63fef0f8da41 4 unsigned char reset[]={0x56,0x00,0x26,0x00};
RAMIRORUBIO 0:63fef0f8da41 5 unsigned char init_end[]="Init end";
RAMIRORUBIO 0:63fef0f8da41 6 unsigned char take_pic[]={0x56,0x00,0x36,0x01,0x00};
RAMIRORUBIO 0:63fef0f8da41 7 unsigned char taking_pic[]={0x76,0x00,0x36,0x00,0x00};
RAMIRORUBIO 0:63fef0f8da41 8 unsigned char read_size[]={0x56,0x00,0x34,0x01,0x00};
RAMIRORUBIO 0:63fef0f8da41 9 unsigned char return_size[]={0x76,0x00,0x34,0x00,0x04,0x00,0x00};
RAMIRORUBIO 0:63fef0f8da41 10 unsigned char read_pic[]={0x56,0x00,0x32,0x0C,0x00,0x0A,0x00,0x00,0x00,0x00,0x00,0x00};
RAMIRORUBIO 0:63fef0f8da41 11 unsigned char wait_time[]={0x00,0x0A};
RAMIRORUBIO 0:63fef0f8da41 12 unsigned char stop_pic[]={0x56,0x00,0x36,0x01,0x03};
RAMIRORUBIO 0:63fef0f8da41 13 unsigned char size[2];
RAMIRORUBIO 0:63fef0f8da41 14 unsigned char data_ready;
RAMIRORUBIO 0:63fef0f8da41 15 unsigned char buff[13000];
RAMIRORUBIO 0:63fef0f8da41 16 unsigned int i;
RAMIRORUBIO 0:63fef0f8da41 17 unsigned int j;
RAMIRORUBIO 0:63fef0f8da41 18 int main() {
RAMIRORUBIO 0:63fef0f8da41 19 i=0;
RAMIRORUBIO 0:63fef0f8da41 20 cam.baud(38400);
RAMIRORUBIO 0:63fef0f8da41 21 do
RAMIRORUBIO 0:63fef0f8da41 22 {
RAMIRORUBIO 0:63fef0f8da41 23 cam.printf("%c",reset[i++]);
RAMIRORUBIO 0:63fef0f8da41 24 }while(i<4);
RAMIRORUBIO 0:63fef0f8da41 25 i=0;
RAMIRORUBIO 0:63fef0f8da41 26 // pc.printf("reset\n");
RAMIRORUBIO 0:63fef0f8da41 27 do
RAMIRORUBIO 0:63fef0f8da41 28 {
RAMIRORUBIO 0:63fef0f8da41 29 if(cam.getc()==init_end[i])
RAMIRORUBIO 0:63fef0f8da41 30 {
RAMIRORUBIO 0:63fef0f8da41 31 i++;
RAMIRORUBIO 0:63fef0f8da41 32 };
RAMIRORUBIO 0:63fef0f8da41 33 }while(init_end[i]);
RAMIRORUBIO 0:63fef0f8da41 34 // pc.printf("START\n");
RAMIRORUBIO 0:63fef0f8da41 35
RAMIRORUBIO 0:63fef0f8da41 36
RAMIRORUBIO 0:63fef0f8da41 37 i=0;
RAMIRORUBIO 0:63fef0f8da41 38 do
RAMIRORUBIO 0:63fef0f8da41 39 {
RAMIRORUBIO 0:63fef0f8da41 40 cam.printf("%c",take_pic[i++]);
RAMIRORUBIO 0:63fef0f8da41 41 }while(i<5);
RAMIRORUBIO 0:63fef0f8da41 42 i=0;
RAMIRORUBIO 0:63fef0f8da41 43 do
RAMIRORUBIO 0:63fef0f8da41 44 {
RAMIRORUBIO 0:63fef0f8da41 45 if(cam.getc()==taking_pic[i])
RAMIRORUBIO 0:63fef0f8da41 46 {
RAMIRORUBIO 0:63fef0f8da41 47 i++;
RAMIRORUBIO 0:63fef0f8da41 48 };
RAMIRORUBIO 0:63fef0f8da41 49 }while(i<5);
RAMIRORUBIO 0:63fef0f8da41 50 i=0;
RAMIRORUBIO 0:63fef0f8da41 51 // pc.printf("pic taken\n");
RAMIRORUBIO 0:63fef0f8da41 52 wait(1);
RAMIRORUBIO 0:63fef0f8da41 53 do
RAMIRORUBIO 0:63fef0f8da41 54 {
RAMIRORUBIO 0:63fef0f8da41 55 cam.printf("%c",read_size[i++]);
RAMIRORUBIO 0:63fef0f8da41 56 }while(i<5);
RAMIRORUBIO 0:63fef0f8da41 57 i=0;
RAMIRORUBIO 0:63fef0f8da41 58 do
RAMIRORUBIO 0:63fef0f8da41 59 {
RAMIRORUBIO 0:63fef0f8da41 60 if(cam.getc()==return_size[i])
RAMIRORUBIO 0:63fef0f8da41 61 {
RAMIRORUBIO 0:63fef0f8da41 62 i++;
RAMIRORUBIO 0:63fef0f8da41 63 };
RAMIRORUBIO 0:63fef0f8da41 64
RAMIRORUBIO 0:63fef0f8da41 65 }while(i<7);
RAMIRORUBIO 0:63fef0f8da41 66 i=0;
RAMIRORUBIO 0:63fef0f8da41 67 size[0]=cam.getc();
RAMIRORUBIO 0:63fef0f8da41 68 size[1]=cam.getc();
RAMIRORUBIO 0:63fef0f8da41 69 /*
RAMIRORUBIO 0:63fef0f8da41 70 do
RAMIRORUBIO 0:63fef0f8da41 71 {
RAMIRORUBIO 0:63fef0f8da41 72 size[i++]=cam.getc();
RAMIRORUBIO 0:63fef0f8da41 73 }while(i<2);
RAMIRORUBIO 0:63fef0f8da41 74 */
RAMIRORUBIO 0:63fef0f8da41 75 i=0;
RAMIRORUBIO 0:63fef0f8da41 76 // pc.printf("got size\n");
RAMIRORUBIO 0:63fef0f8da41 77 do
RAMIRORUBIO 0:63fef0f8da41 78 {
RAMIRORUBIO 0:63fef0f8da41 79 cam.printf("%c",read_pic[i++]);
RAMIRORUBIO 0:63fef0f8da41 80 }while(i<12);
RAMIRORUBIO 0:63fef0f8da41 81 i=0;
RAMIRORUBIO 0:63fef0f8da41 82 do
RAMIRORUBIO 0:63fef0f8da41 83 {
RAMIRORUBIO 0:63fef0f8da41 84 cam.printf("%c",size[i++]);
RAMIRORUBIO 0:63fef0f8da41 85 }while(i<2);
RAMIRORUBIO 0:63fef0f8da41 86 i=0;
RAMIRORUBIO 0:63fef0f8da41 87 do
RAMIRORUBIO 0:63fef0f8da41 88 {
RAMIRORUBIO 0:63fef0f8da41 89 cam.printf("%c",wait_time[i++]);
RAMIRORUBIO 0:63fef0f8da41 90 }while(i<2);
RAMIRORUBIO 0:63fef0f8da41 91 i=0;
RAMIRORUBIO 0:63fef0f8da41 92 do
RAMIRORUBIO 0:63fef0f8da41 93 {
RAMIRORUBIO 0:63fef0f8da41 94 buff[i]=cam.getc();
RAMIRORUBIO 0:63fef0f8da41 95 if(buff[i]==0xFF & !data_ready)
RAMIRORUBIO 0:63fef0f8da41 96 {
RAMIRORUBIO 0:63fef0f8da41 97 data_ready++;
RAMIRORUBIO 0:63fef0f8da41 98 }
RAMIRORUBIO 0:63fef0f8da41 99 else if(buff[i]==0xD9 & data_ready)
RAMIRORUBIO 0:63fef0f8da41 100 {
RAMIRORUBIO 0:63fef0f8da41 101 data_ready++;
RAMIRORUBIO 0:63fef0f8da41 102 }
RAMIRORUBIO 0:63fef0f8da41 103 else
RAMIRORUBIO 0:63fef0f8da41 104 {
RAMIRORUBIO 0:63fef0f8da41 105 data_ready=0;
RAMIRORUBIO 0:63fef0f8da41 106 }
RAMIRORUBIO 0:63fef0f8da41 107 i++;
RAMIRORUBIO 0:63fef0f8da41 108 }while(data_ready<2);
RAMIRORUBIO 0:63fef0f8da41 109 do
RAMIRORUBIO 0:63fef0f8da41 110 {
RAMIRORUBIO 0:63fef0f8da41 111 pc.printf("%c",buff[j++]);
RAMIRORUBIO 0:63fef0f8da41 112 }while(j<i);
RAMIRORUBIO 0:63fef0f8da41 113 }