QC Control software

Dependencies:   mbed

Fork of dgps by Colin Stearns

Committer:
dylanembed123
Date:
Mon May 05 13:20:35 2014 +0000
Revision:
66:5d43988d100c
Parent:
62:31ed14d02627
Final Project;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stearnsc 8:28b866df62cf 1 #include "handleCamera.h"
dylanembed123 7:c75d5e5e6bfc 2
krobertson 20:81d5655fecc2 3 ImageHandle* ImageHandle::hand = NULL;
krobertson 20:81d5655fecc2 4
dylanembed123 7:c75d5e5e6bfc 5 void ImageHandle::setup(){
dylanembed123 12:e42985e3ea64 6 char* version = cam.getVersion();
dylanembed123 12:e42985e3ea64 7 outputDevice.printf("Version %s\n",version);
dylanembed123 14:6be57da62283 8 uint8_t targetSize=VC0706_320x240;//640x480;
dylanembed123 13:a6d3cf2b018e 9 // 320x240
dylanembed123 13:a6d3cf2b018e 10 //VC0706_640x480;//VC0706_160x120;
dylanembed123 7:c75d5e5e6bfc 11 cam.setImageSize(targetSize);
dylanembed123 7:c75d5e5e6bfc 12 uint8_t realSize=cam.getImageSize();
dylanembed123 7:c75d5e5e6bfc 13 }
dylanembed123 7:c75d5e5e6bfc 14
dylanembed123 7:c75d5e5e6bfc 15 void ImageHandle::take(){
dylanembed123 7:c75d5e5e6bfc 16 if (! cam.takePicture()) {
dylanembed123 12:e42985e3ea64 17 outputDevice.printf("Failed to snap!\n");
dylanembed123 7:c75d5e5e6bfc 18 while(1){}
dylanembed123 7:c75d5e5e6bfc 19 }
dylanembed123 15:e3e03a9df89e 20 unsigned int sID;
dylanembed123 15:e3e03a9df89e 21
dylanembed123 15:e3e03a9df89e 22 // Send location
dylanembed123 15:e3e03a9df89e 23 sID=getPS().getSuperID();
dylanembed123 16:4f5d20b87dc3 24 //DH::Locs().getC().getLat()=40.006145f;
dylanembed123 16:4f5d20b87dc3 25 //DH::Locs().getC().getLon()=-105.262173;
dylanembed123 15:e3e03a9df89e 26
krobertson 62:31ed14d02627 27
krobertson 20:81d5655fecc2 28
dylanembed123 15:e3e03a9df89e 29 // Send image
krobertson 62:31ed14d02627 30 //sID=getPS().getSuperID();
krobertson 18:e72ee7aed088 31 getPS().openConnection();
dylanembed123 14:6be57da62283 32 getPS().sendPacket(0,NULL,0,PT_EMPTY);
dylanembed123 12:e42985e3ea64 33 getPS().sendPacket(sID,NULL,0,PT_IMAGE);
dylanembed123 7:c75d5e5e6bfc 34 int size=cam.frameLength();
dylanembed123 15:e3e03a9df89e 35 outputDevice.printf("Image Start %d %d\n",size,sizeof(PacketStruct));
dylanembed123 7:c75d5e5e6bfc 36 int i;
dylanembed123 13:a6d3cf2b018e 37 char backBuffer[PACKETSIZE];
dylanembed123 13:a6d3cf2b018e 38 int bloc=0;
dylanembed123 7:c75d5e5e6bfc 39 for(i=0;i<size;){
dylanembed123 7:c75d5e5e6bfc 40 // read 32 bytes at a time;
dylanembed123 9:da906eeac51e 41 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 42 uint8_t bytesRead=0;
dylanembed123 12:e42985e3ea64 43 char* buffer = (char*)cam.readPicture(bytesToRead,&bytesRead);
dylanembed123 13:a6d3cf2b018e 44 for(int a=0;a<bytesRead;a++){
dylanembed123 13:a6d3cf2b018e 45 if(bloc==PACKETSIZE){
dylanembed123 13:a6d3cf2b018e 46 getPS().sendPacket(sID,backBuffer,bloc);
dylanembed123 13:a6d3cf2b018e 47 bloc=0;
dylanembed123 13:a6d3cf2b018e 48 }
dylanembed123 13:a6d3cf2b018e 49 backBuffer[bloc++]=buffer[a];
dylanembed123 13:a6d3cf2b018e 50 }
dylanembed123 13:a6d3cf2b018e 51 //getPS().sendPacket(sID,buffer,bytesRead);
dylanembed123 12:e42985e3ea64 52 //for(int a=0;a<bytesRead;a++){outputDevice.putc(buffer[a]);}
dylanembed123 7:c75d5e5e6bfc 53 i+=bytesRead;
dylanembed123 7:c75d5e5e6bfc 54 }
dylanembed123 13:a6d3cf2b018e 55 getPS().sendPacket(sID,backBuffer,bloc);
krobertson 62:31ed14d02627 56 getPS().sendPacket(sID,NULL,0,PT_END);
krobertson 62:31ed14d02627 57 getPS().closeConnection();
krobertson 62:31ed14d02627 58
krobertson 62:31ed14d02627 59 wait_us(1000000);
krobertson 62:31ed14d02627 60
dylanembed123 12:e42985e3ea64 61 outputDevice.printf("Image End\n",size);
dylanembed123 66:5d43988d100c 62 //DH::Locs().getC().getAlt()=5;
dylanembed123 66:5d43988d100c 63 //DH::Locs().getC().getHeading()=5;
dylanembed123 66:5d43988d100c 64 //DH::Locs().getC().getTilt()=5;
krobertson 62:31ed14d02627 65 getPS().openConnection();
krobertson 62:31ed14d02627 66 getPS().sendPacket(0,NULL,0,PT_EMPTY);
krobertson 62:31ed14d02627 67 getPS().sendPacket(sID,NULL,0,PT_IMAGEHEAD);
krobertson 62:31ed14d02627 68 getPS().sendPacket(sID,(char*)(&DH::Locs().getC().getLoc()),sizeof(DataLocation));
dylanembed123 12:e42985e3ea64 69 getPS().sendPacket(sID,NULL,0,PT_END);
krobertson 18:e72ee7aed088 70 getPS().closeConnection();
dylanembed123 14:6be57da62283 71 cam.resumeVideo();
dylanembed123 7:c75d5e5e6bfc 72 }
dylanembed123 7:c75d5e5e6bfc 73
dylanembed123 7:c75d5e5e6bfc 74 bool ImageHandle::check(){
dylanembed123 7:c75d5e5e6bfc 75 return true;
dylanembed123 7:c75d5e5e6bfc 76 }
dylanembed123 7:c75d5e5e6bfc 77
dylanembed123 7:c75d5e5e6bfc 78 void ImageHandle::run(){
dylanembed123 7:c75d5e5e6bfc 79 if(!initialized){
dylanembed123 7:c75d5e5e6bfc 80 initialized=true;
dylanembed123 12:e42985e3ea64 81 outputDevice.printf("Setup cam\n");
dylanembed123 7:c75d5e5e6bfc 82 setup();
dylanembed123 7:c75d5e5e6bfc 83 }
dylanembed123 7:c75d5e5e6bfc 84 if(check()){
dylanembed123 7:c75d5e5e6bfc 85 take();
dylanembed123 14:6be57da62283 86 wait(2);
dylanembed123 14:6be57da62283 87 //while(true){}
dylanembed123 7:c75d5e5e6bfc 88 }
dylanembed123 7:c75d5e5e6bfc 89 }