UI improvements, prepare for config overriding

This commit is contained in:
Nik Rozman
2026-03-03 08:34:43 +01:00
parent 5c9aa62cda
commit 8f63d7c0b5
3 changed files with 37 additions and 20 deletions
+27 -11
View File
@@ -11,7 +11,7 @@ const CHR = {
// Local shadow of the current config (kept in sync with device)
const config = { sensitivity:600, deadZone:0.06, accelStrength:0.08, curve:0, axisFlip:0, chargeMode:1,
tapThreshold:12, tapAction:0, tapKey:0, tapMod:0, jerkThreshold:2000 };
tapThreshold:12, tapAction:0, tapKey:0, tapMod:0, tapFreezeEnabled:1, jerkThreshold:2000 };
let device=null, server=null, chars={}, userDisconnected=false;
let currentChargeStatus=0, currentBattPct=null, currentBattVoltage=null;
@@ -200,10 +200,11 @@ async function checkHashMatch() {
}
// ── ConfigBlob read / write ──────────────────────────────────────────────────
// ConfigBlob layout (20 bytes LE):
// ConfigBlob layout (24 bytes LE):
// float sensitivity [0], float deadZone [4], float accelStrength [8]
// uint8 curve [12], uint8 axisFlip [13], uint8 chargeMode [14]
// uint8 tapThreshold [15], uint8 tapAction [16], uint8 tapKey [17], uint8 tapMod [18], uint8 pad [19]
// uint8 tapThreshold [15], uint8 tapAction [16], uint8 tapKey [17], uint8 tapMod [18], uint8 tapFreezeEnabled [19]
// float jerkThreshold [20]
async function readConfigBlob() {
if (!chars.configBlob) return;
@@ -217,10 +218,11 @@ async function readConfigBlob() {
config.axisFlip = view.getUint8(13);
config.chargeMode = view.getUint8(14);
if (view.byteLength >= 20) {
config.tapThreshold = view.getUint8(15);
config.tapAction = view.getUint8(16);
config.tapKey = view.getUint8(17);
config.tapMod = view.getUint8(18);
config.tapThreshold = view.getUint8(15);
config.tapAction = view.getUint8(16);
config.tapKey = view.getUint8(17);
config.tapMod = view.getUint8(18);
config.tapFreezeEnabled = view.getUint8(19);
}
if (view.byteLength >= 24) {
config.jerkThreshold = view.getFloat32(20, true);
@@ -241,8 +243,10 @@ function applyConfigToUI() {
document.getElementById('flipX').checked = !!(config.axisFlip & 1);
document.getElementById('flipY').checked = !!(config.axisFlip & 2);
setChargeModeUI(config.chargeMode);
document.getElementById('tapFreezeEnabled').checked = !!config.tapFreezeEnabled;
document.getElementById('slJerkThreshold').value = config.jerkThreshold;
updateDisplay('jerkThreshold', config.jerkThreshold);
updateTapFreezeUI(!!config.tapFreezeEnabled);
document.getElementById('slTapThreshold').value = config.tapThreshold;
updateDisplay('tapThreshold', config.tapThreshold);
setTapActionUI(config.tapAction);
@@ -272,6 +276,7 @@ async function _doWriteConfigBlob() {
| (document.getElementById('tapModShift').checked ? 0x02 : 0)
| (document.getElementById('tapModAlt').checked ? 0x04 : 0)
| (document.getElementById('tapModGui').checked ? 0x08 : 0);
config.tapFreezeEnabled = document.getElementById('tapFreezeEnabled').checked ? 1 : 0;
config.jerkThreshold = +document.getElementById('slJerkThreshold').value;
// config.curve, config.chargeMode, config.tapAction, config.tapKey updated directly
@@ -287,7 +292,7 @@ async function _doWriteConfigBlob() {
view.setUint8(16, config.tapAction);
view.setUint8(17, config.tapKey);
view.setUint8(18, config.tapMod);
view.setUint8(19, 0);
view.setUint8(19, config.tapFreezeEnabled);
view.setFloat32(20, config.jerkThreshold, true);
try {
@@ -325,6 +330,17 @@ function setChargeModeUI(val) {
document.getElementById('ciMode').textContent = ['Off (0mA)','50 mA','100 mA'][val] ?? '--';
}
function onTapFreezeChange(enabled) {
config.tapFreezeEnabled = enabled ? 1 : 0;
updateTapFreezeUI(enabled);
writeConfigBlob();
}
function updateTapFreezeUI(enabled) {
const slider = document.getElementById('slJerkThreshold');
// Only grey out when connected (on disconnect, setStatus handles all inputs)
if (device) slider.disabled = !enabled;
}
function setTapAction(val) {
config.tapAction = val;
setTapActionUI(val);
@@ -820,12 +836,12 @@ let orientLastT = 0;
function initOrientViewer() {
const el = document.getElementById('orientCanvas');
const W = el.clientWidth || 340, H = 160;
const W = el.clientWidth || 340, H = el.clientHeight || W;
el.width = W; el.height = H;
orientScene = new THREE.Scene();
orientCamera = new THREE.PerspectiveCamera(40, W / H, 0.01, 10);
orientCamera.position.set(0.6, 0.5, 0.9);
orientCamera = new THREE.PerspectiveCamera(55, W / H, 0.01, 10);
orientCamera.position.set(0.75, 0.60, 1.10);
orientCamera.lookAt(0, 0, 0);
orientRenderer = new THREE.WebGLRenderer({ canvas: el, antialias: true, alpha: true });