diff --git a/air-mouse.ino b/air-mouse.ino index 09adacc..eba1e3a 100644 --- a/air-mouse.ino +++ b/air-mouse.ino @@ -759,7 +759,7 @@ void loop() { flags |= 0x01; } else { float rawX = applyAcceleration(applyCurve(-fGz * cfg.sensitivity * dt)); - float rawY = applyAcceleration(applyCurve( fGy * cfg.sensitivity * dt)); + float rawY = applyAcceleration(applyCurve(-fGy * cfg.sensitivity * dt)); if (cfg.axisFlip & 0x01) rawX = -rawX; if (cfg.axisFlip & 0x02) rawY = -rawY; accumX += rawX; accumY += rawY; diff --git a/web-config.html b/web-config.html index 72f4ee8..08370e8 100644 --- a/web-config.html +++ b/web-config.html @@ -297,6 +297,8 @@
DISCONNECTED
+ + AUTO-RECONNECT @@ -456,7 +458,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 }; -let device=null, server=null, chars={}; +let device=null, server=null, chars={}, userDisconnected=false; let currentChargeStatus=0, currentBattPct=null; // ── Logging ────────────────────────────────────────────────────────────────── @@ -474,6 +476,7 @@ function cssVar(n) { return getComputedStyle(document.documentElement).getProper // ── Connection ─────────────────────────────────────────────────────────────── async function doConnect() { if (!navigator.bluetooth) { log('Web Bluetooth not supported.','err'); return; } + userDisconnected = false; setStatus('connecting'); log('Scanning for IMU Mouse…','info'); try { @@ -492,7 +495,11 @@ async function doConnect() { } function doDisconnect() { - if (device && device.gatt.connected) { log('Disconnecting…','warn'); device.gatt.disconnect(); } + if (device && device.gatt.connected) { + userDisconnected = true; + log('Disconnecting…','warn'); + device.gatt.disconnect(); + } } async function discoverServices() { @@ -744,6 +751,7 @@ function setStatus(state) { } function onDisconnected() { log('Device disconnected','warn'); + const savedDevice = device; chars={}; device=null; server=null; setStatus('disconnected'); document.getElementById('battBar').style.display='none'; @@ -751,6 +759,23 @@ function onDisconnected() { document.getElementById('badgeFull').classList.remove('show'); document.getElementById('vizLive').classList.remove('on'); clearTelemetry(); + if (!userDisconnected && document.getElementById('autoReconnect').checked && savedDevice) { + log('Auto-reconnecting…','info'); + setTimeout(async () => { + try { + setStatus('connecting'); + server = await savedDevice.gatt.connect(); + device = savedDevice; + userDisconnected = false; + log('GATT reconnected','ok'); + await discoverServices(); + setStatus('connected'); + log('Ready','ok'); + } catch(e) { log(`Reconnect failed: ${e.message}`,'err'); setStatus('disconnected'); } + }, 1000); + } else { + userDisconnected = false; + } } // ── IMU Stream + Visualiser ──────────────────────────────────────────────────