Colin Stearns
/
qcControl
QC Control software
Fork of dgps by
handle/handleCamera.cpp@12:e42985e3ea64, 2014-04-05 (annotated)
- Committer:
- dylanembed123
- Date:
- Sat Apr 05 22:27:18 2014 +0000
- Revision:
- 12:e42985e3ea64
- Parent:
- 9:da906eeac51e
- Child:
- 13:a6d3cf2b018e
Update packet.h (interface to other c++ code).
Who changed what in which revision?
User | Revision | Line number | New 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 | 7:c75d5e5e6bfc | 6 | uint8_t targetSize=VC0706_160x120;//VC0706_640x480;//VC0706_160x120; |
dylanembed123 | 7:c75d5e5e6bfc | 7 | cam.setImageSize(targetSize); |
dylanembed123 | 7:c75d5e5e6bfc | 8 | uint8_t realSize=cam.getImageSize(); |
dylanembed123 | 7:c75d5e5e6bfc | 9 | } |
dylanembed123 | 7:c75d5e5e6bfc | 10 | |
dylanembed123 | 7:c75d5e5e6bfc | 11 | void ImageHandle::take(){ |
dylanembed123 | 7:c75d5e5e6bfc | 12 | if (! cam.takePicture()) { |
dylanembed123 | 12:e42985e3ea64 | 13 | outputDevice.printf("Failed to snap!\n"); |
dylanembed123 | 7:c75d5e5e6bfc | 14 | while(1){} |
dylanembed123 | 7:c75d5e5e6bfc | 15 | } |
dylanembed123 | 12:e42985e3ea64 | 16 | unsigned int sID=getPS().getSuperID(); |
dylanembed123 | 12:e42985e3ea64 | 17 | getPS().sendPacket(sID,NULL,0,PT_IMAGE); |
dylanembed123 | 7:c75d5e5e6bfc | 18 | int size=cam.frameLength(); |
dylanembed123 | 12:e42985e3ea64 | 19 | outputDevice.printf("Image Start\n",size); |
dylanembed123 | 7:c75d5e5e6bfc | 20 | int i; |
dylanembed123 | 7:c75d5e5e6bfc | 21 | for(i=0;i<size;){ |
dylanembed123 | 7:c75d5e5e6bfc | 22 | // read 32 bytes at a time; |
dylanembed123 | 9:da906eeac51e | 23 | 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 | 24 | uint8_t bytesRead=0; |
dylanembed123 | 12:e42985e3ea64 | 25 | char* buffer = (char*)cam.readPicture(bytesToRead,&bytesRead); |
dylanembed123 | 12:e42985e3ea64 | 26 | getPS().sendPacket(sID,buffer,bytesRead); |
dylanembed123 | 12:e42985e3ea64 | 27 | //for(int a=0;a<bytesRead;a++){outputDevice.putc(buffer[a]);} |
dylanembed123 | 7:c75d5e5e6bfc | 28 | i+=bytesRead; |
dylanembed123 | 7:c75d5e5e6bfc | 29 | } |
dylanembed123 | 12:e42985e3ea64 | 30 | outputDevice.printf("Image End\n",size); |
dylanembed123 | 12:e42985e3ea64 | 31 | getPS().sendPacket(sID,NULL,0,PT_END); |
dylanembed123 | 7:c75d5e5e6bfc | 32 | } |
dylanembed123 | 7:c75d5e5e6bfc | 33 | |
dylanembed123 | 7:c75d5e5e6bfc | 34 | bool ImageHandle::check(){ |
dylanembed123 | 7:c75d5e5e6bfc | 35 | return true; |
dylanembed123 | 7:c75d5e5e6bfc | 36 | } |
dylanembed123 | 7:c75d5e5e6bfc | 37 | |
dylanembed123 | 7:c75d5e5e6bfc | 38 | void ImageHandle::run(){ |
dylanembed123 | 7:c75d5e5e6bfc | 39 | if(!initialized){ |
dylanembed123 | 7:c75d5e5e6bfc | 40 | initialized=true; |
dylanembed123 | 12:e42985e3ea64 | 41 | outputDevice.printf("Setup cam\n"); |
dylanembed123 | 7:c75d5e5e6bfc | 42 | setup(); |
dylanembed123 | 7:c75d5e5e6bfc | 43 | } |
dylanembed123 | 7:c75d5e5e6bfc | 44 | if(check()){ |
dylanembed123 | 7:c75d5e5e6bfc | 45 | take(); |
dylanembed123 | 12:e42985e3ea64 | 46 | while(true){} |
dylanembed123 | 7:c75d5e5e6bfc | 47 | } |
dylanembed123 | 7:c75d5e5e6bfc | 48 | } |