Commits

er...@ordinateur-de-eric-b-2.local  committed 48e1297

macmetallicremote2009 : #i108065 : add a new remote in the list on Mac OS X

  • Participants
  • Parent commits 204a69e

Comments (0)

Files changed (4)

File apple_remote/AppleRemote.m

 	#define NSAppKitVersionNumber10_4 824
 #endif
 
+#ifndef NSAppKitVersionNumber10_5
+    #define NSAppKitVersionNumber10_5 949
+#endif
+
 @implementation AppleRemote
 
 + (const char*) remoteControlDeviceName {
 	return AppleRemoteDeviceName;
 }
 
-- (void) setCookieMappingInDictionary: (NSMutableDictionary*) _cookieToButtonMapping	{	
-    
+- (void) setCookieMappingInDictionary: (NSMutableDictionary*) _cookieToButtonMapping
+{
     // TODO : avoid such magics 
-	if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4) {
-		// 10.4.x Tiger
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlus]		forKey:@"14_12_11_6_"];
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMinus]		forKey:@"14_13_11_6_"];		
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu]		forKey:@"14_7_6_14_7_6_"];			
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay]		forKey:@"14_8_6_14_8_6_"];
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight]		forKey:@"14_9_6_14_9_6_"];
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft]		forKey:@"14_10_6_14_10_6_"];
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight_Hold]	forKey:@"14_6_4_2_"];
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft_Hold]	forKey:@"14_6_3_2_"];
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu_Hold]	forKey:@"14_6_14_6_"];
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay_Hold]	forKey:@"18_14_6_18_14_6_"];
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteControl_Switched]	forKey:@"19_"];			
-	} else {
-		// 10.5.x Leopard
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlus]		forKey:@"31_29_28_19_18_"];
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMinus]		forKey:@"31_30_28_19_18_"];	
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu]		forKey:@"31_20_19_18_31_20_19_18_"];
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay]		forKey:@"31_21_19_18_31_21_19_18_"];
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight]		forKey:@"31_22_19_18_31_22_19_18_"];
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft]		forKey:@"31_23_19_18_31_23_19_18_"];
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight_Hold]	forKey:@"31_19_18_4_2_"];
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft_Hold]	forKey:@"31_19_18_3_2_"];
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu_Hold]	forKey:@"31_19_18_31_19_18_"];
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay_Hold]	forKey:@"35_31_19_18_35_31_19_18_"];
-		[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteControl_Switched]	forKey:@"19_"];			
-	}
+    if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4)
+    {
+        #ifdef DEBUG
+            NSLog( @"setting 10.4 cookies" );
+        #endif
+	// 10.4.x Tiger
+	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlus]		forKey:@"14_12_11_6_"];
+	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMinus]		forKey:@"14_13_11_6_"];		
+	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu]		forKey:@"14_7_6_14_7_6_"];			
+	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay]		forKey:@"14_8_6_14_8_6_"];
+	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight]		forKey:@"14_9_6_14_9_6_"];
+	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft]		forKey:@"14_10_6_14_10_6_"];
+	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight_Hold]	forKey:@"14_6_4_2_"];
+	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft_Hold]	forKey:@"14_6_3_2_"];
+	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu_Hold]	forKey:@"14_6_14_6_"];
+	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay_Hold]	forKey:@"18_14_6_18_14_6_"];
+	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteControl_Switched]	forKey:@"19_"];			
+    }
+    else if( floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_5 )
+    {
+        #ifdef DEBUG
+            NSLog( @"setting 10.5 cookies" );
+        #endif
+        // 10.5.x Leopard
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlus]		forKey:@"31_29_28_19_18_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMinus]		forKey:@"31_30_28_19_18_"];	
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu]		forKey:@"31_20_19_18_31_20_19_18_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay]		forKey:@"31_21_19_18_31_21_19_18_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight]		forKey:@"31_22_19_18_31_22_19_18_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft]		forKey:@"31_23_19_18_31_23_19_18_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight_Hold]	forKey:@"31_19_18_4_2_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft_Hold]	forKey:@"31_19_18_3_2_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu_Hold]	forKey:@"31_19_18_31_19_18_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay_Hold]	forKey:@"35_31_19_18_35_31_19_18_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteControl_Switched]	forKey:@"19_"];			
+    }    
+    else
+    {
+        #ifdef DEBUG
+            NSLog( @"setting >= 10.6 cookies" );
+        #endif
+        // 10.6.x Snow Leopard
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlus]		forKey:@"33_31_30_21_20_2_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMinus]		forKey:@"33_32_30_21_20_2_"];	
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu]		forKey:@"33_22_21_20_2_33_22_21_20_2_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay]		forKey:@"33_23_21_20_2_33_23_21_20_2_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight]		forKey:@"33_24_21_20_2_33_24_21_20_2_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft]		forKey:@"33_25_21_20_2_33_25_21_20_2_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight_Hold]	forKey:@"33_21_20_14_12_2_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft_Hold]	forKey:@"33_21_20_13_12_2_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu_Hold]	forKey:@"33_21_20_2_33_21_20_2_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay_Hold]	forKey:@"37_33_21_20_2_37_33_21_20_2_"];
+        [cookieToButtonMapping setObject:[NSNumber numberWithInt:kMetallicRemote2009ButtonPlay]       forKey:@"33_21_20_8_2_33_21_20_8_2_"];
+        [cookieToButtonMapping setObject:[NSNumber numberWithInt:kMetallicRemote2009ButtonMiddlePlay] forKey:@"33_21_20_3_2_33_21_20_3_2_"];
+        [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteControl_Switched]	forKey:@"19_"];
+    }
 }
 
