desky-agent 0.3.11 → 0.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/assets/win/LICENSE-rcedit +20 -20
- package/assets/win/README.md +4 -4
- package/bin/cli.js +72 -1
- package/electron/main.js +302 -286
- package/firmware/firmware.bin +0 -0
- package/firmware/manifest.json +3 -3
- package/package.json +41 -41
- package/src/core.js +298 -244
- package/src/daemon.js +28 -12
- package/src/release.js +131 -131
- package/src/selfupdate.js +1 -1
- package/ui/app.html +154 -16
package/ui/app.html
CHANGED
|
@@ -392,6 +392,33 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
392
392
|
.confetti i { position: absolute; top: -12px; width: 8px; height: 12px; border-radius: 2px; animation: fall 2.4s ease-in forwards; }
|
|
393
393
|
@keyframes fall { to { transform: translateY(560px) rotate(540deg); opacity: 0; } }
|
|
394
394
|
|
|
395
|
+
/* ---------------------------------------------------------------- emotions */
|
|
396
|
+
.emolist { display: grid; }
|
|
397
|
+
.emo { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto auto; gap: 14px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
|
|
398
|
+
.emo:first-child { border-top: 0; padding-top: 0; }
|
|
399
|
+
.emo:last-child { padding-bottom: 0; }
|
|
400
|
+
.emo svg { width: 56px; height: 42px; display: block; border-radius: 6px; transition: opacity .15s, filter .15s; }
|
|
401
|
+
.emo .t { min-width: 0; }
|
|
402
|
+
.emo .t b { font-weight: 500; }
|
|
403
|
+
.emo .t small { display: block; color: var(--muted); font-size: 12.5px; }
|
|
404
|
+
.emo .tag { font-size: 11.5px; font-weight: 500; padding: 1px 8px; border-radius: 999px; margin-left: 6px; vertical-align: 1px;
|
|
405
|
+
background: var(--sunk); border: 1px solid var(--line); color: var(--muted); }
|
|
406
|
+
.emo .tag.now { background: var(--clawd-soft); border-color: var(--clawd); color: var(--ink); }
|
|
407
|
+
.emo.off svg { opacity: .35; filter: grayscale(1); }
|
|
408
|
+
.emo.off .t b { color: var(--muted); }
|
|
409
|
+
.emo .instead { display: none; color: var(--faint); }
|
|
410
|
+
.emo.off .instead { display: inline; }
|
|
411
|
+
.sw { display: inline-flex; flex: none; }
|
|
412
|
+
.sw input[type=checkbox] { -webkit-appearance: none; appearance: none; position: relative; width: 40px; height: 22px; border-radius: 11px; margin: 0;
|
|
413
|
+
background: var(--line2); cursor: pointer; transition: background .15s; }
|
|
414
|
+
.sw input[type=checkbox]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
|
|
415
|
+
background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .15s; }
|
|
416
|
+
.sw input[type=checkbox]:checked { background: var(--clawd); }
|
|
417
|
+
.sw input[type=checkbox]:checked::after { transform: translateX(18px); }
|
|
418
|
+
.sw input[type=checkbox]:disabled { opacity: .45; cursor: default; }
|
|
419
|
+
.emohead { display: flex; gap: 8px; flex-wrap: wrap; }
|
|
420
|
+
.emonote { color: var(--muted); font-size: 12.5px; }
|
|
421
|
+
|
|
395
422
|
/* ---------------------------------------------------------------- narrow windows */
|
|
396
423
|
@media (max-width: 1100px) { .cols.wide { grid-template-columns: 1fr; } .joints { grid-template-columns: 1fr; } }
|
|
397
424
|
@media (max-width: 900px) {
|
|
@@ -415,6 +442,10 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
415
442
|
}
|
|
416
443
|
@media (max-width: 600px) {
|
|
417
444
|
.btns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
445
|
+
.emo { grid-template-columns: 44px minmax(0, 1fr) auto; column-gap: 12px; row-gap: 8px; }
|
|
446
|
+
.emo svg { width: 44px; height: 33px; }
|
|
447
|
+
.emo .show { grid-column: 2; grid-row: 2; justify-self: start; }
|
|
448
|
+
.emo .sw { grid-column: 3; grid-row: 1; }
|
|
418
449
|
.fader { grid-template-columns: minmax(0, 1fr) 52px; gap: 6px 12px; }
|
|
419
450
|
.fader input { grid-column: 1 / -1; grid-row: 2; }
|
|
420
451
|
.facts { grid-template-columns: 1fr; }
|
|
@@ -435,6 +466,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
435
466
|
<nav role="tablist">
|
|
436
467
|
<button type="button" role="tab" data-tab="home" aria-selected="true"><svg viewBox="0 0 24 24"><path d="M4 11l8-7 8 7v8.5a.5.5 0 0 1-.5.5H15v-6H9v6H4.5a.5.5 0 0 1-.5-.5z"/></svg>Огляд</button>
|
|
437
468
|
<button type="button" role="tab" data-tab="move"><svg viewBox="0 0 24 24"><path d="M4 7h9M19 7h1M4 17h3M13 17h7"/><circle cx="16" cy="7" r="2.5"/><circle cx="10" cy="17" r="2.5"/></svg>Рухи</button>
|
|
469
|
+
<button type="button" role="tab" data-tab="emo"><svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="8.5"/><path d="M8.5 14.2c1.9 2.2 5.1 2.2 7 0"/><path d="M9 9.5v1M15 9.5v1"/></svg>Емоції</button>
|
|
438
470
|
<button type="button" role="tab" data-tab="cal"><svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="7.5"/><circle cx="12" cy="12" r="2.5"/><path d="M12 2.5v3M12 18.5v3M2.5 12h3M18.5 12h3"/></svg>Калібрування</button>
|
|
439
471
|
<button type="button" role="tab" data-tab="cfg"><svg viewBox="0 0 24 24"><path d="M4 6h16M4 12h16M4 18h16"/><circle cx="9" cy="6" r="1.8" fill="currentColor"/><circle cx="15" cy="12" r="1.8" fill="currentColor"/><circle cx="7" cy="18" r="1.8" fill="currentColor"/></svg>Налаштування</button>
|
|
440
472
|
<button type="button" role="tab" data-tab="mon"><svg viewBox="0 0 24 24"><rect x="3" y="4.5" width="18" height="15" rx="2.5"/><path d="M7.5 9.5l3 2.5-3 2.5M13 15h3.5"/></svg>Монітор</button>
|
|
@@ -511,7 +543,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
511
543
|
<button type="button" data-cmd="happy">Радіє</button>
|
|
512
544
|
<button type="button" data-cmd="sleep">Спить</button>
|
|
513
545
|
</div>
|
|
514
|
-
<div class="fader"><label for="spd"
|
|
546
|
+
<div class="fader" id="spdRow" title="темп усіх рухів Desky: сценок, станів агента й ручних рухів; 100% = як задумано"><label for="spd">Темп рухів</label><input type="range" id="spd" min="20" max="100" step="5" value="100"><output id="ospd">100%</output></div>
|
|
515
547
|
<div class="sep"></div>
|
|
516
548
|
<div class="hd"><h2>Серво</h2></div>
|
|
517
549
|
<div class="btns">
|
|
@@ -525,6 +557,16 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
525
557
|
</div>
|
|
526
558
|
</section>
|
|
527
559
|
|
|
560
|
+
<!-- ============================================================ emotions -->
|
|
561
|
+
<section data-page="emo" class="page" hidden>
|
|
562
|
+
<div class="title"><div><h1>Емоції</h1><p>Що Desky показує, поки агент працює. Вимкнена емоція не грає: замість неї Desky спокійно сидить, як коли нічого не відбувається, і її звук теж мовчить.</p></div>
|
|
563
|
+
<div class="emohead"><button type="button" class="ghost" id="emoAll">Увімкнути всі</button><button type="button" id="emoCalm" title="вимкнути все, що рухається активно: друк, кивки, радість, помилки, пробудження">Лише спокійні</button></div></div>
|
|
564
|
+
<div class="card">
|
|
565
|
+
<div class="emolist" id="emoList"></div>
|
|
566
|
+
</div>
|
|
567
|
+
<p class="emonote">«▶ Показати» грає емоцію на Desky зараз, навіть вимкнену. Потім натисни «Повернути агенту» або зачекай хвилину. З терміналу: <span class="mono">npx desky-agent emotions</span>.</p>
|
|
568
|
+
</section>
|
|
569
|
+
|
|
528
570
|
<!-- ============================================================ calibration -->
|
|
529
571
|
<section data-page="cal" class="page" hidden>
|
|
530
572
|
<div class="title"><div><h1>Калібрування</h1></div>
|
|
@@ -539,6 +581,8 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
539
581
|
<div class="set tog">
|
|
540
582
|
<div class="field"><label>Поворот і нахил переплутані<small>Повзунок повороту нахиляє Desky, а нахилу — крутить? Серво під'єднані навпаки. <span id="swapV"></span></small></label>
|
|
541
583
|
<button type="button" class="sm" id="swapYP">Поміняти місцями</button></div>
|
|
584
|
+
<div class="field"><label>Руки переплутані<small>Повзунок правої руки рухає ліву? Серво рук під'єднані навпаки. <span id="armsV"></span></small></label>
|
|
585
|
+
<button type="button" class="sm" id="swapArms">Поміняти руки</button></div>
|
|
542
586
|
<div class="field"><label>Екран догори дриґом<small>Очі-галочки «^ ^» мають дивитися кутиками вгору. <span id="flipV"></span></small></label>
|
|
543
587
|
<span class="in"><button type="button" class="sm ghost" id="faceTest">Показати «^ ^»</button><button type="button" class="sm" id="flipScr">Перевернути</button></span></div>
|
|
544
588
|
</div>
|
|
@@ -662,6 +706,8 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
662
706
|
if (!boardText) return;
|
|
663
707
|
try { await navigator.clipboard.writeText(boardText); toast('Скопійовано: ' + boardText); } catch (e) {}
|
|
664
708
|
};
|
|
709
|
+
const fwAtLeast = (a, b, c) => { const v = String(boardFw || '').split('.').map(Number); return v.length === 3 && (v[0] - a || v[1] - b || v[2] - c) >= 0; };
|
|
710
|
+
let tempoAsked = false;
|
|
665
711
|
const canColor = () => { const v = String(boardFw || '').split('.').map(Number); return v.length === 3 && (v[0] > 0 || v[1] > 2 || (v[1] === 2 && v[2] >= 4)); };
|
|
666
712
|
let CFG = null;
|
|
667
713
|
|
|
@@ -707,7 +753,8 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
707
753
|
return new Promise(resolve => {
|
|
708
754
|
const w = { word };
|
|
709
755
|
w.done = ok => { clearTimeout(w.t); const i = waiters.indexOf(w); if (i >= 0) waiters.splice(i, 1); resolve(ok); };
|
|
710
|
-
|
|
756
|
+
// a slower tempo makes every move longer: wait in proportion, or the next line would cut the move short
|
|
757
|
+
w.t = setTimeout(() => w.done(false), ms * 100 / Math.max(20, Number($('spd').value) || 100));
|
|
711
758
|
waiters.push(w);
|
|
712
759
|
send(cmd);
|
|
713
760
|
});
|
|
@@ -739,7 +786,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
739
786
|
}
|
|
740
787
|
// every hand command takes Desky from the agent; the daemon gives him back 15 s after the last keep-alive
|
|
741
788
|
// calibration writes the board's memory: the firmware takes it only after "factory on" (docs/firmware_contract.md)
|
|
742
|
-
const FACTORY = ['trim', 'inv', 'here', 'save', 'swap', 'flip', 'probe', 'hold', 'yawhold', 'sn', 'calset', 'face'];
|
|
789
|
+
const FACTORY = ['trim', 'inv', 'here', 'save', 'swap', 'aswap', 'flip', 'probe', 'hold', 'yawhold', 'sn', 'calset', 'face'];
|
|
743
790
|
async function send(cmd, quiet) {
|
|
744
791
|
if (FACTORY.includes(cmd.trim().split(/\s+/)[0].toLowerCase())) await api('/cmd', { line: 'factory on', hand: false }).catch(() => {});
|
|
745
792
|
if (cmd === 'on') onUntil = Date.now() + 1800;
|
|
@@ -797,6 +844,11 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
797
844
|
if (connected && !was) { boardColor = null; colorAsked = false; send('cal', true); }
|
|
798
845
|
boardFw = connected && st.board ? st.board.fw : null;
|
|
799
846
|
if (connected && canColor() && !colorAsked) { colorAsked = true; send('color', true); }
|
|
847
|
+
if (!connected) tempoAsked = false;
|
|
848
|
+
else if (!tempoAsked && boardFw) { tempoAsked = true; if (fwAtLeast(0, 3, 13)) send('tempo', true); }
|
|
849
|
+
$('spd').disabled = !connected || !fwAtLeast(0, 3, 13);
|
|
850
|
+
$('spdRow').title = connected && !fwAtLeast(0, 3, 13) ? 'темп рухів з прошивки 0.3.13: онови Desky'
|
|
851
|
+
: 'темп усіх рухів Desky: сценок, станів агента й ручних рухів; 100% = як задумано';
|
|
800
852
|
$('dC3').className = 'dot ' + (connected ? 'on' : 'bad');
|
|
801
853
|
const bd = connected && st.board ? st.board : {};
|
|
802
854
|
$('sC3').textContent = connected ? (bd.sn || st.port) : 'немає';
|
|
@@ -820,7 +872,10 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
820
872
|
showUpdate(st.app_update);
|
|
821
873
|
|
|
822
874
|
$('hState').textContent = NAMES[st.state] || st.state;
|
|
823
|
-
|
|
875
|
+
// a switched-off emotion: Desky sits calm, the line says what the agent really does
|
|
876
|
+
$('hWhat').textContent = st.actual && st.actual !== st.state
|
|
877
|
+
? (WHAT[st.actual] || NAMES[st.actual] || st.actual) + '. Цю емоцію вимкнено, Desky спокійний' : WHAT[st.state] || '';
|
|
878
|
+
showEmoNow(st.actual || st.state);
|
|
824
879
|
$('hQuiet').hidden = !st.quiet_now;
|
|
825
880
|
if (st.quiet_now) $('hQuiet').querySelector('span').textContent = 'Тихі години' + (CFG ? ' до ' + CFG.quiet_hours[1] + ':00' : '');
|
|
826
881
|
|
|
@@ -930,7 +985,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
930
985
|
document.addEventListener('keydown', e => { if (e.key === 'Escape' && !$('updModal').hidden) $('updSkip').click(); });
|
|
931
986
|
|
|
932
987
|
function enable() {
|
|
933
|
-
document.querySelectorAll('[data-cmd], #send, #home, #stop, #swapYP, #flipScr, #faceTest, #calSave, #rawf button, #joints button, #joints input, #statesRow button, #soundsRow button')
|
|
988
|
+
document.querySelectorAll('[data-cmd], #send, #home, #stop, #swapYP, #swapArms, #flipScr, #faceTest, #calSave, #rawf button, #joints button, #joints input, #statesRow button, #soundsRow button, #emoList button')
|
|
934
989
|
.forEach(b => { b.disabled = !connected; });
|
|
935
990
|
F.forEach(f => { f.disabled = !connected; });
|
|
936
991
|
}
|
|
@@ -984,8 +1039,59 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
984
1039
|
NUMS.forEach(k => { $(k).value = c[k]; });
|
|
985
1040
|
$('read_tools').value = c.read_tools.join(', ');
|
|
986
1041
|
units();
|
|
1042
|
+
drawEmotions();
|
|
987
1043
|
}
|
|
988
|
-
async function loadCfg() { try { const r = await api('/config'); DEF = r.defaults; fillCfg(r.config); } catch (e) {} }
|
|
1044
|
+
async function loadCfg() { try { const r = await api('/config'); DEF = r.defaults; EMO = r.emotions || []; fillCfg(r.config); } catch (e) {} }
|
|
1045
|
+
|
|
1046
|
+
// ---------------------------------------------------------------- emotions: which states Desky acts out
|
|
1047
|
+
// the list (names, hints, which are calm) comes from the daemon (src/core.js EMOTIONS); a switch saves at once
|
|
1048
|
+
let EMO = [], emoNow = null;
|
|
1049
|
+
const IDLE_ROW = { key: 'idle', label: 'Нічого не робить', hint: 'спокійна поза: руки опущені, зрідка озирається. Сюди йдуть вимкнені емоції', calm: true, base: true };
|
|
1050
|
+
function emoOff() { return (CFG && CFG.emotions_off) || []; }
|
|
1051
|
+
function drawEmotions() {
|
|
1052
|
+
const host = $('emoList'); if (!host || !CFG) return;
|
|
1053
|
+
host.innerHTML = '';
|
|
1054
|
+
const off = emoOff();
|
|
1055
|
+
for (const e of [...EMO, IDLE_ROW]) {
|
|
1056
|
+
const r = document.createElement('div'); r.className = 'emo' + (off.includes(e.key) ? ' off' : ''); r.dataset.key = e.key;
|
|
1057
|
+
const face = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); face.setAttribute('viewBox', '0 0 64 48'); face.setAttribute('aria-hidden', 'true');
|
|
1058
|
+
drawFace(face, e.key); r.appendChild(face);
|
|
1059
|
+
const t = document.createElement('div'); t.className = 't';
|
|
1060
|
+
const b = document.createElement('b'); b.textContent = e.label; t.appendChild(b);
|
|
1061
|
+
if (e.calm && !e.base) { const g = document.createElement('span'); g.className = 'tag'; g.textContent = 'спокійна'; t.appendChild(g); }
|
|
1062
|
+
const now = document.createElement('span'); now.className = 'tag now'; now.textContent = 'зараз'; now.hidden = true; t.appendChild(now);
|
|
1063
|
+
const sm = document.createElement('small'); sm.textContent = e.hint.charAt(0).toUpperCase() + e.hint.slice(1);
|
|
1064
|
+
const ins = document.createElement('span'); ins.className = 'instead'; ins.textContent = ' · вимкнено, замість неї спокій'; sm.appendChild(ins);
|
|
1065
|
+
t.appendChild(sm); r.appendChild(t);
|
|
1066
|
+
const show = document.createElement('button'); show.type = 'button'; show.className = 'sm show'; show.textContent = '▶ Показати';
|
|
1067
|
+
show.title = 'зіграти «' + e.label + '» на Desky зараз'; show.disabled = !connected;
|
|
1068
|
+
show.onclick = () => { send('state ' + e.key); toast('Desky показує: ' + e.label); };
|
|
1069
|
+
r.appendChild(show);
|
|
1070
|
+
const sw = document.createElement('label'); sw.className = 'sw'; sw.title = e.base ? 'завжди увімкнено' : 'показувати цю емоцію';
|
|
1071
|
+
const cb = document.createElement('input'); cb.type = 'checkbox'; cb.setAttribute('role', 'switch'); cb.checked = !off.includes(e.key);
|
|
1072
|
+
cb.setAttribute('aria-label', e.label); cb.disabled = Boolean(e.base);
|
|
1073
|
+
cb.onchange = () => setEmotion(e.key, cb.checked, e.label);
|
|
1074
|
+
sw.appendChild(cb); r.appendChild(sw);
|
|
1075
|
+
host.appendChild(r);
|
|
1076
|
+
}
|
|
1077
|
+
showEmoNow(emoNow);
|
|
1078
|
+
}
|
|
1079
|
+
function showEmoNow(key) {
|
|
1080
|
+
emoNow = key;
|
|
1081
|
+
document.querySelectorAll('#emoList .emo').forEach(r => { r.querySelector('.tag.now').hidden = r.dataset.key !== key; });
|
|
1082
|
+
}
|
|
1083
|
+
async function saveEmotions(off, msg) {
|
|
1084
|
+
try { CFG = (await api('/config', { emotions_off: off })).config; toast(msg); }
|
|
1085
|
+
catch (e) { toast('Не збережено: ' + e.message, true); }
|
|
1086
|
+
drawEmotions();
|
|
1087
|
+
}
|
|
1088
|
+
function setEmotion(key, on, label) {
|
|
1089
|
+
const off = emoOff().filter(k => k !== key);
|
|
1090
|
+
if (!on) off.push(key);
|
|
1091
|
+
saveEmotions(off, on ? `«${label}» увімкнено` : `«${label}» вимкнено: Desky замість неї спокійний`);
|
|
1092
|
+
}
|
|
1093
|
+
$('emoAll').onclick = () => saveEmotions([], 'Усі емоції увімкнено');
|
|
1094
|
+
$('emoCalm').onclick = () => saveEmotions(EMO.filter(e => !e.calm).map(e => e.key), 'Лише спокійні: друк, кивки, радість і помилки вимкнено');
|
|
989
1095
|
const say = (t, cls) => { const m = $('cfgMsg'); m.className = cls || ''; m.textContent = t;
|
|
990
1096
|
clearTimeout(say.t); say.t = setTimeout(() => { m.className = ''; m.textContent = 'Час — у секундах.'; }, 4000); };
|
|
991
1097
|
$('saveCfg').onclick = async () => {
|
|
@@ -994,7 +1100,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
994
1100
|
try { fillCfg((await api('/config', body)).config); say('Збережено', 'ok'); }
|
|
995
1101
|
catch (e) { say(e.message, 'bad'); }
|
|
996
1102
|
};
|
|
997
|
-
$('defCfg').onclick = () => { if (DEF) { const keep = CFG; fillCfg(DEF); CFG = keep; } say('Підставлено значення за замовчуванням — збережи, щоб застосувати'); };
|
|
1103
|
+
$('defCfg').onclick = () => { if (DEF) { const keep = CFG; fillCfg(DEF); CFG = keep; drawEmotions(); } say('Підставлено значення за замовчуванням — збережи, щоб застосувати'); };
|
|
998
1104
|
loadCfg();
|
|
999
1105
|
|
|
1000
1106
|
// ---------------------------------------------------------------- Desky's colour
|
|
@@ -1064,11 +1170,15 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
1064
1170
|
SWAP = +m[1] > +m[2]; $('swapV').textContent = SWAP ? 'Зараз: поміняні місцями.' : 'Зараз: як на схемі.';
|
|
1065
1171
|
if (m[3]) { FLIP = /перев/.test(m[3]); $('flipV').textContent = FLIP ? 'Зараз: перевернутий.' : 'Зараз: як є.'; }
|
|
1066
1172
|
}
|
|
1173
|
+
m = line.match(/правая рука на GPIO(\d+), левая рука на GPIO(\d+)/);
|
|
1174
|
+
if (m) $('armsV').textContent = +m[1] > +m[2] ? 'Зараз: поміняні місцями.' : 'Зараз: як на схемі.';
|
|
1175
|
+
m = line.match(/^темп (\d+)%/);
|
|
1176
|
+
if (m) { $('spd').value = m[1]; $('ospd').textContent = m[1] + '%'; fill($('spd')); }
|
|
1067
1177
|
if (/^сохранено/.test(line)) { calDirty(false); }
|
|
1068
1178
|
m = line.match(/^цвет ([0-9a-f]{6}) ([0-9a-f]{6})/i);
|
|
1069
1179
|
// only fresh answers: the first poll replays the monitor's history, old colours included (each one sent ours back)
|
|
1070
1180
|
if (m && primed) { boardColor = Object.keys(PALETTE).find(k => PALETTE[k].body.slice(1).toLowerCase() === m[1].toLowerCase()) || 'other'; reconcileColor(); }
|
|
1071
|
-
if (/^err (trim|inv|here|save|swap|flip|face)/.test(line)) toast('Плата не прийняла команду: ' + line.slice(4), true);
|
|
1181
|
+
if (/^err (trim|inv|here|save|swap|aswap|flip|face)/.test(line)) toast('Плата не прийняла команду: ' + line.slice(4), true);
|
|
1072
1182
|
wizLine(line);
|
|
1073
1183
|
}
|
|
1074
1184
|
|
|
@@ -1110,8 +1220,8 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
1110
1220
|
$('stop').onclick = () => send('stop');
|
|
1111
1221
|
document.querySelectorAll('[data-cmd]').forEach(b => b.onclick = () => send(b.dataset.cmd, ['where', 'cal'].includes(b.dataset.cmd)));
|
|
1112
1222
|
const spd = $('spd');
|
|
1113
|
-
spd.oninput = () => { $('ospd').textContent = spd.value + '
|
|
1114
|
-
spd.onchange = () => send('
|
|
1223
|
+
spd.oninput = () => { $('ospd').textContent = spd.value + '%'; fill(spd); };
|
|
1224
|
+
spd.onchange = () => send('tempo ' + spd.value);
|
|
1115
1225
|
fill(spd);
|
|
1116
1226
|
$('rawf').onsubmit = e => { e.preventDefault(); const v = $('raw').value.trim(); if (v) { send(v, /^(where|cal|help|who|ping|sound )/.test(v)); $('raw').value = ''; } };
|
|
1117
1227
|
$('helpBtn').onclick = () => send('help', true);
|
|
@@ -1243,6 +1353,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
1243
1353
|
}
|
|
1244
1354
|
$('calSave').onclick = async () => { await send('save'); toast('Збережено в платі'); };
|
|
1245
1355
|
$('swapYP').onclick = async () => { await send('swap'); await send('cal', true); };
|
|
1356
|
+
$('swapArms').onclick = async () => { await send('aswap'); await send('cal', true); };
|
|
1246
1357
|
$('flipScr').onclick = async () => { await send('flip'); await send('face happy'); await send('cal', true); };
|
|
1247
1358
|
$('faceTest').onclick = async () => { await send('face happy'); await wait(2500); await send('face eyes'); };
|
|
1248
1359
|
$('calWiz').onclick = () => wizOpen('wires');
|
|
@@ -1332,8 +1443,8 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
1332
1443
|
}
|
|
1333
1444
|
|
|
1334
1445
|
// ---------------------------------------------------------------- setup wizard
|
|
1335
|
-
const STEPS = ['hello', 'connect', 'color', 'check', 'wires', 'screen', 'j0', 'j1', 'j2', 'j3', 'done'];
|
|
1336
|
-
const STEP_NAMES = { hello: 'Привіт', connect: 'Підключення', color: 'Колір', check: 'Перевірка', wires: 'Проводи', screen: 'Екран',
|
|
1446
|
+
const STEPS = ['hello', 'connect', 'color', 'check', 'wires', 'arms', 'screen', 'j0', 'j1', 'j2', 'j3', 'done'];
|
|
1447
|
+
const STEP_NAMES = { hello: 'Привіт', connect: 'Підключення', color: 'Колір', check: 'Перевірка', wires: 'Проводи', arms: 'Руки', screen: 'Екран',
|
|
1337
1448
|
j0: 'Поворот', j1: 'Нахил', j2: 'Права рука', j3: 'Ліва рука', done: 'Готово' };
|
|
1338
1449
|
const W = { step: null, sub: null, stop: null, retried: false, orig: null, onTick: null, onLine: null, onCal: null };
|
|
1339
1450
|
const IC_OK = '<svg viewBox="0 0 16 16"><path d="M3.5 8.5l3 3 6-7"/></svg>', IC_BAD = '<svg viewBox="0 0 16 16"><path d="M4.5 4.5l7 7M11.5 4.5l-7 7"/></svg>';
|
|
@@ -1412,7 +1523,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
1412
1523
|
revertCentre();
|
|
1413
1524
|
W.step = name; W.sub = sub || null; W.retried = false;
|
|
1414
1525
|
progress(name);
|
|
1415
|
-
const fixed = { hello: stHello, connect: stConnect, color: stColor, check: stCheck, wires: stWires, screen: stScreen, done: stDone }[name];
|
|
1526
|
+
const fixed = { hello: stHello, connect: stConnect, color: stColor, check: stCheck, wires: stWires, arms: stArms, screen: stScreen, done: stDone }[name];
|
|
1416
1527
|
if (fixed) fixed(); else if (sub === 'centre') stCentre(+name[1]); else stDir(+name[1]);
|
|
1417
1528
|
}
|
|
1418
1529
|
function wizTick() { if (!$('wiz').hidden && W.onTick) W.onTick(); }
|
|
@@ -1512,12 +1623,12 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
1512
1623
|
lead: 'Desky спробує <b>повернути голову вбік</b>. Якщо серво поворота й нахилу під\'єднані навпаки, замість цього він кивне. Що він зробив?',
|
|
1513
1624
|
stage: views(ft), body: [h('<div class="choices"></div>'), note, replay],
|
|
1514
1625
|
scene: { shot: 'yaw', glow: 0, run: c => c.loop(HOME, [22, 0, 65, 65]) }, cap: 'має бути так: поворот убік',
|
|
1515
|
-
foot: [back('check'), spacer(), btn('Пропустити крок', 'ghost', () => go('
|
|
1626
|
+
foot: [back('check'), spacer(), btn('Пропустити крок', 'ghost', () => go('arms'))],
|
|
1516
1627
|
});
|
|
1517
1628
|
const ch = $('wizBody').querySelector('.choices'); ch.append(ca, cb);
|
|
1518
1629
|
async function show() { await servosOn(); await demoMove('j1 25'); }
|
|
1519
1630
|
async function answer(ok) {
|
|
1520
|
-
if (ok) { go('
|
|
1631
|
+
if (ok) { go('arms'); return; }
|
|
1521
1632
|
if (W.retried) { note.hidden = false; note.className = 'note bad';
|
|
1522
1633
|
note.textContent = 'Голова не повертається й після перестановки. Перевір серво J1 і J2 та їхні роз\'єми, потім пройди майстер ще раз.'; return; }
|
|
1523
1634
|
W.retried = true;
|
|
@@ -1526,6 +1637,33 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
1526
1637
|
busy(replay, show);
|
|
1527
1638
|
}
|
|
1528
1639
|
|
|
1640
|
+
// ---- 4b. the arms on each other's pins? Desky lifts his right arm; the other one rising means swapped plugs
|
|
1641
|
+
function stArms() {
|
|
1642
|
+
const [fa, sa] = fig('0 0 240 170', 'має піднятися ця рука');
|
|
1643
|
+
W.stop = animate([P => drawFront(sa, P)], HOME, [0, 0, 150, 65]);
|
|
1644
|
+
const note = h('<div class="note" hidden></div>');
|
|
1645
|
+
const replay = btn('Показати ще раз', 'ghost', () => busy(replay, show));
|
|
1646
|
+
const ca = btn('Так, ця', 'pri', () => answer(true));
|
|
1647
|
+
const cb = btn('Ні, інша', '', () => answer(false));
|
|
1648
|
+
frame({
|
|
1649
|
+
kick: 'Калібрування · руки', title: 'Яка рука піднялась?',
|
|
1650
|
+
lead: 'Desky підніме <b>праву руку</b>: свою праву, тобто ту, що <b>ліворуч від тебе</b>, коли він дивиться на тебе, як на малюнку. Якщо піднялась інша, серво рук під\'єднані навпаки.',
|
|
1651
|
+
stage: views(fa), body: [note, h('<div class="row"></div>')],
|
|
1652
|
+
scene: { shot: 'front', run: c => c.loop(HOME, [0, 0, 150, 65]) }, cap: 'має бути так',
|
|
1653
|
+
foot: [back('wires'), spacer(), btn('Пропустити крок', 'ghost', () => go('screen')), cb, ca],
|
|
1654
|
+
});
|
|
1655
|
+
$('wizBody').querySelector('.slot .row').appendChild(replay);
|
|
1656
|
+
async function show() { await servosOn(); await demoMove('j3 105'); }
|
|
1657
|
+
async function answer(ok) {
|
|
1658
|
+
if (ok) { go('screen'); return; }
|
|
1659
|
+
if (W.retried) { note.hidden = false; note.className = 'note bad';
|
|
1660
|
+
note.textContent = 'Знову не та рука. Перевір серво J3 і J4 та їхні роз\'єми, потім пройди майстер ще раз.'; return; }
|
|
1661
|
+
W.retried = true;
|
|
1662
|
+
await busy(cb, async () => { await send('aswap'); note.hidden = false; note.className = 'note'; note.textContent = 'Поміняв руки місцями й зберіг. Дивись ще раз!'; await show(); });
|
|
1663
|
+
}
|
|
1664
|
+
busy(replay, show);
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1529
1667
|
// ---- 5. the screen upside down? (calibrate.py, check_flip)
|
|
1530
1668
|
function stScreen() {
|
|
1531
1669
|
const P = PALETTE[COLOR];
|
|
@@ -1539,7 +1677,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
1539
1677
|
lead: 'Зараз на екрані Desky <b>усміхнені очі-галочки</b>. Якщо вони перевернуті, екран стоїть догори дриґом. Як вони виглядають?',
|
|
1540
1678
|
stage: [bigFace('happy'), h('<div class="cap">так має бути</div>')], body: [h('<div class="choices"></div>'), note],
|
|
1541
1679
|
scene: { shot: 'face', run: c => { c.pose(HOME); c.face('HAPPY'); } }, cap: 'так має бути',
|
|
1542
|
-
foot: [back('
|
|
1680
|
+
foot: [back('arms'), spacer(), btn('Пропустити крок', 'ghost', () => { send('face eyes'); go('j0'); })],
|
|
1543
1681
|
});
|
|
1544
1682
|
$('wizBody').querySelector('.choices').append(ca, cb);
|
|
1545
1683
|
send('face happy');
|