oculus1

diff libovr/Src/linux/OVR_Linux_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/linux/OVR_Linux_HIDDevice.h	Sat Sep 14 16:14:59 2013 +0300
     1.3 @@ -0,0 +1,124 @@
     1.4 +/************************************************************************************
     1.5 +Filename    :   OVR_Linux_HIDDevice.h
     1.6 +Content     :   Linux HID device implementation.
     1.7 +Created     :   June 13, 2013
     1.8 +Authors     :   Brant Lewis
     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_LINUX_HIDDevice_h
    1.19 +#define OVR_LINUX_HIDDevice_h
    1.20 +
    1.21 +#include "OVR_HIDDevice.h"
    1.22 +#include "OVR_Linux_DeviceManager.h"
    1.23 +#include <libudev.h>
    1.24 +
    1.25 +namespace OVR { namespace Linux {
    1.26 +
    1.27 +class HIDDeviceManager;
    1.28 +
    1.29 +//-------------------------------------------------------------------------------------
    1.30 +// ***** Linux HIDDevice
    1.31 +
    1.32 +class HIDDevice : public OVR::HIDDevice, public DeviceManagerThread::Notifier
    1.33 +{
    1.34 +private:
    1.35 +    friend class HIDDeviceManager;
    1.36 +
    1.37 +public:
    1.38 +    HIDDevice(HIDDeviceManager* manager);
    1.39 +
    1.40 +    // This is a minimal constructor used during enumeration for us to pass
    1.41 +    // a HIDDevice to the visit function (so that it can query feature reports).
    1.42 +    HIDDevice(HIDDeviceManager* manager, int device_handle);
    1.43 +    
    1.44 +    virtual ~HIDDevice();
    1.45 +
    1.46 +    bool HIDInitialize(const String& path);
    1.47 +    void HIDShutdown();
    1.48 +    
    1.49 +    virtual bool SetFeatureReport(UByte* data, UInt32 length);
    1.50 +	virtual bool GetFeatureReport(UByte* data, UInt32 length);
    1.51 +
    1.52 +    // DeviceManagerThread::Notifier
    1.53 +    void OnEvent(int i, int fd);
    1.54 +    UInt64 OnTicks(UInt64 ticksMks);
    1.55 +
    1.56 +    bool OnDeviceNotification(MessageType messageType,
    1.57 +                              HIDDeviceDesc* device_info,
    1.58 +                              bool* error);
    1.59 +
    1.60 +private:
    1.61 +    bool initInfo();
    1.62 +    bool openDevice(const char* dev_path);
    1.63 +    void closeDevice(bool wasUnplugged);
    1.64 +    void closeDeviceOnIOError();
    1.65 +    bool setupDevicePluggedInNotification();
    1.66 +
    1.67 +    bool                    InMinimalMode;
    1.68 +    HIDDeviceManager*       HIDManager;
    1.69 +    int                     DeviceHandle;     // file handle to the device
    1.70 +    HIDDeviceDesc           DevDesc;
    1.71 +    
    1.72 +    enum { ReadBufferSize = 96 };
    1.73 +    UByte                   ReadBuffer[ReadBufferSize];
    1.74 +
    1.75 +    UInt16                  InputReportBufferLength;
    1.76 +    UInt16                  OutputReportBufferLength;
    1.77 +    UInt16                  FeatureReportBufferLength;
    1.78 +};
    1.79 +
    1.80 +
    1.81 +//-------------------------------------------------------------------------------------
    1.82 +// ***** Linux HIDDeviceManager
    1.83 +
    1.84 +class HIDDeviceManager : public OVR::HIDDeviceManager, public DeviceManagerThread::Notifier
    1.85 +{
    1.86 +	friend class HIDDevice;
    1.87 +
    1.88 +public:
    1.89 +    HIDDeviceManager(Linux::DeviceManager* Manager);
    1.90 +    virtual ~HIDDeviceManager();
    1.91 +
    1.92 +    virtual bool Initialize();
    1.93 +    virtual void Shutdown();
    1.94 +
    1.95 +    virtual bool Enumerate(HIDEnumerateVisitor* enumVisitor);
    1.96 +    virtual OVR::HIDDevice* Open(const String& path);
    1.97 +
    1.98 +    static HIDDeviceManager* CreateInternal(DeviceManager* manager);
    1.99 +
   1.100 +    void OnEvent(int i, int fd);
   1.101 +    
   1.102 +private:
   1.103 +    bool initializeManager();
   1.104 +    bool initVendorProductVersion(udev_device* device, HIDDeviceDesc* pDevDesc);
   1.105 +    bool getPath(udev_device* device, String* pPath);
   1.106 +    bool getIntProperty(udev_device* device, const char* key, int32_t* pResult);
   1.107 +    bool getStringProperty(udev_device* device,
   1.108 +                           const char* propertyName,
   1.109 +                           OVR::String* pResult);
   1.110 +    bool getFullDesc(udev_device* device, HIDDeviceDesc* desc);
   1.111 +    bool GetDescriptorFromPath(const char* dev_path, HIDDeviceDesc* desc);
   1.112 +    
   1.113 +    bool AddNotificationDevice(HIDDevice* device);
   1.114 +    bool RemoveNotificationDevice(HIDDevice* device);
   1.115 +    
   1.116 +    DeviceManager*           DevManager;
   1.117 +
   1.118 +    udev*                    UdevInstance;     // a handle to the udev library instance
   1.119 +    udev_monitor*            HIDMonitor;
   1.120 +    int                      HIDMonHandle;     // the udev_monitor file handle
   1.121 +
   1.122 +    Array<HIDDevice*>        NotificationDevices;
   1.123 +};
   1.124 +
   1.125 +}} // namespace OVR::Linux
   1.126 +
   1.127 +#endif // OVR_Linux_HIDDevice_h