Allow position replay on lost connection
This commit is contained in:
@@ -97,7 +97,7 @@ Name: WijiBoard
|
|||||||
|
|
||||||
### Status notifications (firmware → browser)
|
### Status notifications (firmware → browser)
|
||||||
|
|
||||||
`P:<s1>,<s2>` — current step positions for motor 1 and 2, sent every 200 ms while moving.
|
`P:<s1>,<s2>,[<held>]` — current step positions for motor 1 and 2, sent every 200 ms while moving, or on request. 3rd parameter is 1 if holding, 0 if disabled.
|
||||||
`SYS:IDLE_TIMEOUT` — Sent when motors are automatically disabled due to 30 mins of inactivity.
|
`SYS:IDLE_TIMEOUT` — Sent when motors are automatically disabled due to 30 mins of inactivity.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
+2
-1
@@ -231,8 +231,9 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
BLE.on('connected', () => {
|
BLE.on('connected', async () => {
|
||||||
btnDisable.style.display = 'inline-flex';
|
btnDisable.style.display = 'inline-flex';
|
||||||
|
await BLE.write('POS').catch(e => console.warn('POS sync failed:', e));
|
||||||
});
|
});
|
||||||
BLE.on('disconnected', () => {
|
BLE.on('disconnected', () => {
|
||||||
btnDisable.style.display = 'none';
|
btnDisable.style.display = 'none';
|
||||||
|
|||||||
+2
-1
@@ -220,7 +220,8 @@ void sendPosition() {
|
|||||||
if (!bleConnected || !pStatusChar)
|
if (!bleConnected || !pStatusChar)
|
||||||
return;
|
return;
|
||||||
String pos = "P:" + String(stepper1.currentPosition()) + "," +
|
String pos = "P:" + String(stepper1.currentPosition()) + "," +
|
||||||
String(stepper2.currentPosition());
|
String(stepper2.currentPosition()) + "," +
|
||||||
|
String(motorsDisabled ? 0 : 1);
|
||||||
pStatusChar->setValue(pos.c_str());
|
pStatusChar->setValue(pos.c_str());
|
||||||
pStatusChar->notify();
|
pStatusChar->notify();
|
||||||
Serial.printf("[POS] %s\n", pos.c_str());
|
Serial.printf("[POS] %s\n", pos.c_str());
|
||||||
|
|||||||
+15
-3
@@ -15,9 +15,21 @@ let steps2 = 0;
|
|||||||
document.addEventListener('ble:status', (e) => {
|
document.addEventListener('ble:status', (e) => {
|
||||||
const msg = e.detail;
|
const msg = e.detail;
|
||||||
if (msg.startsWith('P:')) {
|
if (msg.startsWith('P:')) {
|
||||||
const [s1, s2] = msg.slice(2).split(',').map(Number);
|
const parts = msg.slice(2).split(',');
|
||||||
steps1 = s1;
|
steps1 = Number(parts[0]);
|
||||||
steps2 = s2;
|
steps2 = Number(parts[1]);
|
||||||
|
|
||||||
|
// parts[2] is the holding status (1 = holding, 0 = disabled)
|
||||||
|
if (parts.length > 2) {
|
||||||
|
const isHolding = parts[2] === '1';
|
||||||
|
if (!isHolding && localStorage.getItem('wiji_homed') === 'true') {
|
||||||
|
localStorage.setItem('wiji_homed', 'false');
|
||||||
|
UI.log('Steppers are not holding. Rehoming required.', 'warn');
|
||||||
|
document.dispatchEvent(new CustomEvent('wiji:unhomed'));
|
||||||
|
const warningEl = document.getElementById('home-warning');
|
||||||
|
if (warningEl) warningEl.style.display = 'block';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user