86 lines
1.8 KiB
JavaScript
86 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
const log = require('../logger');
|
|
|
|
function box(lines) {
|
|
const width = Math.max(...lines.map((line) => line.length), 28);
|
|
const top = `+${'-'.repeat(width + 2)}+`;
|
|
const body = lines.map((line) => `| ${line.padEnd(width)} |`);
|
|
return ['', top, ...body, top, ''].join('\n');
|
|
}
|
|
|
|
class BasicLed {
|
|
constructor(name) {
|
|
this.name = name;
|
|
this._current = null;
|
|
}
|
|
on() { this._set('on'); }
|
|
off() { this._set('off'); }
|
|
blink() { this._set('blink'); }
|
|
destroy() { this._set('off'); }
|
|
_set(next) {
|
|
if (this._current === next) return;
|
|
this._current = next;
|
|
log.debug('led', `[terminal] ${this.name} ${next}`);
|
|
}
|
|
}
|
|
|
|
class StatusLed {
|
|
setSetup() { log.info('status', 'SETUP / waiting for activation'); }
|
|
setApps() { log.info('status', 'APPS / activated'); }
|
|
off() { log.debug('status', 'off'); }
|
|
}
|
|
|
|
class Display {
|
|
showAP() {
|
|
log.info('display', box([
|
|
'Claw Daemon',
|
|
'Waiting for network',
|
|
'Windows/x86 has no AP mode',
|
|
]));
|
|
}
|
|
|
|
showConn() {
|
|
log.info('display', box([
|
|
'Claw Daemon',
|
|
'Connecting to claw cloud...',
|
|
]));
|
|
}
|
|
|
|
showErr0() {
|
|
log.info('display', box([
|
|
'Claw Daemon',
|
|
'Connection error',
|
|
]));
|
|
}
|
|
|
|
showTime() {
|
|
log.info('display', box([
|
|
'Claw Daemon',
|
|
'Running on Windows/x86',
|
|
]));
|
|
}
|
|
|
|
showPin(pin) {
|
|
const s = String(pin || '').trim();
|
|
log.info('display', box([
|
|
'Claw Daemon Activation',
|
|
`PIN: ${s}`,
|
|
'Enter this PIN in the web console',
|
|
]));
|
|
}
|
|
}
|
|
|
|
class LanLed {
|
|
start() { log.debug('led', '[terminal] LAN monitor ignored'); }
|
|
stop() { log.debug('led', '[terminal] LAN monitor stopped'); }
|
|
}
|
|
|
|
const led = new BasicLed('network');
|
|
led.bt = new BasicLed('bt');
|
|
led.status = new StatusLed();
|
|
led.display = new Display();
|
|
led.lan = new LanLed();
|
|
|
|
module.exports = led;
|