Changeset 5471

Show
Ignore:
Timestamp:
04/21/08 23:35:24 (3 weeks ago)
Author:
morris
Message:

Add support for Wii remote

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Spiral/trunk/English.lproj/Preferences.nib/classes.nib

    r5460 r5471  
    5555                                <key>_simplifyFilenamesButton</key> 
    5656                                <string>NSButton</string> 
     57                                <key>_wiiRemoteImageView</key> 
     58                                <string>NSImageView</string> 
     59                                <key>_wiiRemoteProgressIndicator</key> 
     60                                <string>NSProgressIndicator</string> 
     61                                <key>_wiiRemoteTextField</key> 
     62                                <string>NSTextField</string> 
    5763                        </dict> 
    5864                        <key>SUPERCLASS</key> 
  • Spiral/trunk/English.lproj/Preferences.nib/info.nib

    r5460 r5471  
    55        <key>IBFramework Version</key> 
    66        <string>629</string> 
    7         <key>IBLastKnownRelativeProjectPath</key> 
    8         <string>../../Spiral.xcodeproj</string> 
    97        <key>IBOldestOS</key> 
    108        <integer>5</integer> 
  • Spiral/trunk/SPApplicationController.h

    r5460 r5471  
    2929#import "SPAppleRemote.h" 
    3030#import "SPPS3Remote.h" 
     31#import "SPWiiRemote.h" 
    3132 
    3233@class SPPlaylistFile; 
    3334 
    34 @interface SPApplicationController : WIObject <SPAppleRemoteDelegate, SPPS3RemoteDelegate> { 
     35@interface SPApplicationController : WIObject <SPAppleRemoteDelegate, SPPS3RemoteDelegate, SPWiiRemoteDelegate> { 
    3536        IBOutlet NSMenu                         *_chaptersMenu; 
    3637        IBOutlet NSMenu                         *_audioTrackMenu; 
     
    5152        BOOL                                            _holdingAppleRemoteButton; 
    5253        BOOL                                            _holdingPS3RemoteButton; 
     54        BOOL                                            _holdingWiiRemoteButton; 
    5355} 
    5456 
  • Spiral/trunk/SPApplicationController.m

    r5460 r5471  
    3737#import "SPPS3Remote.h" 
    3838#import "SPSettings.h" 
     39#import "SPWiiRemote.h" 
    3940 
    4041static SPApplicationController                  *SPSharedApplicationController; 
     
    6869         
    6970    [[SPAppleRemote sharedRemote] setDelegate:self]; 
    70  
    7171    [[SPPS3Remote sharedRemote] setDelegate:self]; 
    72 //    [[SPPS3Remote sharedRemote] connect]; 
     72    [[SPWiiRemote sharedRemote] setDelegate:self]; 
    7373} 
    7474 
     
    318318        double                                  rate; 
    319319         
    320         NSLog(@"0x%x", button); 
    321          
    322320        if(button == SPPS3RemoteButtonEject) { 
    323321                [[NSWorkspace sharedWorkspace] ejectCDDrive]; 
     
    414412 
    415413- (void)PS3RemoteHeldButton:(SPPS3RemoteButton)button { 
    416         NSLog(@"held 0x%x", button); 
    417          
    418414        _holdingPS3RemoteButton = YES; 
    419                 
     415         
    420416        [self performSelector:@selector(holdPS3RemoteButton:)  
    421417                           withObject:[NSNumber numberWithInt:button]]; 
     
    464460 
    465461 
     462- (void)wiiRemotePressedButton:(SPWiiRemoteButton)button { 
     463        switch(button) { 
     464                case SPWiiRemoteButton1:                NSLog(@"pressed button 1"); break; 
     465                case SPWiiRemoteButton2:                NSLog(@"pressed button 2"); break; 
     466                case SPWiiRemoteButtonB:                NSLog(@"pressed button B"); break; 
     467                case SPWiiRemoteButtonA:                NSLog(@"pressed button A"); break; 
     468                case SPWiiRemoteButtonMinus:    NSLog(@"pressed button minus"); break; 
     469                case SPWiiRemoteButtonHome:             NSLog(@"pressed button home"); break; 
     470                case SPWiiRemoteButtonLeft:             NSLog(@"pressed button left"); break; 
     471                case SPWiiRemoteButtonRight:    NSLog(@"pressed button right"); break; 
     472                case SPWiiRemoteButtonDown:             NSLog(@"pressed button down"); break; 
     473                case SPWiiRemoteButtonUp:               NSLog(@"pressed button up"); break; 
     474                case SPWiiRemoteButtonPlus:             NSLog(@"pressed button plus"); break; 
     475        } 
     476} 
     477 
     478 
     479 
     480- (void)wiiRemoteHeldButton:(SPWiiRemoteButton)button { 
     481        switch(button) { 
     482                case SPWiiRemoteButton1:                NSLog(@"held button 1"); break; 
     483                case SPWiiRemoteButton2:                NSLog(@"held button 2"); break; 
     484                case SPWiiRemoteButtonB:                NSLog(@"held button B"); break; 
     485                case SPWiiRemoteButtonA:                NSLog(@"held button A"); break; 
     486                case SPWiiRemoteButtonMinus:    NSLog(@"held button minus"); break; 
     487                case SPWiiRemoteButtonHome:             NSLog(@"held button home"); break; 
     488                case SPWiiRemoteButtonLeft:             NSLog(@"held button left"); break; 
     489                case SPWiiRemoteButtonRight:    NSLog(@"held button right"); break; 
     490                case SPWiiRemoteButtonDown:             NSLog(@"held button down"); break; 
     491                case SPWiiRemoteButtonUp:               NSLog(@"held button up"); break; 
     492                case SPWiiRemoteButtonPlus:             NSLog(@"held button plus"); break; 
     493        } 
     494         
     495        _holdingWiiRemoteButton = YES; 
     496                 
     497        [self performSelector:@selector(holdWiiRemoteButton:)  
     498                           withObject:[NSNumber numberWithInt:button]]; 
     499} 
     500 
     501 
     502 
     503- (void)holdWiiRemoteButton:(NSNumber *)button { 
     504} 
     505 
     506 
     507 
     508- (void)wiiRemoteReleasedButton { 
     509        _holdingWiiRemoteButton = NO; 
     510} 
     511 
     512 
     513 
    466514- (BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)selector { 
    467515        if(selector == @selector(insertNewline:)) { 
  • Spiral/trunk/SPPS3Remote.h

    r5460 r5471  
    2626 * POSSIBILITY OF SUCH DAMAGE. 
    2727 */ 
     28 
     29#import "SPBluetoothRemote.h" 
    2830 
    2931enum _SPPS3RemoteButton { 
     
    8385 
    8486 
    85 #define SPPS3RemoteWillConnect                          @"SPPS3RemoteWillConnect" 
    86 #define SPPS3RemoteDidConnect                           @"SPPS3RemoteDidConnect" 
    87  
    88  
    8987@protocol SPPS3RemoteDelegate; 
    9088 
    91 @interface SPPS3Remote : WIObject
     89@interface SPPS3Remote : SPBluetoothRemote
    9290        id <SPPS3RemoteDelegate>                                delegate; 
    93          
    94         IOBluetoothDevice                                               *_device; 
    95          
    96         BOOL                                                                    _connected; 
    97         BOOL                                                                    _connecting; 
    9891         
    9992        SPPS3RemoteButton                                               _lastHoldButton; 
     
    111104- (id <SPPS3RemoteDelegate>)delegate; 
    112105 
    113 - (BOOL)isConnecting; 
    114 - (BOOL)isConnected; 
    115 - (BOOL)hasDevice; 
    116  
    117106@end 
    118107 
  • Spiral/trunk/SPPS3Remote.m

    r5460 r5471  
    2929#import "SPPS3Remote.h" 
    3030 
    31 #define SPPS3RemoteName                         @"BD Remote Control" 
    32  
    33  
    3431@interface SPPS3Remote(Private) 
    3532 
    36 + (IOBluetoothDevice *)_recentRemoteDevice; 
    37  
    38 - (void)_connect; 
    39 - (void)_connectAfterDelay; 
    4033- (void)_handleButton:(unsigned char)button; 
    4134 
     
    4437 
    4538@implementation SPPS3Remote(Private) 
    46  
    47 + (IOBluetoothDevice *)_recentRemoteDevice { 
    48         NSArray                         *recentDevices; 
    49         IOBluetoothDevice       *device; 
    50          
    51         recentDevices = [IOBluetoothDevice recentDevices:0]; 
    52          
    53         for(device in recentDevices) { 
    54                 if([[device getName] isEqualToString:SPPS3RemoteName]) 
    55                         return device; 
    56         } 
    57          
    58         return NULL; 
    59 } 
    60  
    61  
    62  
    63 #pragma mark -  
    64  
    65 - (void)_connect { 
    66         IOBluetoothL2CAPChannel         *channel; 
    67         IOReturn                                        result; 
    68          
    69         result = [_device openL2CAPChannelAsync:&channel withPSM:kBluetoothL2CAPPSMHIDInterrupt delegate:self]; 
    70          
    71         if(result != kIOReturnSuccess) 
    72                 [self _connectAfterDelay]; 
    73 } 
    74  
    75  
    76  
    77 - (void)_connectAfterDelay { 
    78         _connecting = YES; 
    79          
    80         [[NSNotificationCenter defaultCenter] postNotificationName:SPPS3RemoteWillConnect object:self]; 
    81          
    82         [self performSelector:@selector(_connect) afterDelay:1.0]; 
    83 } 
    84  
    85  
    8639 
    8740- (void)_handleButton:(unsigned char)button { 
     
    12679@implementation SPPS3Remote 
    12780 
     81+ (NSString *)remoteName { 
     82        return @"BD Remote Control"; 
     83} 
     84 
     85 
     86 
     87+ (BOOL)needsInterruptChannel { 
     88        return YES; 
     89} 
     90 
     91 
     92 
     93#pragma mark - 
     94 
    12895+ (SPPS3Remote *)sharedRemote { 
    12996        static SPPS3Remote              *sharedRemote; 
     
    133100         
    134101        return sharedRemote; 
    135 } 
    136  
    137  
    138  
    139 - (id)init { 
    140         self = [super init]; 
    141          
    142         _device = [[[self class] _recentRemoteDevice] retain]; 
    143          
    144         [IOBluetoothDevice registerForConnectNotifications:self selector:@selector(bluetoothDeviceDidConnect:device:)]; 
    145  
    146         return self; 
    147 } 
    148  
    149  
    150  
    151 - (void)dealloc { 
    152         [_device release]; 
    153          
    154         [super dealloc]; 
    155102} 
    156103 
     
    177124#pragma mark - 
    178125 
    179 - (BOOL)isConnecting { 
    180         return _connecting; 
    181 } 
    182  
    183  
    184  
    185 - (BOOL)isConnected { 
    186         return _connected; 
    187 } 
    188  
    189  
    190  
    191 - (BOOL)hasDevice { 
    192         return (_device != NULL); 
    193 } 
    194  
    195  
    196  
    197 #pragma mark - 
    198  
    199 - (void)l2capChannelOpenComplete:(IOBluetoothL2CAPChannel *)channel status:(IOReturn)status { 
    200         _connecting = NO; 
    201         _connected = (status == kIOReturnSuccess); 
    202          
    203         if(_connected) 
    204                 [[NSNotificationCenter defaultCenter] postNotificationName:SPPS3RemoteDidConnect object:self]; 
    205         else 
    206                 [self _connectAfterDelay]; 
    207 } 
    208  
    209  
    210  
    211126- (void)l2capChannelData:(IOBluetoothL2CAPChannel *)channel data:(unsigned char *)buffer length:(size_t)length { 
    212127        if(length != 13) { 
     
    220135} 
    221136 
    222  
    223  
    224 - (void)bluetoothDeviceDidConnect:(IOBluetoothUserNotification *)notification device:(IOBluetoothDevice *)device { 
    225         if([[device getName] isEqualToString:SPPS3RemoteName]) { 
    226                 [device retain]; 
    227                 [_device release]; 
    228                  
    229                 _device = device; 
    230                  
    231                 [self _connectAfterDelay]; 
    232         } 
    233 } 
    234  
    235137@end 
  • Spiral/trunk/SPPreferencesController.h

    r5460 r5471  
    4343        IBOutlet NSTextField                                    *_PS3RemoteTextField; 
    4444        IBOutlet NSProgressIndicator                    *_PS3RemoteProgressIndicator; 
     45 
     46        IBOutlet NSImageView                                    *_wiiRemoteImageView; 
     47        IBOutlet NSTextField                                    *_wiiRemoteTextField; 
     48        IBOutlet NSProgressIndicator                    *_wiiRemoteProgressIndicator; 
    4549} 
    4650 
  • Spiral/trunk/SPPreferencesController.m

    r5460 r5471  
    3535- (void)_updateFastForwardSpeedTextField; 
    3636- (void)_updatePS3RemoteStatus; 
     37- (void)_updateWiiRemoteStatus; 
    3738 
    3839@end 
     
    5556         
    5657        if(![remote hasDevice]) { 
    57                 [_PS3RemoteTextField setStringValue:NSLS(@"No remote found", @"PS3 remote status")]; 
     58                [_PS3RemoteTextField setStringValue:NSLS(@"No remote found", @"Remote status")]; 
    5859                [_PS3RemoteImageView setImage:[NSImage imageNamed:@"RemoteNoDeviceFound"]]; 
    5960        } 
    6061        else if([remote isConnected]) { 
    61                 [_PS3RemoteTextField setStringValue:NSLS(@"Connected", @"PS3 remote status")]; 
     62                [_PS3RemoteTextField setStringValue:NSLS(@"Connected", @"Remote status")]; 
    6263                [_PS3RemoteImageView setImage:[NSImage imageNamed:@"RemoteConnected"]]; 
    6364        } 
    6465        else if([remote isConnecting]) { 
    65                 [_PS3RemoteTextField setStringValue:NSLS(@"Connecting...", @"PS3 remote status")]; 
     66                [_PS3RemoteTextField setStringValue:NSLS(@"Connecting...", @"Remote status")]; 
    6667                [_PS3RemoteImageView setImage:NULL]; 
    6768        } 
    6869        else { 
    69                 [_PS3RemoteTextField setStringValue:NSLS(@"Not connected", @"PS3 remote status")]; 
     70                [_PS3RemoteTextField setStringValue:NSLS(@"Not connected", @"Remote status")]; 
    7071                [_PS3RemoteImageView setImage:[NSImage imageNamed:@"RemoteNotConnected"]]; 
    7172        } 
     
    7778} 
    7879 
     80 
     81 
     82- (void)_updateWiiRemoteStatus { 
     83        SPWiiRemote             *remote; 
     84 
     85        remote = [SPWiiRemote sharedRemote]; 
     86         
     87        if(![remote hasDevice]) { 
     88                [_wiiRemoteTextField setStringValue:NSLS(@"No remote found", @"Remote status")]; 
     89                [_wiiRemoteImageView setImage:[NSImage imageNamed:@"RemoteNoDeviceFound"]]; 
     90        } 
     91        else if([remote isConnected]) { 
     92                [_wiiRemoteTextField setStringValue:NSLS(@"Connected", @"Remote status")]; 
     93                [_wiiRemoteImageView setImage:[NSImage imageNamed:@"RemoteConnected"]]; 
     94        } 
     95        else if([remote isConnecting]) { 
     96                [_wiiRemoteTextField setStringValue:NSLS(@"Connecting...", @"Remote status")]; 
     97                [_wiiRemoteImageView setImage:NULL]; 
     98        } 
     99        else { 
     100                [_wiiRemoteTextField setStringValue:NSLS(@"Not connected", @"Remote status")]; 
     101                [_wiiRemoteImageView setImage:[NSImage imageNamed:@"RemoteNotConnected"]]; 
     102        } 
     103 
     104        if([remote isConnecting]) 
     105                [_wiiRemoteProgressIndicator startAnimation:self]; 
     106        else 
     107                [_wiiRemoteProgressIndicator stopAnimation:self]; 
     108} 
     109 
    79110@end 
    80111 
     
    99130        [[NSNotificationCenter defaultCenter] 
    100131                addObserver:self 
    101                    selector:@selector(PS3RemoteWillConnect:) 
    102                            name:SPPS3RemoteWillConnect]; 
     132                   selector:@selector(bluetoothRemoteWillConnect:) 
     133                           name:SPBluetoothRemoteWillConnect]; 
    103134 
    104135        [[NSNotificationCenter defaultCenter] 
    105136                addObserver:self 
    106                    selector:@selector(PS3RemoteDidConnect:) 
    107                            name:SPPS3RemoteDidConnect]; 
     137                   selector:@selector(bluetoothRemoteDidConnect:) 
     138                           name:SPBluetoothRemoteDidConnect]; 
    108139         
    109140        return self; 
     
    136167        [self _updateFastForwardSpeedTextField]; 
    137168        [self _updatePS3RemoteStatus]; 
     169        [self _updateWiiRemoteStatus]; 
    138170} 
    139171 
     
    147179 
    148180 
    149 - (void)PS3RemoteWillConnect:(NSNotification *)notification { 
    150         NSLog(@"willconnect"); 
    151         [self _updatePS3RemoteStatus]; 
    152 
    153  
    154  
    155  
    156 - (void)PS3RemoteDidConnect:(NSNotification *)notification { 
    157         NSLog(@"didconnect"); 
    158         [self _updatePS3RemoteStatus]; 
     181- (void)bluetoothRemoteWillConnect:(NSNotification *)notification { 
     182        id              remote; 
     183         
     184        remote = [notification object]; 
     185                 
     186        NSLog(@"willconnect %@", remote); 
     187         
     188        if(remote == [SPPS3Remote sharedRemote]) 
     189                [self _updatePS3RemoteStatus]; 
     190        else if(remote == [SPWiiRemote sharedRemote]) 
     191                [self _updateWiiRemoteStatus]; 
     192
     193 
     194 
     195 
     196- (void)bluetoothRemoteDidConnect:(NSNotification *)notification { 
     197        id              remote; 
     198         
     199        remote = [notification object]; 
     200                 
     201        NSLog(@"didconnect %@", remote); 
     202         
     203        if(remote == [SPPS3Remote sharedRemote]) 
     204                [self _updatePS3RemoteStatus]; 
     205        else if(remote == [SPWiiRemote sharedRemote]) 
     206                [self _updateWiiRemoteStatus]; 
    159207} 
    160208 
  • Spiral/trunk/Spiral.xcodeproj/project.pbxproj

    r5470 r5471  
    149149                A5F34EEB0DB804F3004C3DF6 /* SPDrillGradientView.m in Sources */ = {isa = PBXBuildFile; fileRef = A5F34EE90DB804F3004C3DF6 /* SPDrillGradientView.m */; }; 
    150150                A5F34FBC0DB80CD8004C3DF6 /* SPDrillSelectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = A5F34FBB0DB80CD8004C3DF6 /* SPDrillSelectionView.m */; }; 
     151                A5F353200DBD1481004C3DF6 /* SPBluetoothRemote.m in Sources */ = {isa = PBXBuildFile; fileRef = A5F3531F0DBD1481004C3DF6 /* SPBluetoothRemote.m */; }; 
     152                A5F3535A0DBD23A5004C3DF6 /* SPWiiRemote.m in Sources */ = {isa = PBXBuildFile; fileRef = A5F353590DBD23A5004C3DF6 /* SPWiiRemote.m */; }; 
    151153                A5F518810DB669D7001BE2F8 /* IOBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A5F518800DB669D7001BE2F8 /* IOBluetooth.framework */; }; 
    152154                A5F5189A0DB66E1D001BE2F8 /* SPPS3Remote.m in Sources */ = {isa = PBXBuildFile; fileRef = A5F518990DB66E1D001BE2F8 /* SPPS3Remote.m */; }; 
     
    355357                A5F34FBA0DB80CD8004C3DF6 /* SPDrillSelectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPDrillSelectionView.h; sourceTree = "<group>"; }; 
    356358                A5F34FBB0DB80CD8004C3DF6 /* SPDrillSelectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPDrillSelectionView.m; sourceTree = "<group>"; }; 
     359                A5F3531E0DBD1481004C3DF6 /* SPBluetoothRemote.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPBluetoothRemote.h; sourceTree = "<group>"; }; 
     360                A5F3531F0DBD1481004C3DF6 /* SPBluetoothRemote.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPBluetoothRemote.m; sourceTree = "<group>"; }; 
     361                A5F353580DBD23A5004C3DF6 /* SPWiiRemote.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPWiiRemote.h; sourceTree = "<group>"; }; 
     362                A5F353590DBD23A5004C3DF6 /* SPWiiRemote.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPWiiRemote.m; sourceTree = "<group>"; }; 
    357363                A5F518800DB669D7001BE2F8 /* IOBluetooth.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOBluetooth.framework; path = /System/Library/Frameworks/IOBluetooth.framework; sourceTree = "<absolute>"; }; 
    358364                A5F518980DB66E1D001BE2F8 /* SPPS3Remote.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPPS3Remote.h; sourceTree = "<group>"; }; 
     
    722728                                A5C7B6150CC7FB4C008FAF45 /* SPAppleRemote.m */, 
    723729                                A5C7B6160CC7FB4C008FAF45 /* SPAppleRemote.h */, 
     730                                A5F3531F0DBD1481004C3DF6 /* SPBluetoothRemote.m */, 
     731                                A5F3531E0DBD1481004C3DF6 /* SPBluetoothRemote.h */, 
    724732                                A5F518990DB66E1D001BE2F8 /* SPPS3Remote.m */, 
    725733                                A5F518980DB66E1D001BE2F8 /* SPPS3Remote.h */, 
     734                                A5F353590DBD23A5004C3DF6 /* SPWiiRemote.m */, 
     735                                A5F353580DBD23A5004C3DF6 /* SPWiiRemote.h */, 
    726736                        ); 
    727737                        name = Remotes; 
     
    9901000                                A5F34EEB0DB804F3004C3DF6 /* SPDrillGradientView.m in Sources */, 
    9911001                                A5F34FBC0DB80CD8004C3DF6 /* SPDrillSelectionView.m in Sources */, 
     1002                                A5F353200DBD1481004C3DF6 /* SPBluetoothRemote.m in Sources */, 
     1003                                A5F3535A0DBD23A5004C3DF6 /* SPWiiRemote.m in Sources */, 
    9921004                        ); 
    9931005                        runOnlyForDeploymentPostprocessing = 0;