oculus1

diff libovr/Src/osx/OVR_OSX_HIDDevice.h @ 1:e2f9e4603129

added LibOVR and started a simple vr wrapper.
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Sep 2013 16:14:59 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libovr/Src/osx/OVR_OSX_HIDDevice.h	Sat Sep 14 16:14:59 2013 +0300
     1.3 @@ -0,0 +1,149 @@
     1.4 +/************************************************************************************
     1.5 +Filename    :   OVR_OSX_HIDDevice.h
     1.6 +Content     :   OSX HID device implementation.
     1.7 +Created     :   February 26, 2013
     1.8 +Authors     :   Lee Cooper
     1.9 +
    1.10 +Copyright   :   Copyright 2013 Oculus VR, Inc. All Rights reserved.
    1.11 +
    1.12 +Use of this software is subject to the terms of the Oculus license
    1.13 +agreement provided at the time of installation or download, or which
    1.14 +otherwise accompanies this software in either electronic or hard copy form.
    1.15 +
    1.16 +*************************************************************************************/
    1.17 +
    1.18 +#ifndef OVR_OSX_HIDDevice_h
    1.19 +#define OVR_OSX_HIDDevice_h
    1.20 +
    1.21 +#include "OVR_HIDDevice.h"
    1.22 +
    1.23 +#include "OVR_OSX_DeviceManager.h"
    1.24 +
    1.25 +#include <IOKit/IOKitLib.h>
    1.26 +
    1.27 +namespace OVR { namespace OSX {
    1.28 +
    1.29 +class HIDDeviceManager;
    1.30 +
    1.31 +//-------------------------------------------------------------------------------------
    1.32 +// ***** OSX HIDDevice
    1.33 +
    1.34 +class HIDDevice : public OVR::HIDDevice, public DeviceManagerThread::Notifier
    1.35 +{
    1.36 +private:
    1.37 +    friend class HIDDeviceManager;
    1.38 +
    1.39 +public:
    1.40 +    HIDDevice(HIDDeviceManager* manager);
    1.41 +
    1.42 +    // This is a minimal constructor used during enumeration for us to pass
    1.43 +    // a HIDDevice to the visit function (so that it can query feature reports).
    1.44 +    HIDDevice(HIDDeviceManager* manager, IOHIDDeviceRef device);
    1.45 +    
    1.46 +    virtual ~HIDDevice();
    1.47 +
    1.48 +    bool HIDInitialize(const String& path);
    1.49 +    void HIDShutdown();
    1.50 +    
    1.51 +    virtual bool SetFeatureReport(UByte* data, UInt32 length);
    1.52 +	virtual bool GetFeatureReport(UByte* data, UInt32 length);
    1.53 +
    1.54 +    bool Write(UByte* data, UInt32 length);
    1.55 +
    1.56 +    bool Read(UByte* pData, UInt32 length, UInt32 timeoutMilliS);
    1.57 +    bool ReadBlocking(UByte* pData, UInt32 length);
    1.58 +
    1.59 +
    1.60 +    // DeviceManagerThread::Notifier
    1.61 +    UInt64 OnTicks(UInt64 ticksMks);
    1.62 +    
    1.63 +private:
    1.64 +    bool initInfo();
    1.65 +    bool openDevice();
    1.66 +    void closeDevice(bool wasUnplugged);
    1.67 +    bool setupDevicePluggedInNotification();
    1.68 +    CFStringRef generateRunLoopModeString(IOHIDDeviceRef device);
    1.69 +    
    1.70 +    static void staticHIDReportCallback(void* pContext,
    1.71 +                                        IOReturn result,
    1.72 +                                        void* pSender,
    1.73 +                                        IOHIDReportType reportType,
    1.74 +                                        uint32_t reportId,
    1.75 +                                        uint8_t* pReport,
    1.76 +                                        CFIndex reportLength);
    1.77 +    void hidReportCallback(UByte* pData, UInt32 length);
    1.78 +
    1.79 +    static void staticDeviceRemovedCallback(void* pContext,
    1.80 +                                            IOReturn result,
    1.81 +                                            void* pSender);
    1.82 +    void deviceRemovedCallback();
    1.83 +    
    1.84 +    static void staticDeviceAddedCallback(void* pContext,
    1.85 +                                          io_iterator_t iterator);
    1.86 +    void deviceAddedCallback(io_iterator_t iterator);
    1.87 +    
    1.88 +    bool                    InMinimalMode;
    1.89 +    HIDDeviceManager*       HIDManager;
    1.90 +    IOHIDDeviceRef          Device;
    1.91 +    HIDDeviceDesc           DevDesc;
    1.92 +    
    1.93 +    enum { ReadBufferSize = 96 };
    1.94 +    UByte                   ReadBuffer[ReadBufferSize];
    1.95 +
    1.96 +    UInt16                  InputReportBufferLength;
    1.97 +    UInt16                  OutputReportBufferLength;
    1.98 +    UInt16                  FeatureReportBufferLength;
    1.99 +    
   1.100 +    IONotificationPortRef   RepluggedNotificationPort;
   1.101 +    io_iterator_t           RepluggedNotification;
   1.102 +};
   1.103 +
   1.104 +
   1.105 +//-------------------------------------------------------------------------------------
   1.106 +// ***** OSX HIDDeviceManager
   1.107 +
   1.108 +class HIDDeviceManager : public OVR::HIDDeviceManager
   1.109 +{
   1.110 +	friend class HIDDevice;
   1.111 +
   1.112 +public:
   1.113 +    HIDDeviceManager(OSX::DeviceManager* Manager);
   1.114 +    virtual ~HIDDeviceManager();
   1.115 +
   1.116 +    virtual bool Initialize();
   1.117 +    virtual void Shutdown();
   1.118 +
   1.119 +    virtual bool Enumerate(HIDEnumerateVisitor* enumVisitor);
   1.120 +    virtual OVR::HIDDevice* Open(const String& path);
   1.121 +
   1.122 +    static HIDDeviceManager* CreateInternal(DeviceManager* manager);
   1.123 +    
   1.124 +private:
   1.125 +    CFRunLoopRef getRunLoop();
   1.126 +    bool initializeManager();
   1.127 +    bool initVendorProductVersion(IOHIDDeviceRef device, HIDDeviceDesc* pDevDesc);
   1.128 +    bool initUsage(IOHIDDeviceRef device, HIDDeviceDesc* pDevDesc);
   1.129 +    bool initStrings(IOHIDDeviceRef device, HIDDeviceDesc* pDevDesc);
   1.130 +    bool initSerialNumber(IOHIDDeviceRef device, HIDDeviceDesc* pDevDesc);
   1.131 +    bool getVendorId(IOHIDDeviceRef device, UInt16* pResult);
   1.132 +    bool getProductId(IOHIDDeviceRef device, UInt16* pResult);
   1.133 +    bool getLocationId(IOHIDDeviceRef device, SInt32* pResult);
   1.134 +    bool getSerialNumberString(IOHIDDeviceRef device, String* pResult);
   1.135 +    bool getPath(IOHIDDeviceRef device, String* pPath);
   1.136 +    bool getIntProperty(IOHIDDeviceRef device, CFStringRef key, int32_t* pResult);
   1.137 +    bool getStringProperty(IOHIDDeviceRef device, CFStringRef propertyName, String* pResult);
   1.138 +    bool getFullDesc(IOHIDDeviceRef device, HIDDeviceDesc* desc);
   1.139 +    
   1.140 +    static void staticDeviceMatchingCallback(void *inContext,
   1.141 +                                             IOReturn inResult,
   1.142 +                                             void *inSender,
   1.143 +                                             IOHIDDeviceRef inIOHIDDeviceRef);
   1.144 +    
   1.145 +    DeviceManager* DevManager;
   1.146 +
   1.147 +    IOHIDManagerRef HIDManager;
   1.148 +};
   1.149 +
   1.150 +}} // namespace OVR::OSX
   1.151 +
   1.152 +#endif // OVR_OSX_HIDDevice_h