ndofdev_external.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. @file ndofdev_external.h
  3. @brief libndofdev main header file for external use.
  4. Copyright (c) 2007, 3Dconnexion, Inc. - All rights reserved.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions are met:
  7. - Redistributions of source code must retain the above copyright notice,
  8. this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright notice,
  10. this list of conditions and the following disclaimer in the documentation
  11. and/or other materials provided with the distribution.
  12. - Neither the name of the 3Dconnexion, Inc. nor the names of its contributors
  13. may be used to endorse or promote products derived from this software
  14. without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  19. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  22. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifndef __ndofdev_external_h__
  27. #define __ndofdev_external_h__
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #define NDOF_MAX_AXES_COUNT 6
  32. #define NDOF_MAX_BUTTONS_COUNT 32
  33. typedef enum NDOF_HotPlugResult {
  34. NDOF_KEEP_HOTPLUGGED,
  35. NDOF_DISCARD_HOTPLUGGED
  36. } NDOF_HotPlugResult;
  37. /** Do NOT create NDOF_Device variables manually. Always use ndof_create. */
  38. typedef struct NDOF_Device {
  39. long axes[NDOF_MAX_AXES_COUNT]; /* axes current values */
  40. long buttons[NDOF_MAX_BUTTONS_COUNT]; /* buttons current values */
  41. short axes_count; /* actual # axes (self sensed on OS X) */
  42. short btn_count; /* actual # buttons (self sensed on OS X) */
  43. long axes_max; /* logical max */
  44. long axes_min; /* logical min */
  45. unsigned char absolute; /* if 0 calc delta. On OSX we always have deltas. */
  46. unsigned char valid; /* if 0, clients should not access this device. */
  47. char manufacturer[256]; /* name of device manufacturer */
  48. char product[256]; /* name of the device */
  49. void *private_data; /* ptr to platform specific/private data */
  50. } NDOF_Device;
  51. /** Callback type for new hot-plugged devices.
  52. * Parameters: dev - pointer to the newly added NDOF device. A new NDOF_Device
  53. * struct is allocated for the client. Clients can express
  54. * interest in the device by returning NDOF_KEEP_HOTPLUGGED,
  55. * otherwise the memory pointed by dev will be released. */
  56. typedef NDOF_HotPlugResult (*NDOF_DeviceAddCallback)(NDOF_Device *dev);
  57. /** Removal callback type. Parameter points to the removed device. */
  58. typedef void (*NDOF_DeviceRemovalCallback)(NDOF_Device *device);
  59. /** Purpose: Initializes the library.
  60. * Parameters: in_add_cb - Callback invoked when a new device is hotplugged in.
  61. * Pass NULL if you don't care.
  62. * in_removal_cb - Callback invoked when a device is removed.
  63. * Pass NULL if you don't care.
  64. * platform_specific - On Windows, it can be a pointer to a already
  65. * initialized LPDIRECTINPUT8 value; pass NULL
  66. * for full initialization. Unused on OS X.
  67. * Notes: The callbacks functionality is currently implemented on Mac OS X
  68. * only. The callbacks functions are currently ignored on Windows.
  69. * Returns: 0 if ok.
  70. */
  71. extern int ndof_libinit(NDOF_DeviceAddCallback in_add_cb,
  72. NDOF_DeviceRemovalCallback in_removal_cb,
  73. void *platform_specific);
  74. /** Purpose: Clean up. Must be called before program termination.
  75. */
  76. extern void ndof_libcleanup();
  77. /** Purpose: Allocates memory for a new NDOF_Device struct and initializes
  78. * it with default values.
  79. * Notes: Always use this function to allocate a new NDOF_Device.
  80. * Call ndof_libcleanup to free the memory.
  81. * Returns: Pointer to a mallocated struct.
  82. */
  83. extern NDOF_Device *ndof_create();
  84. /** Purpose: Get the _first_ NDOF device found in the USB bus.
  85. * Notes: It will be attempted to use the max and min values of the
  86. * input struct as the range of returned values from the device.
  87. * This may not work for every device. In any case, when this
  88. * function returns, the axes_min, axes_max values will contain
  89. * the actual range.
  90. * Parameters: in_out_dev - Must be allocated externally using ndof_create().
  91. * param - On Windows, you may use this to pass in a
  92. * LPDIRECTINPUTDEVICE8. It will be attempted to use
  93. * that instead of creating a new one. In all other cases
  94. * just pass NULL.
  95. * Returns: 0 if all is ok, -1 otherwise.
  96. */
  97. extern int ndof_init_first(NDOF_Device *in_out_dev, void *param);
  98. /** Purpose: Reads the current status of the input device.
  99. * Parameters: Must be initialized with ndof_create().
  100. */
  101. extern void ndof_update(NDOF_Device *in_dev);
  102. /** Purpose: Dumps device info on specified FILE*. */
  103. extern void ndof_dump(FILE* stream, NDOF_Device *dev);
  104. /** Purpose: Dumps list of NDOF devices currently in use on specified FILE*. */
  105. extern void ndof_dump_list(FILE* stream);
  106. #if TARGET_OS_MAC
  107. /** Returns the number of connected NDOF devices. Implemented only on OS X. */
  108. extern int ndof_devcount();
  109. #endif
  110. #ifdef __cplusplus
  111. }
  112. #endif
  113. #endif /* __ndofdev_external_h__ */