Implement proper stepper idling. Should close #3
This commit is contained in:
+36
@@ -86,6 +86,14 @@
|
||||
|
||||
<!-- BLE actions -->
|
||||
<div class="topbar-actions">
|
||||
<!-- Disable steppers button (hidden by default) -->
|
||||
<button class="btn btn-sm btn-ghost" id="btn-disable-steppers" style="display:none; margin-right:8px; padding:0 8px; color: var(--danger-color);" title="Disable Motors (Requires Rehoming)" aria-label="Disable Steppers">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M18.36 6.64a9 9 0 1 1-12.73 0"></path>
|
||||
<line x1="12" y1="2" x2="12" y2="12"></line>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<!-- BLE status pill -->
|
||||
<div class="ble-status" id="ble-status" aria-live="polite">
|
||||
<div class="ble-dot" id="ble-dot"></div>
|
||||
@@ -202,6 +210,34 @@
|
||||
window.dispatchEvent(new Event('pwa-installable'));
|
||||
});
|
||||
|
||||
// ── Disable Steppers & Idle Timeout Logic ──────────────────────
|
||||
const btnDisable = document.getElementById('btn-disable-steppers');
|
||||
btnDisable.addEventListener('click', async () => {
|
||||
if (BLE.isConnected()) {
|
||||
await BLE.write('DISABLE').catch(e => UI.log(e.message, 'error'));
|
||||
localStorage.setItem('wiji_homed', 'false');
|
||||
UI.log('Steppers manually disabled. Rehoming required.', 'warn');
|
||||
const warningEl = document.getElementById('home-warning');
|
||||
if (warningEl) warningEl.style.display = 'block';
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('ble:status', (e) => {
|
||||
if (e.detail === 'SYS:IDLE_TIMEOUT') {
|
||||
localStorage.setItem('wiji_homed', 'false');
|
||||
UI.log('Steppers disabled due to 30 mins inactivity. Rehoming required.', 'warn');
|
||||
const warningEl = document.getElementById('home-warning');
|
||||
if (warningEl) warningEl.style.display = 'block';
|
||||
}
|
||||
});
|
||||
|
||||
BLE.on('connected', () => {
|
||||
btnDisable.style.display = 'inline-flex';
|
||||
});
|
||||
BLE.on('disconnected', () => {
|
||||
btnDisable.style.display = 'none';
|
||||
});
|
||||
|
||||
// ── Check Web Bluetooth availability ──────────────────────────
|
||||
if (!navigator.bluetooth) {
|
||||
setTimeout(() => {
|
||||
|
||||
Reference in New Issue
Block a user