1 #pragma once
2 
3 #include <hidapi.h>
4 #include <stdint.h>
5 
6 #define VENDOR_CORSAIR     0x1b1c
7 #define VENDOR_LOGITECH    0x046d
8 #define VENDOR_STEELSERIES 0x1038
9 #define VENDOR_ROCCAT      0x1e7d
10 
11 /// Convert given number to bitmask
12 #define B(X) (1 << X)
13 
14 /** @brief A list of all features settable/queryable
15  *         for headsets
16  *
17  *  B(CAP_X) converts them to a bitmask value
18  */
19 enum capabilities {
20     CAP_SIDETONE = 0,
21     CAP_BATTERY_STATUS,
22     CAP_NOTIFICATION_SOUND,
23     CAP_LIGHTS,
24     CAP_INACTIVE_TIME,
25     CAP_CHATMIX_STATUS,
26     CAP_VOICE_PROMPTS,
27     CAP_ROTATE_TO_MUTE,
28     NUM_CAPABILITIES
29 };
30 
31 /// Long name of every capability
32 extern const char* const capabilities_str[NUM_CAPABILITIES];
33 /// Short name of every capability
34 extern const char capabilities_str_short[NUM_CAPABILITIES];
35 
36 struct capability_detail {
37     // Usage page, only used when usageid is not 0; HID Protocol specific
38     int usagepage;
39     // Used instead of interface when not 0, and only used on Windows currently; HID Protocol specific
40     int usageid;
41     /// Interface ID - zero means first enumerated interface!
42     int interface;
43 };
44 
45 /** @brief Flags for battery status
46  */
47 enum battery_status {
48     BATTERY_UNAVAILABLE = 65534,
49     BATTERY_CHARGING    = 65535
50 };
51 
52 enum headsetcontrol_errors {
53     HSC_ERROR = -100
54 };
55 
56 /** @brief Defines the basic data of a device
57  *
58  *  Also defines function pointers for using supported features
59  */
60 struct device {
61     /// USB Vendor id
62     uint16_t idVendor;
63     /// USB Product id used (and found as connected), set by device_registry.c
64     uint16_t idProduct;
65     /// The USB Product ids this instance of "struct device" supports
66     const uint16_t* idProductsSupported;
67     /// Size of idProducts
68     int numIdProducts;
69 
70     /// Name of device, used as information for the user
71     char device_name[64];
72 
73     /// Bitmask of currently supported features the software can currently handle
74     int capabilities;
75     /// Details of all capabilities (e.g. to which interface to connect)
76     struct capability_detail capability_details[NUM_CAPABILITIES];
77 
78     /** @brief Function pointer for setting headset sidetone
79      *
80      *  Forwards the request to the device specific implementation
81      *
82      *  @param  device_handle   The hidapi handle. Must be the same
83      *                          device as defined here (same ids)
84      *  @param  num             Level of the sidetone, between 0 - 128
85      *
86      *  @returns    > 0         on success
87      *              HSC_ERROR   on error specific to this software
88      *              -1          HIDAPI error
89      */
90     int (*send_sidetone)(hid_device* hid_device, uint8_t num);
91 
92     /** @brief Function pointer for retrieving the headsets battery status
93      *
94      *  Forwards the request to the device specific implementation
95      *
96      *  @param  device_handle   The hidapi handle. Must be the same
97      *                          device as defined here (same ids)
98      *
99      *  @returns    >= 0            battery level (in %)
100      *              BATTERY_LOADING when the battery is currently being loaded
101      *              -1              HIDAPI error
102      */
103     int (*request_battery)(hid_device* hid_device);
104 
105     /** @brief Function pointer for sending a notification sound to the headset
106      *
107      *  Forwards the request to the device specific implementation
108      *
109      *  @param  device_handle   The hidapi handle. Must be the same
110      *                          device as defined here (same ids)
111      *  @param  soundid         The soundid which should be used
112      *
113      *  @returns    > 0         success
114      *              -1          HIDAPI error
115      */
116     int (*notifcation_sound)(hid_device* hid_device, uint8_t soundid);
117 
118     /** @brief Function pointer for turning light on or off of the headset
119      *
120      *  Forwards the request to the device specific implementation
121      *
122      *  @param  device_handle   The hidapi handle. Must be the same
123      *                          device as defined here (same ids)
124      *  @param  on              1 if it should be turned on; 0 otherwise
125      *
126      *  @returns    > 0         success
127      *              -1          HIDAPI error
128      */
129     int (*switch_lights)(hid_device* hid_device, uint8_t on);
130 
131     /** @brief Function pointer for setting headset inactive time
132      *
133      *  Forwards the request to the device specific implementation
134      *
135      *  @param  device_handle   The hidapi handle. Must be the same
136      *                          device as defined here (same ids)
137      *  @param  num             Number of minutes after which the device
138      *                          is turned off, between 0 - 90,
139      *                          0 disables the automatic shutdown feature
140      *
141      *  @returns    > 0         on success
142      *              HSC_ERROR   on error specific to this software
143      *              -1          HIDAPI error
144      */
145     int (*send_inactive_time)(hid_device* hid_device, uint8_t num);
146 
147     /** @brief Function pointer for retrieving the headsets chatmix level
148      *
149      *  Forwards the request to the device specific implementation
150      *
151      *  @param  device_handle   The hidapi handle. Must be the same
152      *                          device as defined here (same ids)
153      *
154      *  @returns    >= 0            chatmix level
155      *              -1              HIDAPI error
156      */
157     int (*request_chatmix)(hid_device* hid_device);
158 
159     /** @brief Function pointer for enabling or disabling voice
160      *  prompts on the headset
161      *
162      *  Forwards the request to the device specific implementation
163      *
164      *  @param  device_handle   The hidapi handle. Must be the same
165      *                          device as defined here (same ids)
166      *  @param  on              1 if it should be turned on; 0 otherwise
167      *
168      *  @returns    > 0         success
169      *              -1          HIDAPI error
170      */
171     int (*switch_voice_prompts)(hid_device* hid_device, uint8_t on);
172 
173     /** @brief Function pointer for enabling or disabling auto-muting
174      *  when rotating the headset microphone
175      *
176      *  Forwards the request to the device specific implementation
177      *
178      *  @param  device_handle   The hidapi handle. Must be the same
179      *                          device as defined here (same ids)
180      *  @param  on              1 if it should be turned on; 0 otherwise
181      *
182      *  @returns    > 0         success
183      *              -1          HIDAPI error
184      */
185     int (*switch_rotate_to_mute)(hid_device* hid_device, uint8_t on);
186 };
187