-- (void) sendRemoteButtonEvent: (RemoteControlEventIdentifier) event pressedDown: (BOOL) pressedDown {
-	if (pressedDown == NO && event == kRemoteButtonMenu_Hold) {
-		// There is no seperate event for pressed down on menu hold. We are simulating that event here
-		[super sendRemoteButtonEvent:event pressedDown:YES];
-	}	
+- (void) sendRemoteButtonEvent: (RemoteControlEventIdentifier) event pressedDown: (BOOL) pressedDown
+{
+    if (pressedDown == NO && event == kRemoteButtonMenu_Hold)
+    {
+	// There is no seperate event for pressed down on menu hold. We are simulating that event here
+	[super sendRemoteButtonEvent:event pressedDown:YES];
+    }	
 	
-	[super sendRemoteButtonEvent:event pressedDown:pressedDown];
-	
-	if (pressedDown && (event == kRemoteButtonRight || event == kRemoteButtonLeft || event == kRemoteButtonPlay || event == kRemoteButtonMenu || event == kRemoteButtonPlay_Hold)) {
-		// There is no seperate event when the button is being released. We are simulating that event here
-		[super sendRemoteButtonEvent:event pressedDown:NO];
-	}
+    [super sendRemoteButtonEvent:event pressedDown:pressedDown];
+
+    if (pressedDown && (event == kRemoteButtonRight || event == kRemoteButtonLeft || event == kRemoteButtonPlay || event == kRemoteButtonMenu || event == kRemoteButtonPlay_Hold))
+    {
+	// There is no seperate event when the button is being released. We are simulating that event here
+	[super sendRemoteButtonEvent:event pressedDown:NO];
+    }
 }
 
 @end

File apple_remote/HIDRemoteControlDevice.m

 		
 	NSNumber* buttonId = [[self cookieToButtonMapping] objectForKey: cookieString];
 	if (buttonId != nil) {
-		[self sendRemoteButtonEvent: [buttonId intValue] pressedDown: (sumOfValues>0)];
+	    switch ( buttonId )
+	    {
+		case kMetallicRemote2009ButtonPlay:
+		case kMetallicRemote2009ButtonMiddlePlay:
+		    buttonId = [NSNumber numberWithInt:kRemoteButtonPlay];
+		    break;
+		default:
+		    break;
+	    }
+	    [self sendRemoteButtonEvent: [buttonId intValue] pressedDown: (sumOfValues>0)];
+
 	} else {
-		// let's see if a number of events are stored in the cookie string. this does
-		// happen when the main thread is too busy to handle all incoming events in time.
-		NSString* subCookieString;
-		NSString* lastSubCookieString=nil;
-		while( (subCookieString = [self validCookieSubstring: cookieString]) ) {
-			cookieString = [cookieString substringFromIndex: [subCookieString length]];
-			lastSubCookieString = subCookieString;
-			if (processesBacklog) [self handleEventWithCookieString: subCookieString sumOfValues:sumOfValues];
-		}
-		if (processesBacklog == NO && lastSubCookieString != nil) {
-			// process the last event of the backlog and assume that the button is not pressed down any longer.
-			// The events in the backlog do not seem to be in order and therefore (in rare cases) the last event might be 
-			// a button pressed down event while in reality the user has released it. 
-			// NSLog(@"processing last event of backlog");
-			[self handleEventWithCookieString: lastSubCookieString sumOfValues:0];
-		}
-		if ([cookieString length] > 0) {
-			NSLog(@"Unknown button for cookiestring %@", cookieString);
-		}		
+	    // let's see if a number of events are stored in the cookie string. this does
+	    // happen when the main thread is too busy to handle all incoming events in time.
+	    NSString* subCookieString;
+	    NSString* lastSubCookieString=nil;
+	    while( (subCookieString = [self validCookieSubstring: cookieString]) ) {
+		cookieString = [cookieString substringFromIndex: [subCookieString length]];
+		lastSubCookieString = subCookieString;
+		if (processesBacklog) [self handleEventWithCookieString: subCookieString sumOfValues:sumOfValues];
+	    }
+	    if (processesBacklog == NO && lastSubCookieString != nil) {
+		// process the last event of the backlog and assume that the button is not pressed down any longer.
+		// The events in the backlog do not seem to be in order and therefore (in rare cases) the last event might be 
+		// a button pressed down event while in reality the user has released it. 
+		// NSLog(@"processing last event of backlog");
+		[self handleEventWithCookieString: lastSubCookieString sumOfValues:0];
+	    }
+	    if ([cookieString length] > 0) {
+		NSLog(@"Unknown button for cookiestring %@", cookieString);
+	    }		
 	}
 }
 

File apple_remote/MultiClickRemoteBehavior.m

 }
 - (void) setClickCountingEnabled: (BOOL) value {
 	if (value) {
-		[self setClickCountEnabledButtons: kRemoteButtonPlus | kRemoteButtonMinus | kRemoteButtonPlay | kRemoteButtonLeft | kRemoteButtonRight | kRemoteButtonMenu];
+		[self setClickCountEnabledButtons: kRemoteButtonPlus | kRemoteButtonMinus | kRemoteButtonPlay | kRemoteButtonLeft | kRemoteButtonRight | kRemoteButtonMenu | kMetallicRemote2009ButtonPlay | kMetallicRemote2009ButtonMiddlePlay];
 	} else {
 		[self setClickCountEnabledButtons: 0];
 	}

File apple_remote/inc/RemoteControl.h

 	
 	// special events (not supported by all devices)	
 	kRemoteControl_Switched			=1<<13,
+
+	// New values for the "metallic" Remote (2009 model)
+	kMetallicRemote2009ButtonPlay		=1<<14,
+	kMetallicRemote2009ButtonMiddlePlay	=1<<15
+
 } RemoteControlEventIdentifier;
 
 @interface NSObject(RemoteControlDelegate)