00001 #include "../F2.h"
00002
00003 int main(int argc, char **argv) {
00004 FCam::F2::Lens lens;
00005
00006
00007 int counter = 0;
00008 while (lens.getState() != FCam::F2::Lens::Ready && counter < 20) {
00009 usleep(100000);
00010 counter++;
00011 }
00012 if (counter == 20) {
00013 if (lens.getState() == FCam::F2::Lens::NoLens) {
00014 std::cout << "No lens plugged in yet. How about you put one in and try again" << std::endl;
00015 } else {
00016 std::cout << "Lens isn't becoming ready. Probably a communication problem with the controller"<<std::endl;
00017 }
00018 exit(0);
00019 }
00020
00021 lens.setFocus(lens.farFocus());
00022 std::cout << "Tried to focus at 0 diop, actual: "<<lens.getFocus() << std::endl;
00023
00024 lens.setFocus(lens.nearFocus());
00025 std::cout << "Tried to focus at "<<lens.nearFocus()<<" diop, actual: "<<lens.getFocus() << std::endl;
00026
00027 std::cout << "Lens focus speed range: " << lens.minFocusSpeed() << " to "<< lens.minFocusSpeed()<<" diopters/sec" << std::endl;
00028
00029 std::cout << "Lens focal length: " << lens.getZoom() <<std::endl;
00030
00031 lens.setAperture(lens.wideAperture());
00032 std::cout << "Tried to open aperture, actual: "<<lens.getAperture() << std::endl;
00033
00034 lens.setAperture(lens.narrowAperture());
00035 std::cout << "Tried to close aperture, actual: "<<lens.getAperture() << std::endl;
00036
00037 FCam::EF232LensDatabase db;
00038
00039 const FCam::EF232LensInfo *currentLens = db.find(lens.minZoom(),
00040 lens.maxZoom());
00041
00042 std::cout << "Database for the current lens" <<std::endl;
00043 currentLens->print(std::cout);
00044
00045 usleep(1000000);
00046
00047
00048 if (argc > 1) {
00049 std::string arg1(argv[1]);
00050
00051 if (arg1 == "-f") {
00052 std::cout << "Testing focus movement speed"<<std::endl;
00053 float startDiop = lens.nearFocus();
00054 float endDiop = lens.farFocus();
00055 int steps = 10;
00056 for (float diop = startDiop; diop > endDiop; diop -= (startDiop-endDiop)/steps ) {
00057 lens.setFocus(startDiop);
00058 while (!lens.focusChanging()) usleep(1000);
00059 while (lens.focusChanging()) usleep(1000);
00060 FCam::Time startT = FCam::Time::now();
00061 lens.setFocus(diop);
00062 while (!lens.focusChanging()) usleep(1000);
00063 while (lens.focusChanging()) usleep(1000);
00064 FCam::Time endT = FCam::Time::now();
00065 std::cout << "Moving from "<<startDiop<<" to "<<diop<<
00066 " diopters took "<<(endT-startT)/1000.0<<" ms, which is "<<(startDiop-diop)/((endT-startT)/1000000.0)<<" diop/sec"<<std::endl;
00067 }
00068 } else if (arg1 == "-c") {
00069 std::cout << "Starting full lens calibration"<<std::endl;
00070
00071
00072 std::cout << "Please move lens to the minimum focal length (largest field of view)" << std::endl;
00073 int timeout_count = 0;
00074 while (timeout_count < 50) {
00075 if (lens.getZoom() == lens.minZoom()) break;
00076 timeout_count++;
00077 usleep(100000);
00078 }
00079 if (timeout_count == 50) {
00080 std::cout << "Timeout on calibration, bye!\n";
00081 return 1;
00082 }
00083
00084 std::cout << "Please move lens to the maximum focal length (smallest field of view)" << std::endl;
00085 timeout_count = 0;
00086 while (timeout_count < 500) {
00087 if (lens.getZoom() == lens.maxZoom()) break;
00088 timeout_count++;
00089 usleep(10000);
00090 }
00091 if (timeout_count == 50) {
00092 std::cout << "Timeout on calibration, bye!\n";
00093 return 1;
00094 }
00095 currentLens = db.find(lens.minZoom(),
00096 lens.maxZoom());
00097
00098
00099 if (currentLens->name == "Unknown") {
00100 FCam::EF232LensInfo updatedLens = *currentLens;
00101 std::cout << "Please enter name for current lens: "<<std::endl;
00102 std::getline(std::cin, updatedLens.name);
00103 currentLens = db.update(updatedLens);
00104 }
00105
00106 std::cout << "Calibrated database for the current lens" <<std::endl;
00107 currentLens->print(std::cout);
00108
00109 std::cout << "Ok to save? (y/n)"<<std::endl;
00110 std::string tmp;
00111 std::cin>>std::ws;
00112 std::cin>>tmp;
00113 if (tmp == "y"){
00114 std::cout << "Saving database" << std::endl;
00115 db.save();
00116 }
00117 }
00118 }
00119 }