Module spnav

spacenav - Nim bindings for libspnav, the free 3Dconnexion device driver and SDK.

This file is part of the Nim I/O package collection. See the file LICENSE included in this distribution for licensing details. GitHub pull requests are encouraged. (c) 2015 Headcrash Industries LLC.


The spnav module declares all types and functions exported by the libspnav library. The integration of 3Dconnexion devices using this module typically involves the following three steps:

  • On application startup, open a connection to the Spacenav driver daemon using spnavOpen
  • In the application's event loop, poll the driver for available input events using spnavPollEvent
  • Process any received SpnavEvent events in your application
  • Close the connection to the Spacenav driver daemon using spnavClose on application shutdown.

Check the examples directory of this distribution for demonstrations of this approach.


Note: The X11 related Spacenav APIs have been ommitted from this module as they were provided only for backward compatibility with existing 3dxWare based software and are not needed for new applications.

Types

SpnavEventTypes = enum
  any = 0,                      ## Matches any event
  motion = 1,                   ## Motion events
  button = 2                    ## Button events (includes both press and release)
Spacenav event types.   Source
SpnavMotionEvent = object
  motionType*: cint
  x*, y*, z*: cint
  rx*, ry*, rz*: cint
  period*: cuint
  data*: ptr cint
Structure for motion events.   Source
SpnavButtonEvent = object
  buttonType*: cint
  pressed*: cint
  buttonId*: cint
Structure for button events.   Source
SpnavEvent = object
  eventType*: cint
  motion*: SpnavMotionEvent
  button*: SpnavButtonEvent
Union type for events.   Source

Consts

spnavError = -1
Error return code for selected procs.   Source
spnavSuccess = 0
Success return code for selected procs.   Source

Procs

proc spnavOpen(): cint {.cdecl, dynlib: dllname, importc: "spnav_open".}
Open a connection to the Spacenav daemon.
result

See also spnavClose

  Source
proc spnavClose(): cint {.cdecl, dynlib: dllname, importc: "spnav_close".}
Close a previously opened connection to the Spacenav daemon.
result

See also spnavOpen

  Source
proc spnavFd(): cint {.cdecl, dynlib: dllname, importc: "spnav_fd".}
Retrieve the file descriptor used for communication with the daemon.
result
  • The file descriptor on success
  • spnavError on error or if no connection is open
  Source
proc spnavSensitivity(sens: float64): cint {.cdecl, dynlib: dllname,
    importc: "spnav_sensitivity".}
Set the sensitivity of the device(s).
sens
The sensitivity to set
result
  Source
proc spnavWaitEvent(event: ptr SpnavEvent): SpnavEventTypes {.cdecl, dynlib: dllname,
    importc: "spnav_wait_event".}
Wait for Spacenav events.
event
A pointer to a SpnavEvent object that will hold the event data if the call succeeded
result
  • The event type on success
  • 0 if an error occured

This function blocks until an event is available. For non-blocking checks use spnavPollEvent instead.

  Source
proc spnavPollEvent(event: ptr SpnavEvent): SpnavEventTypes {.cdecl, dynlib: dllname,
    importc: "spnav_poll_event".}
Check for availability of Spacenav events.
event
A pointer to a SpnavEvent object that will hold the event data if the call succeeded
result

Unlike spnavWaitEvent, this function returns immediately.

  Source
proc spnavRemoveEvents(eventType: SpnavEventTypes): cint {.cdecl, dynlib: dllname,
    importc: "spnav_remove_events".}
Remove any pending events of the specified type.
eventType
The type of events to remove, or SpnavEventTypes.any to remove all events
result
The number of removed events
  Source