2011-08-03 20:45:46 +08:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2012-05-25 13:44:25 +08:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
|
2011-08-03 20:45:46 +08:00
|
|
|
'''
|
|
|
|
Proximity Monitor test script
|
|
|
|
'''
|
|
|
|
|
|
|
|
import gobject
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import dbus
|
|
|
|
import dbus.mainloop.glib
|
|
|
|
from optparse import OptionParser, make_option
|
2012-12-05 20:51:30 +08:00
|
|
|
import bluezutils
|
2011-08-03 20:45:46 +08:00
|
|
|
|
2012-12-14 17:13:04 +08:00
|
|
|
BUS_NAME = 'org.bluez'
|
|
|
|
PROXIMITY_MONITOR_INTERFACE = 'org.bluez.ProxymityMonitor1'
|
|
|
|
|
2012-11-09 20:33:21 +08:00
|
|
|
def properties_changed(interface, changed, invalidated):
|
2012-12-14 17:13:04 +08:00
|
|
|
if interface != PROXIMITY_MONITOR_INTERFACE:
|
2012-11-09 20:33:21 +08:00
|
|
|
return
|
2011-08-03 20:45:46 +08:00
|
|
|
|
2012-11-09 20:33:21 +08:00
|
|
|
for name, value in changed.iteritems():
|
|
|
|
print("Property %s changed: %s" % (name, str(value)))
|
2011-08-03 20:45:46 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
|
|
|
|
|
|
|
bus = dbus.SystemBus()
|
|
|
|
|
|
|
|
option_list = [
|
|
|
|
make_option("-i", "--adapter", action="store",
|
|
|
|
type="string", dest="dev_id"),
|
|
|
|
make_option("-b", "--device", action="store",
|
|
|
|
type="string", dest="address"),
|
|
|
|
|
|
|
|
]
|
|
|
|
parser = OptionParser(option_list=option_list)
|
|
|
|
|
2013-02-04 20:29:15 +08:00
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
2011-08-03 20:45:46 +08:00
|
|
|
if (len(args) < 1):
|
2012-05-25 13:44:25 +08:00
|
|
|
print("Usage: %s <command>" % (sys.argv[0]))
|
|
|
|
print("")
|
|
|
|
print(" -b MAC LinkLossAlertLevel <none|mild|high>")
|
|
|
|
print(" -b MAC ImmediateAlertLevel <none|mild|high>")
|
2011-08-03 20:45:46 +08:00
|
|
|
sys.exit(1)
|
|
|
|
|
2012-12-05 20:51:39 +08:00
|
|
|
device = bluezutils.find_device(options.address, options.dev_id)
|
|
|
|
device_path = device.object_path
|
2011-08-03 20:45:46 +08:00
|
|
|
|
2012-12-14 17:13:04 +08:00
|
|
|
bus.add_signal_receiver(properties_changed, bus_name=BUS_NAME,
|
2012-11-09 20:33:21 +08:00
|
|
|
path=device_path,
|
|
|
|
dbus_interface="org.freedesktop.DBus.Properties",
|
|
|
|
signal_name="PropertiesChanged")
|
2011-08-03 20:45:46 +08:00
|
|
|
|
2012-12-14 17:13:04 +08:00
|
|
|
proximity = dbus.Interface(bus.get_object(BUS_NAME, device_path),
|
|
|
|
PROXIMITY_MONITOR_INTERFACE)
|
2011-08-03 20:45:46 +08:00
|
|
|
|
2012-12-14 17:13:04 +08:00
|
|
|
device_prop = dbus.Interface(bus.get_object(BUS_NAME, device_path),
|
2012-11-09 20:33:21 +08:00
|
|
|
"org.freedesktop.DBus.Properties")
|
|
|
|
|
2012-05-25 13:44:25 +08:00
|
|
|
print("Proximity SetProperty('%s', '%s')" % (args[0], args[1]))
|
2012-12-14 17:13:04 +08:00
|
|
|
device_prop.Set(PROXIMITY_MONITOR_INTERFACE, args[0], args[1])
|
2011-08-03 20:45:46 +08:00
|
|
|
|
|
|
|
mainloop = gobject.MainLoop()
|
|
|
|
mainloop.run()
|