|
MythTV
0.25-pre
|
00001 #ifndef APPLEREMOTE 00002 #define APPLEREMOTE 00003 00004 // C++ headers 00005 #include <string> 00006 #include <vector> 00007 #include <map> 00008 00009 // MythTV headers 00010 #include "mthread.h" 00011 00012 #include <QTimer> 00013 00014 #include <IOKit/IOKitLib.h> 00015 #include <IOKit/IOCFPlugIn.h> 00016 #include <IOKit/hid/IOHIDLib.h> 00017 #include <IOKit/hid/IOHIDKeys.h> 00018 #include <CoreFoundation/CoreFoundation.h> 00019 00020 class AppleRemote : public QObject, public MThread 00021 { 00022 Q_OBJECT 00023 public: 00024 enum Event 00025 { // label/meaning on White ... and Aluminium remote 00026 Up = 0, // VolumePlus Up 00027 Down, // VolumeMinus Down 00028 Menu, 00029 Select, // Play Select 00030 Right, 00031 Left, 00032 RightHold, 00033 LeftHold, 00034 MenuHold, 00035 PlayHold, // was PlaySleep 00036 ControlSwitched, 00037 PlayPause, // Play or Pause 00038 Undefined // Used to handle the Apple TV > v2.3 00039 }; 00040 00041 class Listener 00042 { 00043 public: 00044 virtual ~Listener(); 00045 virtual void appleRemoteButton(Event button, bool pressedDown) = 0; 00046 }; 00047 00048 static AppleRemote * Get(); 00049 ~AppleRemote(); 00050 00051 bool isListeningToRemote(); 00052 void setListener(Listener* listener); 00053 Listener* listener() { return _listener; } 00054 void setOpenInExclusiveMode(bool in) { openInExclusiveMode = in; }; 00055 bool isOpenInExclusiveMode() { return openInExclusiveMode; }; 00056 void startListening(); 00057 void stopListening(); 00058 void run(); 00059 00060 protected: 00061 AppleRemote(); // will be a singleton class 00062 00063 static AppleRemote* _instance; 00064 00065 00066 private: 00067 bool openInExclusiveMode; 00068 IOHIDDeviceInterface** hidDeviceInterface; 00069 IOHIDQueueInterface** queue; 00070 std::vector<int> cookies; 00071 std::map< std::string, Event > cookieToButtonMapping; 00072 int remoteId; 00073 Listener* _listener; 00074 00075 bool mUsingNewAtv; 00076 AppleRemote::Event mLastEvent; 00077 int mEventCount; 00078 bool mKeyIsDown; 00079 QTimer* mCallbackTimer; 00080 00081 void _initCookieMap(); 00082 bool _initCookies(); 00083 bool _createDeviceInterface(io_object_t hidDevice); 00084 bool _openDevice(); 00085 00086 static void QueueCallbackFunction(void* target, IOReturn result, 00087 void* refcon, void* sender); 00088 void _queueCallbackFunction(IOReturn result, 00089 void* refcon, void* sender); 00090 void _queueCallbackATV23(IOReturn result); 00091 void _handleEventWithCookieString(std::string cookieString, 00092 SInt32 sumOfValues); 00093 void _handleEventATV23(std::string cookieString, SInt32 sumOfValues); 00094 00095 private slots: 00096 // Key up event handling on the ATV v2.3 and above 00097 void TimeoutHandler(); 00098 }; 00099 00100 #endif // APPLEREMOTE
1.7.6.1