#! /usr/bin/python from time import sleep from commands import getoutput pocket = False while True: f = open("/sys/devices/platform/gpio-switch/proximity/state") closed = f.readline().strip() == "closed" f.close() f = open("/sys/class/i2c-adapter/i2c-3/3-001d/coord") coords = [int(w) for w in f.readline().split()] f.close() # check phone is not flat on face or back newstate = closed and ((coords[0] < -300 or coords[0] > 300) or (coords[1] < -300 or coords[1] > 300)) if pocket and not newstate: print "took out of pocket" print getoutput("dbus-send --print-reply --dest='com.nokia.profiled' /com/nokia/profiled com.nokia.profiled.set_value string:general string:vibrating.alert.enabled string:Off") elif newstate and not pocket: print "put into pocket" print getoutput("dbus-send --print-reply --dest='com.nokia.profiled' /com/nokia/profiled com.nokia.profiled.set_value string:general string:vibrating.alert.enabled string:On") pocket = newstate sleep(5)