libstratcom  1.1.0
A cross-platform library for interfacing with the Microsoft SideWinder Strategic Commander
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Pages
stratcom.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (c) 2010-2014 Andreas Weis <der_ghulbus@ghulbus-inc.de>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  *****************************************************************************/
22 
31 #ifndef LIBSTRATCOM_INCLUDE_GUARD_STRATCOM_H_
32 #define LIBSTRATCOM_INCLUDE_GUARD_STRATCOM_H_
33 
34 #ifdef _WIN32
35 # ifdef LIBSTRATCOM_EXPORT
36 # define LIBSTRATCOM_API __declspec(dllexport)
37 # else
38 # define LIBSTRATCOM_API __declspec(dllimport)
39 # endif
40 #else
41 # define LIBSTRATCOM_API
42 #endif
43 
44 #include <stdint.h>
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50  struct stratcom_device_;
54  typedef struct stratcom_device_ stratcom_device;
55 
56 
68  typedef enum stratcom_button_ {
69  STRATCOM_BUTTON_1 = 0x0001,
70  STRATCOM_BUTTON_2 = 0x0002,
71  STRATCOM_BUTTON_3 = 0x0004,
72  STRATCOM_BUTTON_4 = 0x0008,
73  STRATCOM_BUTTON_5 = 0x0010,
74  STRATCOM_BUTTON_6 = 0x0020,
83 
89  typedef enum stratcom_button_led_ {
100 
105  typedef enum stratcom_axis_ {
109  } stratcom_axis;
110 
122  typedef enum stratcom_led_state_ {
127 
132  typedef enum stratcom_slider_state_ {
138 
144  typedef uint16_t stratcom_button_word;
149  typedef int16_t stratcom_axis_word;
159  typedef struct stratcom_input_state_ {
160  stratcom_button_word buttons;
161  stratcom_axis_word axisX;
162  stratcom_axis_word axisY;
163  stratcom_axis_word axisZ;
166 
181  typedef struct stratcom_input_event_button_ {
183  int status;
185 
189  typedef struct stratcom_input_event_slider_ {
192 
196  typedef struct stratcom_input_event_axis_ {
198  stratcom_axis_word status;
200 
203  typedef enum stratcom_input_event_type_ {
208 
213  typedef struct stratcom_input_event_ {
218  union event_desc_T {
222  } desc;
223  struct stratcom_input_event_* next;
226 
232  typedef enum stratcom_return_ {
236  } stratcom_return;
237 
248  LIBSTRATCOM_API stratcom_return stratcom_init();
249 
255  LIBSTRATCOM_API void stratcom_shutdown();
256 
270  LIBSTRATCOM_API stratcom_device* stratcom_open_device();
271 
281  LIBSTRATCOM_API stratcom_device* stratcom_open_device_on_path(char const* device_path);
282 
287  LIBSTRATCOM_API void stratcom_close_device(stratcom_device* device);
288 
317  stratcom_button_led led);
318 
334 
347  stratcom_led_state state);
348 
357 
365  LIBSTRATCOM_API int stratcom_led_state_has_unflushed_changes(stratcom_device* device);
366 
373  LIBSTRATCOM_API void stratcom_get_led_blink_interval(stratcom_device* device,
374  uint8_t* out_on_time, uint8_t* out_off_time);
375 
386  uint8_t on_time, uint8_t off_time);
387 
396 
405 
411 
441  LIBSTRATCOM_API stratcom_return stratcom_read_input(stratcom_device* device);
442 
452  LIBSTRATCOM_API stratcom_return stratcom_read_input_with_timeout(stratcom_device* device, int timeout_milliseconds);
453 
464 
476 
483  LIBSTRATCOM_API int stratcom_is_button_pressed(stratcom_device* device, stratcom_button button);
484 
490  LIBSTRATCOM_API stratcom_axis_word stratcom_get_axis_value(stratcom_device* device, stratcom_axis axis);
491 
497 
520 
524 
528 
548  stratcom_input_state* new_state);
549 
560  stratcom_input_state* old_state,
561  stratcom_input_state* new_state);
562 
567  LIBSTRATCOM_API void stratcom_free_input_events(stratcom_input_event* events);
568 
571 #ifdef __cplusplus
572 }
573 #endif
574 
575 #endif
LIBSTRATCOM_API stratcom_button_led stratcom_get_led_for_button(stratcom_button button)
Obtain the matching LED for a given button.
The button labeled '+'.
Definition: stratcom.h:75
Slider event.
Definition: stratcom.h:189
stratcom_slider_state slider
State of the slider.
Definition: stratcom.h:164
stratcom_input_event_slider slider
Slider event.
Definition: stratcom.h:220
Slider set to the position marked with three circles.
Definition: stratcom.h:136
The LED of the button labeled '4'.
Definition: stratcom.h:93
Rotational Z-axis.
Definition: stratcom.h:108
stratcom_axis axis
Axis this event refers to.
Definition: stratcom.h:197
LIBSTRATCOM_API stratcom_return stratcom_read_led_blink_intervals(stratcom_device *device)
Read the led blink intervals from the physical device.
The input event union.
Definition: stratcom.h:218
The LED of the button labeled 'REC'.
Definition: stratcom.h:96
LIBSTRATCOM_API stratcom_device * stratcom_open_device_on_path(char const *device_path)
Open a Strategic Commander device on a certain HID device 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.
A read operation returned without reading any new data.
Definition: stratcom.h:235
int status
1 if the button is pressed.
Definition: stratcom.h:183
The LED of the button labeled '5'.
Definition: stratcom.h:94
The button labeled '1'.
Definition: stratcom.h:69
The top shift button.
Definition: stratcom.h:77
Addresses all LEDs at once.
Definition: stratcom.h:97
The button labeled '3'.
Definition: stratcom.h:71
The LED of the button labeled '1'.
Definition: stratcom.h:90
stratcom_axis_word axisY
Y-axis state (-512: full up; 0: center; +511: full down).
Definition: stratcom.h:162
Vertical Y-axis.
Definition: stratcom.h:107
The button labeled 'REC'.
Definition: stratcom.h:80
Slider set to the position marked with two circles.
Definition: stratcom.h:135
stratcom_input_event_type
Different input types that can form a stratcom_input_event.
Definition: stratcom.h:203
LIBSTRATCOM_API void stratcom_shutdown()
Finalize the libstratcom library.
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.
stratcom_button_word buttons
Combined state of all buttons.
Definition: stratcom.h:160
stratcom_input_event_axis axis
Axis event.
Definition: stratcom.h:221
stratcom_led_state
LED State.
Definition: stratcom.h:122
An error occured while executing.
Definition: stratcom.h:234
Slider event.
Definition: stratcom.h:205
LIBSTRATCOM_API stratcom_button stratcom_iterate_buttons_range_end()
The end of the button range.
The function completed successfully.
Definition: stratcom.h:233
stratcom_input_event_button button
Button event.
Definition: stratcom.h:219
Axis event.
Definition: stratcom.h:206
stratcom_slider_state status
New position of the slider.
Definition: stratcom.h:190
stratcom_axis_word status
New position of the axis.
Definition: stratcom.h:198
LIBSTRATCOM_API stratcom_return stratcom_init()
Initialize the libstratcom library.
Slider position is unknown.
Definition: stratcom.h:133
LED is constantly lit.
Definition: stratcom.h:123
stratcom_axis_word axisZ
Z-axis state (-512: full left; 0: center; +511: full right).
Definition: stratcom.h:163
Combined state of all buttons and axes on the device.
Definition: stratcom.h:159
Axis event.
Definition: stratcom.h:196
stratcom_input_event_type type
Type of the contained input event.
Definition: stratcom.h:214
LED is constantly dark.
Definition: stratcom.h:124
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.
LIBSTRATCOM_API stratcom_button stratcom_iterate_buttons_range_begin()
The beginning of the button range.
LED is blinking.
Definition: stratcom.h:125
Refers to no button.
Definition: stratcom.h:81
LIBSTRATCOM_API stratcom_input_state stratcom_get_input_state(stratcom_device *device)
Retrieve a copy of the internal input state.
stratcom_slider_state
Slider State.
Definition: stratcom.h:132
The button labeled '6'.
Definition: stratcom.h:74
struct stratcom_device_ stratcom_device
Opaque device structure.
Definition: stratcom.h:54
LIBSTRATCOM_API stratcom_slider_state stratcom_get_slider_state(stratcom_device *device)
Get the position of the slider in the internal input state.
The button labeled '5'.
Definition: stratcom.h:73
The middle shift button.
Definition: stratcom.h:78
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...
Button event.
Definition: stratcom.h:204
LIBSTRATCOM_API stratcom_button stratcom_iterate_buttons_range_increment(stratcom_button button)
Increment a button range iterator.
Button event.
Definition: stratcom.h:181
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.
The button labeled '2'.
Definition: stratcom.h:70
LIBSTRATCOM_API stratcom_return stratcom_read_button_led_state(stratcom_device *device)
Read the button led state from the physical device.
LIBSTRATCOM_API void stratcom_close_device(stratcom_device *device)
Close a device.
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.
stratcom_button
Button Identifiers.
Definition: stratcom.h:68
The button labeled '-'.
Definition: stratcom.h:76
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.
uint16_t stratcom_button_word
Button Word.
Definition: stratcom.h:144
stratcom_button_led
Button LED Identifiers.
Definition: stratcom.h:89
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.
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.
The button labeled '4'.
Definition: stratcom.h:72
Horizontal X-axis.
Definition: stratcom.h:106
struct stratcom_input_event_ * next
Pointer to the next element in the linked list structure.
Definition: stratcom.h:223
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.
The LED of the button labeled '2'.
Definition: stratcom.h:91
Slider set to the position marked with one circle.
Definition: stratcom.h:134
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...
int16_t stratcom_axis_word
Axis Word.
Definition: stratcom.h:149
Input event structure.
Definition: stratcom.h:213
The LED of the button labeled '6'.
Definition: stratcom.h:95
The LED of the button labeled '3'.
Definition: stratcom.h:92
LIBSTRATCOM_API void stratcom_free_input_events(stratcom_input_event *events)
Free a list of input events.
stratcom_axis_word axisX
X-axis state (-512: full left; 0: center; +511: full right).
Definition: stratcom.h:161
stratcom_return
Return type.
Definition: stratcom.h:232
stratcom_axis
Axis Identifier.
Definition: stratcom.h:105
LIBSTRATCOM_API stratcom_device * stratcom_open_device()
Open a Strategic Commander device for use with the library.
LIBSTRATCOM_API stratcom_return stratcom_flush_button_led_state(stratcom_device *device)
Flush the current internal LED state to the physical device.
LIBSTRATCOM_API int stratcom_led_state_has_unflushed_changes(stratcom_device *device)
Check whether the internal LED state contains unflushed changes.
The lower shift button.
Definition: stratcom.h:79
Addresses nothing.
Definition: stratcom.h:98
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.
stratcom_button button
The button this event refers to.
Definition: stratcom.h:182