Make tap freezing configurable, add toggles to other functions, minor UI changes

This commit is contained in:
Nik Rozman
2026-03-03 08:49:22 +01:00
parent 8f63d7c0b5
commit dcc50150b8
6 changed files with 97 additions and 41 deletions
+28 -4
View File
@@ -9,9 +9,16 @@ const CHR = {
gitHash: '00001239-0000-1000-8000-00805f9b34fb', // GitHash R 8 bytes
};
// Runtime feature-override flag bitmask constants (mirror firmware FLAG_* defines)
const FLAG_TAP_ENABLED = 0x01;
const FLAG_TEMP_COMP_ENABLED = 0x02;
const FLAG_AUTO_RECAL_ENABLED = 0x04;
const FLAG_ALL_DEFAULT = FLAG_TAP_ENABLED | FLAG_TEMP_COMP_ENABLED | FLAG_AUTO_RECAL_ENABLED;
// 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, tapFreezeEnabled:1, jerkThreshold:2000 };
tapThreshold:12, tapAction:0, tapKey:0, tapMod:0, tapFreezeEnabled:1, jerkThreshold:2000,
featureFlags:FLAG_ALL_DEFAULT };
let device=null, server=null, chars={}, userDisconnected=false;
let currentChargeStatus=0, currentBattPct=null, currentBattVoltage=null;
@@ -200,11 +207,11 @@ async function checkHashMatch() {
}
// ── ConfigBlob read / write ──────────────────────────────────────────────────
// ConfigBlob layout (24 bytes LE):
// ConfigBlob layout (25 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 tapFreezeEnabled [19]
// float jerkThreshold [20]
// float jerkThreshold [20], uint8 featureFlags [24]
async function readConfigBlob() {
if (!chars.configBlob) return;
@@ -227,6 +234,11 @@ async function readConfigBlob() {
if (view.byteLength >= 24) {
config.jerkThreshold = view.getFloat32(20, true);
}
if (view.byteLength >= 25) {
config.featureFlags = view.getUint8(24);
} else {
config.featureFlags = FLAG_ALL_DEFAULT; // old firmware — assume all on
}
applyConfigToUI();
log(`Config loaded — sens=${config.sensitivity.toFixed(0)} dz=${config.deadZone.toFixed(3)} tapThr=${config.tapThreshold}`,'ok');
} catch(e) { log(`Config read error: ${e.message}`,'err'); }
@@ -255,6 +267,9 @@ function applyConfigToUI() {
document.getElementById('tapModShift').checked = !!(config.tapMod & 0x02);
document.getElementById('tapModAlt').checked = !!(config.tapMod & 0x04);
document.getElementById('tapModGui').checked = !!(config.tapMod & 0x08);
document.getElementById('capTapEnabled').checked = !!(config.featureFlags & FLAG_TAP_ENABLED);
document.getElementById('capTempComp').checked = !!(config.featureFlags & FLAG_TEMP_COMP_ENABLED);
document.getElementById('capAutoRecal').checked = !!(config.featureFlags & FLAG_AUTO_RECAL_ENABLED);
}
let _writeConfigTimer = null;
@@ -278,9 +293,12 @@ async function _doWriteConfigBlob() {
| (document.getElementById('tapModGui').checked ? 0x08 : 0);
config.tapFreezeEnabled = document.getElementById('tapFreezeEnabled').checked ? 1 : 0;
config.jerkThreshold = +document.getElementById('slJerkThreshold').value;
config.featureFlags = (document.getElementById('capTapEnabled').checked ? FLAG_TAP_ENABLED : 0)
| (document.getElementById('capTempComp').checked ? FLAG_TEMP_COMP_ENABLED : 0)
| (document.getElementById('capAutoRecal').checked ? FLAG_AUTO_RECAL_ENABLED : 0);
// config.curve, config.chargeMode, config.tapAction, config.tapKey updated directly
const buf = new ArrayBuffer(24);
const buf = new ArrayBuffer(25);
const view = new DataView(buf);
view.setFloat32(0, config.sensitivity, true);
view.setFloat32(4, config.deadZone, true);
@@ -294,6 +312,7 @@ async function _doWriteConfigBlob() {
view.setUint8(18, config.tapMod);
view.setUint8(19, config.tapFreezeEnabled);
view.setFloat32(20, config.jerkThreshold, true);
view.setUint8(24, config.featureFlags);
try {
await gattWrite(chars.configBlob, buf);
@@ -330,6 +349,11 @@ function setChargeModeUI(val) {
document.getElementById('ciMode').textContent = ['Off (0mA)','50 mA','100 mA'][val] ?? '--';
}
function onCapTapChange(enabled) {
writeConfigBlob();
log('Tap detection ' + (enabled ? 'enabled' : 'disabled') + ' — restart device to apply', 'warn');
}
function onTapFreezeChange(enabled) {
config.tapFreezeEnabled = enabled ? 1 : 0;
updateTapFreezeUI(enabled);
+19
View File
@@ -155,6 +155,25 @@
</div>
</div>
<div class="section-label">Device Capabilities</div>
<div class="card">
<div class="flip-row">
<div class="flip-label">Tap Detection</div>
<div class="param-desc" style="flex:1;font-size:9px;color:var(--label)">Double-tap click action &nbsp;<span class="restart-note">· restart to apply</span></div>
<label class="toggle"><input type="checkbox" id="capTapEnabled" onchange="onCapTapChange(this.checked)" disabled><div class="toggle-track"></div><div class="toggle-thumb"></div></label>
</div>
<div class="flip-row">
<div class="flip-label">Temp Compensation</div>
<div class="param-desc" style="flex:1;font-size:9px;color:var(--label)">Gyro drift correction by temperature</div>
<label class="toggle"><input type="checkbox" id="capTempComp" onchange="writeConfigBlob()" disabled><div class="toggle-track"></div><div class="toggle-thumb"></div></label>
</div>
<div class="flip-row" style="border-bottom:none">
<div class="flip-label">Auto Recalibration</div>
<div class="param-desc" style="flex:1;font-size:9px;color:var(--label)">Recalibrate gyro after long idle period</div>
<label class="toggle"><input type="checkbox" id="capAutoRecal" onchange="writeConfigBlob()" disabled><div class="toggle-track"></div><div class="toggle-thumb"></div></label>
</div>
</div>
<div class="section-label">Device Commands</div>
<div class="cmd-grid">
<button class="cmd-btn calibrate" id="btnCal" onclick="sendCalibrate()" disabled>
+4 -2
View File
@@ -110,7 +110,7 @@
.logo-sub { font-size:10px; color:var(--label); letter-spacing:0.25em; text-transform:uppercase; margin-top:3px; }
.header-right { margin-left:auto; display:flex; align-items:center; gap:10px; flex-wrap:wrap; justify-content:flex-end; }
.status-pill { display:flex; align-items:center; gap:8px; padding:8px 14px; border:1px solid var(--border); font-size:11px; letter-spacing:0.15em; text-transform:uppercase; color:var(--label); transition:all 0.3s; white-space:nowrap; }
.status-pill { display:flex; align-items:center; gap:8px; height:34px; padding:0 14px; border:1px solid var(--border); font-size:11px; letter-spacing:0.15em; text-transform:uppercase; color:var(--label); transition:all 0.3s; white-space:nowrap; }
.status-pill.connected { border-color:var(--ok); color:var(--ok); }
.status-pill.connecting { border-color:var(--warn); color:var(--warn); }
.dot { width:7px; height:7px; border-radius:50%; background:var(--dim); flex-shrink:0; }
@@ -131,7 +131,7 @@
.btn:disabled { border-color:var(--dim); color:var(--dim); cursor:not-allowed; }
.btn:disabled::before { display:none; }
.btn:disabled:hover { color:var(--dim); }
.btn-debug { border:1px solid var(--dim); color:var(--label); min-width:52px; text-align:center; font-size:10px; padding:6px 10px; }
.btn-debug { border:1px solid var(--dim); color:var(--label); min-width:52px; text-align:center; font-size:10px; height:34px; padding:0 10px; }
.btn-debug::before { background:var(--accent); }
.btn-theme { border:1px solid var(--dim); color:var(--label); min-width:72px; text-align:center; }
.btn-theme::before { background:var(--text); }
@@ -303,6 +303,8 @@
.mod-btn input:checked + span { background:var(--accent); color:var(--bg); border-color:var(--accent); font-weight:bold; }
.mod-btn input:disabled + span { opacity:0.35; cursor:not-allowed; }
.restart-note { color:var(--warn); font-family:var(--mono); font-size:9px; }
.tap-flash { position:absolute; inset:0; pointer-events:none; opacity:0; transition:opacity 0.25s; }
.tap-flash.left { background:radial-gradient(circle at center, var(--tap-left) 0%, transparent 70%); }
.tap-flash.right { background:radial-gradient(circle at center, var(--tap-right) 0%, transparent 70%); }