Home | History | Annotate | Download | only in tests
      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" argument may also be provided, just as with all the test
     30     scripts.
     31 
     32     If no exposure value is provided, the camera will be used to measure
     33     the scene and set a level that will result in the luma (with linear
     34     tonemap) being at the 0.5 level. This requires camera 3A and capture
     35     to be functioning.
     36 
     37     For bring-up purposes, the exposure value may be manually set to a hard-
     38     coded value, without the camera having to be able to perform 3A (or even
     39     capture a shot reliably).
     40     """
     41 
     42     # Command line args, ignoring any "reboot..." args.
     43     non_reboot_argv = [s for s in sys.argv if s[:6] != "reboot"]
     44 
     45     if len(non_reboot_argv) == 1:
     46         with its.device.ItsSession() as cam:
     47             # Automatically measure target exposure.
     48             its.target.clear_cached_target_exposure()
     49             its.target.get_target_exposure(cam)
     50     elif len(non_reboot_argv) == 2:
     51         # Hard-code the target exposure.
     52         exposure = float(non_reboot_argv[1])
     53         its.target.set_hardcoded_exposure(exposure)
     54     else:
     55         print "Usage: python %s [EXPOSURE]"
     56         sys.exit(0)
     57     exposure = its.target.get_target_exposure()
     58     print "New target exposure set to", exposure
     59     print "This corresponds to %dms at ISO 100" % int(exposure/100/1000000.0)
     60 
     61 if __name__ == '__main__':
     62     main()
     63 
     64