packages/web/353/php_top/focus.php

Go to the documentation of this file.
00001 <?php
00002 /*!*******************************************************************************
00003 *! FILE NAME  : focus.php
00004 *! DESCRIPTION: Controls FPGA focus calculation and visualization
00005 *! Copyright (C) 2008 Elphel, Inc
00006 *! -----------------------------------------------------------------------------**
00007 *!
00008 *!  This program is free software: you can redistribute it and/or modify
00009 *!  it under the terms of the GNU General Public License as published by
00010 *!  the Free Software Foundation, either version 3 of the License, or
00011 *!  (at your option) any later version.
00012 *!
00013 *!  This program is distributed in the hope that it will be useful,
00014 *!  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 *!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 *!  GNU General Public License for more details.
00017 *!
00018 *!  You should have received a copy of the GNU General Public License
00019 *!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 *! -----------------------------------------------------------------------------**
00021 *!  $Log: focus.php,v $
00022 *!  Revision 1.3  2008/02/01 06:57:15  elphel
00023 *!  Made focus.html read current camera settings at startup
00024 *!
00025 *!  Revision 1.2  2008/02/01 04:52:10  elphel
00026 *!  Fixed focus visualization code in FPGA and related software
00027 *!
00028 *!  Revision 1.1  2008/01/27 06:26:47  elphel
00029 *!  Added Web Focusing Helper
00030 *!
00031 */
00032 
00033 $focus_rdonly=array(
00034   "FOCUS_SHOW"=>0,
00035   "FOCUS_SHOW1"=>0,
00036   "FOCUS_VALUE"=>0,
00037   "FOCUS_LEFT"=>0,
00038   "FOCUS_WIDTH"=>0,
00039   "FOCUS_TOP"=>0,
00040   "FOCUS_HEIGHT"=>0,
00041   "FOCUS_FILTER"=>0
00042 );
00043 $filter=array(
00044  array(0,    0.1,  0.25, 0.5,  1.0,  1.0,  0.5,  0,
00045        0.1,  0.1,  0.25, 0.5,  1.0,  1.0,  0.5,  0,
00046        0.25, 0.25, 0.5,  1.0,  1.0,  0.5,  0.25, 0,
00047        0.5,  0.5,  1.0,  1.0,  0.5,  0.25, 0.15, 0,
00048        1.0,  1.0,  1.0,  0.5,  0.25, 0.15, 0.1,  0,
00049        1.0,  1.0,  0.5,  0.25, 0.15, 0.1,  0,    0,
00050        0.5,  0.5,  0.25, 0.15, 0.1,  0,    0,    0,
00051        0,    0,    0,    0,    0,    0,    0,    0),
00052 
00053  array(0,    0.1,  0.25, 0.5,  1.0,  1.0,  0.5,  0,
00054        0,    0.1,  0.25, 0.5,  1.0,  1.0,  0.5,  0,
00055        0,    0.1,  0.25, 0.5,  1.0,  1.0,  0.5,  0,
00056        0,    0.1,  0.25, 0.5,  1.0,  1.0,  0.5,  0,
00057        0,    0.1,  0.25, 0.5,  1.0,  1.0,  0.5,  0,
00058        0,    0.1,  0.25, 0.5,  1.0,  1.0,  0.5,  0,
00059        0,    0.1,  0.25, 0.5,  1.0,  1.0,  0.5,  0,
00060        0,    0,    0,    0,    0,    0,    0,    0),
00061 
00062  array(0,    0,    0,    0,    0,    0,    0,    0,
00063        0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.1,
00064        0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
00065        0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,
00066        1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,
00067        1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,
00068        0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,
00069          0,  0,    0,    0,    0,    0,    0,    0),
00070 
00071  array(0,    0,    0.1,  0.3,  0.8,  1.0,  1.0,  0,
00072        0,    0.1,  0.15, 0.4,  0.9,  1.0,  1.0,  0,
00073        0.1,  0.15, 0.4,  0.6,  1.0,  1.0,  1.0,  0,
00074        0.3,  0.4,  0.6,  1.0,  1.0,  1.0,  1.0,  0,
00075        0.8,  0.9,  1.0,  1.0,  1.0,  1.0,  1.0,  0,
00076        1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  0,
00077        1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  0,
00078        0,    0,    0,    0,    0,    0,    0,    0),
00079 
00080  array(0,    0,    0.1,  0.3,  0.8,  1.0,  1.0,  0,
00081        0,    0,    0.1,  0.3,  0.8,  1.0,  1.0,  0,
00082        0,    0,    0.1,  0.3,  0.8,  1.0,  1.0,  0,
00083        0,    0,    0.1,  0.3,  0.8,  1.0,  1.0,  0,
00084        0,    0,    0.1,  0.3,  0.8,  1.0,  1.0,  0,
00085        0,    0,    0.1,  0.3,  0.8,  1.0,  1.0,  0,
00086        0,    0,    0.1,  0.3,  0.8,  1.0,  1.0,  0,
00087        0,    0,    0,    0,    0,    0,    0,    0),
00088 
00089  array(0,    0,    0,    0,    0,    0,    0,    0,
00090        0,    0,    0,    0,    0,    0,    0,    0,
00091        0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.1,
00092        0.3,  0.3,  0.3,  0.3,  0.3,  0.3,  0.3,  0.3,
00093        0.8,  0.8,  0.8,  0.8,  0.8,  0.8,  0.8,  0.8,
00094        1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,
00095        1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,
00096          0,  0,    0,    0,    0,    0,    0,    0),
00097 
00098  array(0,    0,    0,    0,    0.2,  1.0,  1.0,  0,
00099        0,    0,    0,    0,    0.2,  1.0,  1.0,  0,
00100        0,    0,    0,    0,    0.2,  1.0,  1.0,  0,
00101        0,    0,    0,    0,    0.2,  1.0,  1.0,  0,
00102        0.2,  0.2,  0.2,  0.2,  0.2,  1.0,  1.0,  0,
00103        1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  0,
00104        1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  0,
00105        0,    0,    0,    0,    0,    0,    0,    0),
00106 
00107  array(0,    0,    0,    0,    0.2,  1.0,  1.0,  0,
00108        0,    0,    0,    0,    0.2,  1.0,  1.0,  0,
00109        0,    0,    0,    0,    0.2,  1.0,  1.0,  0,
00110        0,    0,    0,    0,    0.2,  1.0,  1.0,  0,
00111        0,    0,    0,    0,    0.2,  1.0,  1.0,  0,
00112        0,    0,    0,    0,    0.2,  1.0,  1.0,  0,
00113        0,    0,    0,    0,    0.2,  1.0,  1.0,  0,
00114        0,    0,    0,    0,    0,    0,    0,    0),
00115 
00116  array(0,    0,    0,    0,    0,    0,    0,    0,
00117        0,    0,    0,    0,    0,    0,    0,    0,
00118        0,    0,    0,    0,    0,    0,    0,    0,
00119        0,    0,    0,    0,    0,    0,    0,    0,
00120        0.2,  0.2,  0.2,  0.2,  0.2,  1.0,  1.0,  0,
00121        1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  0,
00122        1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  0,
00123        0,    0,    0,    0,    0,    0,    0,    0),
00124 
00125  array(0,    0,    0,    0,    0,    0.2,  1.0,  0,
00126        0,    0,    0,    0,    0.2,  1.0,  1.0,  0,
00127        0,    0,    0,    0.2,  1.0,  1.0,  1.0,  0,
00128        0,    0,    0.2,  1.0,  1.0,  1.0,  1.0,  0,
00129        0,    0.2,  1.0,  1.0,  1.0,  1.0,  1.0,  0,
00130        0.2,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  0,
00131        1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  0,
00132        0,    0,    0,    0,    0,    0,    0,    0),
00133 
00134  array(0,    0,    0,    0,    0,    0.2,  1.0,  0,
00135        0,    0,    0,    0,    0,    0.2,  1.0,  0,
00136        0,    0,    0,    0,    0,    0.2,  1.0,  0,
00137        0,    0,    0,    0,    0,    0.2,  1.0,  0,
00138        0,    0,    0,    0,    0,    0.2,  1.0,  0,
00139        0,    0,    0,    0,    0,    0.2,  1.0,  0,
00140        0,    0,    0,    0,    0,    0.2,  1.0,  0,
00141        0,    0,    0,    0,    0,    0,    0,    0),
00142 
00143  array(0,    0,    0,    0,    0,    0,    0,    0,
00144        0,    0,    0,    0,    0,    0,    0,    0,
00145        0,    0,    0,    0,    0,    0,    0,    0,
00146        0,    0,    0,    0,    0,    0,    0,    0,
00147        0,    0,    0,    0,    0,    0,    0,    0,
00148        0.2,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  0,
00149        1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  0,
00150        0,    0,    0,    0,    0,    0,    0,    0),
00151 
00152  array(0,    0,    0,    0,    0,    0,    0.2,  0,
00153        0,    0,    0,    0,    0,    0.2,  1.0,  0,
00154        0,    0,    0,    0,    0.2,  1.0,  1.0,  0,
00155        0,    0,    0,    0.2,  1.0,  1.0,  1.0,  0,
00156        0,    0,    0.2,  1.0,  1.0,  1.0,  1.0,  0,
00157        0,    0.2,  1.0,  1.0,  1.0,  1.0,  1.0,  0,
00158        0.2,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  0,
00159        0,    0,    0,    0,    0,    0,    0,    0),
00160 
00161 
00162  array(0,    0,    0.1,  0.3,  0.8,  1.0,  0.2,  0,
00163        0,    0.1,  0.15, 0.4,  0.9,  1.0,  0.2,  0,
00164        0.1,  0.15, 0.4,  0.6,  1.0,  0.8,  0.2,  0,
00165        0.3,  0.4,  0.6,  1.0,  1.0,  0.5,  0.2,  0,
00166        0.8,  0.9,  1.0,  1.0,  1.0,  0.5,  0.2,  0,
00167        1.0,  1.0,  0.8,  0.5,  0.5,  0.2,  0.2,  0,
00168        0.2,  0.2,  0.2,  0.2,  0.2,  0.2,  0.1,  0,
00169        0,    0,    0,    0,    0,    0,    0,    0),
00170 
00171  array(0,    0,    0.1,  0.3,  0.8,  1.0,  0.2,  0,
00172        0,    0,    0.1,  0.3,  0.8,  1.0,  0.2,  0,
00173        0,    0,    0.1,  0.3,  0.8,  1.0,  0.2,  0,
00174        0,    0,    0.1,  0.3,  0.8,  1.0,  0.2,  0,
00175        0,    0,    0.1,  0.3,  0.8,  1.0,  0.2,  0,
00176        0,    0,    0.1,  0.3,  0.8,  1.0,  0.2,  0,
00177        0,    0,    0.1,  0.1,  0.1,  1.1,  0.1,  0,
00178        0,    0,    0,    0,    0,    0,    0,    0)
00179 );
00180 $scale=$_GET["SCALE"]*1.0;
00181 $nowait=false;
00182 
00183 if (!(($scale>0) && ($scale<100000))) $scale=4096;
00184 if (count($_GET) > 0 ) {
00185   $pars=array();
00186   foreach($_GET as $key=>$value) {
00187      if ($key=="SCALE") {
00188      } else if ($key=="TABLE") {
00189        $fn=$value+0;
00190        if ($fn<0) $fn=0;
00191        else if ($fn>14) $fn=14;
00192        for ($i=0; $i<64; $i++) {
00193         $filter[$fn][$i]=intval($scale*$filter[$fn][$i]);
00194         if ($filter[$fn][$i]>65535) $filter[$fn][$i]=65535;
00195        }
00196        $binary_tab="";
00197        for ($i=0; $i<64; $i++) $binary_tab.=pack("L",$filter[$fn][$i]);
00198        $tables_file  = fopen('/dev/fpga_tables', 'w');
00199        fseek ($tables_file, 0x2000+256*$fn) ; // start of filter table
00200        fwrite($tables_file, $binary_tab);
00201        fclose($tables_file);
00202        elphel_set_P_value(ELPHEL_FOCUS_FILTER,$fn);
00203        $pars["FOCUS_FILTER"]=$fn;
00204      } else if ($key=="NOWAIT") {
00205        $nowait=true;
00206      } else {
00207        $pars[$key]=$value+0;
00208      }
00209   }
00210 }
00212   if (count($pars) > 0 ) {
00213     elphel_set_P_arr ($pars);
00214     elphel_program_sensor (1); //nonstop
00215   }
00218   if (!$nowait) elphel_wait_frame();
00219   $state=elphel_get_P_arr ($focus_rdonly);
00220   $msg="<?xml version=\"1.0\"?>\n<focus>\n";
00221   foreach($state as $key=>$value) {
00222     $msg.=sprintf("<%s>%d</%s>\n",$key,$value,$key);
00223   }
00224   $msg.="</focus>\n";
00225   header("Content-Type: text/xml");
00226   header("Content-Length: ".strlen($msg)."\n");
00227   header("Pragma: no-cache\n");
00228   printf($msg);
00229 ?> 

Generated on Thu Aug 7 16:19:01 2008 for elphel by  doxygen 1.5.1