Home | History | Annotate | Download | only in scene0
      1 # Copyright 2014 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.caps
     17 import time
     18 
     19 def main():
     20     """Basic test to query and print out sensor events.
     21 
     22     Test will only work if the screen is on (i.e.) the device isn't in standby.
     23     Pass if some of each event are received.
     24     """
     25 
     26     with its.device.ItsSession() as cam:
     27         props = cam.get_camera_properties()
     28         props = cam.override_with_hidden_physical_camera_props(props)
     29         # Only run test if the appropriate caps are claimed.
     30         its.caps.skip_unless(its.caps.sensor_fusion(props))
     31 
     32         sensors = cam.get_sensors()
     33         cam.start_sensor_events()
     34         time.sleep(1)
     35         events = cam.get_sensor_events()
     36         print "Events over 1s: %d gyro, %d accel, %d mag"%(
     37                 len(events["gyro"]), len(events["accel"]), len(events["mag"]))
     38         for key, existing in sensors.iteritems():
     39             if existing:
     40                 e_msg = 'Sensor %s has no events!' % key
     41                 assert len(events[key]) > 0, e_msg
     42 
     43 if __name__ == '__main__':
     44     main()
     45 
     46