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