Ruben Brunk | 370e243 | 2014-10-14 18:33:23 -0700 | [diff] [blame] | 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 | # Only run test if the appropriate caps are claimed. |
Chien-Yu Chen | bad96ca | 2014-10-20 17:30:56 -0700 | [diff] [blame] | 29 | its.caps.skip_unless(its.caps.sensor_fusion(props)) |
Ruben Brunk | 370e243 | 2014-10-14 18:33:23 -0700 | [diff] [blame] | 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 | |
| 40 | if __name__ == '__main__': |
| 41 | main() |
| 42 | |