168 lines
4.5 KiB
JavaScript
168 lines
4.5 KiB
JavaScript
|
export function VendorId() { return 0x1b1c; }
|
||
|
export function ProductId() { return 0x0A64; }
|
||
|
export function Publisher() { return "WhirlwindFX"; }
|
||
|
export function Documentation(){ return "troubleshooting/corsair"; }
|
||
|
export function Size() { return [1, 1]; }
|
||
|
export function DefaultPosition(){return [145, 85];}
|
||
|
export function DefaultScale(){return 10.0;}
|
||
|
|
||
|
|
||
|
/* global
|
||
|
LightingMode:readonly
|
||
|
forcedColor:readonly
|
||
|
micLedMode:readonly
|
||
|
micLedDefState:readonly
|
||
|
micColorOn:readonly
|
||
|
micColorOff:readonly
|
||
|
*/
|
||
|
export function ControllableParameters() {
|
||
|
return [
|
||
|
{"property":"LightingMode", "group":"lighting", "label":"Lighting Mode", "type":"combobox", "values":["Canvas", "Forced"], "default":"Canvas"},
|
||
|
{"property":"forcedColor", "group":"lighting", "label":"Forced Color", "min":"0", "max":"360", "type":"color", "default":"#009bde"},
|
||
|
{"property":"micLedMode", "group":"lighting", "label":"Microphone LED Mode", "type":"combobox", "values":["Effect", "MicState"], "default":"Effect"},
|
||
|
{"property":"micLedDefState", "group":"lighting", "label":"Microphone Default State", "type":"combobox", "values":["OFF", "ON"], "default":"OFF"},
|
||
|
{"property":"micColorOn", "group":"lighting", "label":"Microphone Color ON", "min":"0", "max":"360", "type":"color", "default":"#33cc33"},
|
||
|
{"property":"micColorOff", "group":"lighting", "label":"Microphone Color OFF", "min":"0", "max":"360", "type":"color", "default":"#cc0000"},
|
||
|
];
|
||
|
}
|
||
|
export function Documentation(){ return "troubleshooting/corsair"; }
|
||
|
|
||
|
let headsetMode;
|
||
|
let micState;
|
||
|
|
||
|
const vLedNames = ["Logo", "Mic"];
|
||
|
|
||
|
const vLedPositions = [ [0, 0], [0, 1] ];
|
||
|
|
||
|
export function LedNames() {
|
||
|
return vLedNames;
|
||
|
}
|
||
|
|
||
|
export function LedPositions() {
|
||
|
return vLedPositions;
|
||
|
}
|
||
|
|
||
|
function sendColor(shutdown = false) {
|
||
|
let mxPxColor;
|
||
|
const packet = new Array(64).fill(0x00);
|
||
|
|
||
|
packet[0] = 0x02;
|
||
|
packet[1] = headsetMode;
|
||
|
packet[2] = 0x06;
|
||
|
packet[4] = 0x09;
|
||
|
|
||
|
if(shutdown) {
|
||
|
packet[2] = 0x01;
|
||
|
packet[3] = 0x02;
|
||
|
packet[4] = 0x00;
|
||
|
device.write(packet, 64);
|
||
|
} else {
|
||
|
for(let iIdx = 0; iIdx < vLedPositions.length; iIdx++) {
|
||
|
if(iIdx == 1 && micLedMode == "MicState") {
|
||
|
mxPxColor = hexToRgb(micState == 0 ? micColorOff : micColorOn);
|
||
|
} else {
|
||
|
const iPxX = vLedPositions[iIdx][0];
|
||
|
const iPxY = vLedPositions[iIdx][1];
|
||
|
|
||
|
if (LightingMode === "Forced") {
|
||
|
mxPxColor = hexToRgb(forcedColor);
|
||
|
} else {
|
||
|
mxPxColor = device.color(iPxX, iPxY);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
packet[(iIdx*2)+8] = mxPxColor[0];
|
||
|
packet[(iIdx*2)+11] = mxPxColor[1];
|
||
|
packet[(iIdx*2)+14] = mxPxColor[2];
|
||
|
}
|
||
|
|
||
|
device.write(packet, 64);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export function Initialize() {
|
||
|
headsetMode = ProductId() == 0x0a6b ? 0x09 : 0x08;
|
||
|
device.set_endpoint(3, 0x0001, 0xFF42);
|
||
|
SetSoftwareMode();
|
||
|
}
|
||
|
|
||
|
function SetSoftwareMode() {
|
||
|
micState = micLedDefState == "ON" ? 1 : 0;
|
||
|
|
||
|
const packet = new Array(64).fill(0x00);
|
||
|
packet[0] = 0x02;
|
||
|
packet[1] = headsetMode;
|
||
|
packet[2] = 0x01;
|
||
|
packet[3] = 0x03;
|
||
|
packet[5] = 0x02;
|
||
|
device.write(packet, 64);
|
||
|
|
||
|
packet[2] = 0x0D;
|
||
|
packet[3] = 0x00;
|
||
|
packet[4] = 0x01;
|
||
|
packet[5] = 0x00;
|
||
|
device.write(packet, 64);
|
||
|
|
||
|
packet[2] = 0x01;
|
||
|
packet[3] = 0x02;
|
||
|
packet[4] = 0x00;
|
||
|
packet[5] = 0xE8;
|
||
|
packet[6] = 0x03;
|
||
|
device.write(packet, 64);
|
||
|
}
|
||
|
|
||
|
export function Render() {
|
||
|
readDevice();
|
||
|
device.pause(1);
|
||
|
sendColor();
|
||
|
}
|
||
|
|
||
|
function readDevice() {
|
||
|
device.set_endpoint(3, 0x0002, 0xFF42);
|
||
|
|
||
|
const packet = device.read([0x00], 64, 3);
|
||
|
device.set_endpoint(3, 0x0001, 0xFF42);
|
||
|
|
||
|
if(packet[0] == 0x03 && packet[1] == 0x01 && packet[2] == 0x01 && packet[3] == 0x10 && packet[4] == 0x00 && packet[5] == 0x02) {
|
||
|
SetSoftwareMode();
|
||
|
}
|
||
|
|
||
|
if(packet[0] == 0x03 && packet[2] == 0x01 && packet[3] == 0xA6 && packet[4] == 0x00 && packet[5] == 0x00) {
|
||
|
micState = 1;
|
||
|
}
|
||
|
|
||
|
if(packet[0] == 0x03 && packet[2] == 0x01 && packet[3] == 0xA6 && packet[4] == 0x00 && packet[5] == 0x01) {
|
||
|
micState = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export function Shutdown() {
|
||
|
sendColor(true);
|
||
|
|
||
|
const packet = new Array(64).fill(0x00);
|
||
|
packet[0] = 0x02;
|
||
|
packet[1] = headsetMode;
|
||
|
packet[2] = 0x01;
|
||
|
packet[3] = 0x03;
|
||
|
packet[5] = 0x01;
|
||
|
device.write(packet, 64);
|
||
|
}
|
||
|
|
||
|
export function Validate(endpoint) {
|
||
|
return endpoint.interface === 3 && endpoint.usage === 0x0001 && endpoint.usage_page === 0xFF42;
|
||
|
}
|
||
|
|
||
|
function hexToRgb(hex) {
|
||
|
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||
|
const colors = [];
|
||
|
colors[0] = parseInt(result[1], 16);
|
||
|
colors[1] = parseInt(result[2], 16);
|
||
|
colors[2] = parseInt(result[3], 16);
|
||
|
|
||
|
return colors;
|
||
|
}
|
||
|
|
||
|
export function Image() {
|
||
|
return "https://assets.signalrgb.com/devices/default/audio/headset-render.png";
|
||
|
}
|