libx52  0.3.2
Saitek X52/X52Pro drivers for Linux/Unix
Data Structures | Typedefs | Enumerations | Functions
IO Library APIs

Data Structures

struct  libx52io_report
 X52 HID Report. More...
 

Typedefs

typedef struct libx52io_context libx52io_context
 Device context structure used by libx52io. More...
 

Enumerations

enum  libx52io_error_code {
  LIBX52IO_SUCCESS , LIBX52IO_ERROR_INIT_FAILURE , LIBX52IO_ERROR_NO_DEVICE , LIBX52IO_ERROR_INVALID ,
  LIBX52IO_ERROR_CONN , LIBX52IO_ERROR_IO , LIBX52IO_ERROR_TIMEOUT
}
 libx52 IO error codes More...
 
enum  libx52io_axis {
  LIBX52IO_AXIS_X , LIBX52IO_AXIS_Y , LIBX52IO_AXIS_RZ , LIBX52IO_AXIS_Z ,
  LIBX52IO_AXIS_RX , LIBX52IO_AXIS_RY , LIBX52IO_AXIS_SLIDER , LIBX52IO_AXIS_THUMBX ,
  LIBX52IO_AXIS_THUMBY , LIBX52IO_AXIS_HATX , LIBX52IO_AXIS_HATY , LIBX52IO_AXIS_MAX
}
 X52 Axis definitions. More...
 
enum  libx52io_button {
  LIBX52IO_BTN_TRIGGER , LIBX52IO_BTN_TRIGGER_2 , LIBX52IO_BTN_FIRE , LIBX52IO_BTN_PINKY ,
  LIBX52IO_BTN_A , LIBX52IO_BTN_B , LIBX52IO_BTN_C , LIBX52IO_BTN_D ,
  LIBX52IO_BTN_E , LIBX52IO_BTN_T1_UP , LIBX52IO_BTN_T1_DN , LIBX52IO_BTN_T2_UP ,
  LIBX52IO_BTN_T2_DN , LIBX52IO_BTN_T3_UP , LIBX52IO_BTN_T3_DN , LIBX52IO_BTN_POV_1_N ,
  LIBX52IO_BTN_POV_1_E , LIBX52IO_BTN_POV_1_S , LIBX52IO_BTN_POV_1_W , LIBX52IO_BTN_POV_2_N ,
  LIBX52IO_BTN_POV_2_E , LIBX52IO_BTN_POV_2_S , LIBX52IO_BTN_POV_2_W , LIBX52IO_BTN_CLUTCH ,
  LIBX52IO_BTN_MOUSE_PRIMARY , LIBX52IO_BTN_MOUSE_SECONDARY , LIBX52IO_BTN_MOUSE_SCROLL_UP , LIBX52IO_BTN_MOUSE_SCROLL_DN ,
  LIBX52IO_BTN_FUNCTION , LIBX52IO_BTN_START_STOP , LIBX52IO_BTN_RESET , LIBX52IO_BTN_PG_UP ,
  LIBX52IO_BTN_PG_DN , LIBX52IO_BTN_UP , LIBX52IO_BTN_DN , LIBX52IO_BTN_SELECT ,
  LIBX52IO_BTN_MODE_1 , LIBX52IO_BTN_MODE_2 , LIBX52IO_BTN_MODE_3 , LIBX52IO_BUTTON_MAX
}
 X52 Button definitions. More...
 

Functions

int libx52io_init (libx52io_context **ctx)
 Initialize the IO library. More...
 
void libx52io_exit (libx52io_context *ctx)
 Exit the library and free up any resources used. More...
 
int libx52io_open (libx52io_context *ctx)
 Open a connection to a supported joystick. More...
 
int libx52io_close (libx52io_context *ctx)
 Close an existing connection to a supported joystick. More...
 
int libx52io_read_timeout (libx52io_context *ctx, libx52io_report *report, int timeout)
 Read and parse a HID report. More...
 
