libstratcom
1.1.0
A cross-platform library for interfacing with the Microsoft SideWinder Strategic Commander
|
Main Header File. More...
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | stratcom_input_state |
Combined state of all buttons and axes on the device. More... | |
struct | stratcom_input_event_button |
Button event. More... | |
struct | stratcom_input_event_slider |
Slider event. More... | |
struct | stratcom_input_event_axis |
Axis event. More... | |
struct | stratcom_input_event |
Input event structure. More... | |
union | stratcom_input_event::event_desc_T |
The input event union. More... | |
Typedefs | |
typedef struct stratcom_device_ | stratcom_device |
Opaque device structure. More... | |
Functions | |
Initialization and Shutdown. | |
LIBSTRATCOM_API stratcom_return | stratcom_init () |
Initialize the libstratcom library. More... | |
LIBSTRATCOM_API void | stratcom_shutdown () |
Finalize the libstratcom library. More... | |
LIBSTRATCOM_API stratcom_device * | stratcom_open_device () |
Open a Strategic Commander device for use with the library. More... | |
LIBSTRATCOM_API stratcom_device * | stratcom_open_device_on_path (char const *device_path) |
Open a Strategic Commander device on a certain HID device path. More... | |
LIBSTRATCOM_API void | stratcom_close_device (stratcom_device *device) |
Close a device. More... | |
Button LEDs. | |
Use these functions to interact with the LEDs on the device. Note that the stratcom_device object maintains a cached state of which LEDs are currently lit and what the blink intervals are. This is referred to as the internal state. This is in contrast to the physical state which is the actual state of the Strategic Commander device. It is possible for the internal and the physical state to diverge, for example if a function call fails to execute successfully or if an internal state change is not flushed to the device. The user can recover from this divergence by either attempting to write the internal state to the device, or by reading the physical state from the device, which will overwrite the internal state. | |
LIBSTRATCOM_API stratcom_led_state | stratcom_get_button_led_state (stratcom_device *device, stratcom_button_led led) |
Retrieve the current state of a specific LED. More... | |
LIBSTRATCOM_API stratcom_return | stratcom_set_button_led_state (stratcom_device *device, stratcom_button_led led, stratcom_led_state state) |
Set the state of a specific LED. More... | |
LIBSTRATCOM_API void | stratcom_set_button_led_state_without_flushing (stratcom_device *device, stratcom_button_led led, stratcom_led_state state) |
Set the state of a specific LED in the internal state. More... | |
LIBSTRATCOM_API stratcom_return | stratcom_flush_button_led_state (stratcom_device *device) |
Flush the current internal LED state to the physical device. More... | |
LIBSTRATCOM_API int | stratcom_led_state_has_unflushed_changes (stratcom_device *device) |
Check whether the internal LED state contains unflushed changes. More... | |
LIBSTRATCOM_API void | stratcom_get_led_blink_interval (stratcom_device *device, uint8_t *out_on_time, uint8_t *out_off_time) |
Retrieve the current blink intervals from the internal state. More... | |
LIBSTRATCOM_API stratcom_return | stratcom_set_led_blink_interval (stratcom_device *device, uint8_t on_time, uint8_t off_time) |
Set the blink intervals for blinking LEDs. More... | |
LIBSTRATCOM_API stratcom_return | stratcom_read_button_led_state (stratcom_device *device) |
Read the button led state from the physical device. More... | |
LIBSTRATCOM_API stratcom_return | stratcom_read_led_blink_intervals (stratcom_device *device) |
Read the led blink intervals from the physical device. More... | |
LIBSTRATCOM_API stratcom_button_led | stratcom_get_led_for_button (stratcom_button button) |
Obtain the matching LED for a given button. More... | |
Device Input. | |
Use these functions to obtain the input state of the device, such as which buttons are currently pressed. Input state is read from the Strategic Commander by reading input reports. Each action on the physical device (like pressing a button, or moving the axis or slider) will cause an input report to be generated. In case of no input, the read functions may block. Input reports that are not read immediately will be buffered by the HID layer and returned upon the next read. Thus, multiple read operations might be required to arrive at the latest input state. A return code of STRATCOM_RET_ERROR by one of these functions usually indicates that the physical device was unplugged by the user. While these functions allow to query the current state of the device (that is, answer questions like "Is Button 1 currently pressed?"), they do not generate input events (that is, answer questions like "Which Button has been pressed by the user?"). If you are more interested in the second kind of question, be sure to check out the section on Input Events below. | |
LIBSTRATCOM_API stratcom_return | stratcom_read_input (stratcom_device *device) |
Wait for a new input report and read it from the physical device to update the internal input state. More... | |
LIBSTRATCOM_API stratcom_return | stratcom_read_input_with_timeout (stratcom_device *device, int timeout_milliseconds) |
Wait for a new input report and read it from the physical device to update the internal input state. More... | |
LIBSTRATCOM_API stratcom_return | stratcom_read_input_non_blocking (stratcom_device *device) |
Read a new input report from the physical device to update the internal input state, if available. More... | |
LIBSTRATCOM_API stratcom_input_state | stratcom_get_input_state (stratcom_device *device) |
Retrieve a copy of the internal input state. More... | |
LIBSTRATCOM_API int | stratcom_is_button_pressed (stratcom_device *device, stratcom_button button) |
Check the state of a single button in the internal input state. More... | |
LIBSTRATCOM_API stratcom_axis_word | stratcom_get_axis_value (stratcom_device *device, stratcom_axis axis) |
Get the value of a particular axis in the internal input state. More... | |
LIBSTRATCOM_API stratcom_slider_state | stratcom_get_slider_state (stratcom_device *device) |
Get the position of the slider in the internal input state. More... | |
Iterating Button Identifiers. | |
Use these functions if you need to iterate over all the buttons in a loop. stratcom_button it;
for(it = stratcom_iterate_buttons_range_begin();
it != stratcom_iterate_buttons_range_end();
it = stratcom_iterate_buttons_range_increment(it))
{
...
}
| |
LIBSTRATCOM_API stratcom_button | stratcom_iterate_buttons_range_begin () |
The beginning of the button range. | |
LIBSTRATCOM_API stratcom_button | stratcom_iterate_buttons_range_end () |
The end of the button range. | |
LIBSTRATCOM_API stratcom_button | stratcom_iterate_buttons_range_increment (stratcom_button button) |
Increment a button range iterator. | |
State. | |
State types are used for modeling the current state of a certain part of the device for input, such as whether button is pressed or where an axis is positioned. | |
enum | stratcom_led_state { STRATCOM_LED_ON, STRATCOM_LED_OFF, STRATCOM_LED_BLINK } |
LED State. More... | |
enum | stratcom_slider_state { STRATCOM_SLIDER_UNKNOWN = 0, STRATCOM_SLIDER_1, STRATCOM_SLIDER_2, STRATCOM_SLIDER_3 } |
Slider State. More... | |
typedef uint16_t | stratcom_button_word |
Button Word. More... | |
typedef int16_t | stratcom_axis_word |
Axis Word. More... | |
Input Events. | |
Use these functions to generate a list of input events from two input states retrieved from stratcom_get_input_state(). Instead of comparing input states manually, these functions generate a linked list of stratcom_input_event values, representing the changes between the two input states. | |
enum | stratcom_input_event_type { STRATCOM_INPUT_EVENT_BUTTON, STRATCOM_INPUT_EVENT_SLIDER, STRATCOM_INPUT_EVENT_AXIS } |
Different input types that can form a stratcom_input_event. More... | |
LIBSTRATCOM_API stratcom_input_event * | stratcom_create_input_events_from_states (stratcom_input_state *old_state, stratcom_input_state *new_state) |
Generate a linked list of input events, describing the changes between two input states. More... | |
LIBSTRATCOM_API stratcom_input_event * | stratcom_append_input_events_from_states (stratcom_input_event *events, stratcom_input_state *old_state, stratcom_input_state *new_state) |
Append input events created from two input states to an existing list. More... | |
LIBSTRATCOM_API void | stratcom_free_input_events (stratcom_input_event *events) |
Free a list of input events. More... | |
Main Header File.
libstratcom - A Library for interacting with Microsoft SideWinder Strategic Commander
typedef int16_t stratcom_axis_word |
Axis Word.
Represents the state of a single axis. Values range from -512 to +511 where 0 is the axis center.
typedef uint16_t stratcom_button_word |
Button Word.
A bitwise combination of stratcom_button flags indicating the state of all buttons on the device. If a bit is set, it means that the corresponding button is pressed.
typedef struct stratcom_device_ stratcom_device |
Opaque device structure.
Maintains the internal state for interacting with the device.
enum stratcom_axis |
Axis Identifier.
This type is used for querying the state of one of the three device axes.
Enumerator | |
---|---|
STRATCOM_AXIS_X |
Horizontal X-axis. |
STRATCOM_AXIS_Y |
Vertical Y-axis. |
STRATCOM_AXIS_Z |
Rotational Z-axis. |
enum stratcom_button |
Button Identifiers.
This type is used for querying the state of a button. Iterating over all button identifiers can be achieved with the stratcom_iterate_buttons_range* functions.
enum stratcom_button_led |
Button LED Identifiers.
This type is used for setting or querying the state of the button LEDs. You can obtain the matching LED identifier from a given stratcom_button by calling stratcom_get_led_for_button().
Different input types that can form a stratcom_input_event.
Enumerator | |
---|---|
STRATCOM_INPUT_EVENT_BUTTON |
Button event.
|
STRATCOM_INPUT_EVENT_SLIDER |
Slider event.
|
STRATCOM_INPUT_EVENT_AXIS |
Axis event.
|
enum stratcom_led_state |
enum stratcom_return |
Slider State.
The slider may rest in one of three positions. For cases where the state of the slider cannot be determined we use STRATCOM_SLIDER_UNKNOWN.
LIBSTRATCOM_API stratcom_input_event* stratcom_append_input_events_from_states | ( | stratcom_input_event * | events, |
stratcom_input_state * | old_state, | ||
stratcom_input_state * | new_state | ||
) |
Append input events created from two input states to an existing list.
[in,out] | events | A non-empty list of input events, retrieved from stratcom_create_input_events_from_states(). |
[in] | old_state | An older input state. |
[in] | new_state | A newer input state. |
LIBSTRATCOM_API void stratcom_close_device | ( | stratcom_device * | device | ) |
Close a device.
[in] | device | A device structure returned from stratcom_open_device() or stratcom_open_device_on_path(). |
LIBSTRATCOM_API stratcom_input_event* stratcom_create_input_events_from_states | ( | stratcom_input_state * | old_state, |
stratcom_input_state * | new_state | ||
) |
Generate a linked list of input events, describing the changes between two input states.
[in] | old_state | An older input state. |
[in] | new_state | A newer input state. |
LIBSTRATCOM_API stratcom_return stratcom_flush_button_led_state | ( | stratcom_device * | device | ) |
Flush the current internal LED state to the physical device.
This will send a feature report to the device to update the state of the button LEDs. In case of successful execution, all button LEDs will light up according to the internal state.
[in] | device | A device structure returned from stratcom_open_device() or stratcom_open_device_on_path(). |
LIBSTRATCOM_API void stratcom_free_input_events | ( | stratcom_input_event * | events | ) |
Free a list of input events.
[in] | events | An input event list obtained from stratcom_create_input_events_from_states(). |
LIBSTRATCOM_API stratcom_axis_word stratcom_get_axis_value | ( | stratcom_device * | device, |
stratcom_axis | axis | ||
) |
Get the value of a particular axis in the internal input state.
[in] | device | A device structure returned from stratcom_open_device() or stratcom_open_device_on_path(). |
[in] | axis | The axis which is to be queried. |
LIBSTRATCOM_API stratcom_led_state stratcom_get_button_led_state | ( | stratcom_device * | device, |
stratcom_button_led | led | ||
) |
Retrieve the current state of a specific LED.
[in] | device | A device structure returned from stratcom_open_device() or stratcom_open_device_on_path(). |
[in] | led | The button LED which is to be queried. |
LIBSTRATCOM_API stratcom_input_state stratcom_get_input_state | ( | stratcom_device * | device | ) |
Retrieve a copy of the internal input state.
The input state contains state information for all the buttons, axes and sliders of the device. This function does not read any data from the physical device. Use stratcom_read_input() for that.
[in] | device | A device structure returned from stratcom_open_device() or stratcom_open_device_on_path(). |
LIBSTRATCOM_API void stratcom_get_led_blink_interval | ( | stratcom_device * | device, |
uint8_t * | out_on_time, | ||
uint8_t * | out_off_time | ||
) |
Retrieve the current blink intervals from the internal state.
[in] | device | A device structure returned from stratcom_open_device() or stratcom_open_device_on_path(). |
[out] | out_on_time | Time that the LED is lit when blinking. |
[out] | out_off_time | Time that the LED is dark when blinking. |
LIBSTRATCOM_API stratcom_button_led stratcom_get_led_for_button | ( | stratcom_button | button | ) |
Obtain the matching LED for a given button.
[in] | button | Button of which to retrieve the LED. |
LIBSTRATCOM_API stratcom_slider_state stratcom_get_slider_state | ( | stratcom_device * | device | ) |
Get the position of the slider in the internal input state.
[in] | device | A device structure returned from stratcom_open_device() or stratcom_open_device_on_path(). |
LIBSTRATCOM_API stratcom_return stratcom_init | ( | ) |
Initialize the libstratcom library.
Call this function once per process before invoking any other function of the library. Call stratcom_shutdown() before exiting your program to free the static data allocated by this function.
LIBSTRATCOM_API int stratcom_is_button_pressed | ( | stratcom_device * | device, |
stratcom_button | button | ||
) |
Check the state of a single button in the internal input state.
[in] | device | A device structure returned from stratcom_open_device() or stratcom_open_device_on_path(). |
[in] | button | The button which is to be queried. |
LIBSTRATCOM_API int stratcom_led_state_has_unflushed_changes | ( | stratcom_device * | device | ) |
Check whether the internal LED state contains unflushed changes.
[in] | device | A device structure returned from stratcom_open_device() or stratcom_open_device_on_path(). |
LIBSTRATCOM_API stratcom_device* stratcom_open_device | ( | ) |
Open a Strategic Commander device for use with the library.
This function will automatically attempt to open the first device with matching HID vendor and product ids. Usually this just works. In case you need more control over which device is opened (for instance when having more than one device attached to the same machine), use stratcom_open_device_on_path() instead.
0x045e
and a Product Id of 0x0033
. stratcom_read_input*
functions. LIBSTRATCOM_API stratcom_device* stratcom_open_device_on_path | ( | char const * | device_path | ) |
Open a Strategic Commander device on a certain HID device path.
[in] | device_path | The HID path of the device to open. |
stratcom_read_input*
functions. LIBSTRATCOM_API stratcom_return stratcom_read_button_led_state | ( | stratcom_device * | device | ) |
Read the button led state from the physical device.
Upon successful execution, this function will overwrite the internal led state with the values obtained from the physical device. This function will cause a feature report to be read from the device.
[in] | device | A device structure returned from stratcom_open_device() or stratcom_open_device_on_path(). |
LIBSTRATCOM_API stratcom_return stratcom_read_input | ( | stratcom_device * | device | ) |
Wait for a new input report and read it from the physical device to update the internal input state.
This function will block until the user performs an action on the Strategic Commander that generates an input event. Upon returning, the internal input state will have been updated according to that input report.
[in] | device | A device structure returned from stratcom_open_device() or stratcom_open_device_on_path(). |
LIBSTRATCOM_API stratcom_return stratcom_read_input_non_blocking | ( | stratcom_device * | device | ) |
Read a new input report from the physical device to update the internal input state, if available.
Unlike stratcom_read_input(), this function will always return immediately. If an input report is available upon invocation, it will be read and the internal state will be updated accordingly. Otherwise this function does nothing.
[in] | device | A device structure returned from stratcom_open_device() or stratcom_open_device_on_path(). |
LIBSTRATCOM_API stratcom_return stratcom_read_input_with_timeout | ( | stratcom_device * | device, |
int | timeout_milliseconds | ||
) |
Wait for a new input report and read it from the physical device to update the internal input state.
This function works exactly like stratcom_read_input(), except if no input report becomes available within a certain timeframe, it will return without reading anything.
[in] | device | A device structure returned from stratcom_open_device() or stratcom_open_device_on_path(). |
[in] | timeout_milliseconds | Time in milliseconds that the function will wait for an input report to become available before returning. |
LIBSTRATCOM_API stratcom_return stratcom_read_led_blink_intervals | ( | stratcom_device * | device | ) |
Read the led blink intervals from the physical device.
Upon successful execution, this function will overwrite the internal state blink intervals with the values obtained from the physical device. This function will cause a feature report to be read from the device.
[in] | device | A device structure returned from stratcom_open_device() or stratcom_open_device_on_path(). |
LIBSTRATCOM_API stratcom_return stratcom_set_button_led_state | ( | stratcom_device * | device, |
stratcom_button_led | led, | ||
stratcom_led_state | state | ||
) |
Set the state of a specific LED.
This function changes the state of an LED in both the internal state and flushes the internal state to the physical device. This will result in sending a feature report to the device. When setting multiple LEDs at once, consider using stratcom_set_button_led_state_without_flushing() and stratcom_flush_button_led_state() instead, to avoid having to send multiple feature reports in a row. Note though, that setting STRATCOM_LEDBUTTON_ALL with this function will also only send a single feature report.
[in] | device | A device structure returned from stratcom_open_device() or stratcom_open_device_on_path(). |
[in] | led | The button LED which is to be changed. |
[in] | state | Requested new state of the LED. |
LIBSTRATCOM_API void stratcom_set_button_led_state_without_flushing | ( | stratcom_device * | device, |
stratcom_button_led | led, | ||
stratcom_led_state | state | ||
) |
Set the state of a specific LED in the internal state.
This function changes the state of an LED in the internal state only. To apply the change made by this function to the physical device you have to flush the changes by calling either stratcom_flush_button_led_state() or stratcom_set_button_led_state().
[in] | device | A device structure returned from stratcom_open_device() or stratcom_open_device_on_path(). |
[in] | led | The button LED which is to be changed. |
[in] | state | Requested new state of the LED. |
LIBSTRATCOM_API stratcom_return stratcom_set_led_blink_interval | ( | stratcom_device * | device, |
uint8_t | on_time, | ||
uint8_t | off_time | ||
) |
Set the blink intervals for blinking LEDs.
This function will send a feature report to update the blink state on the physical device. The blink intervals are the same for all buttons.
[in] | device | A device structure returned from stratcom_open_device() or stratcom_open_device_on_path(). |
[in] | on_time | Time that the LED is lit when blinking. |
[in] | off_time | Time that the LED is dark when blinking. |
LIBSTRATCOM_API void stratcom_shutdown | ( | ) |
Finalize the libstratcom library.
This function frees all static data allocated by stratcom_init(). Call it once at the end of the program to prevent memory leaks.