Better auto-reconnect, flip Y by default
This commit is contained in:
+1
-1
@@ -759,7 +759,7 @@ void loop() {
|
|||||||
flags |= 0x01;
|
flags |= 0x01;
|
||||||
} else {
|
} else {
|
||||||
float rawX = applyAcceleration(applyCurve(-fGz * cfg.sensitivity * dt));
|
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 & 0x01) rawX = -rawX;
|
||||||
if (cfg.axisFlip & 0x02) rawY = -rawY;
|
if (cfg.axisFlip & 0x02) rawY = -rawY;
|
||||||
accumX += rawX; accumY += rawY;
|
accumX += rawX; accumY += rawY;
|
||||||
|
|||||||
+27
-2
@@ -297,6 +297,8 @@
|
|||||||
<div class="status-pill" id="statusPill"><div class="dot"></div><span id="statusText">DISCONNECTED</span></div>
|
<div class="status-pill" id="statusPill"><div class="dot"></div><span id="statusText">DISCONNECTED</span></div>
|
||||||
<button class="btn btn-connect" id="connectBtn" onclick="doConnect()"><span>Connect</span></button>
|
<button class="btn btn-connect" id="connectBtn" onclick="doConnect()"><span>Connect</span></button>
|
||||||
<button class="btn btn-disconnect" id="disconnectBtn" onclick="doDisconnect()" style="display:none"><span>Disconnect</span></button>
|
<button class="btn btn-disconnect" id="disconnectBtn" onclick="doDisconnect()" style="display:none"><span>Disconnect</span></button>
|
||||||
|
<label class="toggle" title="Auto-Reconnect" style="margin-left:6px;flex-shrink:0"><input type="checkbox" id="autoReconnect"><div class="toggle-track"></div><div class="toggle-thumb"></div></label>
|
||||||
|
<span style="font-family:var(--mono);font-size:9px;color:var(--label);white-space:nowrap">AUTO-RECONNECT</span>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
@@ -456,7 +458,7 @@ const CHR = {
|
|||||||
// Local shadow of the current config (kept in sync with device)
|
// 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 };
|
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;
|
let currentChargeStatus=0, currentBattPct=null;
|
||||||
|
|
||||||
// ── Logging ──────────────────────────────────────────────────────────────────
|
// ── Logging ──────────────────────────────────────────────────────────────────
|
||||||
@@ -474,6 +476,7 @@ function cssVar(n) { return getComputedStyle(document.documentElement).getProper
|
|||||||
// ── Connection ───────────────────────────────────────────────────────────────
|
// ── Connection ───────────────────────────────────────────────────────────────
|
||||||
async function doConnect() {
|
async function doConnect() {
|
||||||
if (!navigator.bluetooth) { log('Web Bluetooth not supported.','err'); return; }
|
if (!navigator.bluetooth) { log('Web Bluetooth not supported.','err'); return; }
|
||||||
|
userDisconnected = false;
|
||||||
setStatus('connecting');
|
setStatus('connecting');
|
||||||
log('Scanning for IMU Mouse…','info');
|
log('Scanning for IMU Mouse…','info');
|
||||||
try {
|
try {
|
||||||
@@ -492,7 +495,11 @@ async function doConnect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function doDisconnect() {
|
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() {
|
async function discoverServices() {
|
||||||
@@ -744,6 +751,7 @@ function setStatus(state) {
|
|||||||
}
|
}
|
||||||
function onDisconnected() {
|
function onDisconnected() {
|
||||||
log('Device disconnected','warn');
|
log('Device disconnected','warn');
|
||||||
|
const savedDevice = device;
|
||||||
chars={}; device=null; server=null;
|
chars={}; device=null; server=null;
|
||||||
setStatus('disconnected');
|
setStatus('disconnected');
|
||||||
document.getElementById('battBar').style.display='none';
|
document.getElementById('battBar').style.display='none';
|
||||||
@@ -751,6 +759,23 @@ function onDisconnected() {
|
|||||||
document.getElementById('badgeFull').classList.remove('show');
|
document.getElementById('badgeFull').classList.remove('show');
|
||||||
document.getElementById('vizLive').classList.remove('on');
|
document.getElementById('vizLive').classList.remove('on');
|
||||||
clearTelemetry();
|
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 ──────────────────────────────────────────────────
|
// ── IMU Stream + Visualiser ──────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user