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        cam.start_sensor_events()
32        time.sleep(1)
33        events = cam.get_sensor_events()
34        print "Events over 1s: %d gyro, %d accel, %d mag"%(
35                len(events["gyro"]), len(events["accel"]), len(events["mag"]))
36        assert(len(events["gyro"]) > 0)
37        assert(len(events["accel"]) > 0)
38        assert(len(events["mag"]) > 0)
39
40if __name__ == '__main__':
41    main()
42
43