UNDER CONSTRUCTION
Reference
Home
Overview
Hardware
News
Download
License
Documentation
Reference
Help
FAQs
Contributing
Contact
Links

Haptik.hpp

Go to the documentation of this file.
00001 //---CREDITS
00002 // Name: Haptik Library
00003 // Desc: Component Based Haptic Devices Access Library
00004 // Auto: Maurizio de Pascale
00005 // Date: July 17th 2005
00006 // Vers: 1.0.27
00007 // Tabs: tabbed at 3
00008 // Http: www.haptiklibrary.org
00009 //-------------------------------->
00010 #ifndef ___RSLIB_HAPTIK___
00011 #define ___RSLIB_HAPTIK___
00012  
00013  
00014  
00015 //---INCLUDE
00016 //--------------------->
00017 #include <RSLib\Types.hpp>
00018 #include <RSLib\LowLevel.hpp>
00019 #include <RSLib\Math\3D.hpp>
00020  
00021  
00022  
00023 //---DLL IMPORT EXPORT
00024 //------------------------------>
00025 #ifndef HAPTIK_DLL_IMPORT_EXPORT
00026    #pragma comment(lib,"Haptik.Library.lib")
00027    #define HAPTIK_DLL_IMPORT_EXPORT __declspec(dllimport)
00028 #endif
00029  
00030  
00031  
00032 //---INTERFACE IDS
00033 //----------------------------------------------->
00034 #define HAPTIK_IHAPTIKLIBRARY          0x80008001
00035 #define HAPTIK_IHAPTIKDEVICE           0x80008011
00036 #define HAPTIK_IHAPTIKPLUGIN           0x80008031
00037  
00038  
00039  
00040 //---MACRO
00041 //------------------------------------------------------------------->
00042 #define RELEASE_HAPTIK_INTERFACE(ptr) if(ptr){ptr->Release();ptr=NULL;}
00043  
00044  
00045  
00046 //---FUNCTION
00047 // Desc: C-based entrypoint to retrieve IHaptikLibrary interfaces
00048 //------------------------------------------------------------------------------------------------------------->
00049 extern "C" HAPTIK_DLL_IMPORT_EXPORT PVOID GetHaptikLibraryInterface(IN UINT32 interfaceId = HAPTIK_IHAPTIKLIBRARY);
00050  
00051  
00052  
00053 //---RETURN VALUES
00054 // Desc: HRESULT-like return values.
00055 //       Use the FAILED(ret) and SUCCEEDED(ret) macros
00056 //---------------------------------------------------->
00057 #define HAPTIK_SUCCESS                 0x00000000
00058 #define HAPTIK_WARNING                 0x00000001
00059 #define HAPTIK_ALREADY                 0x00000001
00060 #define HAPTIK_CALIBRATED              0x00000010
00061 #define HAPTIK_NOTCALIBRATED           0x00000020
00062 #define HAPTIK_ERROR                   0x80000000
00063 #define HAPTIK_FAILURE                 0x80000000
00064 #define HAPTIK_SDK_ERROR               0x80000001
00065 #define HAPTIK_MEMORY_ERROR            0x80000002
00066 #define HAPTIK_UNSUPPORTED             0x80000003
00067 #define HAPTIK_OUT_OF_RANGE            0x80000004
00068 #define HAPTIK_NO_SUCH_DEVICE          0x80000005
00069 #define HAPTIK_NOT_INITIALIZED         0x80000006
00070 
00071  
00072  
00073  
00074 //---DEVICE IDS
00075 //----------------------------------------------->
00076 #define HAPTIK_DEFAULT_DEVICE          0x80FFFFFF
00077 #define HAPTIK_MOUSE_SPECTRE           0x80FF8001
00078 #define HAPTIK_BETAMAX_PLAYER          0x80FF8002
00079 #define HAPTIK_BETAMAX_RECORDER        0x80FF8003
00080 #define HAPTIK_PHANTOM_PREMIUM         0x80FF4001
00081 #define HAPTIK_PHANTOM_DESKTOP         0x80FF4002
00082 #define HAPTIK_PHANTOM_OMNI            0x80FF4003
00083 #define HAPTIK_PHANTOM_PREMIUM6D       0x80FF4004
00084 #define HAPTIK_DELTA                   0x80FFC001
00085 #define HAPTIK_OMEGA                   0x80FFC002
00086 #define HAPTIK_FREEDOM6S               0x80FF2001
00087 #define HAPTIK_CUBIC                   0x80FF2002
00088  
00089  
00090  
00091 namespace RSLib {
00092  
00093  
00094  
00095 //---CLASS
00096 // Desc: Describe library implementation
00097 //-------------------------------------->
00098 typedef class HaptikLibraryInfo
00099 {
00100    public:
00101    PCHAR8 name;
00102    PCHAR8 company;
00103    PCHAR8 version;
00104    UINT32 versionNumbers[4];
00105    
00106    private:
00107    DWORD reserved[9];
00108 }*HaptikLibraryInfoPtr;
00109  
00110  
00111  
00112 //---CLASS
00113 // Desc: Describe a plugin
00114 //---------------------------->
00115 typedef class HaptikPluginInfo
00116 {
00117    public:
00118    PCHAR8 name;
00119    PCHAR8 company;
00120    PCHAR8 version;
00121    UINT32 versionNumbers[4];
00122    UINT32 numberOfDevices;
00123    
00124    private:
00125    DWORD reserved[8];
00126 }*HaptikPluginInfoPtr;
00127  
00128  
00129  
00130 //---CLASS
00131 // Desc: Describe an installed device
00132 //------------------------------------>
00133 typedef class HaptikDeviceInfo
00134 {
00135    public:
00136    UINT32 id;              //device unique id
00137    
00138    public:
00139    PCHAR8 name;            //device name
00140    PCHAR8 model;           //device model
00141    PCHAR8 manufacturer;    //device manifacturer
00142    
00143    public:
00144    BOOL32 ready;           //device ready
00145    
00146 // EXTENDED INFOS
00147    public:
00148 // Rate
00149    FLT32 currentRate;
00150    FLT32 defaultRate;
00151    FLT32 maxRate;
00152    FLT32 minRate;
00153 
00154 // Workspace
00155    FLT32 maxX;
00156    FLT32 maxY;
00157    FLT32 maxZ;
00158    FLT32 minX;
00159    FLT32 minY;
00160    FLT32 minZ;
00161    
00162 // Force Feedback
00163    FLT32 maxForceIntensity;
00164    FLT32 maxTorqueIntensity;
00165    
00166 // Buttons
00167    UINT32 numberOfButtons;
00168    
00169 // Hardware Capabilities
00170    UINT32 capabilities;
00171    
00172    private:
00173    DWORD reserved[4];
00174    
00175 }*HaptikDeviceInfoArray,*HaptikDeviceInfoPtr;
00176  
00177  
00178  
00179 //---CAPABILITIES
00180 // Desc: If corresponding bit is set in the capabilities mask
00181 //       then the device supports this feature in hardware
00182 //--------------------------------------------------------->
00183 #define HAPTIK_CAPABILITY_POSITION           0x00000001
00184 #define HAPTIK_CAPABILITY_VELOCITY           0x00000002
00185 #define HAPTIK_CAPABILITY_ORIENTATION        0x00000004
00186 #define HAPTIK_CAPABILITY_FORCEFEEDBACK      0x00000010
00187 #define HAPTIK_CAPABILITY_TORQUEFEEDBACK     0x00000020
00188 #define HAPTIK_CAPABILITY_VARIABLE_RATE      0x00000100
00189  
00190  
00191  
00192 //---CLASS
00193 // Desc: Data exchanged with an IHaptikDevice 
00194 // Note: This is only a template. You can define another struct 
00195 //       using your classes for matrix/vector computations.
00196 //       Memory layout and order should be preserved.
00197 //       adding of "operator HaptikData&()" allows for unchanged syntax
00198 //--------------------------------------------------------------------->
00199 typedef class HaptikData
00200 {
00201 public:
00202 // Output from Device
00203    Math::Matrix4x4 matrix;
00204    Math::Vector3 position;
00205    Math::Vector3 velocity;
00206    UINT32 buttonMask;
00207    
00208 private:
00209    DWORD reserved0[1];
00210    
00211 public:
00212 // Input to Device
00213    Math::Vector3 forceFeedback;
00214    Math::Vector3 torqueFeedback;
00215    
00216 private:
00217    DWORD reserved1[2];
00218    
00219 public:
00220 // Helper Methods
00221    BOOL32 Button(UINT32 index = 0)  {return buttonMask & (1<<index);}
00222    
00223 public:
00224    HaptikData()   {ZeroMemory(this,sizeof(*this));}
00225 }*HaptikDataPtr;
00226  
00227  
00228  
00229 //---STRUCT
00230 // Desc: User Data exchanged with an IHaptikDevice
00231 // Note: Applications can also ignore this data.
00232 //---------------------------------------------->
00233 typedef class HaptikUserData
00234 {
00235 public:
00236    DWORD userData;
00237    UINT32 lastError;
00238    
00239 // Make struct 32 bytes aligned and reserve space for extensions
00240 private:
00241    DWORD reserved[6];
00242    
00243 public:
00244    HaptikUserData()  {userData = 0; lastError = HAPTIK_SUCCESS;}
00245 }*HaptikUserDataPtr;
00246  
00247  
00248  
00249 //---INTERFACE
00250 // Desc: Interface exposed by the library component
00251 //------------------------------------------------->
00252 typedef class IHaptikLibrary
00253 {
00254    public:
00255    virtual UINT32 Init(IN PVOID reserved = NULL) PURE;
00256    virtual UINT32 Release() PURE;
00257       
00258    virtual UINT32 GetNumberOfDevices() PURE;
00259    virtual UINT32 GetDeviceInfo(IN UINT32 deviceId,OUT HaptikDeviceInfo& info) PURE;
00260    virtual PVOID GetDeviceInterface(IN UINT32 deviceId = HAPTIK_DEFAULT_DEVICE,IN UINT32 interfaceId = HAPTIK_IHAPTIKDEVICE) PURE;
00261    
00262 // All methods below are reserved for future uses and will currently return HAPTIK_UNSUPPORTED
00263    virtual UINT32 GetNumberOfPlugins() PURE;
00264    virtual UINT32 GetPluginInfo(IN UINT32 pluginId,OUT HaptikPluginInfo& info) PURE;
00265    virtual PVOID GetPluginInterface(IN UINT32 pluginId,IN UINT32 interfaceId = HAPTIK_IHAPTIKPLUGIN) PURE;
00266    
00267    virtual UINT32 GetLibraryInfo(OUT HaptikLibraryInfo& info) PURE;
00268 }*IHaptikLibraryInterface;
00269  
00270  
00271  
00272 //---INTERFACE
00273 // Desc: Represent a 6DOF haptic device
00274 //------------------------------------->
00275 typedef class IHaptikDevice
00276 {
00277    public:
00278    virtual UINT32 Init(IN PVOID method = NULL,IN PVOID object = NULL) PURE;
00279    virtual UINT32 Release() PURE;
00280    
00281 // Control  
00282    virtual UINT32 Start() PURE;
00283    virtual UINT32 Stop() PURE;
00284 
00285 // Access
00286    virtual UINT32 Read(OUT HaptikData& data) PURE;
00287    virtual UINT32 Write(IN HaptikData& data) PURE;
00288    
00289 // Info & Configuration
00290    virtual UINT32 SetRate(IN FLT32 rateInHz) PURE;
00291    virtual FLT32 GetRate() PURE;
00292    virtual UINT32 GetInfo(OUT HaptikDeviceInfo& info) PURE;
00293    virtual UINT32 SetUserData(IN DWORD userData) PURE;
00294    virtual DWORD GetUserData() PURE;
00295    virtual UINT32 SetCallback(IN PVOID method = NULL,PVOID object = NULL, IN DWORD reserved = NULL) PURE;
00296    virtual UINT32 GetCallback(OUT PVOID& method,OUT PVOID& object = NULL_REFERENCE(PVOID),IN DWORD reserved = NULL) PURE;
00297    virtual UINT32 GetLastError() PURE;
00298    
00299 // Recalibration
00300    virtual UINT32 GetCalibrationStatus() PURE;
00301    virtual UINT32 Recalibrate(IN UINT32 reserved = NULL) PURE;
00302 }*IHaptikDeviceInterface;
00303  
00304  
00305  
00306 //---TYPEDEF
00307 // Desc: Prototype for callbacks
00308 //-------------------------------------------->
00309 typedef VOID (*HaptikCallbackPtr)(HaptikData&);
00310 typedef VOID (*HaptikCallbackExPtr)(HaptikData&,HaptikUserData&);
00311  
00312  
00313  
00314 //---CLASS
00315 // Name: Haptik
00316 // Desc: C++ Wrapper Class around the IHaptikLibrary interface
00317 //------------------------------------------------------------>
00318 class Haptik
00319 {
00320    public:
00321    UINT32 numberOfDevices;
00322    HaptikDeviceInfoArray device;
00323    IHaptikLibraryInterface library;
00324    
00325    public:
00326    Haptik()
00327    {
00328       device = NULL;
00329       numberOfDevices = 0;
00330       library = (IHaptikLibraryInterface)GetHaptikLibraryInterface();
00331       if (library)
00332       {
00333          library->Init(NULL);
00334          RefreshDeviceList();
00335       }
00336    }
00337    ~Haptik()
00338    {
00339       if (library)   library->Release();
00340       if (device)    delete[]device;
00341    }
00342    
00343    public:
00344    PVOID GetDeviceInterface(IN UINT32 deviceId = HAPTIK_DEFAULT_DEVICE,IN UINT32 interfaceId = HAPTIK_IHAPTIKDEVICE)
00345    {
00346       if (library)
00347       {
00348          PVOID interfacePtr = library->GetDeviceInterface(deviceId,interfaceId);
00349          RefreshDeviceList();
00350          return interfacePtr;
00351       }
00352       else return NULL;
00353    }
00354    UINT32 RefreshDeviceList()
00355    {
00356       if (library)
00357       {
00358          if (device) delete[] device;
00359          numberOfDevices = library->GetNumberOfDevices();
00360          device = new HaptikDeviceInfo[numberOfDevices];
00361          for(UINT32 i=0 ; i<numberOfDevices ; i++) library->GetDeviceInfo(i,device[i]);
00362          return HAPTIK_SUCCESS;
00363       }
00364       else return HAPTIK_UNSUPPORTED;
00365    }
00366    
00367    public:
00368    IHaptikDeviceInterface GetHaptikDeviceInterface(IN UINT32 deviceId = HAPTIK_DEFAULT_DEVICE)
00369    {
00370       return (IHaptikDeviceInterface)GetDeviceInterface(deviceId,HAPTIK_IHAPTIKDEVICE);
00371    }
00372    
00373    public:
00374    static PCHAR8 ResultToString(UINT32 result)
00375    {
00376       switch(result)
00377       {
00378          case HAPTIK_SUCCESS:
00379          return "Operation Completed Successfully";
00380          
00381          case HAPTIK_WARNING:
00382          return "Warning";
00383          
00384          case HAPTIK_ERROR:
00385          return "Generic Error";
00386          
00387          case HAPTIK_SDK_ERROR:
00388          return "An error has been reported from a device SDK";
00389          
00390          case HAPTIK_MEMORY_ERROR:
00391          return "A Memory Allocation Failed";
00392          
00393          case HAPTIK_UNSUPPORTED:
00394          return "Operation/Interface not Supported";
00395          
00396          case HAPTIK_OUT_OF_RANGE:
00397          return "Request is out of range";
00398          
00399          case HAPTIK_NO_SUCH_DEVICE:
00400          return "No such Device";
00401          
00402          case HAPTIK_NOT_INITIALIZED:
00403          return "Interface has not been initialized";
00404          
00405          default:
00406          return "Unknown Return Value";
00407       }
00408    }
00409 };
00410  
00411  
00412  
00413 };//namespace RSLib
00414  
00415  
00416  
00417 #endif//__RSLIB_HAPTIK___
Last Updated on 2006/02/01 09:53:39 UTC info@haptiklibrary.org