MythTV master
AppleRemote.h
Go to the documentation of this file.
1#ifndef APPLEREMOTE
2#define APPLEREMOTE
3
4// C++ headers
5#include <string>
6#include <vector>
7#include <map>
8
9// MythTV headers
10#include "libmythbase/mthread.h"
11
12#include <QTimer>
13
14#include <IOKit/IOKitLib.h>
15#include <IOKit/IOCFPlugIn.h>
16#include <IOKit/hid/IOHIDLib.h>
17#include <IOKit/hid/IOHIDKeys.h>
18#include <CoreFoundation/CoreFoundation.h>
19
20class AppleRemote : public QObject, public MThread
21{
22 Q_OBJECT
23public:
24 enum Event
25 { // label/meaning on White ... and Aluminium remote
26 Up = 0, // VolumePlus Up
27 Down, // VolumeMinus Down
29 Select, // Play Select
35 PlayHold, // was PlaySleep
37 PlayPause, // Play or Pause
38 Undefined // Used to handle the Apple TV > v2.3
39 };
40
42 {
43 public:
44 virtual ~Listener() = default;
45 virtual void appleRemoteButton(Event button, bool pressedDown) = 0;
46 };
47
48 static AppleRemote * Get();
50
56 void startListening();
57 void stopListening();
58 void run() override; // MThread
59
60protected:
61 AppleRemote(); // will be a singleton class
62
64
65
66private:
68 IOHIDDeviceInterface** hidDeviceInterface {nullptr};
69 IOHIDQueueInterface** queue {nullptr};
70 std::vector<int> cookies;
71 std::map< std::string, Event > cookieToButtonMapping;
72 int remoteId {0};
73 Listener* _listener {nullptr};
74
76 int mEventCount {0};
77 bool mKeyIsDown {false};
78 QTimer* mCallbackTimer {nullptr};
79
80 void _initCookieMap();
81 bool _initCookies();
82 bool _createDeviceInterface(io_object_t hidDevice);
83 bool _openDevice();
84
85 static void QueueCallbackFunction(void* target, IOReturn result,
86 void* refcon, void* sender);
87 void _queueCallbackFunction(IOReturn result,
88 void* refcon, void* sender);
89 void _handleEventWithCookieString(std::string cookieString,
90 SInt32 sumOfValues);
91};
92
93#endif // APPLEREMOTE
virtual ~Listener()=default
virtual void appleRemoteButton(Event button, bool pressedDown)=0
void _handleEventWithCookieString(std::string cookieString, SInt32 sumOfValues)
std::vector< int > cookies
Definition: AppleRemote.h:70
IOHIDDeviceInterface ** hidDeviceInterface
Definition: AppleRemote.h:68
void _initCookieMap()
Apple keeps changing the "interface" between the remote and the OS.
bool openInExclusiveMode
Definition: AppleRemote.h:67
std::map< std::string, Event > cookieToButtonMapping
Definition: AppleRemote.h:71
static AppleRemote * _instance
Definition: AppleRemote.h:63
int mEventCount
Definition: AppleRemote.h:76
void setListener(Listener *listener)
Definition: AppleRemote.cpp:69
bool _initCookies()
bool mKeyIsDown
Definition: AppleRemote.h:77
void setOpenInExclusiveMode(bool in)
Definition: AppleRemote.h:54
bool _createDeviceInterface(io_object_t hidDevice)
bool isOpenInExclusiveMode()
Definition: AppleRemote.h:55
Listener * _listener
Definition: AppleRemote.h:73
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
bool _openDevice()
QTimer * mCallbackTimer
Definition: AppleRemote.h:78
static AppleRemote * Get()
Definition: AppleRemote.cpp:42
Listener * listener()
Definition: AppleRemote.h:53
IOHIDQueueInterface ** queue
Definition: AppleRemote.h:69
void _queueCallbackFunction(IOReturn result, void *refcon, void *sender)
bool isListeningToRemote()
Definition: AppleRemote.cpp:64
void stopListening()
Definition: AppleRemote.cpp:96
static void QueueCallbackFunction(void *target, IOReturn result, void *refcon, void *sender)
void startListening()
Definition: AppleRemote.cpp:74
AppleRemote::Event mLastEvent
Definition: AppleRemote.h:75
Event details.
Definition: zmdefines.h:28
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:49