27721b400c01732180476607ef18be460e4117f3
3 '''Try to implement the example in python'''
5 import PyWiiUse
as wiiuse
14 print '--- EVENT [wiimote id %i] ---' % wm
.unid
, wm
.btns
, wm
.btns_held
, wm
.btns_released
16 for name
,b
in wiiuse
.button
.items():
17 if wiiuse
.is_pressed(wm
, b
):
20 if wiiuse
.is_just_pressed(wm
, wiiuse
.button
['-']):
21 wiiuse
.motion_sensing(wmp
, 0)
22 if wiiuse
.is_just_pressed(wm
, wiiuse
.button
['+']):
23 wiiuse
.motion_sensing(wmp
, 1)
24 if wiiuse
.is_just_pressed(wm
, wiiuse
.button
['B']):
25 wiiuse
.toggle_rumble(wmp
)
26 if wiiuse
.is_just_pressed(wm
, wiiuse
.button
['Up']):
28 if wiiuse
.is_just_pressed(wm
, wiiuse
.button
['Down']):
31 if wiiuse
.using_acc(wm
):
32 print 'roll = %f' % wm
.orient
.roll
33 print 'pitch = %f' % wm
.orient
.pitch
34 print 'yaw = %f' % wm
.orient
.yaw
36 if wiiuse
.using_ir(wm
):
38 if wm
.ir
.dot
[i
].visible
:
39 print 'IR source %i: (%u, %u)' % (i
, wm
.ir
.dot
[i
].x
, wm
.ir
.dot
[i
].y
)
40 print 'IR cursor: (%u, %u)' % (wm
.ir
.x
, wm
.ir
.y
)
41 print 'IR z distance: %f' % wm
.ir
.z
43 if wm
.exp
.type == wiiuse
.EXP_NUNCHUK
:
46 for name
,b
in wiiuse
.nunchuk_button
.items():
47 if wiiuse
.is_pressed(nc
, b
):
48 print 'Nunchuk: %s is pressed' % name
50 print 'nunchuk roll = %f' % nc
.orient
.roll
51 print 'nunchuk pitch = %f' % nc
.orient
.pitch
52 print 'nunchuk yaw = %f' % nc
.orient
.yaw
53 print 'nunchuk joystick angle: %f' % nc
.js
.ang
54 print 'nunchuk joystick magnitude: %f' % nc
.js
.mag
57 def handle_ctrl_status(wmp
, attachment
, speaker
, ir
, led
, battery_level
):
59 print '--- Controller Status [wiimote id %i] ---' % wm
.unid
60 print 'attachment', attachment
61 print 'speaker', speaker
63 print 'leds', led
[0], led
[1], led
[2], led
[3]
64 print 'battery', battery_level
66 def handle_disconnect(wmp
):
69 if os
.name
!= 'nt': print 'Press 1&2'
71 wiimotes
= wiiuse
.init(nmotes
)
73 found
= wiiuse
.find(wiimotes
, nmotes
, 5)
78 connected
= wiiuse
.connect(wiimotes
, nmotes
)
80 print 'Connected to %i wiimotes (of %i found).' % (connected
, found
)
82 print 'failed to connect to any wiimote.'
85 for i
in range(nmotes
):
86 wiiuse
.set_leds(wiimotes
[i
], wiiuse
.LED
[i
])
87 #wiiuse.rumble(wiimotes[i], 1)
89 # for i in range(nmotes):
90 # wiiuse.rumble(wiimotes[i], 0)
92 #wiiuse.status(wiimotes[0])
94 wiiuse
.motion_sensing(wiimotes
[0], 1)
96 fp
= file('mydata.txt', 'w')
100 if wiiuse
.poll(wiimotes
, nmotes
):
101 for i
in range(nmotes
):
103 if wiimotes
[i
][0].event
== wiiuse
.EVENT
:
104 #handle_event(wiimotes[i][0])
107 print >>fp
, i
, t
, wm
.gforce
.x
, wm
.gforce
.y
, wm
.gforce
.z
108 except KeyboardInterrupt:
109 for i
in range(nmotes
):
110 wiiuse
.set_leds(wiimotes
[i
], 0)
111 #wiiuse.disconnect(wiimotes[i])