|
| 1 | +#include "../device.h" |
| 2 | +#include "../utility.h" |
| 3 | + |
| 4 | +#include <hidapi.h> |
| 5 | +#include <string.h> |
| 6 | +#include <stdlib.h> |
| 7 | + |
| 8 | +static struct device device_arctis7_2019; |
| 9 | + |
| 10 | +static int arctis7_2019_send_sidetone(hid_device *device_handle, uint8_t num); |
| 11 | +static int arctis7_2019_request_battery(hid_device *device_handle); |
| 12 | + |
| 13 | +void arctis7_2019_init(struct device** device) |
| 14 | +{ |
| 15 | + device_arctis7_2019.idVendor = VENDOR_STEELSERIES; |
| 16 | + device_arctis7_2019.idProduct = 0x12ad; |
| 17 | + device_arctis7_2019.idInterface = 0x05; |
| 18 | + |
| 19 | + strcpy(device_arctis7_2019.device_name, "SteelSeries Arctis 7"); |
| 20 | + |
| 21 | + device_arctis7_2019.capabilities = CAP_SIDETONE | CAP_BATTERY_STATUS; |
| 22 | + device_arctis7_2019.send_sidetone = &arctis7_2019_send_sidetone; |
| 23 | + device_arctis7_2019.request_battery = &arctis7_2019_request_battery; |
| 24 | + |
| 25 | + *device = &device_arctis7_2019; |
| 26 | +} |
| 27 | + |
| 28 | +static int arctis7_2019_send_sidetone(hid_device *device_handle, uint8_t num) |
| 29 | +{ |
| 30 | + int ret = -1; |
| 31 | + |
| 32 | + // the range of the Arctis 7 seems to be from 0 to 0x12 (18) |
| 33 | + num = map(num, 0, 128, 0x00, 0x12); |
| 34 | + |
| 35 | + unsigned char *buf = calloc(31, 1); |
| 36 | + |
| 37 | + if (!buf) |
| 38 | + { |
| 39 | + return ret; |
| 40 | + } |
| 41 | + |
| 42 | + const unsigned char data_on[5] = {0x06, 0x35, 0x01, 0x00, num}; |
| 43 | + const unsigned char data_off[2] = {0x06, 0x35}; |
| 44 | + |
| 45 | + if (num) |
| 46 | + { |
| 47 | + memmove(buf, data_on, sizeof(data_on)); |
| 48 | + } |
| 49 | + else |
| 50 | + { |
| 51 | + memmove(buf, data_off, sizeof(data_off)); |
| 52 | + } |
| 53 | + |
| 54 | + ret = hid_write(device_handle, buf, 31); |
| 55 | + |
| 56 | + SAFE_FREE(buf); |
| 57 | + |
| 58 | + return ret; |
| 59 | +} |
| 60 | + |
| 61 | +static int arctis7_2019_request_battery(hid_device *device_handle) |
| 62 | +{ |
| 63 | + |
| 64 | + int r = 0; |
| 65 | + |
| 66 | + // request battery status |
| 67 | + unsigned char data_request[2] = {0x06, 0x18}; |
| 68 | + |
| 69 | + r = hid_write(device_handle, data_request, 2); |
| 70 | + |
| 71 | + if (r < 0) return r; |
| 72 | + |
| 73 | + // read battery status |
| 74 | + unsigned char data_read[8]; |
| 75 | + |
| 76 | + r = hid_read(device_handle, data_read, 8); |
| 77 | + |
| 78 | + if (r < 0) return r; |
| 79 | + |
| 80 | + int bat = data_read[2]; |
| 81 | + |
| 82 | + if (bat > 100) return 100; |
| 83 | + |
| 84 | + return bat; |
| 85 | +} |
0 commit comments