QC Control software

Dependencies:   mbed

Fork of dgps by Colin Stearns

handle/handleCamera.cpp

Committer:
stearnsc
Date:
2014-04-01
Revision:
8:28b866df62cf
Parent:
7:c75d5e5e6bfc
Child:
9:da906eeac51e

File content as of revision 8:28b866df62cf:

#include "handleCamera.h"

void ImageHandle::setup(){
    //char* version = cam.getVersion();
    uint8_t targetSize=VC0706_160x120;//VC0706_640x480;//VC0706_160x120;
    cam.setImageSize(targetSize);
    uint8_t realSize=cam.getImageSize();
}

void ImageHandle::take(){
    if (! cam.takePicture()) {
        USB::getSerial().printf("Failed to snap!\n");
        while(1){}
    }
    int size=cam.frameLength();
    USB::getSerial().printf("Image Start\n",size);
    int i;
    for(i=0;i<size;){
        // read 32 bytes at a time;
        uint8_t bytesToRead = min(64, size-i); // change 32 to 64 for a speedup but may not work with all setups!
        uint8_t bytesRead=0;
        uint8_t* buffer = cam.readPicture(bytesToRead,&bytesRead);
        for(int a=0;a<bytesRead;a++){USB::getSerial().putc(buffer[a]);}
        i+=bytesRead;
    }
    USB::getSerial().printf("Image End\n",size);
}

bool ImageHandle::check(){
    return true;
}

void ImageHandle::run(){
    if(!initialized){
        initialized=true;
        setup();
    }
    if(check()){
        take();
    }
}