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