1cdf0e10cSrcweir/*****************************************************************************
2cdf0e10cSrcweir * KeyspanFrontRowControl.m
3cdf0e10cSrcweir * RemoteControlWrapper
4cdf0e10cSrcweir *
5cdf0e10cSrcweir * Created by Martin Kahr on 11.03.06 under a MIT-style license.
6cdf0e10cSrcweir * Copyright (c) 2006 martinkahr.com. All rights reserved.
7cdf0e10cSrcweir *
8cdf0e10cSrcweir * Code modified and adapted to OpenOffice.org
9cdf0e10cSrcweir * by Eric Bachard on 11.08.2008 under the same License
10cdf0e10cSrcweir *
11cdf0e10cSrcweir * Permission is hereby granted, free of charge, to any person obtaining a
12cdf0e10cSrcweir * copy of this software and associated documentation files (the "Software"),
13cdf0e10cSrcweir * to deal in the Software without restriction, including without limitation
14cdf0e10cSrcweir * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15cdf0e10cSrcweir * and/or sell copies of the Software, and to permit persons to whom the
16cdf0e10cSrcweir * Software is furnished to do so, subject to the following conditions:
17cdf0e10cSrcweir *
18cdf0e10cSrcweir * The above copyright notice and this permission notice shall be included
19cdf0e10cSrcweir * in all copies or substantial portions of the Software.
20cdf0e10cSrcweir *
21cdf0e10cSrcweir * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22cdf0e10cSrcweir * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23cdf0e10cSrcweir * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24cdf0e10cSrcweir * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25cdf0e10cSrcweir * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26cdf0e10cSrcweir * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27cdf0e10cSrcweir * THE SOFTWARE.
28cdf0e10cSrcweir *
29cdf0e10cSrcweir *****************************************************************************/
30cdf0e10cSrcweir
31cdf0e10cSrcweir#import "KeyspanFrontRowControl.h"
32cdf0e10cSrcweir#import <mach/mach.h>
33cdf0e10cSrcweir#import <mach/mach_error.h>
34cdf0e10cSrcweir#import <IOKit/IOKitLib.h>
35cdf0e10cSrcweir#import <IOKit/IOCFPlugIn.h>
36cdf0e10cSrcweir#import <IOKit/hid/IOHIDKeys.h>
37cdf0e10cSrcweir
38cdf0e10cSrcweir@implementation KeyspanFrontRowControl
39cdf0e10cSrcweir
40cdf0e10cSrcweir- (void) setCookieMappingInDictionary: (NSMutableDictionary*) _cookieToButtonMapping	{
41cdf0e10cSrcweir	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlus]		 forKey:@"11_18_99_10_"];
42cdf0e10cSrcweir	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMinus]		 forKey:@"11_18_98_10_"];
43cdf0e10cSrcweir	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu]		 forKey:@"11_18_58_10_"];
44cdf0e10cSrcweir	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay]		 forKey:@"11_18_61_10_"];
45cdf0e10cSrcweir	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight]		 forKey:@"11_18_96_10_"];
46cdf0e10cSrcweir	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft]		 forKey:@"11_18_97_10_"];
47cdf0e10cSrcweir	/* hold events are not being send by this device
48cdf0e10cSrcweir	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight_Hold]	forKey:@"14_6_4_2_"];
49cdf0e10cSrcweir	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft_Hold]	forKey:@"14_6_3_2_"];
50cdf0e10cSrcweir	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu_Hold]	forKey:@"14_6_14_6_"];
51cdf0e10cSrcweir	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay_Sleep]	forKey:@"18_14_6_18_14_6_"];
52cdf0e10cSrcweir	[_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteControl_Switched]	forKey:@"19_"];
53cdf0e10cSrcweir	*/
54cdf0e10cSrcweir}
55cdf0e10cSrcweir
56cdf0e10cSrcweir+ (io_object_t) findRemoteDevice {
57cdf0e10cSrcweir	CFMutableDictionaryRef hidMatchDictionary = NULL;
58cdf0e10cSrcweir	IOReturn ioReturnValue = kIOReturnSuccess;
59cdf0e10cSrcweir	io_iterator_t hidObjectIterator = 0;
60cdf0e10cSrcweir	io_object_t	hidDevice = 0;
61cdf0e10cSrcweir	SInt32                  idVendor = 1741;
62cdf0e10cSrcweir	SInt32                  idProduct = 0x420;
63cdf0e10cSrcweir
64cdf0e10cSrcweir	// Set up a matching dictionary to search the I/O Registry by class
65cdf0e10cSrcweir	// name for all HID class devices
66cdf0e10cSrcweir	hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey);
67cdf0e10cSrcweir
68cdf0e10cSrcweir	CFNumberRef numberRefVendor = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &idVendor);
69cdf0e10cSrcweir    if ( numberRefVendor )
70cdf0e10cSrcweir    {
71cdf0e10cSrcweir        CFDictionaryAddValue(hidMatchDictionary, CFSTR(kIOHIDVendorIDKey), numberRefVendor);
72cdf0e10cSrcweir        CFRelease(numberRefVendor);
73cdf0e10cSrcweir	}
74cdf0e10cSrcweir
75cdf0e10cSrcweir    CFNumberRef numberRefProduct = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &idProduct);
76cdf0e10cSrcweir    if ( numberRefProduct )
77cdf0e10cSrcweir    {
78cdf0e10cSrcweir        CFDictionaryAddValue(hidMatchDictionary, CFSTR(kIOHIDProductIDKey), numberRefProduct);
79cdf0e10cSrcweir        CFRelease(numberRefProduct);
80cdf0e10cSrcweir	}
81cdf0e10cSrcweir
82cdf0e10cSrcweir	// Now search I/O Registry for matching devices.
83cdf0e10cSrcweir	ioReturnValue = IOServiceGetMatchingServices(kIOMasterPortDefault, hidMatchDictionary, &hidObjectIterator);
84cdf0e10cSrcweir
85cdf0e10cSrcweir	if ((ioReturnValue == kIOReturnSuccess) && (hidObjectIterator != 0)) {
86cdf0e10cSrcweir		hidDevice = IOIteratorNext(hidObjectIterator);
87cdf0e10cSrcweir	}
88cdf0e10cSrcweir
89cdf0e10cSrcweir	// release the iterator
90cdf0e10cSrcweir    if ( hidObjectIterator )
91cdf0e10cSrcweir        IOObjectRelease(hidObjectIterator);
92cdf0e10cSrcweir
93cdf0e10cSrcweir	return hidDevice;
94cdf0e10cSrcweir
95cdf0e10cSrcweir}
96cdf0e10cSrcweir
97cdf0e10cSrcweir@end
98