Skip to content
This repository
Browse code

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

  • Loading branch information...
commit c268f70fc3b665e0e23ddefbc51b257c9f54c8c3 1 parent 3f165b0
Thomas Perl authored June 02, 2012
9  contrib/README
@@ -12,3 +12,12 @@ Here are some files that might be useful for users of the library:
12 12
  so that a PS Move controller (also works for Sixaxis) can connect
13 13
  as HID device without problems.
14 14
 
  15
+ create_move.py:
  16
+ This is a less intrusive variant of the above "bluez-register-move"
  17
+ script. It uses D-Bus to communicate with bluetoothd and tells it
  18
+ to add a Move Controller to the system. If that works, the device
  19
+ is set as Trusted, so that bluetoothd will accept connections from
  20
+ the Move Controller. It might still be necessary to restart Bluez
  21
+ after this script has been run, but it won't tamper with the state
  22
+ files directly.
  23
+
44  contrib/create_move.py
... ...
@@ -0,0 +1,44 @@
  1
+#!/usr/bin/python
  2
+# -*- coding: utf-8 -*-
  3
+#
  4
+# create_move.py - Create device entry for a Move Motion Controller
  5
+# 2012-06-02 Thomas Perl <thp.io/about>
  6
+#
  7
+
  8
+import dbus
  9
+import sys
  10
+
  11
+if len(sys.argv) != 2:
  12
+    print >>sys.stderr, """
  13
+    Usage: %s <btaddr>
  14
+
  15
+    Tries to add the controller with address <btaddr> to the
  16
+    bluetoothd list of known devices via D-Bus.
  17
+    """ % sys.argv[0]
  18
+    sys.exit(1)
  19
+
  20
+address = sys.argv[1]
  21
+
  22
+system_bus = dbus.SystemBus()
  23
+
  24
+manager_object = system_bus.get_object('org.bluez', '/')
  25
+manager = dbus.Interface(manager_object, 'org.bluez.Manager')
  26
+
  27
+adapter_path = manager.DefaultAdapter()
  28
+adapter_object = system_bus.get_object('org.bluez', adapter_path)
  29
+adapter = dbus.Interface(adapter_object, 'org.bluez.Adapter')
  30
+
  31
+try:
  32
+    adapter.CreateDevice(address)
  33
+except Exception, e:
  34
+    print 'CreateDevice exception:', e
  35
+
  36
+for device in adapter.ListDevices():
  37
+    device_object = system_bus.get_object('org.bluez', device)
  38
+    device = dbus.Interface(device_object, 'org.bluez.Device')
  39
+    properties = device.GetProperties()
  40
+    if properties['Address'].lower() == address.lower():
  41
+        print 'Setting device as trusted...'
  42
+        device.SetProperty('Trusted', True)
  43
+        break
  44
+

0 notes on commit c268f70

Please sign in to comment.
Something went wrong with that request. Please try again.