oculus1

diff libovr/Src/OVR_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/OVR_HIDDevice.h	Sat Sep 14 16:14:59 2013 +0300
     1.3 @@ -0,0 +1,143 @@
     1.4 +/************************************************************************************
     1.5 +
     1.6 +Filename    :   OVR_HIDDevice.h
     1.7 +Content     :   Cross platform HID device interface.
     1.8 +Created     :   February 22, 2013
     1.9 +Authors     :   Lee Cooper
    1.10 +
    1.11 +Copyright   :   Copyright 2013 Oculus VR, Inc. All Rights reserved.
    1.12 +
    1.13 +Use of this software is subject to the terms of the Oculus license
    1.14 +agreement provided at the time of installation or download, or which
    1.15 +otherwise accompanies this software in either electronic or hard copy form.
    1.16 +
    1.17 +*************************************************************************************/
    1.18 +
    1.19 +#ifndef OVR_HIDDevice_h
    1.20 +#define OVR_HIDDevice_h
    1.21 +
    1.22 +#include "OVR_HIDDeviceBase.h"
    1.23 +
    1.24 +#include "Kernel/OVR_RefCount.h"
    1.25 +#include "Kernel/OVR_String.h"
    1.26 +#include "Kernel/OVR_Timer.h"
    1.27 +
    1.28 +namespace OVR {
    1.29 +
    1.30 +class HIDDevice;
    1.31 +class DeviceManager;
    1.32 +
    1.33 +// HIDDeviceDesc contains interesting attributes of a HID device, including a Path
    1.34 +// that can be used to create it.
    1.35 +struct HIDDeviceDesc
    1.36 +{
    1.37 +    UInt16  VendorId;
    1.38 +    UInt16  ProductId;
    1.39 +    UInt16  VersionNumber;
    1.40 +    UInt16  Usage;
    1.41 +    UInt16  UsagePage;
    1.42 +    String  Path;           // Platform specific.
    1.43 +    String  Manufacturer;
    1.44 +    String  Product;
    1.45 +    String  SerialNumber;
    1.46 +};
    1.47 +
    1.48 +// HIDEnumerateVisitor exposes a Visit interface called for every detected device
    1.49 +// by HIDDeviceManager::Enumerate. 
    1.50 +class HIDEnumerateVisitor
    1.51 +{
    1.52 +public:
    1.53 +
    1.54 +    // Should return true if we are interested in supporting
    1.55 +    // this HID VendorId and ProductId pair.
    1.56 +    virtual bool MatchVendorProduct(UInt16 vendorId, UInt16 productId)
    1.57 +    { OVR_UNUSED2(vendorId, productId); return true; }
    1.58 +
    1.59 +    // Override to get notified about available device. Will only be called for
    1.60 +    // devices that matched MatchVendorProduct.
    1.61 +    virtual void Visit(HIDDevice&, const HIDDeviceDesc&) { }
    1.62 +};
    1.63 +
    1.64 +
    1.65 +//-------------------------------------------------------------------------------------
    1.66 +// ***** HIDDeviceManager
    1.67 +
    1.68 +// Internal manager for enumerating and opening HID devices.
    1.69 +// If an OVR::DeviceManager is created then an OVR::HIDDeviceManager will automatically be created and can be accessed from the
    1.70 +// DeviceManager by calling 'GetHIDDeviceManager()'. When using HIDDeviceManager in standalone mode, the client must call
    1.71 +// 'Create' below.
    1.72 +class HIDDeviceManager : public RefCountBase<HIDDeviceManager>
    1.73 +{
    1.74 +public:
    1.75 +
    1.76 +    // Creates a new HIDDeviceManager. Only one instance of HIDDeviceManager should be created at a time.
    1.77 +    static HIDDeviceManager* Create();
    1.78 +
    1.79 +    // Enumerate HID devices using a HIDEnumerateVisitor derived visitor class.
    1.80 +    virtual bool Enumerate(HIDEnumerateVisitor* enumVisitor) = 0;
    1.81 +
    1.82 +    // Open a HID device with the specified path.
    1.83 +    virtual HIDDevice* Open(const String& path) = 0;
    1.84 +
    1.85 +protected:
    1.86 +    HIDDeviceManager()
    1.87 +    { }
    1.88 +};
    1.89 +
    1.90 +//-------------------------------------------------------------------------------------
    1.91 +// ***** HIDDevice
    1.92 +
    1.93 +// HID device object. This is designed to be operated in synchronous
    1.94 +// and asynchronous modes. With no handler set, input messages will be
    1.95 +// stored and can be retrieved by calling 'Read' or 'ReadBlocking'.
    1.96 +class HIDDevice : public RefCountBase<HIDDevice>, public HIDDeviceBase
    1.97 +{
    1.98 +public:
    1.99 +
   1.100 +    HIDDevice()
   1.101 +     :  Handler(NULL)
   1.102 +    {
   1.103 +    }
   1.104 +
   1.105 +    virtual ~HIDDevice() {}
   1.106 +
   1.107 +    virtual bool SetFeatureReport(UByte* data, UInt32 length) = 0;
   1.108 +    virtual bool GetFeatureReport(UByte* data, UInt32 length) = 0;
   1.109 +
   1.110 +// Not yet implemented.
   1.111 +/*
   1.112 +    virtual bool Write(UByte* data, UInt32 length) = 0;
   1.113 +
   1.114 +    virtual bool Read(UByte* pData, UInt32 length, UInt32 timeoutMilliS) = 0;
   1.115 +    virtual bool ReadBlocking(UByte* pData, UInt32 length) = 0;
   1.116 +*/
   1.117 +
   1.118 +    class HIDHandler
   1.119 +    {
   1.120 +    public:
   1.121 +        virtual void OnInputReport(UByte* pData, UInt32 length)
   1.122 +        { OVR_UNUSED2(pData, length); }
   1.123 +
   1.124 +        virtual UInt64 OnTicks(UInt64 ticksMks)
   1.125 +        { OVR_UNUSED1(ticksMks);  return Timer::MksPerSecond * 1000; ; }
   1.126 +
   1.127 +        enum HIDDeviceMessageType
   1.128 +        {
   1.129 +            HIDDeviceMessage_DeviceAdded    = 0,
   1.130 +            HIDDeviceMessage_DeviceRemoved  = 1
   1.131 +        };
   1.132 +
   1.133 +        virtual void OnDeviceMessage(HIDDeviceMessageType messageType) 
   1.134 +        { OVR_UNUSED1(messageType); }
   1.135 +    };
   1.136 +
   1.137 +    void SetHandler(HIDHandler* handler)
   1.138 +    { Handler = handler; }
   1.139 +
   1.140 +protected:
   1.141 +    HIDHandler* Handler;
   1.142 +};
   1.143 +
   1.144 +} // namespace OVR
   1.145 +
   1.146 +#endif