Hi,
I've coded some little script which allows you to reject incoming phone calls by
putting your phone on the desk with its screen facing the desk.
Additionally, after rejecting the phone call, script sends an SMS with
your apologise
and note that you'll contact the caller later.
So, use case is like this:
1. You're on some meeting/lecture/at work etc., your phone is laying on the desk
somewhere near you with it's screen oriented up.
2. The phone rings, but you don'w want to/have time to answer it
3. Insted of clicking the reject button, you can simply place the
phone so it has it's
screen oriented down.
4. Phone rejects the call and sends sms.
script works on the FSO and is using Call and SMS DBus interfaces.
Kamil
#!/usr/bin/python
import dbus
from dbus.mainloop.glib import DBusGMainLoop
import gobject
import os
import threading
import struct
DBusGMainLoop(set_as_default=True)
gobject.threads_init()
bus = dbus.SystemBus()
gsm_device_obj = bus.get_object( 'org.freesmartphone.ogsmd', '/org/freesmartphone/GSM/Device' )
gsm_call_iface = dbus.Interface(gsm_device_obj, 'org.freesmartphone.GSM.Call')
sms_iface = dbus.Interface(gsm_device_obj, 'org.freesmartphone.GSM.SMS')
#audio_iface = dbus.Interface(gsm_device_obj, 'org.freesmartphone.Device.Audio')
#audio_iface.StopAllSounds()
class Worker(threading.Thread):
position = "unknown"
call_status = "unknown"
call_peer_no = "unknown"
def __init__ (self, sensor_file_name):
self.sensor = open(sensor_file_name, "rb")
threading.Thread.__init__(self)
def run (self):
event = self.sensor.read(16)
print "Sensor reading..."
while event:
(time1,time2, type, code, value) = struct.unpack("iihhi",event)
time = time1 + time2 / 1000000.0
if type == 2:
if code == 0:
x = value
if code == 1:
y = value
if code == 2:
z = value
if type == 0 and code == 0:
self.interpret_position(x,y,z)
#print x, y, z
event = self.sensor.read(16)
def interpret_position ( self, x, y, z ):
if ( z < -400 ):
if self.position == "face_up":
print "Laying on my face! Call status=" + self.call_status
if self.call_status == "incoming":
self.reject_incoming_call()
self.position = "face_down"
if ( z > 400 ):
if self.position == "face_down":
print "Laying on my back!"
self.position = "face_up"
def call_status_changed ( self, id, new_status, properties ):
print "Call status changed to " + new_status
self.call_status = new_status
if new_status == "incoming":
self.call_peer_no = properties[u'peer']
else:
self.call_peer_no = "undef"
def reject_incoming_call ( self ):
print "There is incoming call, rejecting it"
gsm_call_iface.ReleaseAll()
if self.call_peer_no != "undef":
try:
sms_iface.SendMessage( self.call_peer_no, "Hi, I'm really busy right now, but I'll call you later!", {})
except:
print "Some error while sending sms"
worker = Worker("/dev/input/event3")
mainloop = gobject.MainLoop()
bus.add_signal_receiver(
worker.call_status_changed, "CallStatus", "org.freesmartphone.GSM.Call", "org.freesmartphone.ogsmd", "/org/freesmartphone/GSM/Device" )
gobject.idle_add(worker.start)
mainloop.run()
_______________________________________________
Openmoko community mailing list
[email protected]
http://lists.openmoko.org/mailman/listinfo/community