int libx52io_read (libx52io_context *ctx, libx52io_report *report)
 Read and parse a HID report. More...
 
int libx52io_get_axis_range (libx52io_context *ctx, libx52io_axis axis, int32_t *min, int32_t *max)
 Retrieve the range of an axis. More...
 
const char * libx52io_strerror (libx52io_error_code code)
 Get the string representation of an error code. More...
 
const char * libx52io_axis_to_str (libx52io_axis axis)
 Get the string representation of an axis. More...
 
const char * libx52io_button_to_str (libx52io_button button)
 Get the string representation of a button. More...
 
uint16_t libx52io_get_vendor_id (libx52io_context *ctx)
 Get the vendor ID of the connected X52 device. More...
 
uint16_t libx52io_get_product_id (libx52io_context *ctx)
 Get the product ID of the connected X52 device. More...
 
uint16_t libx52io_get_device_version (libx52io_context *ctx)
 Get the device version of the connected X52 device. More...
 
const char * libx52io_get_manufacturer_string (libx52io_context *ctx)
 Get the manufacturer string of the connected X52 device. More...
 
const char * libx52io_get_product_string (libx52io_context *ctx)
 Get the product string of the connected X52 device. More...
 
const char * libx52io_get_serial_number_string (libx52io_context *ctx)
 Get the serial number of the connected X52 device. More...
 

Detailed Description

These functions allow an application to connect to a supported X52/X52Pro joystick and read the state of the buttons and axes.

Typedef Documentation

◆ libx52io_context

Device context structure used by libx52io.

All libx52io API functions require the application to pass in a pointer to a valid device context structure. A pointer can be obtained by calling libx52io_init

Enumeration Type Documentation

◆ libx52io_axis

X52 Axis definitions.

Enumerator
LIBX52IO_AXIS_X 

Stick X axis

LIBX52IO_AXIS_Y 

Stick Y axis

LIBX52IO_AXIS_RZ 

Stick twist axis

LIBX52IO_AXIS_Z 

Throttle axis

LIBX52IO_AXIS_RX 

Throttle Rotary X

LIBX52IO_AXIS_RY 

Throttle Rotary Y

LIBX52IO_AXIS_SLIDER 

Throttle Slider

LIBX52IO_AXIS_THUMBX 

Thumbstick X

LIBX52IO_AXIS_THUMBY 

Thumbstick Y

LIBX52IO_AXIS_HATX 

Hat X

LIBX52IO_AXIS_HATY 

Hat Y

◆ libx52io_button

X52 Button definitions.

Enumerator
LIBX52IO_BTN_TRIGGER 

Primary trigger

LIBX52IO_BTN_TRIGGER_2 

Secondary trigger

LIBX52IO_BTN_FIRE 

Fire button

LIBX52IO_BTN_PINKY 

Pinky trigger

LIBX52IO_BTN_A 

A button, on stick

LIBX52IO_BTN_B 

B button, on stick

LIBX52IO_BTN_C 

C button, on stick

LIBX52IO_BTN_D 

D button, on throttle

LIBX52IO_BTN_E 

E button, on throttle

LIBX52IO_BTN_T1_UP 

Toggle 1 up

LIBX52IO_BTN_T1_DN 

Toggle 1 down

LIBX52IO_BTN_T2_UP 

Toggle 2 up

LIBX52IO_BTN_T2_DN 

Toggle 2 down

LIBX52IO_BTN_T3_UP 

Toggle 3 up

LIBX52IO_BTN_T3_DN 

Toggle 3 down

LIBX52IO_BTN_POV_1_N 

POV 1 Up, on stick

LIBX52IO_BTN_POV_1_E 

POV 1 Right, on stick

LIBX52IO_BTN_POV_1_S 

POV 1 Down, on stick

LIBX52IO_BTN_POV_1_W 

POV 1 Left, on stick

LIBX52IO_BTN_POV_2_N 

POV 2 Up, on throttle

LIBX52IO_BTN_POV_2_E 

POV 2 Right, on throttle

