Re: [Pyobjc-dev] Using WiiRemote framework from Python [solved]
Brought to you by:
ronaldoussoren
|
From: Arnar B. <ar...@gm...> - 2008-02-11 09:39:38
|
Folks,
On Feb 11, 2008 9:29 AM, Arnar Birgisson <ar...@gm...> wrote:
> In the meantime, I figured out the bus errors. My selectors were
> wrong, I was missing the names of the parameters (which I guess in
> Obj-C are part of the method name). Now I'm dealing with some
> commnication errors that I'm sure are more related to the Wiimote
> library than the objc-bridge.
I figured out the last bit. I'm posting the code here in case anyone
(in the present or the future) is trying to connect the WiiMote on
OS-X to their python app.
The code is based on an example from John Stoner.
cheers,
Arnar
import objc
objc.loadBundle("WiiRemote", globals(), bundle_path="WiiRemote.framework")
from Foundation import *
from AppKit import *
from PyObjCTools import AppHelper
IRData = objc.createStructType("IRData", "iii", ["x", "y", "s"])
WiiRemoteDiscoveryDelegate = objc.informal_protocol(
"WiiRemoteDiscoveryDelegate",
[
objc.selector(None,
selector="WiiRemoteDiscovered:",signature="v@:@",isRequired=0),
objc.selector(None, selector="WiiRemoteDiscoveryError:",
signature="v@:i",isRequired=0)
])
WiiRemoteDelegate = objc.informal_protocol(
"WiiRemoteDelegate",
[
objc.selector(None, selector="irPointMovedX:Y:wiiRemote:",
signature="v@:ff@", isRequired=False),
objc.selector(None, selector="rawIRData:wiiRemote:",
signature="v@:[4{IRData=iii}]@", isRequired=False),
objc.selector(None,
selector="buttonChanged:isPressed:wiiRemote:", signature="v@:Sc@",
isRequired=False),
objc.selector(None,
selector="accelerationChanged:accX:accY:accZ:wiiRemote:",
signature="v@:SCCC@", isRequired=False),
objc.selector(None,
selector="joyStickChanged:tiltX:tiltY:wiiRemote:",
signature="v@:SCC@", isRequired=False),
objc.selector(None,
selector="analogButtonChanged:amount:wiiRemote:", signature="v@:SI@",
isRequired=False),
objc.selector(None, selector="wiiRemoteDisconnected:",
signature="v@:@", isRequired=False),
])
wii = None
class wii_remote_discovery_delegate(NSObject):
def WiiRemoteDiscovered_(self, wiimote):
wd.stop()
global wii
wii = wiimote.retain()
print "discovered"
delegate = wii_remote_delegate.new()
wii.setDelegate_(delegate)
print "set delegate"
wii.setLEDEnabled1_enabled2_enabled3_enabled4_(True, False, True, False)
wii.setMotionSensorEnabled_(True)
def WiiRemoteDiscoveryError_(self, code):
print "not discovered, error ", code
AppHelper.stopEventLoop()
class wii_remote_delegate(NSObject):
def irPointMovedX_Y_wiiRemote_(self, px, py, wiiRemote):
print 'irPointMovedX:Y:wiiRemote:'
def rawIRData_wiiRemote_(self, irData, wiiRemote):
print 'rawIRData:wiiRemote:'
def buttonChanged_isPressed_wiiRemote_(self, type, isPressed, wiiRemote):
print 'buttonChanged:isPressed:wiiRemote:'
def accelerationChanged_accX_accY_accZ_wiiRemote_(self, type,
accX, accY, accZ, wiiRemote):
print 'accelerationChanged:accX:accY:accZ:wiiRemote:', type,
accX, accY, accZ
def joyStickChanged_tiltX_tiltY_wiiRemote_(self, type, tiltX,
tiltY, wiiRemote):
print 'joyStickChanged:tiltX:tiltY:wiiRemote:'
def analogButtonChanged_amount_wiiRemote_(self, type, press, wiiRemote):
print 'analogButtonChanged:amount:wiiRemote:'
def wiiRemoteDisconnected_(self, device):
print 'wiiRemoteDisconnected:'
wd = WiiRemoteDiscovery.new()
x = wii_remote_discovery_delegate.new()
wd.setDelegate_(x)
wd.start()
try:
AppHelper.runConsoleEventLoop(installInterrupt=True)
except KeyboardInterrupt:
print "Ctrl-C received, quitting."
AppHelper.stopEventLoop()
|