Ctypes and Structures

Martijn Arts arts.martijn at gmail.com
Sun Oct 25 12:46:01 CET 2009

I'm working with ctypes on a bridge (?) from WiiUse; a new and improved
PyWiiUse, but I'm having a problem:

When connecting to the wiimotes with the init function it gives me back
an array with pointers. Every pointer points to a WiiMote structure, this
goes well.
Now when trying to poll the wiimotes (check for events like button presses)
it should edit the WiiMote structures where's button presses using
but it doesn't.

Here's a bit of code:
wiimotes = pywiiuse.init(1) # connect to the wiimotes
pywiiuse.rumble(wiimotes[0], 1) # little example of how it works

init function:
def init(nwiimotes):
    c_array = wiimote_p * nwiimotes
    wiiusedll.wiiuse_init.restype = c_array
    return wiiusedll.wiiuse_init(c_int(nwiimotes))

Now I'm going to poll it:

while True:
    if pywiiuse.poll(wiimotes, 1):
        i = 0
        while i < 1:
            print 'EVENT:'
            print pywiiuse.is_pressed(wiimotes[0], pywiiuse.button['Right'])
            i += 1

pywiiuse.button['Right']is 0x0200

This is the is_pressed function:
def is_pressed(dev, button):
    return (dev.contents.btns & button) == button

To be honest: I have no idea what is_pressed actually does, but it should
return True
or False?

After testing around a bit I found out that dev.contents.btns always equals

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091025/58695e92/attachment.html>

More information about the Python-list mailing list