LIBX52IO_BTN_POV_2_S 

POV 2 Down, on throttle

LIBX52IO_BTN_POV_2_W 

POV 2 Left, on throttle

LIBX52IO_BTN_CLUTCH 

Clutch button, on throttle

LIBX52IO_BTN_MOUSE_PRIMARY 

Primary mouse button, next to thumbstick

LIBX52IO_BTN_MOUSE_SECONDARY 

Secondary mouse button, press scroll wheel on throttle

LIBX52IO_BTN_MOUSE_SCROLL_UP 

Scroll wheel up, on throttle

LIBX52IO_BTN_MOUSE_SCROLL_DN 

Scroll wheel down, on throttle

LIBX52IO_BTN_FUNCTION 

Function button

LIBX52IO_BTN_START_STOP 

Start/Stop button

LIBX52IO_BTN_RESET 

Reset button

LIBX52IO_BTN_PG_UP 

Page Up button, X52 Pro only

LIBX52IO_BTN_PG_DN 

Page Down button, X52 Pro only

LIBX52IO_BTN_UP 

Up button, X52 Pro only

LIBX52IO_BTN_DN 

Down button, X52 Pro only

LIBX52IO_BTN_SELECT 

Select button, X52 Pro only

LIBX52IO_BTN_MODE_1 

Mode 1 - reported as a button

LIBX52IO_BTN_MODE_2 

Mode 2 - reported as a button

LIBX52IO_BTN_MODE_3 

Mode 3 - reported as a button

◆ libx52io_error_code

libx52 IO error codes

Error codes returned by libx52io

Enumerator
LIBX52IO_SUCCESS 

No error, indicates success

LIBX52IO_ERROR_INIT_FAILURE 

Initialization failure

LIBX52IO_ERROR_NO_DEVICE 

No compatible device found

LIBX52IO_ERROR_INVALID 

Invalid arguments for function

LIBX52IO_ERROR_CONN 

Connection error

LIBX52IO_ERROR_IO 

Read error from device

LIBX52IO_ERROR_TIMEOUT 

Timeout during read from device

Function Documentation

◆ libx52io_axis_to_str()

const char* libx52io_axis_to_str ( libx52io_axis  axis)

Get the string representation of an axis.

Parameters
[in]axisAxis ID - see libx52io_axis
Returns
String representation of the axis. This pointer must not be freed. If axis is outside the defined range, then this returns NULL.

◆ libx52io_button_to_str()

const char* libx52io_button_to_str ( libx52io_button  button)

Get the string representation of a button.

Parameters
[in]buttonButton ID - see libx52io_button
Returns
String representation of the button. This pointer must not be freed. If button is outside the defined range, then this returns NULL.

◆ libx52io_close()

int libx52io_close ( libx52io_context ctx)

Close an existing connection to a supported joystick.

This function closes any existing connection to a joystick. It is acceptable to call this function if no connection exists.

Parameters
[in]ctxPointer to the device context
Returns

◆ libx52io_exit()

void libx52io_exit ( libx52io_context ctx)

Exit the library and free up any resources used.

This function releases any resources allocated by libx52io_init and terminates the library. Using the freed device now is invalid and can cause errors.

Parameters
[in]ctxPointer to the device context
Returns
None

◆ libx52io_get_axis_range()

int libx52io_get_axis_range ( libx52io_context ctx,
libx52io_axis  axis,
int32_t *  min,
int32_t *  max 
)

Retrieve the range of an axis.

This saves the minimum and maximum values of the requested axis in the output parameters. This will only be valid if the device is connected.

Parameters
[in]ctxPointer to the device context
[in]axisAxis identifier - see libx52io_axis
[out]minPointer to save the axis minimum value
[out]maxPointer to save the axis maximum value
Returns

◆ libx52io_get_device_version()

uint16_t libx52io_get_device_version ( libx52io_context ctx)

Get the device version of the connected X52 device.

Parameters
[in]ctxPointer to the device context
Returns
Device version of the connected device. Returns 0 if no device is connected.

