Permalink
Browse files

contrib/create_move.py: D-Bus based Bluez add script

  • Loading branch information...
1 parent 3f165b0 commit c268f70fc3b665e0e23ddefbc51b257c9f54c8c3 @thp committed Jun 2, 2012
Showing with 53 additions and 0 deletions.
  1. +9 −0 contrib/README
  2. +44 −0 contrib/create_move.py
View
@@ -12,3 +12,12 @@ Here are some files that might be useful for users of the library:
so that a PS Move controller (also works for Sixaxis) can connect
as HID device without problems.
+ create_move.py:
+ This is a less intrusive variant of the above "bluez-register-move"
+ script. It uses D-Bus to communicate with bluetoothd and tells it
+ to add a Move Controller to the system. If that works, the device
+ is set as Trusted, so that bluetoothd will accept connections from
+ the Move Controller. It might still be necessary to restart Bluez
+ after this script has been run, but it won't tamper with the state
+ files directly.
+
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# create_move.py - Create device entry for a Move Motion Controller
+# 2012-06-02 Thomas Perl <thp.io/about>
+#
+
+import dbus
+import sys
+
+if len(sys.argv) != 2:
+ print >>sys.stderr, """
+ Usage: %s <btaddr>
+
+ Tries to add the controller with address <btaddr> to the
+ bluetoothd list of known devices via D-Bus.
+ """ % sys.argv[0]
+ sys.exit(1)
+
+address = sys.argv[1]
+
+system_bus = dbus.SystemBus()
+
+manager_object = system_bus.get_object('org.bluez', '/')
+manager = dbus.Interface(manager_object, 'org.bluez.Manager')
+
+adapter_path = manager.DefaultAdapter()
+adapter_object = system_bus.get_object('org.bluez', adapter_path)
+adapter = dbus.Interface(adapter_object, 'org.bluez.Adapter')
+
+try:
+ adapter.CreateDevice(address)
+except Exception, e:
+ print 'CreateDevice exception:', e
+
+for device in adapter.ListDevices():
+ device_object = system_bus.get_object('org.bluez', device)
+ device = dbus.Interface(device_object, 'org.bluez.Device')
+ properties = device.GetProperties()
+ if properties['Address'].lower() == address.lower():
+ print 'Setting device as trusted...'
+ device.SetProperty('Trusted', True)
+ break
+

0 comments on commit c268f70

Please sign in to comment.