Simple wiimote usage assistant and mapping manager

Skip to: Content | Sidebar | Footer

Example clients for wiican-service

8 June, 2010 (22:48) | devpost | By: Felix

By wiican revision 77 we have now a dbus session service that can run on demand when a client requires it. This still being a dbus api draft for wiican but fully functional as i’ve showed in yesterday post.

A full example as been commited, but let me expose some minor examples.

Behold! the most simple client example:

import dbus
if __name__ == '__main__':
    bus = dbus.SessionBus()
    wiican_iface = dbus.Interface(bus.get_object ('org.gnome.Wiican',
        '/org/gnome/Wiican'), 'org.gnome.Wiican')
    wiican_iface.ConnectWiimote('', False)
    print 'Press 1+2 to connect wiimote'

In wiican_iface we got the Wiican dbus service interface proxy so the ConnectWiimote method could be called. Behind, a wminput will be launched in a thread, in this case, the two args means no config_file (so default mapping will be loaded) and daemon-mode off.

# The status codes
from wiican.service import WC_BLUEZ_PRESENT, WC_UINPUT_PRESENT,
# Check the current wiimote connection status before trying to connect
cur_status = wiican_iface.GetStatus()
if not cur_status && WC_UINPUT_PRESENT:
    print 'Not uinput module present'
elif not cur_status & WC_BLUEZ_PRESENT:
    print 'Not bluetooth adapter present'
elif cur_status & WC_WIIMOTE_DISCOVERING:
    print 'Wiimote still in use!'

Here is a way to know the wiimote status on-demand. The status property contains a bitwise xor operation of the WC_* constants.

import gobject
from dbus.mainloop.glib import DBusGMainLoop
# A callback to receive wiimote connection status changes
def status_cb(new_status):
    # Only check if wiimote it's disconnected
    if not new_status & WC_WIIMOTE_DISCOVERING:
        print 'Wiimote its disconnected'
wiican_iface.connect_to_signal('StatusChanged', status_cb,

And finally you could be noticed of events about wiimote connection status by binding a callback function to the StatusChanged signal.

The dbus api still in hard development, so this examples can not be taked as final but a proof of concept. Maybe i’ll fill a blueprint describing it in Wiican Launchpad site.

VN:F [1.8.1_1037]
Rating: 10.0/10 (2 votes cast)
Example clients for wiican-service10.0102
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • BarraPunto
  • Bitacoras.com
  • FriendFeed
  • Identi.ca
  • LinkedIn
  • Meneame
  • Slashdot
  • Twitter

Write a comment