Better auto-reconnect, flip Y by default
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -297,6 +297,8 @@
|
||||
<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-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>
|
||||
</header>
|
||||
|
||||
@@ -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 ──────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user