QC Control software

Dependencies:   mbed

Fork of dgps by Colin Stearns

Committer:
dylanembed123
Date:
Thu Apr 10 02:19:07 2014 +0000
Revision:
14:6be57da62283
Parent:
13:a6d3cf2b018e
Child:
15:e3e03a9df89e
Update GPS;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stearnsc 8:28b866df62cf 1 #include "handleCamera.h"
dylanembed123 7:c75d5e5e6bfc 2
dylanembed123 7:c75d5e5e6bfc 3 void ImageHandle::setup(){
dylanembed123 12:e42985e3ea64 4 char* version = cam.getVersion();
dylanembed123 12:e42985e3ea64 5 outputDevice.printf("Version %s\n",version);
dylanembed123 14:6be57da62283 6 uint8_t targetSize=VC0706_320x240;//640x480;
dylanembed123 13:a6d3cf2b018e 7 // 320x240
dylanembed123 13:a6d3cf2b018e 8 //VC0706_640x480;//VC0706_160x120;
dylanembed123 7:c75d5e5e6bfc 9 cam.setImageSize(targetSize);
dylanembed123 7:c75d5e5e6bfc 10 uint8_t realSize=cam.getImageSize();
dylanembed123 7:c75d5e5e6bfc 11 }
dylanembed123 7:c75d5e5e6bfc 12
dylanembed123 7:c75d5e5e6bfc 13 void ImageHandle::take(){
dylanembed123 7:c75d5e5e6bfc 14 if (! cam.takePicture()) {
dylanembed123 12:e42985e3ea64 15 outputDevice.printf("Failed to snap!\n");
dylanembed123 7:c75d5e5e6bfc 16 while(1){}
dylanembed123 7:c75d5e5e6bfc 17 }
dylanembed123 12:e42985e3ea64 18 unsigned int sID=getPS().getSuperID();
dylanembed123 14:6be57da62283 19 getPS().sendPacket(0,NULL,0,PT_EMPTY);
dylanembed123 12:e42985e3ea64 20 getPS().sendPacket(sID,NULL,0,PT_IMAGE);
dylanembed123 7:c75d5e5e6bfc 21 int size=cam.frameLength();
dylanembed123 13:a6d3cf2b018e 22 outputDevice.printf("Image Start %d\n",size);
dylanembed123 7:c75d5e5e6bfc 23 int i;
dylanembed123 13:a6d3cf2b018e 24 char backBuffer[PACKETSIZE];
dylanembed123 13:a6d3cf2b018e 25 int bloc=0;
dylanembed123 7:c75d5e5e6bfc 26 for(i=0;i<size;){
dylanembed123 7:c75d5e5e6bfc 27 // read 32 bytes at a time;
dylanembed123 9:da906eeac51e 28 uint8_t bytesToRead = std::min(64, size-i); // change 32 to 64 for a speedup but may not work with all setups!
dylanembed123 7:c75d5e5e6bfc 29 uint8_t bytesRead=0;
dylanembed123 12:e42985e3ea64 30 char* buffer = (char*)cam.readPicture(bytesToRead,&bytesRead);
dylanembed123 13:a6d3cf2b018e 31 for(int a=0;a<bytesRead;a++){
dylanembed123 13:a6d3cf2b018e 32 if(bloc==PACKETSIZE){
dylanembed123 13:a6d3cf2b018e 33 getPS().sendPacket(sID,backBuffer,bloc);
dylanembed123 13:a6d3cf2b018e 34 bloc=0;
dylanembed123 13:a6d3cf2b018e 35 }
dylanembed123 13:a6d3cf2b018e 36 backBuffer[bloc++]=buffer[a];
dylanembed123 13:a6d3cf2b018e 37 }
dylanembed123 13:a6d3cf2b018e 38 //getPS().sendPacket(sID,buffer,bytesRead);
dylanembed123 12:e42985e3ea64 39 //for(int a=0;a<bytesRead;a++){outputDevice.putc(buffer[a]);}
dylanembed123 7:c75d5e5e6bfc 40 i+=bytesRead;
dylanembed123 7:c75d5e5e6bfc 41 }
dylanembed123 13:a6d3cf2b018e 42 getPS().sendPacket(sID,backBuffer,bloc);
dylanembed123 12:e42985e3ea64 43 outputDevice.printf("Image End\n",size);
dylanembed123 12:e42985e3ea64 44 getPS().sendPacket(sID,NULL,0,PT_END);
dylanembed123 14:6be57da62283 45 cam.resumeVideo();
dylanembed123 7:c75d5e5e6bfc 46 }
dylanembed123 7:c75d5e5e6bfc 47
dylanembed123 7:c75d5e5e6bfc 48 bool ImageHandle::check(){
dylanembed123 7:c75d5e5e6bfc 49 return true;
dylanembed123 7:c75d5e5e6bfc 50 }
dylanembed123 7:c75d5e5e6bfc 51
dylanembed123 7:c75d5e5e6bfc 52 void ImageHandle::run(){
dylanembed123 7:c75d5e5e6bfc 53 if(!initialized){
dylanembed123 7:c75d5e5e6bfc 54 initialized=true;
dylanembed123 12:e42985e3ea64 55 outputDevice.printf("Setup cam\n");
dylanembed123 7:c75d5e5e6bfc 56 setup();
dylanembed123 7:c75d5e5e6bfc 57 }
dylanembed123 7:c75d5e5e6bfc 58 if(check()){
dylanembed123 7:c75d5e5e6bfc 59 take();
dylanembed123 14:6be57da62283 60 wait(2);
dylanembed123 14:6be57da62283 61 //while(true){}
dylanembed123 7:c75d5e5e6bfc 62 }
dylanembed123 7:c75d5e5e6bfc 63 }