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 15import its.device 16import its.caps 17import time 18 19def 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 # Only run test if the appropriate caps are claimed. 29 its.caps.skip_unless(its.caps.sensor_fusion(props)) 30 31 sensors = cam.get_sensors() 32 cam.start_sensor_events() 33 time.sleep(1) 34 events = cam.get_sensor_events() 35 print "Events over 1s: %d gyro, %d accel, %d mag"%( 36 len(events["gyro"]), len(events["accel"]), len(events["mag"])) 37 for key, existing in sensors.iteritems(): 38 if existing: 39 e_msg = 'Sensor %s has no events!' % key 40 assert len(events[key]) > 0, e_msg 41 42if __name__ == '__main__': 43 main() 44 45