Reply
Thread Tools
Posts: 137 | Thanked: 150 times | Joined on Jan 2010
#1
I've written a short python script to turn vibration on when I put my phone in my pocket (using the proximity sensor and accelerometer to check it is not just face down or covered). It is working great but I am struggling to get it to run properly on startup. I tried an upstart script in /etc/event.d/ and guessed at what event I wanted to run at. That seems to run things as root, but even if I su to user I don't seem to have access to the dbus session bus to talk to profiled. Is there somewhere else I should be launching this script from? Script is below

Code:
#! /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)
 
Posts: 1,224 | Thanked: 1,763 times | Joined on Jul 2007
#2
I use
Code:
file = open('/tmp/dbus-info')
raw = file.read()
temp = raw.split('\n')
temp2= temp[0].split('=',1)
os.environ[temp2[0]] = temp2[1]
But it might be better to run your program with run-standalone.sh.

And of course, you must make sure it runs after the session bus is already in existence.
__________________
My repository

"N900 community support for the MeeGo-Harmattan" Is the new "Mer is Fremantle for N810".

No more Nokia devices for me.
 

The Following User Says Thank You to Matan For This Useful Post:
Posts: 137 | Thanked: 150 times | Joined on Jan 2010
#3
That did the trick, Thanks!
 
Reply


 
Forum Jump


All times are GMT. The time now is 18:49.