rev |
line source |
nuclear@1
|
1 /************************************************************************************
|
nuclear@1
|
2 Filename : OVR_OSX_HIDDevice.h
|
nuclear@1
|
3 Content : OSX HID device implementation.
|
nuclear@1
|
4 Created : February 26, 2013
|
nuclear@1
|
5 Authors : Lee Cooper
|
nuclear@1
|
6
|
nuclear@1
|
7 Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved.
|
nuclear@1
|
8
|
nuclear@1
|
9 Use of this software is subject to the terms of the Oculus license
|
nuclear@1
|
10 agreement provided at the time of installation or download, or which
|
nuclear@1
|
11 otherwise accompanies this software in either electronic or hard copy form.
|
nuclear@1
|
12
|
nuclear@1
|
13 *************************************************************************************/
|
nuclear@1
|
14
|
nuclear@1
|
15 #ifndef OVR_OSX_HIDDevice_h
|
nuclear@1
|
16 #define OVR_OSX_HIDDevice_h
|
nuclear@1
|
17
|
nuclear@1
|
18 #include "OVR_HIDDevice.h"
|
nuclear@1
|
19
|
nuclear@1
|
20 #include "OVR_OSX_DeviceManager.h"
|
nuclear@1
|
21
|
nuclear@1
|
22 #include <IOKit/IOKitLib.h>
|
nuclear@1
|
23
|
nuclear@1
|
24 namespace OVR { namespace OSX {
|
nuclear@1
|
25
|
nuclear@1
|
26 class HIDDeviceManager;
|
nuclear@1
|
27
|
nuclear@1
|
28 //-------------------------------------------------------------------------------------
|
nuclear@1
|
29 // ***** OSX HIDDevice
|
nuclear@1
|
30
|
nuclear@1
|
31 class HIDDevice : public OVR::HIDDevice, public DeviceManagerThread::Notifier
|
nuclear@1
|
32 {
|
nuclear@1
|
33 private:
|
nuclear@1
|
34 friend class HIDDeviceManager;
|
nuclear@1
|
35
|
nuclear@1
|
36 public:
|
nuclear@1
|
37 HIDDevice(HIDDeviceManager* manager);
|
nuclear@1
|
38
|
nuclear@1
|
39 // This is a minimal constructor used during enumeration for us to pass
|
nuclear@1
|
40 // a HIDDevice to the visit function (so that it can query feature reports).
|
nuclear@1
|
41 HIDDevice(HIDDeviceManager* manager, IOHIDDeviceRef device);
|
nuclear@1
|
42
|
nuclear@1
|
43 virtual ~HIDDevice();
|
nuclear@1
|
44
|
nuclear@1
|
45 bool HIDInitialize(const String& path);
|
nuclear@1
|
46 void HIDShutdown();
|
nuclear@1
|
47
|
nuclear@1
|
48 virtual bool SetFeatureReport(UByte* data, UInt32 length);
|
nuclear@1
|
49 virtual bool GetFeatureReport(UByte* data, UInt32 length);
|
nuclear@1
|
50
|
nuclear@1
|
51 bool Write(UByte* data, UInt32 length);
|
nuclear@1
|
52
|
nuclear@1
|
53 bool Read(UByte* pData, UInt32 length, UInt32 timeoutMilliS);
|
nuclear@1
|
54 bool ReadBlocking(UByte* pData, UInt32 length);
|
nuclear@1
|
55
|
nuclear@1
|
56
|
nuclear@1
|
57 // DeviceManagerThread::Notifier
|
nuclear@1
|
58 UInt64 OnTicks(UInt64 ticksMks);
|
nuclear@1
|
59
|
nuclear@1
|
60 private:
|
nuclear@1
|
61 bool initInfo();
|
nuclear@1
|
62 bool openDevice();
|
nuclear@1
|
63 void closeDevice(bool wasUnplugged);
|
nuclear@1
|
64 bool setupDevicePluggedInNotification();
|
nuclear@1
|
65 CFStringRef generateRunLoopModeString(IOHIDDeviceRef device);
|
nuclear@1
|
66
|
nuclear@1
|
67 static void staticHIDReportCallback(void* pContext,
|
nuclear@1
|
68 IOReturn result,
|
nuclear@1
|
69 void* pSender,
|
nuclear@1
|
70 IOHIDReportType reportType,
|
nuclear@1
|
71 uint32_t reportId,
|
nuclear@1
|
72 uint8_t* pReport,
|
nuclear@1
|
73 CFIndex reportLength);
|
nuclear@1
|
74 void hidReportCallback(UByte* pData, UInt32 length);
|
nuclear@1
|
75
|
nuclear@1
|
76 static void staticDeviceRemovedCallback(void* pContext,
|
nuclear@1
|
77 IOReturn result,
|
nuclear@1
|
78 void* pSender);
|
nuclear@1
|
79 void deviceRemovedCallback();
|
nuclear@1
|
80
|
nuclear@1
|
81 static void staticDeviceAddedCallback(void* pContext,
|
nuclear@1
|
82 io_iterator_t iterator);
|
nuclear@1
|
83 void deviceAddedCallback(io_iterator_t iterator);
|
nuclear@1
|
84
|
nuclear@1
|
85 bool InMinimalMode;
|
nuclear@1
|
86 HIDDeviceManager* HIDManager;
|
nuclear@1
|
87 IOHIDDeviceRef Device;
|
nuclear@1
|
88 HIDDeviceDesc DevDesc;
|
nuclear@1
|
89
|
nuclear@1
|
90 enum { ReadBufferSize = 96 };
|
nuclear@1
|
91 UByte ReadBuffer[ReadBufferSize];
|
nuclear@1
|
92
|
nuclear@1
|
93 UInt16 InputReportBufferLength;
|
nuclear@1
|
94 UInt16 OutputReportBufferLength;
|
nuclear@1
|
95 UInt16 FeatureReportBufferLength;
|
nuclear@1
|
96
|
nuclear@1
|
97 IONotificationPortRef RepluggedNotificationPort;
|
nuclear@1
|
98 io_iterator_t RepluggedNotification;
|
nuclear@1
|
99 };
|
nuclear@1
|
100
|
nuclear@1
|
101
|
nuclear@1
|
102 //-------------------------------------------------------------------------------------
|
nuclear@1
|
103 // ***** OSX HIDDeviceManager
|
nuclear@1
|
104
|
nuclear@1
|
105 class HIDDeviceManager : public OVR::HIDDeviceManager
|
nuclear@1
|
106 {
|
nuclear@1
|
107 friend class HIDDevice;
|
nuclear@1
|
108
|
nuclear@1
|
109 public:
|
nuclear@1
|
110 HIDDeviceManager(OSX::DeviceManager* Manager);
|
nuclear@1
|
111 virtual ~HIDDeviceManager();
|
nuclear@1
|
112
|
nuclear@1
|
113 virtual bool Initialize();
|
nuclear@1
|
114 virtual void Shutdown();
|
nuclear@1
|
115
|
nuclear@1
|
116 virtual bool Enumerate(HIDEnumerateVisitor* enumVisitor);
|
nuclear@1
|
117 virtual OVR::HIDDevice* Open(const String& path);
|
nuclear@1
|
118
|
nuclear@1
|
119 static HIDDeviceManager* CreateInternal(DeviceManager* manager);
|
nuclear@1
|
120
|
nuclear@1
|
121 private:
|
nuclear@1
|
122 CFRunLoopRef getRunLoop();
|
nuclear@1
|
123 bool initializeManager();
|
nuclear@1
|
124 bool initVendorProductVersion(IOHIDDeviceRef device, HIDDeviceDesc* pDevDesc);
|
nuclear@1
|
125 bool initUsage(IOHIDDeviceRef device, HIDDeviceDesc* pDevDesc);
|
nuclear@1
|
126 bool initStrings(IOHIDDeviceRef device, HIDDeviceDesc* pDevDesc);
|
nuclear@1
|
127 bool initSerialNumber(IOHIDDeviceRef device, HIDDeviceDesc* pDevDesc);
|
nuclear@1
|
128 bool getVendorId(IOHIDDeviceRef device, UInt16* pResult);
|
nuclear@1
|
129 bool getProductId(IOHIDDeviceRef device, UInt16* pResult);
|
nuclear@1
|
130 bool getLocationId(IOHIDDeviceRef device, SInt32* pResult);
|
nuclear@1
|
131 bool getSerialNumberString(IOHIDDeviceRef device, String* pResult);
|
nuclear@1
|
132 bool getPath(IOHIDDeviceRef device, String* pPath);
|
nuclear@1
|
133 bool getIntProperty(IOHIDDeviceRef device, CFStringRef key, int32_t* pResult);
|
nuclear@1
|
134 bool getStringProperty(IOHIDDeviceRef device, CFStringRef propertyName, String* pResult);
|
nuclear@1
|
135 bool getFullDesc(IOHIDDeviceRef device, HIDDeviceDesc* desc);
|
nuclear@1
|
136
|
nuclear@1
|
137 static void staticDeviceMatchingCallback(void *inContext,
|
nuclear@1
|
138 IOReturn inResult,
|
nuclear@1
|
139 void *inSender,
|
nuclear@1
|
140 IOHIDDeviceRef inIOHIDDeviceRef);
|
nuclear@1
|
141
|
nuclear@1
|
142 DeviceManager* DevManager;
|
nuclear@1
|
143
|
nuclear@1
|
144 IOHIDManagerRef HIDManager;
|
nuclear@1
|
145 };
|
nuclear@1
|
146
|
nuclear@1
|
147 }} // namespace OVR::OSX
|
nuclear@1
|
148
|
nuclear@1
|
149 #endif // OVR_OSX_HIDDevice_h
|