Home | History | Annotate | Download | only in tools
      1 # Copyright 2013 The Android Open Source Project
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
      4 # you may not use this file except in compliance with the License.
      5 # You may obtain a copy of the License at
      6 #
      7 #      http://www.apache.org/licenses/LICENSE-2.0
      8 #
      9 # Unless required by applicable law or agreed to in writing, software
     10 # distributed under the License is distributed on an "AS IS" BASIS,
     11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     14 
     15 import its.device
     16 import its.target
     17 import sys
     18 
     19 def main():
     20     """Set the target exposure.
     21 
     22     This program is just a wrapper around the its.target module, to allow the
     23     functions in it to be invoked from the command line.
     24 
     25     Usage:
     26         python config.py        - Measure the target exposure, and cache it.
     27         python config.py EXP    - Hard-code (and cache) the target exposure.
     28 
     29     The "reboot" or "reboot=<N>" and "camera=<N>" arguments may also be
     30     provided, just as with all the test scripts. The "target" argument is
     31     may also be provided but it has no effect on this script since the cached
     32     exposure value is cleared regardless.
     33 
     34     If no exposure value is provided, the camera will be used to measure
     35     the scene and set a level that will result in the luma (with linear
     36     tonemap) being at the 0.5 level. This requires camera 3A and capture
     37     to be functioning.
     38 
     39     For bring-up purposes, the exposure value may be manually set to a hard-
     40     coded value, without the camera having to be able to perform 3A (or even
     41     capture a shot reliably).
     42     """
     43 
     44     # Command line args, ignoring any args that will be passed down to the
     45     # ItsSession constructor.
     46     args = [s for s in sys.argv if s[:6] not in \
     47             ["reboot", "camera", "target", "device"]]
     48 
     49     if len(args) == 1:
     50         with its.device.ItsSession() as cam:
     51             # Automatically measure target exposure.
     52             its.target.clear_cached_target_exposure()
     53             exposure = its.target.get_target_exposure(cam)
     54     elif len(args) == 2:
     55         # Hard-code the target exposure.
     56         exposure = int(args[1])
     57         its.target.set_hardcoded_exposure(exposure)
     58     else:
     59         print "Usage: python %s [EXPOSURE]"
     60         sys.exit(0)
     61     print "New target exposure set to", exposure
     62     print "This corresponds to %dms at ISO 100" % int(exposure/100/1000000.0)
     63 
     64 if __name__ == '__main__':
     65     main()
     66 
     67