libx52  0.3.2
Saitek X52/X52Pro drivers for Linux/Unix
Integration

libx52 performs all its operations with a device context pointer. The application must call libx52_init before performing any operation, and must call libx52_exit prior to terminating.

Also, the application must call libx52_connect to ensure that it connects to a supported joystick. This function must be called after libx52_init

Example Initialization/Deinitialization Code

#include <libx52.h>
libx52_device* init_libx52(void)
{
int rc;
// Initialize the libx52 library
rc = libx52_init(&dev);
if (rc != LIBX52_SUCCESS) {
fputs(libx52_strerror(rc), stderr);
return NULL;
}
// Connect to the supported joystick
rc = libx52_connect(dev);
if (rc != LIBX52_SUCCESS) {
fputs(libx52_strerror(rc), stderr);
// A failure usually just means that there is no joystick connected
// Look at the return codes for more information.
}
return dev;
}
// Close the library and any associated devices
int libx52_connect(libx52_device *dev)
Connect to the X52 device.
void libx52_exit(libx52_device *dev)
Exit the library and free up any resources used.
struct libx52_device libx52_device
Device context structure used by libx52.
Definition: libx52.h:46
int libx52_init(libx52_device **dev)
Initialize the X52 library.
@ LIBX52_SUCCESS
Definition: libx52.h:165
const char * libx52_strerror(libx52_error_code error)
Return a string representation of the error code.
Functions, structures and enumerations for the Saitek X52 MFD & LED driver library.

Joystick Updates

Most libx52 functions to update the joystick state do not directly write to the connected joystick, but only update internal data structures within the device context. In order to actually update the joystick, the application must call libx52_update. This function writes the updates to the joystick and resets any internal state.

Example

libx52_set_text(dev, 0, " Saitek ", 16);
libx52_set_text(dev, 1, " X52 Flight ", 16);
libx52_set_text(dev, 2, " Control System ", 16);
int libx52_set_text(libx52_device *x52, uint8_t line, const char *text, uint8_t length)
Set the text on an MFD line.
int libx52_update(libx52_device *x52)
Update the X52.

Error handling

Most libx52 functions return a standard libx52_error_code integer value that indicates the status of the operation. As long as the operation succeeded, the function will return LIBX52_SUCCESS. Other values returned indicate a failure of some sort.

libx52_strerror can convert the return code into a descriptive string that may be displayed to users.

Internationalization of error strings

libx52_strerror automatically handles internationalization. As long as your application sets up the locale correctly, and the error strings have been translated to that locale, the returned strings will correspond to the translated values for your locale.