Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef OVR_OSX_HIDDevice_h
00016 #define OVR_OSX_HIDDevice_h
00017
00018 #include "OVR_HIDDevice.h"
00019
00020 #include "OVR_OSX_DeviceManager.h"
00021
00022 #include <IOKit/IOKitLib.h>
00023
00024 namespace OVR { namespace OSX {
00025
00026 class HIDDeviceManager;
00027
00028
00029
00030
00031 class HIDDevice : public OVR::HIDDevice, public DeviceManagerThread::Notifier
00032 {
00033 private:
00034 friend class HIDDeviceManager;
00035
00036 public:
00037 HIDDevice(HIDDeviceManager* manager);
00038
00039
00040
00041 HIDDevice(HIDDeviceManager* manager, IOHIDDeviceRef device);
00042
00043 virtual ~HIDDevice();
00044
00045 bool HIDInitialize(const String& path);
00046 void HIDShutdown();
00047
00048 virtual bool SetFeatureReport(UByte* data, UInt32 length);
00049 virtual bool GetFeatureReport(UByte* data, UInt32 length);
00050
00051 bool Write(UByte* data, UInt32 length);
00052
00053 bool Read(UByte* pData, UInt32 length, UInt32 timeoutMilliS);
00054 bool ReadBlocking(UByte* pData, UInt32 length);
00055
00056
00057
00058 UInt64 OnTicks(UInt64 ticksMks);
00059
00060 private:
00061 bool initInfo();
00062 bool openDevice();
00063 void closeDevice(bool wasUnplugged);
00064 bool setupDevicePluggedInNotification();
00065 CFStringRef generateRunLoopModeString(IOHIDDeviceRef device);
00066
00067 static void staticHIDReportCallback(void* pContext,
00068 IOReturn result,
00069 void* pSender,
00070 IOHIDReportType reportType,
00071 uint32_t reportId,
00072 uint8_t* pReport,
00073 CFIndex reportLength);
00074 void hidReportCallback(UByte* pData, UInt32 length);
00075
00076 static void staticDeviceRemovedCallback(void* pContext,
00077 IOReturn result,
00078 void* pSender);
00079 void deviceRemovedCallback();
00080
00081 static void staticDeviceAddedCallback(void* pContext,
00082 io_iterator_t iterator);
00083 void deviceAddedCallback(io_iterator_t iterator);
00084
00085 bool InMinimalMode;
00086 HIDDeviceManager* HIDManager;
00087 IOHIDDeviceRef Device;
00088 HIDDeviceDesc DevDesc;
00089
00090 enum { ReadBufferSize = 96 };
00091 UByte ReadBuffer[ReadBufferSize];
00092
00093 UInt16 InputReportBufferLength;
00094 UInt16 OutputReportBufferLength;
00095 UInt16 FeatureReportBufferLength;
00096
00097 IONotificationPortRef RepluggedNotificationPort;
00098 io_iterator_t RepluggedNotification;
00099 };
00100
00101
00102
00103
00104
00105 class HIDDeviceManager : public OVR::HIDDeviceManager
00106 {
00107 friend class HIDDevice;
00108
00109 public:
00110 HIDDeviceManager(OSX::DeviceManager* Manager);
00111 virtual ~HIDDeviceManager();
00112
00113 virtual bool Initialize();
00114 virtual void Shutdown();
00115
00116 virtual bool Enumerate(HIDEnumerateVisitor* enumVisitor);
00117 virtual OVR::HIDDevice* Open(const String& path);
00118
00119 static HIDDeviceManager* CreateInternal(DeviceManager* manager);
00120
00121 private:
00122 CFRunLoopRef getRunLoop();
00123 bool initializeManager();
00124 bool initVendorProductVersion(IOHIDDeviceRef device, HIDDeviceDesc* pDevDesc);
00125 bool initUsage(IOHIDDeviceRef device, HIDDeviceDesc* pDevDesc);
00126 bool initStrings(IOHIDDeviceRef device, HIDDeviceDesc* pDevDesc);
00127 bool initSerialNumber(IOHIDDeviceRef device, HIDDeviceDesc* pDevDesc);
00128 bool getVendorId(IOHIDDeviceRef device, UInt16* pResult);
00129 bool getProductId(IOHIDDeviceRef device, UInt16* pResult);
00130 bool getLocationId(IOHIDDeviceRef device, SInt32* pResult);
00131 bool getSerialNumberString(IOHIDDeviceRef device, String* pResult);
00132 bool getPath(IOHIDDeviceRef device, String* pPath);
00133 bool getIntProperty(IOHIDDeviceRef device, CFStringRef key, int32_t* pResult);
00134 bool getStringProperty(IOHIDDeviceRef device, CFStringRef propertyName, String* pResult);
00135 bool getFullDesc(IOHIDDeviceRef device, HIDDeviceDesc* desc);
00136
00137 static void staticDeviceMatchingCallback(void *inContext,
00138 IOReturn inResult,
00139 void *inSender,
00140 IOHIDDeviceRef inIOHIDDeviceRef);
00141
00142 DeviceManager* DevManager;
00143
00144 IOHIDManagerRef HIDManager;
00145 };
00146
00147 }}
00148
00149 #endif // OVR_OSX_HIDDevice_h