From: pin Date: Fri, 2 Apr 2010 13:30:08 +0000 (+0000) Subject: qq bidouilles de l'ordre de l'expérimentation. X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/commitdiff_plain/d3c874a6ec682857cb29095cb83c679354306f05 qq bidouilles de l'ordre de l'expérimentation. git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@122 fe552daf-6dbe-4428-90eb-1537e0879342 --- diff --git a/src/pywiiuse/PyWiiUse.py b/src/pywiiuse/PyWiiUse.py index 55a1c98..baeeb9f 100755 --- a/src/pywiiuse/PyWiiUse.py +++ b/src/pywiiuse/PyWiiUse.py @@ -14,6 +14,7 @@ import os import ctypes from ctypes import c_char_p, c_int, c_byte, c_uint, c_uint16, c_float, c_short, c_void_p, c_char from ctypes import CFUNCTYPE, Structure, POINTER, Union, byref, cdll +from ctypes.util import find_library import sys # duplicate the wiiuse data structures @@ -89,6 +90,16 @@ class ir(_Structure): ('z', c_float), ] + def __str__(self) : + l = [] + pr = l.append + for name, typ in self._fields_ : + try : + pr('(%s, %s)' % (name, getattr(self, name))) + except : + pass + return '\n'.join(l) + class joystick(_Structure): _fields_ = [('max', vec2b), ('min', vec2b), @@ -239,10 +250,13 @@ min_val,max_val,min_loc,max_loc = cvMinMaxLoc(img) return CFUNCTYPE(result, *atypes)((name, dll), tuple(aflags)) # get the shared library -if os.name == 'nt': - dll = cdll.LoadLibrary('wiiuse.dll') -else: - dll = cdll.LoadLibrary('libwiiuse.so') +lib = find_library('wiiuse') or find_library('libwiiuse') +dll = cdll.LoadLibrary(lib) + +#if os.name == 'nt': +# dll = cdll.LoadLibrary('wiiuse.dll') +#else: +# dll = cdll.LoadLibrary('libwiiuse.so') # access the functions init = cfunc('wiiuse_init', dll, wiimote_pp, @@ -266,6 +280,7 @@ set_accel_threshold = dll.wiiuse_set_accel_threshold set_orient_threshold = dll.wiiuse_set_orient_threshold set_orient_threshold.argtypes = [wiimote_p, c_float] set_timeout = dll.wiiuse_set_timeout +set_ir = dll.wiiuse_set_ir def is_pressed(dev, button): return dev.btns & button @@ -332,7 +347,8 @@ nunchuk_button = { 'Z':0x01, if __name__ == '__main__': def handle_event(wm): print 'EVENT', wm.unid, wm.btns - print wm.gforce.x, wm.gforce.y, wm.gforce.z + #print wm.gforce.x, wm.gforce.y, wm.gforce.z + print wm.ir nmotes = 1 wiimotes = init(nmotes) @@ -349,13 +365,18 @@ if __name__ == '__main__': print 'failed to connect to any wiimote.' sys.exit(1) - set_leds(wiimotes[0], 0x50) + set_leds(wiimotes[0], 0x20) motion_sensing(wiimotes[0], 1) + set_ir(wiimotes[0], 1) while True: - if poll(wiimotes, nmotes): - for i in range(nmotes): - m = wiimotes[i][0] - if wiimotes[i][0].event == EVENT: - handle_event(wiimotes[i][0]) + try : + if poll(wiimotes, nmotes): + print '.' + for i in range(nmotes): + m = wiimotes[i][0] + if wiimotes[i][0].event == EVENT: + handle_event(wiimotes[i][0]) + except KeyboardInterrupt : + break