IR Mode in WiiRemote lib stops working

Help
Anonymous
2012-10-08
2013-05-23

  • Anonymous
    2012-10-08

    Hello,

    I am making use of the WiiRemote library within Xcode on a Mac (lion), I have managed to pair with the wii mote, however when I try to start the IR mode by calling , I get initial output in the debug log which looks promising and shows long output consistent with IR output (based on running the DarwiinRemote app in debug), but then after a while it stops outputting the long string and the only X and Y values I get are -100 and -100 respectively.

    What am I doing wrong here?
    AppDelegate.h :

    //
    //  AppDelegate.h
    //  WiiRawmote
    //
    //  Created on 02/10/2012.
    //
    //
    #import <Cocoa/Cocoa.h>
    #import <WiiRemote/WiiRemote.h>
    #import <WiiRemote/WiiRemoteDiscovery.h>
    @interface AppDelegate : NSObject <NSApplicationDelegate>
    @property (assign) IBOutlet NSWindow *window;
    @property (weak) IBOutlet NSTextField *statusTextField;
    @property (weak) IBOutlet NSTextField *xValueTextField;
    @property (weak) IBOutlet NSTextField *yValueTextField;
    @property (weak) IBOutlet NSTextField *zValueTextField;
    @property (weak) IBOutlet NSProgressIndicator *discoverySpinner;
    @property (weak) IBOutlet NSButton *discoverButton;
    - (IBAction)discoverWiiMotes:(id)sender;
    - (IBAction)setStatusWithString:(id)sender;
    - (IBAction)setXDisplayValueFromFloat:(id)sender;
    - (IBAction)setYDisplayValueFromFloat:(id)sender;
    - (IBAction)setZDisplayValueFromFloat:(id)sender;
    @end
    WiiRemoteDiscovery *discovery;
    WiiRemote* wii;
    BOOL spinnerAnimating;
    

    AppDelegate.m :

    //
    //  AppDelegate.m
    //  WiiRawmote
    //
    //  Created by Kingswood on 02/10/2012.
    //
    //
    #import "AppDelegate.h"
    @implementation AppDelegate
    @synthesize statusTextField;
    @synthesize xValueTextField;
    @synthesize yValueTextField;
    @synthesize zValueTextField;
    @synthesize discoverySpinner;
    @synthesize discoverButton;
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
        NSLog(@"applicationDidFinishLaunching");
    }
    - (void)awakeFromNib{
        NSLog(@"awakeFromNib");
        discovery = [[WiiRemoteDiscovery alloc] init];
        [discovery setDelegate:self];
    }
    - (void) dealloc
    {
        //apparently ARC is going to take care of all of this :S
    }
    - (IBAction)discoverWiiMotes:(id)sender {
        NSLog(@"find / give up button pressed");
        
        if(spinnerAnimating == NO)
        {
            NSLog(@"starting the discovery process");
            [self makeTheSpinnerGo:YES];
            [discovery start];
            [statusTextField setStringValue:@"trying to connect..."];
            [discoverButton setTitle:@"Give up :("];
        }
        else
        {
            NSLog(@"stopping the discovery process");
            [self makeTheSpinnerGo:NO];
            [discovery stop];
            [statusTextField setStringValue:@""];
            [statusTextField setToolTip:@"not connected"];
            [discoverButton setTitle:@"Find Wiimotes"];
        }
        
    }
    - (IBAction)setStatusWithString:(id)sender {
    }
    - (IBAction)setXDisplayValueFromFloat:(id)sender {
    }
    - (IBAction)setYDisplayValueFromFloat:(id)sender {
    }
    - (IBAction)setZDisplayValueFromFloat:(id)sender {
    }
    -(void) makeTheSpinnerGo:(BOOL)setGoing {
        
        if(setGoing == YES)
        {
            [discoverySpinner setHidden:NO];
            [discoverySpinner startAnimation:self];
            spinnerAnimating = YES;
        }
        else
        {
            [discoverySpinner setHidden:YES];
            [discoverySpinner stopAnimation:self];
            spinnerAnimating = NO;
        }
        
    }
    #pragma mark -
    #pragma mark WiiRemoteDiscovery delegates
    - (void) WiiRemoteDiscoveryError:(int)code {
        [discoverySpinner stopAnimation:self];
        NSLog([NSString stringWithFormat:@"===== WiiRemoteDiscovery error.  If clicking Find Wiimote gives this error, try System Preferences > Bluetooth > Devices, delete Nintendo. (%d) =====", code]);
    }
    - (void) willStartWiimoteConnections {
        NSLog(@"\n===== WiiRemote discovered.  Opening connection. =====");
    }
    - (void) WiiRemoteDiscovered:(WiiRemote*)wiimote {
    
        //  [discovery stop];
    
        // the wiimote must be retained because the discovery provides us with an autoreleased object
        wii = wiimote;
        //wii = [wiimote retain];
        [wiimote setDelegate:self];
    
        NSLog(@"\n===== Connected to WiiRemote =====");
        [discoverySpinner stopAnimation:self];
    
        [wiimote setLEDEnabled1:YES enabled2:NO enabled3:YES enabled4:NO];
    
        
        [wiimote setMotionSensorEnabled:YES];
        [wiimote setIRSensorEnabled:YES];
    
    }
    - (void) irPointMovedX:(float) px Y:(float) py{
        //NSLog([NSString stringWithFormat:@"x: %f y: %f", px, py]);
        [xValueTextField setStringValue:[NSString stringWithFormat:@"%f",px]];
        [yValueTextField setStringValue:[NSString stringWithFormat:@"%f",py]];
        
    }
    - (void) rawIRData: (IRData[4]) irData{
        
        //[outputPanel setString:[NSString stringWithFormat:@"%@\n===== Mouse Mode On (Motion Sensors) =====", [outputPanel setSt]]];
        NSLog(@"rawIRData");
    }
    - (void) buttonChanged:(WiiButtonType) type isPressed:(BOOL) isPressed{
    }
    - (void) accelerationChanged:(WiiAccelerationSensorType) type accX:(unsigned short) accX accY:(unsigned short) accY accZ:(unsigned short) accZ{
    }
    - (void) joyStickChanged:(WiiJoyStickType) type tiltX:(unsigned short) tiltX tiltY:(unsigned short) tiltY{
    }
    - (void) analogButtonChanged:(WiiButtonType) type amount:(unsigned short) press{
    }
    - (void) pressureChanged:(WiiPressureSensorType) type pressureTR:(float) bPressureTR pressureBR:(float) bPressureBR
                  pressureTL:(float) bPressureTL pressureBL:(float) bPressureBL{
    }
    - (void) batteryLevelChanged:(double) level{
    }
    - (void) wiiRemoteDisconnected:(IOBluetoothDevice*) device{
    }
    - (void) gotMiiData: (Mii*) mii_data_buf at: (int) slot{
    }
    - (void) rawPressureChanged:(WiiBalanceBoardGrid) bbData{
    }
    - (void) allPressureChanged:(WiiPressureSensorType) type bbData:(WiiBalanceBoardGrid) bbData bbDataInKg:(WiiBalanceBoardGrid) bbDataInKg{
    }
    - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
    {
        return YES;
    }
    @end
    

    Any help / pointers welcome.

    Thanks