python for android : 传感器

来源:互联网 发布:手机安装windows软件 编辑:程序博客网 时间:2024/06/05 16:21

参考: file:///sl4a/doc/SensorManagerFacade.html

sensor.py

import android, timedroid = android.Android()droid.startSensingTimed(1, 250)time.sleep(1)s1 = droid.readSensors().results2 = droid.sensorsGetAccuracy().results3 = droid.sensorsGetLight().results4 = droid.sensorsReadAccelerometer().results5 = droid.sensorsReadMagnetometer().results6 = droid.sensorsReadOrientation().resultdroid.stopSensing()print 's1=',s1print 's2=',s2print 's3=',s3print 's4=',s4print 's5=',s5print 's6=',s6


在手机上测试了多次,观察数据后写出 function

def sensor():    droid.startSensingTimed(1, 250)    time.sleep(0.2)    s4 = droid.sensorsReadAccelerometer().result    droid.stopSensing()    x,y,z =s4        if x<1.0 and y>3.0 :        droid.makeToast('portrait  纵向 ')    if x>3.0 and y<1.0 :        droid.makeToast('landscape 横向 ')    if x<1.0 and y<1.0 :        droid.makeToast('horizontal 水平')    return





0 0