Corsair_Virtuoso_XT_Headset.js.bad aktualisiert

This commit is contained in:
s-mendyka 2024-07-24 14:04:52 +02:00
parent c29910d2e0
commit 816f94ffc5

View File

@ -3,7 +3,7 @@ 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 Size() { return [1, 2]; }
export function DefaultPosition(){return [145, 85];}
export function DefaultScale(){return 10.0;}
/* global
@ -18,7 +18,7 @@ export function ControllableParameters() {
{"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":"idleTimeout", "group":"", "label":"Enable Device Sleep", "type":"boolean", "default":"true"},
{"property":"idleTimeoutLength", "group":"", "label":"Device Sleep Timeout (Minutes)", "type":"combobox", "values":["1","2","3","4","5","10","15","20","25","30"], "default":"10"},
{"property":"idleTimeoutLength", "group":"", "label":"Device Sleep Timeout (Minutes)", "type":"combobox", "values":["1", "2", "3", "4", "5", "10", "15", "20", "25", "30"], "default":"10"},
{"property":"SidetoneAmount", "group":"", "label":"Sidetone", "step":"1", "type":"number", "min":"0", "max":"100", "default":"0"},
];
}
@ -28,7 +28,7 @@ let device_status;
let previousBatteryLevel = -1;
let batteryPercentage = -1;
const vLeds = [ 0, 1 ]
const vLeds = [ 0, 1 ];
const vLedNames = [
"Logo", "Mic"
@ -51,7 +51,7 @@ export function Initialize() {
headsetMode = (ProductId() == 0x0a6b || ProductId() == 0x0a64) ? 0x09 : 0x08;
device.addFeature("battery");
setSoftwareMode();
setMicOn()
setMicOn();
setSidetone();
setIdleTimeout(idleTimeoutLength);
}
@ -76,8 +76,8 @@ export function onSidetoneAmountChanged() {
export function onidleTimeoutLengthChanged() {
if (idleTimeout){
console.log ("Set Idle Timeout to: " + idleTimeoutLength + "Minutes")
setIdleTimeout(idleTimeoutLength)
console.log ("Set Idle Timeout to: " + idleTimeoutLength + "Minutes");
setIdleTimeout(idleTimeoutLength);
}
}
@ -110,22 +110,23 @@ function sendColors(overrideColor) {
}
device.set_endpoint(3, 0x0001, 0xFF42);
device.write(packet, 64);
device.write(packet.concat(RGBData), 64);
}
function setSidetone() {
device.set_endpoint(3, 0x0001, 0xFF42);
const packet = [];
// Header
packet[0] = 0x02;
packet[1] = headsetMode;
packet[2] = 0x01;
packet[3] = 0x47;
device.set_endpoint(3, 0x0001, 0xFF42);
let sidetoneValue = Math.round((SidetoneAmount / 100) * 1000);
const packet = [];
// Header
packet[0] = 0x02;
packet[1] = headsetMode;
packet[2] = 0x01;
packet[3] = 0x47;
packet[0x05] = sidetoneValue & 0xFF;
packet[0x06] = (sidetoneValue >> 8) & 0xFF;
const sidetoneValue = Math.round((SidetoneAmount / 100) * 1000);
packet[0x05] = sidetoneValue & 0xFF;
packet[0x06] = (sidetoneValue >> 8) & 0xFF;
device.write(packet, 64);
}
@ -134,7 +135,7 @@ export function onidleTimeoutChanged() {
device.set_endpoint(3, 0x0001, 0xFF42);
device.write([0x02, headsetMode, 0x01, 0x0d, 0x01], 128);
device.pause(1);
setIdleTimeout(idleTimeoutLength)
setIdleTimeout(idleTimeoutLength);
}else{
device.set_endpoint(3, 0x0001, 0xFF42);
device.write([0x02, headsetMode, 0x01, 0x0d], 128);
@ -154,6 +155,7 @@ function setSoftwareMode() {
function readDevice() {
device.set_endpoint(3, 0x0002, 0xFF42);
const packet = device.read([0x00], 16, 15);
if(packet[0] == 0x03 && packet[1] == 0x01 && packet[2] == 0x01 && packet[3] == 0x10 && packet[4] == 0x00 && packet[5] == 0x02) {
@ -161,24 +163,27 @@ function readDevice() {
}
if(packet[0] == 0x03 && packet[2] == 0x01 && packet[3] == 0x46 && packet[4] == 0x00 && packet[5] == 0x00) {
console.log("Microphone: ON")
console.log("Microphone: ON");
}
if(packet[0] == 0x03 && packet[2] == 0x01 && packet[3] == 0x46 && packet[4] == 0x00 && packet[5] == 0x01) {
console.log("Microphone: OFF")
console.log("Microphone: OFF");
}
if(packet[0] == 0x03 && packet[2] == 0x01 && packet[3] == 0x10 && packet[4] == 0x00 && packet[5] == 0x01) {
battery.setBatteryState(2)
console.log("Headset is charging")
battery.setBatteryState(2);
console.log("Headset is charging");
}
if(packet[0] == 0x03 && packet[2] == 0x01 && packet[3] == 0x10 && packet[4] == 0x00 && packet[5] == 0x02) {
battery.setBatteryState(1)
console.log("Headset is draining")
battery.setBatteryState(1);
console.log("Headset is draining");
}
if (packet[0] == 0x03 && packet[1] == 0x01 && packet[2] == 0x01 && packet[3] == 0x0f && packet[4] == 0x00) {
let batteryValue = (packet[5] & 0xFF) | ((packet[6] & 0xFF) << 8);
let maxBatteryValue = 1023; // 0xff03 in Dezimal
const batteryValue = (packet[5] & 0xFF) | ((packet[6] & 0xFF) << 8);
const maxBatteryValue = 1023; // 0xff03 in Dezimal
batteryPercentage = Math.round((batteryValue / maxBatteryValue) * 100);
@ -194,6 +199,7 @@ function readDevice() {
battery.setBatteryState(2);
}
}
previousBatteryLevel = batteryPercentage;
}
}
@ -205,8 +211,8 @@ function setMicOn() {
}
function setIdleTimeout(idleTimeoutLength) {
applyPreConfig()
applyIdleTimeout(idleTimeoutLength)
applyPreConfig();
applyIdleTimeout(idleTimeoutLength);
}
function applyIdleTimeout(idleTimeoutLength) {
@ -218,15 +224,15 @@ function applyIdleTimeout(idleTimeoutLength) {
packet[2] = 0x01;
packet[3] = 0x0e;
const timeoutValue = idleTimeoutLength * 60000;
const hexValue = timeoutValue.toString(16).padStart(6, '0');
const littleEndianHex = hexValue.match(/../g).reverse();
const timeoutValue = idleTimeoutLength * 60000;
const hexValue = timeoutValue.toString(16).padStart(6, '0');
const littleEndianHex = hexValue.match(/../g).reverse();
packet[5] = parseInt(littleEndianHex[0], 16);
packet[6] = parseInt(littleEndianHex[1], 16);
packet[7] = parseInt(littleEndianHex[2], 16);
console.log ("Idle Timeout: " + idleTimeoutLength + "Min")
device.write(packet, 128);
packet[5] = parseInt(littleEndianHex[0], 16);
packet[6] = parseInt(littleEndianHex[1], 16);
packet[7] = parseInt(littleEndianHex[2], 16);
console.log ("Idle Timeout: " + idleTimeoutLength + "Min");
device.write(packet, 128);
}
function applyPreConfig() {