|
| 1 | +#include "../device.h" |
| 2 | + |
| 3 | +#include <inttypes.h> |
| 4 | +#include <stdio.h> |
| 5 | +#include <string.h> |
| 6 | +#include <time.h> |
| 7 | + |
| 8 | +static struct device device_elo71Air; |
| 9 | + |
| 10 | +static const uint16_t PRODUCT_ID = 0x3a37; |
| 11 | + |
| 12 | +static int elo71Air_switch_lights(hid_device* hid_device, uint8_t on); |
| 13 | +static int elo71Air_send_inactive_time(hid_device* hid_device, uint8_t num); |
| 14 | + |
| 15 | +void elo71Air_init(struct device** device) |
| 16 | +{ |
| 17 | + device_elo71Air.idVendor = VENDOR_ROCCAT; |
| 18 | + device_elo71Air.idProductsSupported = &PRODUCT_ID; |
| 19 | + device_elo71Air.numIdProducts = 1; |
| 20 | + device_elo71Air.idInterface = 0; |
| 21 | + |
| 22 | + strncpy(device_elo71Air.device_name, "ROCCAT Elo 7.1 Air", sizeof(device_elo71Air.device_name)); |
| 23 | + |
| 24 | + device_elo71Air.capabilities = CAP_LIGHTS | CAP_INACTIVE_TIME; |
| 25 | + device_elo71Air.switch_lights = &elo71Air_switch_lights; |
| 26 | + device_elo71Air.send_inactive_time = &elo71Air_send_inactive_time; |
| 27 | + |
| 28 | + *device = &device_elo71Air; |
| 29 | +} |
| 30 | + |
| 31 | +/* |
| 32 | + * Sends size bytes from data to the headset. |
| 33 | + * If out_buffer points to 64 byte of preallocated memory, send_receive will |
| 34 | + * receive 64 byte into id over the HID stream. |
| 35 | + * |
| 36 | + * The Roccat Elo 71 Air hates, if it gets 64 bytes blocks to quickly. The |
| 37 | + * windows software seems just to wait a bit, so send_receive does as well. :-/ |
| 38 | + * |
| 39 | + * This function returns the code from hid_read or hid_write, if either no read |
| 40 | + * was requested or hid_write already failed. |
| 41 | + */ |
| 42 | +static int send_receive(hid_device* hid_device, const uint8_t* data, |
| 43 | + int size, uint8_t* out_buffer) |
| 44 | +{ |
| 45 | + struct timespec ts; |
| 46 | + int r; |
| 47 | + |
| 48 | + r = hid_write(hid_device, data, size); |
| 49 | + if ((out_buffer != NULL) && (r >= 0)) { |
| 50 | + r = hid_read(hid_device, out_buffer, 64); |
| 51 | + } |
| 52 | + |
| 53 | + ts.tv_sec = 0; |
| 54 | + ts.tv_nsec = 75 * 1000000; |
| 55 | + nanosleep(&ts, NULL); |
| 56 | + |
| 57 | + return r; |
| 58 | +} |
| 59 | + |
| 60 | +static int elo71Air_switch_lights(hid_device* hid_device, uint8_t on) |
| 61 | +{ |
| 62 | + // All commands are related to the LEDs, the following Hex codes cause |
| 63 | + // the LEDs to become 'static', the exact meaning of most commands & their |
| 64 | + // parameters is further unknown. |
| 65 | + uint8_t cmd92[64] = { 0xff, 0x02 }; |
| 66 | + uint8_t cmd93[64] = { 0xff, 0x03, 0x00, 0x01, 0x00, 0x01 }; |
| 67 | + |
| 68 | + // sets LED color as RGB value |
| 69 | + uint8_t cmd94[64] = { 0xff, 0x04, 0x00, 0x00, |
| 70 | + on ? 0xff : 0, on ? 0xff : 0, on ? 0xff : 0 }; |
| 71 | + uint8_t cmd95[64] = { 0xff, 0x01 }; |
| 72 | + int r; |
| 73 | + |
| 74 | + r = send_receive(hid_device, cmd92, sizeof(cmd92), NULL); |
| 75 | + if (r <= 0) { |
| 76 | + return r; |
| 77 | + } |
| 78 | + |
| 79 | + r = send_receive(hid_device, cmd93, sizeof(cmd93), NULL); |
| 80 | + if (r <= 0) { |
| 81 | + return r; |
| 82 | + } |
| 83 | + |
| 84 | + r = send_receive(hid_device, cmd94, sizeof(cmd94), NULL); |
| 85 | + if (r <= 0) { |
| 86 | + return r; |
| 87 | + } |
| 88 | + |
| 89 | + r = send_receive(hid_device, cmd95, sizeof(cmd95), NULL); |
| 90 | + if (r <= 0) { |
| 91 | + return r; |
| 92 | + } |
| 93 | + |
| 94 | + return 0; |
| 95 | +} |
| 96 | + |
| 97 | +static int elo71Air_send_inactive_time(hid_device* hid_device, uint8_t num) |
| 98 | +{ |
| 99 | + if (num > 60) { |
| 100 | + printf("Device only supports up to 60 minutes.\n"); |
| 101 | + return -2; |
| 102 | + } |
| 103 | + |
| 104 | + int seconds = num * 60; |
| 105 | + uint8_t cmd[64] = { 0xa1, 0x04, 0x06, 0x54, seconds >> 8, seconds & 0xFF }; |
| 106 | + uint8_t response[64]; |
| 107 | + |
| 108 | + return send_receive(hid_device, cmd, sizeof(cmd), response); |
| 109 | + //meaning of response of headset is not clear yet, fetch & ignore it for now |
| 110 | +} |
0 commit comments