QC Control software

Dependencies:   mbed

Fork of dgps by Colin Stearns

Committer:
dylanembed123
Date:
Mon Apr 07 01:30:04 2014 +0000
Revision:
13:a6d3cf2b018e
Parent:
12:e42985e3ea64
Child:
14:6be57da62283
Send Image over Xbee

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 13:a6d3cf2b018e 6 uint8_t targetSize=VC0706_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 12:e42985e3ea64 19 getPS().sendPacket(sID,NULL,0,PT_IMAGE);
dylanembed123 7:c75d5e5e6bfc 20 int size=cam.frameLength();
dylanembed123 13:a6d3cf2b018e 21 outputDevice.printf("Image Start %d\n",size);
dylanembed123 7:c75d5e5e6bfc 22 int i;
dylanembed123 13:a6d3cf2b018e 23 char backBuffer[PACKETSIZE];
dylanembed123 13:a6d3cf2b018e 24 int bloc=0;
dylanembed123 7:c75d5e5e6bfc 25 for(i=0;i<size;){
dylanembed123 7:c75d5e5e6bfc 26 // read 32 bytes at a time;
dylanembed123 9:da906eeac51e 27 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 28 uint8_t bytesRead=0;
dylanembed123 12:e42985e3ea64 29 char* buffer = (char*)cam.readPicture(bytesToRead,&bytesRead);
dylanembed123 13:a6d3cf2b018e 30 for(int a=0;a<bytesRead;a++){
dylanembed123 13:a6d3cf2b018e 31 if(bloc==PACKETSIZE){
dylanembed123 13:a6d3cf2b018e 32 getPS().sendPacket(sID,backBuffer,bloc);
dylanembed123 13:a6d3cf2b018e 33 bloc=0;
dylanembed123 13:a6d3cf2b018e 34 }
dylanembed123 13:a6d3cf2b018e 35 backBuffer[bloc++]=buffer[a];
dylanembed123 13:a6d3cf2b018e 36 }
dylanembed123 13:a6d3cf2b018e 37 //getPS().sendPacket(sID,buffer,bytesRead);
dylanembed123 12:e42985e3ea64 38 //for(int a=0;a<bytesRead;a++){outputDevice.putc(buffer[a]);}
dylanembed123 7:c75d5e5e6bfc 39 i+=bytesRead;
dylanembed123 7:c75d5e5e6bfc 40 }
dylanembed123 13:a6d3cf2b018e 41 getPS().sendPacket(sID,backBuffer,bloc);
dylanembed123 12:e42985e3ea64 42 outputDevice.printf("Image End\n",size);
dylanembed123 12:e42985e3ea64 43 getPS().sendPacket(sID,NULL,0,PT_END);
dylanembed123 7:c75d5e5e6bfc 44 }
dylanembed123 7:c75d5e5e6bfc 45
dylanembed123 7:c75d5e5e6bfc 46 bool ImageHandle::check(){
dylanembed123 7:c75d5e5e6bfc 47 return true;
dylanembed123 7:c75d5e5e6bfc 48 }
dylanembed123 7:c75d5e5e6bfc 49
dylanembed123 7:c75d5e5e6bfc 50 void ImageHandle::run(){
dylanembed123 7:c75d5e5e6bfc 51 if(!initialized){
dylanembed123 7:c75d5e5e6bfc 52 initialized=true;
dylanembed123 12:e42985e3ea64 53 outputDevice.printf("Setup cam\n");
dylanembed123 7:c75d5e5e6bfc 54 setup();
dylanembed123 7:c75d5e5e6bfc 55 }
dylanembed123 7:c75d5e5e6bfc 56 if(check()){
dylanembed123 7:c75d5e5e6bfc 57 take();
dylanembed123 12:e42985e3ea64 58 while(true){}
dylanembed123 7:c75d5e5e6bfc 59 }
dylanembed123 7:c75d5e5e6bfc 60 }