5 // Created by Martin Kahr on 11.03.06.
6 // Copyright 2006 martinkahr.com. All rights reserved.
9 #import <Cocoa/Cocoa.h>
11 #import <mach/mach_error.h>
12 #import <IOKit/IOKitLib.h>
13 #import <IOKit/IOCFPlugIn.h>
14 #import <IOKit/hid/IOHIDLib.h>
15 #import <IOKit/hid/IOHIDKeys.h>
17 enum AppleRemoteEventIdentifier
19 kRemoteButtonVolume_Plus=0,
20 kRemoteButtonVolume_Minus,
25 kRemoteButtonRight_Hold,
26 kRemoteButtonLeft_Hold,
27 kRemoteButtonMenu_Hold,
28 kRemoteButtonPlay_Sleep,
29 kRemoteControl_Switched
31 typedef enum AppleRemoteEventIdentifier AppleRemoteEventIdentifier;
33 /* Encapsulates usage of the apple remote control
34 This class is implemented as a singleton as there is exactly one remote per machine (until now)
35 The class is not thread safe
37 @interface AppleRemote : NSObject {
38 IOHIDDeviceInterface** hidDeviceInterface;
39 IOHIDQueueInterface** queue;
40 NSMutableArray* allCookies;
41 NSMutableDictionary* cookieToButtonMapping;
43 BOOL openInExclusiveMode;
50 - (void) setRemoteId: (int) aValue;
53 - (BOOL) isRemoteAvailable;
55 - (BOOL) isListeningToRemote;
56 - (void) setListeningToRemote: (BOOL) value;
58 - (BOOL) isOpenInExclusiveMode;
59 - (void) setOpenInExclusiveMode: (BOOL) value;
61 - (void) setDelegate: (id) delegate;
64 - (IBAction) startListening: (id) sender;
65 - (IBAction) stopListening: (id) sender;
68 @interface AppleRemote (Singleton)
70 + (AppleRemote*) sharedRemote;
74 /* Method definitions for the delegate of the AppleRemote class
76 @interface NSObject(NSAppleRemoteDelegate)
78 - (void) appleRemoteButton: (AppleRemoteEventIdentifier)buttonIdentifier pressedDown: (BOOL) pressedDown;
82 @interface AppleRemote (PrivateMethods)
83 - (NSDictionary*) cookieToButtonMapping;
84 - (IOHIDQueueInterface**) queue;
85 - (IOHIDDeviceInterface**) hidDeviceInterface;
86 - (void) handleEventWithCookieString: (NSString*) cookieString sumOfValues: (SInt32) sumOfValues;
89 @interface AppleRemote (IOKitMethods)
90 - (io_object_t) findAppleRemoteDevice;
91 - (IOHIDDeviceInterface**) createInterfaceForDevice: (io_object_t) hidDevice;
92 - (BOOL) initializeCookies;