◆ libx52io_get_manufacturer_string()

const char* libx52io_get_manufacturer_string ( libx52io_context ctx)

Get the manufacturer string of the connected X52 device.

Returns a pointer to a string which can be passed to printf or puts. This pointer must not be freed.

Parameters
[in]ctxPointer to the device context
Returns
Pointer to the manufacturer string, which may be NULL. Return value is always NULL if no device is connected.

◆ libx52io_get_product_id()

uint16_t libx52io_get_product_id ( libx52io_context ctx)

Get the product ID of the connected X52 device.

Parameters
[in]ctxPointer to the device context
Returns
Product ID of the connected device. Returns 0 if no device is connected.

◆ libx52io_get_product_string()

const char* libx52io_get_product_string ( libx52io_context ctx)

Get the product string of the connected X52 device.

Returns a pointer to a string which can be passed to printf or puts. This pointer must not be freed.

Parameters
[in]ctxPointer to the device context
Returns
Pointer to the product string, which may be NULL. Return value is always NULL if no device is connected.

◆ libx52io_get_serial_number_string()

const char* libx52io_get_serial_number_string ( libx52io_context ctx)

Get the serial number of the connected X52 device.

Returns a pointer to a string which can be passed to printf or puts. This pointer must not be freed.

Parameters
[in]ctxPointer to the device context
Returns
Pointer to the serial number string, which may be NULL. Return value is always NULL if no device is connected.

◆ libx52io_get_vendor_id()

uint16_t libx52io_get_vendor_id ( libx52io_context ctx)

Get the vendor ID of the connected X52 device.

Parameters
[in]ctxPointer to the device context
Returns
Vendor ID of the connected device. Returns 0 if no device is connected.

◆ libx52io_init()

int libx52io_init ( libx52io_context **  ctx)

Initialize the IO library.

This function initializes the libx52io library, sets up any internal data structures to access the joystick, and returns a libx52io_context pointer in the output parameter. All calls to libx52io use the returned pointer to control the device.

Example
int rc;
rc = libx52io_init(&ctx);
if (rc != LIBX52IO_SUCCESS) {
// Error handling omitted for brevity
}
// Save ctx for use later
int libx52io_init(libx52io_context **ctx)
Initialize the IO library.
struct libx52io_context libx52io_context
Device context structure used by libx52io.
Definition: libx52io.h:51
@ LIBX52IO_SUCCESS
Definition: libx52io.h:60
Parameters
[out]ctxPointer to a libx52io_context *. This function will allocate a device context and return the pointer to the context in this variable.
Returns
libx52io_error_code indicating status

◆ libx52io_open()

int libx52io_open ( libx52io_context ctx)

Open a connection to a supported joystick.

This function scans for and opens a connection to a supported X52/X52Pro joystick. If no supported joystick is found, it will return LIBX52IO_ERROR_NO_DEVICE.

Parameters
[in]ctxPointer to the device context
Returns

◆ libx52io_read()

int libx52io_read ( libx52io_context ctx,
libx52io_report report 
)

Read and parse a HID report.

This behaves the same as libx52io_read_timeout with a timeout of -1. This function will block until some data is available from the joystick.

Parameters
[in]ctxPointer to the device context
[out]reportPointer to save the decoded HID report
Returns

◆ libx52io_read_timeout()

int libx52io_read_timeout ( libx52io_context ctx,
libx52io_report report,
int  timeout 
)

Read and parse a HID report.

This function reads and parses a HID report from a connected joystick. This function will block until some data is available from the joystick, or the timeout is hit, whichever is first.

Parameters
[in]ctxPointer to the device context
[out]reportPointer to save the decoded HID report
[in]timeoutTimeout value in milliseconds
Returns

◆ libx52io_strerror()

const char* libx52io_strerror ( libx52io_error_code  code)

Get the string representation of an error code.

Parameters
[in]codeReturn code from one of the libx52io APIs
Returns
String representation of the error. This pointer must not be freed.