/**
* WijiBoard – Home Section
* web/js/sections/home.js
*
* A minimal placeholder home section.
*/
import BLE from '../ble.js';
const HomeSection = {
_cleanup: [],
mount(container) {
container.innerHTML = `
WijiBoard
WiFi Spirit Board — SCARA arm controller. Select a section from the sidebar to get started.
Connection
BLE
${BLE.isConnected() ? `✓ ${BLE.getDeviceName()}` : 'Not connected'}
Use the Connect button
in the top bar to pair with the WijiBoard via Bluetooth.
The device name is WijiBoard.
About
This dashboard controls a two-arm SCARA robot that moves a planchette
across a spirit board. It uses Web Bluetooth
to communicate with an ESP32-C3 running two 28BYJ-48 stepper motors
with AccelStepper.
Sections
Install App
Install WijiBoard to your device for a native app experience and full-screen control.
`;
// Keep home BLE status label in sync
const statusEl = container.querySelector('#home-ble-status');
const update = () => {
if (statusEl) statusEl.textContent = BLE.isConnected()
? `✓ ${BLE.getDeviceName()}`
: 'Not connected';
};
BLE.on('connected', update);
BLE.on('disconnected', update);
// PWA Install Logic
const pwaCard = container.querySelector('#home-pwa-install-card');
const pwaBtn = container.querySelector('#home-btn-install-pwa');
const checkPwaStatus = () => {
if (window.deferredPrompt && pwaCard) {
pwaCard.style.display = 'block';
}
};
// Check initially in case the event fired before we mounted
checkPwaStatus();
window.addEventListener('pwa-installable', checkPwaStatus);
if (pwaBtn) {
pwaBtn.addEventListener('click', async () => {
if (!window.deferredPrompt) return;
window.deferredPrompt.prompt();
const { outcome } = await window.deferredPrompt.userChoice;
console.log(`User response to the install prompt: ${outcome}`);
window.deferredPrompt = null;
pwaCard.style.display = 'none';
});
}
this._cleanup = [
() => BLE.off('connected', update),
() => BLE.off('disconnected', update),
() => window.removeEventListener('pwa-installable', checkPwaStatus),
];
},
unmount() {
this._cleanup.forEach(fn => fn());
this._cleanup = [];
},
};
export default HomeSection;