chromapi 1.0.0__py3-none-any.whl
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.
- chromapi/__init__.py +2 -0
- chromapi/__main__.py +6 -0
- chromapi/assets/audio/alert.wav +0 -0
- chromapi/assets/audio/chromapi_scream.wav +0 -0
- chromapi/assets/audio/confused.wav +0 -0
- chromapi/assets/audio/dizzy.wav +0 -0
- chromapi/assets/audio/excited.wav +0 -0
- chromapi/assets/audio/greeting.wav +0 -0
- chromapi/assets/audio/happy.wav +0 -0
- chromapi/assets/audio/no.wav +0 -0
- chromapi/assets/audio/purring.wav +0 -0
- chromapi/assets/audio/sad.wav +0 -0
- chromapi/assets/audio/scared.wav +0 -0
- chromapi/assets/audio/sleepy.wav +0 -0
- chromapi/assets/audio/squeak.wav +0 -0
- chromapi/assets/audio/surprised.wav +0 -0
- chromapi/assets/audio/thinking.wav +0 -0
- chromapi/assets/audio/upset.wav +0 -0
- chromapi/assets/audio/yes.wav +0 -0
- chromapi/assets/favicon.ico +0 -0
- chromapi/assets/firmware/chromapi_stm32_core_v2.0.0.hex +2222 -0
- chromapi/assets/firmware/flash.sh +88 -0
- chromapi/assets/moves/README.md +48 -0
- chromapi/assets/moves/angry.json +1 -0
- chromapi/assets/moves/confused.json +1 -0
- chromapi/assets/moves/dizzy.json +1 -0
- chromapi/assets/moves/excited.json +1 -0
- chromapi/assets/moves/greeting.json +1 -0
- chromapi/assets/moves/happy.json +1 -0
- chromapi/assets/moves/joy.json +1 -0
- chromapi/assets/moves/kick.json +1 -0
- chromapi/assets/moves/metadata.jsonl +15 -0
- chromapi/assets/moves/no.json +1 -0
- chromapi/assets/moves/purring.json +1 -0
- chromapi/assets/moves/sad.json +1 -0
- chromapi/assets/moves/scared.json +1 -0
- chromapi/assets/moves/surprised.json +1 -0
- chromapi/assets/moves/tired.json +1 -0
- chromapi/assets/moves/yes.json +1 -0
- chromapi/chromapi.py +1460 -0
- chromapi/cli.py +106 -0
- chromapi/config/config.yaml +118 -0
- chromapi/estimation/__init__.py +6 -0
- chromapi/estimation/attitude.py +107 -0
- chromapi/hardware/__init__.py +2 -0
- chromapi/hardware/battery.py +54 -0
- chromapi/hardware/fan.py +165 -0
- chromapi/hardware/motherboard_bridge.py +345 -0
- chromapi/input/__init__.py +2 -0
- chromapi/input/gamepad.py +379 -0
- chromapi/input/pairing.py +98 -0
- chromapi/kinematics/__init__.py +10 -0
- chromapi/kinematics/kromatics.py +324 -0
- chromapi/kinematics/poses.py +29 -0
- chromapi/kinematics/topology.py +26 -0
- chromapi/kinematics/types.py +21 -0
- chromapi/locomotion/__init__.py +7 -0
- chromapi/locomotion/balance.py +284 -0
- chromapi/locomotion/gait.py +595 -0
- chromapi/locomotion/recorded_move.py +290 -0
- chromapi/media/__init__.py +2 -0
- chromapi/media/audio.py +424 -0
- chromapi/media/led.py +461 -0
- chromapi/model/LICENSE +438 -0
- chromapi/model/mjcf/additional.xml +21 -0
- chromapi/model/mjcf/assets/18650_li_ion_battery.msh +0 -0
- chromapi/model/mjcf/assets/18650_li_ion_battery.part +13 -0
- chromapi/model/mjcf/assets/battery_holder.msh +0 -0
- chromapi/model/mjcf/assets/battery_holder.part +13 -0
- chromapi/model/mjcf/assets/camera_imx219_d160.msh +0 -0
- chromapi/model/mjcf/assets/camera_imx219_d160.part +13 -0
- chromapi/model/mjcf/assets/chromapi_logo.msh +0 -0
- chromapi/model/mjcf/assets/chromapi_logo.part +13 -0
- chromapi/model/mjcf/assets/chromapi_logo_circle.msh +0 -0
- chromapi/model/mjcf/assets/chromapi_logo_inner.msh +0 -0
- chromapi/model/mjcf/assets/chromapi_logo_outer.msh +0 -0
- chromapi/model/mjcf/assets/chromapi_motherboard.msh +0 -0
- chromapi/model/mjcf/assets/chromapi_motherboard.part +13 -0
- chromapi/model/mjcf/assets/composant2_1__corps1.msh +0 -0
- chromapi/model/mjcf/assets/composant2_1__corps1.part +13 -0
- chromapi/model/mjcf/assets/composant3_1__corps1.msh +0 -0
- chromapi/model/mjcf/assets/composant3_1__corps1.part +13 -0
- chromapi/model/mjcf/assets/composant4_1__corps1.msh +0 -0
- chromapi/model/mjcf/assets/composant4_1__corps1.part +13 -0
- chromapi/model/mjcf/assets/connector_f_1__corps1.msh +0 -0
- chromapi/model/mjcf/assets/connector_f_1__corps1.part +13 -0
- chromapi/model/mjcf/assets/connector_f_1__corps1_1.msh +0 -0
- chromapi/model/mjcf/assets/connector_f_1__corps1_1.part +13 -0
- chromapi/model/mjcf/assets/corps14.msh +0 -0
- chromapi/model/mjcf/assets/corps14.part +13 -0
- chromapi/model/mjcf/assets/fan_nf_a4x10.msh +0 -0
- chromapi/model/mjcf/assets/fan_nf_a4x10.part +13 -0
- chromapi/model/mjcf/assets/foot.msh +0 -0
- chromapi/model/mjcf/assets/foot.part +13 -0
- chromapi/model/mjcf/assets/left_coxa.msh +0 -0
- chromapi/model/mjcf/assets/left_coxa.part +13 -0
- chromapi/model/mjcf/assets/left_femur.msh +0 -0
- chromapi/model/mjcf/assets/left_femur.part +13 -0
- chromapi/model/mjcf/assets/left_tibia.msh +0 -0
- chromapi/model/mjcf/assets/left_tibia.part +13 -0
- chromapi/model/mjcf/assets/microswitch.msh +0 -0
- chromapi/model/mjcf/assets/microswitch.part +13 -0
- chromapi/model/mjcf/assets/power_switch.msh +0 -0
- chromapi/model/mjcf/assets/power_switch.part +13 -0
- chromapi/model/mjcf/assets/raspberry_pi_4_model_b.msh +0 -0
- chromapi/model/mjcf/assets/raspberry_pi_4_model_b.part +13 -0
- chromapi/model/mjcf/assets/right_coxa.msh +0 -0
- chromapi/model/mjcf/assets/right_coxa.part +13 -0
- chromapi/model/mjcf/assets/right_femur.msh +0 -0
- chromapi/model/mjcf/assets/right_femur.part +13 -0
- chromapi/model/mjcf/assets/right_tibia.msh +0 -0
- chromapi/model/mjcf/assets/right_tibia.part +13 -0
- chromapi/model/mjcf/assets/robot_case_bottom.msh +0 -0
- chromapi/model/mjcf/assets/robot_case_bottom.part +13 -0
- chromapi/model/mjcf/assets/robot_case_top.msh +0 -0
- chromapi/model/mjcf/assets/robot_case_top.part +13 -0
- chromapi/model/mjcf/assets/rpi_battery_bracket.msh +0 -0
- chromapi/model/mjcf/assets/rpi_battery_bracket.part +13 -0
- chromapi/model/mjcf/assets/speaker.msh +0 -0
- chromapi/model/mjcf/assets/speaker.part +13 -0
- chromapi/model/mjcf/assets/vis_1__corps1.msh +0 -0
- chromapi/model/mjcf/assets/vis_1__corps1.part +13 -0
- chromapi/model/mjcf/assets/vis_1__corps1_1.msh +0 -0
- chromapi/model/mjcf/assets/vis_1__corps1_1.part +13 -0
- chromapi/model/mjcf/assets/vis_a_tete_tronconique_jis_b_1111_m3x4_h_acier_inoxydable_a2_standard_v1_1__corps1.msh +0 -0
- chromapi/model/mjcf/assets/vis_a_tete_tronconique_jis_b_1111_m3x4_h_acier_inoxydable_a2_standard_v1_1__corps1.part +13 -0
- chromapi/model/mjcf/assets/ws2812b_cob_pixel_ring_27mm.msh +0 -0
- chromapi/model/mjcf/assets/ws2812b_cob_pixel_ring_27mm.part +13 -0
- chromapi/model/mjcf/config.json +14 -0
- chromapi/model/mjcf/robot.xml +639 -0
- chromapi/model/mjcf/scene.xml +24 -0
- chromapi/model/urdf/assets/18650_li_ion_battery.part +13 -0
- chromapi/model/urdf/assets/18650_li_ion_battery.stl +0 -0
- chromapi/model/urdf/assets/battery_holder.part +13 -0
- chromapi/model/urdf/assets/battery_holder.stl +0 -0
- chromapi/model/urdf/assets/camera_imx219_d160.part +13 -0
- chromapi/model/urdf/assets/camera_imx219_d160.stl +0 -0
- chromapi/model/urdf/assets/chromapi_logo.part +13 -0
- chromapi/model/urdf/assets/chromapi_logo.stl +0 -0
- chromapi/model/urdf/assets/chromapi_logo_circle.stl +0 -0
- chromapi/model/urdf/assets/chromapi_logo_inner.stl +0 -0
- chromapi/model/urdf/assets/chromapi_logo_outer.stl +0 -0
- chromapi/model/urdf/assets/chromapi_motherboard.part +13 -0
- chromapi/model/urdf/assets/chromapi_motherboard.stl +0 -0
- chromapi/model/urdf/assets/composant2_1__corps1.part +13 -0
- chromapi/model/urdf/assets/composant2_1__corps1.stl +0 -0
- chromapi/model/urdf/assets/composant3_1__corps1.part +13 -0
- chromapi/model/urdf/assets/composant3_1__corps1.stl +0 -0
- chromapi/model/urdf/assets/composant4_1__corps1.part +13 -0
- chromapi/model/urdf/assets/composant4_1__corps1.stl +0 -0
- chromapi/model/urdf/assets/connector_f_1__corps1.part +13 -0
- chromapi/model/urdf/assets/connector_f_1__corps1.stl +0 -0
- chromapi/model/urdf/assets/connector_f_1__corps1_1.part +13 -0
- chromapi/model/urdf/assets/connector_f_1__corps1_1.stl +0 -0
- chromapi/model/urdf/assets/corps14.part +13 -0
- chromapi/model/urdf/assets/corps14.stl +0 -0
- chromapi/model/urdf/assets/fan_nf_a4x10.part +13 -0
- chromapi/model/urdf/assets/fan_nf_a4x10.stl +0 -0
- chromapi/model/urdf/assets/foot.part +13 -0
- chromapi/model/urdf/assets/foot.stl +0 -0
- chromapi/model/urdf/assets/left_coxa.part +13 -0
- chromapi/model/urdf/assets/left_coxa.stl +0 -0
- chromapi/model/urdf/assets/left_femur.part +13 -0
- chromapi/model/urdf/assets/left_femur.stl +0 -0
- chromapi/model/urdf/assets/left_tibia.part +13 -0
- chromapi/model/urdf/assets/left_tibia.stl +0 -0
- chromapi/model/urdf/assets/microswitch.part +13 -0
- chromapi/model/urdf/assets/microswitch.stl +0 -0
- chromapi/model/urdf/assets/power_switch.part +13 -0
- chromapi/model/urdf/assets/power_switch.stl +0 -0
- chromapi/model/urdf/assets/raspberry_pi_4_model_b.part +13 -0
- chromapi/model/urdf/assets/raspberry_pi_4_model_b.stl +0 -0
- chromapi/model/urdf/assets/right_coxa.part +13 -0
- chromapi/model/urdf/assets/right_coxa.stl +0 -0
- chromapi/model/urdf/assets/right_femur.part +13 -0
- chromapi/model/urdf/assets/right_femur.stl +0 -0
- chromapi/model/urdf/assets/right_tibia.part +13 -0
- chromapi/model/urdf/assets/right_tibia.stl +0 -0
- chromapi/model/urdf/assets/robot_case_bottom.part +13 -0
- chromapi/model/urdf/assets/robot_case_bottom.stl +0 -0
- chromapi/model/urdf/assets/robot_case_top.part +13 -0
- chromapi/model/urdf/assets/robot_case_top.stl +0 -0
- chromapi/model/urdf/assets/rpi_battery_bracket.part +13 -0
- chromapi/model/urdf/assets/rpi_battery_bracket.stl +0 -0
- chromapi/model/urdf/assets/speaker.part +13 -0
- chromapi/model/urdf/assets/speaker.stl +0 -0
- chromapi/model/urdf/assets/vis_1__corps1.part +13 -0
- chromapi/model/urdf/assets/vis_1__corps1.stl +0 -0
- chromapi/model/urdf/assets/vis_1__corps1_1.part +13 -0
- chromapi/model/urdf/assets/vis_1__corps1_1.stl +0 -0
- chromapi/model/urdf/assets/vis_a_tete_tronconique_jis_b_1111_m3x4_h_acier_inoxydable_a2_standard_v1_1__corps1.part +13 -0
- chromapi/model/urdf/assets/vis_a_tete_tronconique_jis_b_1111_m3x4_h_acier_inoxydable_a2_standard_v1_1__corps1.stl +0 -0
- chromapi/model/urdf/assets/ws2812b_cob_pixel_ring_27mm.part +13 -0
- chromapi/model/urdf/assets/ws2812b_cob_pixel_ring_27mm.stl +0 -0
- chromapi/model/urdf/config.json +8 -0
- chromapi/model/urdf/robot.urdf +2587 -0
- chromapi/utils/calibrate_imu_mount.py +80 -0
- chromapi/utils/calibrate_servo_centers.py +432 -0
- chromapi/utils/flash.py +141 -0
- chromapi/utils/health.py +210 -0
- chromapi/utils/report.py +75 -0
- chromapi/utils/setup_motors.py +189 -0
- chromapi/utils/sim_server.py +126 -0
- chromapi/web/__init__.py +2 -0
- chromapi/web/access.py +167 -0
- chromapi/web/app.py +1136 -0
- chromapi/web/camera.py +202 -0
- chromapi/web/static/fonts/varela-round.woff2 +0 -0
- chromapi/web/static/index.html +1079 -0
- chromapi/web/static/logo.png +0 -0
- chromapi/web/static/motherboard_front.png +0 -0
- chromapi/web/static/socket.io.min.js +7 -0
- chromapi-1.0.0.dist-info/METADATA +222 -0
- chromapi-1.0.0.dist-info/RECORD +219 -0
- chromapi-1.0.0.dist-info/WHEEL +5 -0
- chromapi-1.0.0.dist-info/entry_points.txt +2 -0
- chromapi-1.0.0.dist-info/licenses/LICENSE +201 -0
- chromapi-1.0.0.dist-info/licenses/src/chromapi/model/LICENSE +438 -0
- chromapi-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1079 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover">
|
|
6
|
+
<meta name="theme-color" content="#120a1c">
|
|
7
|
+
<title>Chromapi</title>
|
|
8
|
+
<link rel="icon" href="/favicon.ico">
|
|
9
|
+
<script src="/static/socket.io.min.js"></script>
|
|
10
|
+
<style>
|
|
11
|
+
/* Chroma identity: violet, violet to pink gradient, Varela Round */
|
|
12
|
+
@font-face { font-family: 'Varela Round'; font-weight: 400; font-display: swap;
|
|
13
|
+
src: url('/static/fonts/varela-round.woff2') format('woff2'); }
|
|
14
|
+
:root {
|
|
15
|
+
--primary: rgb(148, 20, 223); --pink: #f93eff;
|
|
16
|
+
--grad: linear-gradient(83deg, var(--primary) 0%, var(--pink) 100%);
|
|
17
|
+
--grad-text: linear-gradient(83deg, var(--primary) 0%, #b927d0 100%); --bad-fill: #d42a47;
|
|
18
|
+
--bg: #0d0814; --surface: #1a1124; --surface-2: #251833; --line: rgba(200, 120, 255, 0.18);
|
|
19
|
+
--text: #f4eefa; --muted: #a596b8; --ok: #2fe08a; --warn: #ffc53d; --bad: #ff4d6d;
|
|
20
|
+
--radius: 22px; --round: 56px; --stick: 150px;
|
|
21
|
+
--glass: rgba(20, 12, 30, 0.85); /* >= 4.5:1 over a white image */
|
|
22
|
+
}
|
|
23
|
+
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
|
|
24
|
+
|
|
25
|
+
input[type=range] { height: 44px; }
|
|
26
|
+
[hidden] { display: none !important; }
|
|
27
|
+
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
|
|
28
|
+
font-family: 'Varela Round', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
|
|
29
|
+
-webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overflow: hidden; }
|
|
30
|
+
body { background: radial-gradient(1200px 600px at 50% -10%, rgba(148, 20, 223, 0.25), transparent 60%), var(--bg); }
|
|
31
|
+
button { font: inherit; color: inherit; }
|
|
32
|
+
:focus-visible { outline: 2px solid var(--pink); outline-offset: 2px; }
|
|
33
|
+
svg.i { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
|
|
34
|
+
@keyframes blink { 50% { opacity: 0.35; } }
|
|
35
|
+
|
|
36
|
+
/* ---------- Top bar ---------- */
|
|
37
|
+
.top { display: flex; align-items: center; gap: 10px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); }
|
|
38
|
+
.brand { order: 0; display: flex; align-items: center; gap: 8px; font-size: 1.15em; letter-spacing: 0.3px; }
|
|
39
|
+
.brand img { width: 34px; height: 34px; }
|
|
40
|
+
.chips { order: 1; display: flex; gap: 6px; flex: 1; justify-content: center; align-items: center; flex-wrap: wrap; }
|
|
41
|
+
#b-settings { order: 2; } #b-power { order: 3; }
|
|
42
|
+
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
|
|
43
|
+
background: var(--surface); border: 1px solid var(--line); font-size: 0.9em; white-space: nowrap; }
|
|
44
|
+
.chip svg.i { width: 18px; height: 18px; }
|
|
45
|
+
/* Battery chip: click to show the charge on the ring */
|
|
46
|
+
.chip-btn { position: relative; cursor: pointer; color: inherit; margin: 0; touch-action: manipulation; }
|
|
47
|
+
.chip-btn::after { content: ''; position: absolute; inset: -8px -4px; }
|
|
48
|
+
.chip.low { color: var(--warn); } .chip.critical, .chip.empty, .chip.bad { color: var(--bad); }
|
|
49
|
+
.chip.empty { animation: blink 1s steps(2) infinite; }
|
|
50
|
+
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); }
|
|
51
|
+
.chip.live .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
|
|
52
|
+
.chip.sim .dot { background: #27c2f5; box-shadow: 0 0 8px #27c2f5; }
|
|
53
|
+
.chip.warn .dot { background: var(--warn); }
|
|
54
|
+
.chip.bt .dot { background: #2f7bff; box-shadow: 0 0 8px #2f7bff; }
|
|
55
|
+
#chip-link .i { display: none; } #chip-link.bt .i { display: inline-block; }
|
|
56
|
+
|
|
57
|
+
/* ---------- Round buttons ---------- */
|
|
58
|
+
.round { width: var(--round); height: var(--round); border-radius: 50%; border: 1px solid var(--line);
|
|
59
|
+
background: var(--surface); display: inline-grid; place-items: center; cursor: pointer; touch-action: manipulation;
|
|
60
|
+
transition: transform 0.1s, background 0.2s; }
|
|
61
|
+
.round:hover { background: var(--surface-2); }
|
|
62
|
+
.round:active { transform: scale(0.94); }
|
|
63
|
+
.round:disabled { opacity: 0.35; cursor: default; transform: none; }
|
|
64
|
+
.round.small { --round: 44px; }
|
|
65
|
+
.round.danger { color: var(--bad); }
|
|
66
|
+
.round.badge { position: relative; }
|
|
67
|
+
.round.badge::after { content: ''; position: absolute; top: 4px; right: 4px; width: 10px; height: 10px; border-radius: 50%;
|
|
68
|
+
background: var(--pink); box-shadow: 0 0 8px var(--pink); }
|
|
69
|
+
.round.rec.on { background: var(--bad); border-color: transparent; animation: blink 1s steps(2) infinite; }
|
|
70
|
+
.rec-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--bad); }
|
|
71
|
+
.talkie { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 10px; }
|
|
72
|
+
.talkie .round { background: var(--glass); backdrop-filter: blur(8px); }
|
|
73
|
+
.round.talk { background: var(--grad-text); color: #fff; border-color: transparent; box-shadow: 0 0 18px rgba(249, 62, 255, 0.6); }
|
|
74
|
+
.round.torch.on { background: #fff; color: #1a1124; box-shadow: 0 0 18px rgba(255, 255, 255, 0.6); }
|
|
75
|
+
.stick.off { opacity: 0.3; pointer-events: none; }
|
|
76
|
+
/* Watching page: controls greyed out */
|
|
77
|
+
.off-pilot { opacity: 0.35; pointer-events: none; }
|
|
78
|
+
.sheet h3 { margin: 14px 0 8px; font-size: 0.78em; font-weight: 400; color: var(--muted); text-transform: uppercase; letter-spacing: 1.2px; }
|
|
79
|
+
.ctl { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 2px; }
|
|
80
|
+
.ctl input[type=range] { width: 160px; accent-color: var(--primary); }
|
|
81
|
+
/* Row with several controls: the slider shrinks */
|
|
82
|
+
.ctl .group { display: flex; align-items: center; gap: 8px; min-width: 0; }
|
|
83
|
+
.ctl .group input[type=range] { flex: 0 1 160px; min-width: 60px; margin: 0; }
|
|
84
|
+
.ctl .v { color: var(--muted); display: inline-block; width: 4.5em; text-align: right; font-variant-numeric: tabular-nums; }
|
|
85
|
+
/* Ring colour: a hue slider */
|
|
86
|
+
#s-ring { -webkit-appearance: none; appearance: none; height: 14px; border-radius: 999px; margin: 15px 0;
|
|
87
|
+
background: linear-gradient(90deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); }
|
|
88
|
+
#s-ring::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%;
|
|
89
|
+
background: var(--ring, #b605fc); border: 3px solid #fff; box-shadow: 0 0 6px rgba(0, 0, 0, 0.5); }
|
|
90
|
+
#s-ring::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%;
|
|
91
|
+
background: var(--ring, #b605fc); border: 3px solid #fff; box-shadow: 0 0 6px rgba(0, 0, 0, 0.5); }
|
|
92
|
+
.round.rec.on .rec-dot { background: #fff; border-radius: 4px; }
|
|
93
|
+
|
|
94
|
+
.seg { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
|
|
95
|
+
.seg button { border: none; background: transparent; min-height: 44px; padding: 5px 14px; border-radius: 999px; cursor: pointer; color: var(--muted); }
|
|
96
|
+
.seg button.active { background: var(--primary); color: #fff; }
|
|
97
|
+
|
|
98
|
+
/* ---------- Stage: video + two control columns ---------- */
|
|
99
|
+
.stage { height: calc(100dvh - 64px); display: grid; gap: 12px; padding: 0 14px 14px;
|
|
100
|
+
padding-bottom: max(14px, env(safe-area-inset-bottom));
|
|
101
|
+
grid-template-columns: auto minmax(0, 1fr) auto; grid-template-rows: minmax(0, 1fr);
|
|
102
|
+
grid-template-areas: "left video right"; }
|
|
103
|
+
#side-l { grid-area: left; } #side-r { grid-area: right; }
|
|
104
|
+
.side { display: flex; flex-direction: column; justify-content: space-between; align-items: center; gap: 12px; }
|
|
105
|
+
.side .buttons { display: flex; flex-direction: column; gap: 12px; }
|
|
106
|
+
.stick-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; }
|
|
107
|
+
.lbl { font-size: 0.72em; color: var(--muted); text-transform: uppercase; letter-spacing: 1.5px; }
|
|
108
|
+
.stick { width: var(--stick); height: var(--stick); border-radius: 50%; position: relative; touch-action: none;
|
|
109
|
+
background: radial-gradient(circle, var(--surface-2) 0%, var(--surface) 70%); border: 1px solid var(--line); }
|
|
110
|
+
.knob { position: absolute; left: 50%; top: 50%; width: 42%; height: 42%; transform: translate(-50%, -50%);
|
|
111
|
+
border-radius: 50%; background: var(--grad); box-shadow: 0 0 18px rgba(249, 62, 255, 0.45); pointer-events: none; }
|
|
112
|
+
|
|
113
|
+
.video { grid-area: video; position: relative; border-radius: var(--radius); overflow: hidden; min-height: 0;
|
|
114
|
+
background: #000 linear-gradient(160deg, #1d1029, #07040b); border: 1px solid var(--line); }
|
|
115
|
+
.video img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
|
|
116
|
+
.video .off { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
|
|
117
|
+
.rec-badge { position: absolute; top: 12px; right: 12px; padding: 5px 11px; border-radius: 999px;
|
|
118
|
+
background: var(--glass); backdrop-filter: blur(8px); font-size: 0.85em; display: none; align-items: center; gap: 6px; }
|
|
119
|
+
.rec-badge.on { display: inline-flex; }
|
|
120
|
+
.rec-badge::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); animation: blink 1s steps(2) infinite; }
|
|
121
|
+
.pill { position: absolute; right: 12px; bottom: 12px; min-height: 44px; padding: 9px 18px; border-radius: 999px; border: none; cursor: pointer;
|
|
122
|
+
background: var(--grad-text); color: #fff; box-shadow: 0 6px 18px rgba(148, 20, 223, 0.45); touch-action: manipulation; }
|
|
123
|
+
.pill:active { transform: scale(0.97); }
|
|
124
|
+
/* Speed and height: fixed columns */
|
|
125
|
+
.quick { grid-area: video; align-self: end; justify-self: start; margin: 12px; z-index: 1; max-width: calc(100% - 174px);
|
|
126
|
+
display: grid; gap: 0; padding: 0 12px; border-radius: 16px;
|
|
127
|
+
background: var(--glass); backdrop-filter: blur(8px); border: 1px solid var(--line); }
|
|
128
|
+
.q { display: grid; grid-template-columns: 4.6em minmax(56px, 130px) 4.2em; align-items: center; gap: 8px; }
|
|
129
|
+
.q input[type=range] { width: 100%; margin: 0; accent-color: var(--primary); touch-action: manipulation; }
|
|
130
|
+
.q .v { font-size: 0.85em; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
|
131
|
+
.pill.awake { background: var(--glass); border: 1px solid var(--line); box-shadow: none; backdrop-filter: blur(8px); }
|
|
132
|
+
.pill:disabled { opacity: 0.4; box-shadow: none; }
|
|
133
|
+
.diag { position: absolute; top: 12px; left: 12px; display: grid; grid-template-columns: auto auto; gap: 2px 12px;
|
|
134
|
+
padding: 8px 12px; border-radius: 14px; background: var(--glass); backdrop-filter: blur(8px); border: 1px solid var(--line);
|
|
135
|
+
font-size: 0.78em; font-variant-numeric: tabular-nums; pointer-events: none; max-width: calc(100% - 110px); }
|
|
136
|
+
.diag span { color: var(--muted); }
|
|
137
|
+
.diag b { font-weight: 400; }
|
|
138
|
+
.toast { position: absolute; top: 12px; left: 50%; transform: translate(-50%, -8px); max-width: 70%; padding: 8px 14px;
|
|
139
|
+
border-radius: 14px; background: var(--glass); backdrop-filter: blur(8px); font-size: 0.9em; text-align: center;
|
|
140
|
+
opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none; }
|
|
141
|
+
.toast.show { opacity: 1; transform: translate(-50%, 0); }
|
|
142
|
+
|
|
143
|
+
/* ---------- Sheets, panels, modals ---------- */
|
|
144
|
+
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 10; }
|
|
145
|
+
.scrim.show { opacity: 1; pointer-events: auto; }
|
|
146
|
+
.sheet { position: fixed; left: 50%; bottom: 0; width: min(640px, 100%); transform: translate(-50%, 105%);
|
|
147
|
+
background: var(--surface); border: 1px solid var(--line); border-bottom: none; border-radius: 28px 28px 0 0;
|
|
148
|
+
padding: 10px 18px max(20px, env(safe-area-inset-bottom)); transition: transform 0.25s ease; z-index: 11; }
|
|
149
|
+
.sheet.show { transform: translate(-50%, 0); }
|
|
150
|
+
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
|
|
151
|
+
.head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
|
|
152
|
+
.head h2 { margin: 0; font-size: 1.15em; font-weight: 400; }
|
|
153
|
+
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
|
|
154
|
+
.tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 14px 6px;
|
|
155
|
+
border-radius: 18px; background: var(--surface-2); border: 1px solid var(--line); cursor: pointer; text-decoration: none; color: inherit; }
|
|
156
|
+
.tile .emoji { font-size: 1.9em; line-height: 1; }
|
|
157
|
+
.tile:active { transform: scale(0.96); }
|
|
158
|
+
.tile:disabled { opacity: 0.35; cursor: default; }
|
|
159
|
+
.hint { color: var(--muted); font-size: 0.85em; margin: 10px 2px 0; min-height: 1.2em; }
|
|
160
|
+
|
|
161
|
+
.panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100%); background: var(--surface);
|
|
162
|
+
border-left: 1px solid var(--line); transform: translateX(105%); transition: transform 0.25s ease; z-index: 11;
|
|
163
|
+
padding: max(16px, env(safe-area-inset-top)) 18px 18px; overflow-y: auto; }
|
|
164
|
+
.panel.show { transform: none; }
|
|
165
|
+
.panel h3 { margin: 22px 0 8px; font-size: 0.78em; font-weight: 400; color: var(--muted); text-transform: uppercase; letter-spacing: 1.2px; }
|
|
166
|
+
.rows { border-radius: 18px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
|
|
167
|
+
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 14px;
|
|
168
|
+
border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
|
|
169
|
+
.row:last-child { border-bottom: none; }
|
|
170
|
+
.row .v { color: var(--muted); text-align: right; }
|
|
171
|
+
a.row { cursor: pointer; }
|
|
172
|
+
.row.soon { opacity: 0.45; }
|
|
173
|
+
button.row { width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); font: inherit; text-align: left; cursor: pointer; }
|
|
174
|
+
button.row:disabled { opacity: 0.45; cursor: default; }
|
|
175
|
+
.log { white-space: pre-wrap; max-height: 30vh; overflow-y: auto; font-size: 0.75em; }
|
|
176
|
+
.row input[type=range] { width: 150px; accent-color: var(--primary); }
|
|
177
|
+
.feet { display: inline-flex; gap: 5px; }
|
|
178
|
+
.feet i { width: 10px; height: 10px; border-radius: 50%; background: #7d6c95; }
|
|
179
|
+
.feet i.on { background: var(--ok); }
|
|
180
|
+
|
|
181
|
+
.media { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
|
|
182
|
+
.media button { padding: 0; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; aspect-ratio: 4 / 3;
|
|
183
|
+
background: var(--surface-2); cursor: pointer; }
|
|
184
|
+
.media img { width: 100%; height: 100%; object-fit: cover; display: block; }
|
|
185
|
+
.media .tile { aspect-ratio: 4 / 3; padding: 8px; font-size: 0.75em; text-align: center; word-break: break-all; }
|
|
186
|
+
.empty-note { color: var(--muted); }
|
|
187
|
+
|
|
188
|
+
.modal { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(0.96); width: min(360px, 90%);
|
|
189
|
+
background: var(--surface); border: 1px solid var(--line); border-radius: 26px; padding: 22px; z-index: 12;
|
|
190
|
+
opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; text-align: center; }
|
|
191
|
+
.modal.show { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
|
|
192
|
+
.modal p { color: var(--muted); margin: 6px 0 18px; }
|
|
193
|
+
/* Motherboard top view, in KiCad's coordinates [mm]: the servo connector of an assembly step */
|
|
194
|
+
.board { width: 100%; margin: -6px 0 14px; }
|
|
195
|
+
.board .conn rect { fill: none; stroke: none; }
|
|
196
|
+
.board .conn.on rect { fill: var(--pink); fill-opacity: 0.3; stroke: var(--pink); stroke-width: 0.7;
|
|
197
|
+
animation: conn-pulse 1.2s ease-in-out infinite alternate; }
|
|
198
|
+
@keyframes conn-pulse { to { fill-opacity: 0.05; } }
|
|
199
|
+
@media (prefers-reduced-motion: reduce) { .board .conn.on rect { animation: none; } }
|
|
200
|
+
.stack { display: flex; flex-direction: column; gap: 10px; }
|
|
201
|
+
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 13px; border-radius: 16px;
|
|
202
|
+
border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; color: inherit; text-decoration: none; }
|
|
203
|
+
.btn.danger { background: var(--bad-fill); border-color: transparent; color: #fff; }
|
|
204
|
+
.btn.ghost { background: none; color: var(--muted); }
|
|
205
|
+
.btn.dev { background: #2ad4c4; border-color: transparent; color: var(--bg); }
|
|
206
|
+
.btn.small { padding: 6px 14px; min-height: 36px; }
|
|
207
|
+
.row .group { display: flex; align-items: center; gap: 10px; }
|
|
208
|
+
.viewer { position: fixed; inset: 0; z-index: 13; background: rgba(0, 0, 0, 0.92); display: flex; flex-direction: column;
|
|
209
|
+
align-items: center; justify-content: center; gap: 14px; padding: 16px; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
|
|
210
|
+
.viewer.show { opacity: 1; pointer-events: auto; }
|
|
211
|
+
.viewer img { max-width: 100%; max-height: calc(100% - 80px); border-radius: 16px; }
|
|
212
|
+
.viewer .row-btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
|
|
213
|
+
.viewer p { color: #fff; margin: 0; }
|
|
214
|
+
.gate { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 19; padding: 24px; }
|
|
215
|
+
.gate form { width: min(340px, 100%); display: flex; flex-direction: column; gap: 12px; text-align: center; }
|
|
216
|
+
.gate h2 { font-weight: 400; margin: 6px 0 0; }
|
|
217
|
+
.gate p { color: var(--muted); margin: 0; }
|
|
218
|
+
.gate input { min-height: 44px; padding: 10px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
|
|
219
|
+
color: var(--text); font: inherit; font-size: 1.1em; text-align: center; letter-spacing: 2px; -webkit-user-select: text; user-select: text; }
|
|
220
|
+
.gate .error { color: var(--bad); min-height: 1.2em; }
|
|
221
|
+
.goodbye { position: fixed; inset: 0; display: none; place-items: center; text-align: center; background: var(--bg); z-index: 20; padding: 24px; }
|
|
222
|
+
.goodbye.show { display: grid; }
|
|
223
|
+
|
|
224
|
+
/* ---------- Portrait phone ---------- */
|
|
225
|
+
@media (orientation: portrait) {
|
|
226
|
+
:root { --stick: min(150px, 40vw); }
|
|
227
|
+
.side .buttons .round { --round: min(52px, 12.5vw); }
|
|
228
|
+
.top { flex-wrap: wrap; }
|
|
229
|
+
#b-power { order: 0; } .brand { order: 1; flex: 1; justify-content: center; } #b-settings { order: 2; }
|
|
230
|
+
.brand img { width: 48px; height: 48px; } .brand span { display: none; }
|
|
231
|
+
.chips { order: 3; flex-basis: 100%; }
|
|
232
|
+
.stage { height: auto; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-content: start; row-gap: 20px;
|
|
233
|
+
grid-template-rows: auto auto auto; grid-template-areas: "video video" "quick quick" "left right"; }
|
|
234
|
+
.quick { grid-area: quick; margin: 0; justify-self: stretch; max-width: none; padding: 2px 14px; gap: 0;
|
|
235
|
+
background: var(--surface); backdrop-filter: none; }
|
|
236
|
+
.q { grid-template-columns: 4.6em minmax(0, 1fr) 4.2em; }
|
|
237
|
+
body { overflow-y: auto; }
|
|
238
|
+
.video { aspect-ratio: 4 / 3; }
|
|
239
|
+
.side { justify-content: flex-start; gap: 20px; }
|
|
240
|
+
.side .buttons { flex-direction: row; gap: 8px; }
|
|
241
|
+
.stick-wrap { flex-direction: column-reverse; }
|
|
242
|
+
}
|
|
243
|
+
@media (orientation: landscape) and (max-height: 500px) {
|
|
244
|
+
:root { --stick: min(130px, 34vh); --round: 46px; }
|
|
245
|
+
.top { padding-top: 6px; padding-bottom: 6px; }
|
|
246
|
+
.stage { height: calc(100dvh - 52px); }
|
|
247
|
+
.side .buttons { gap: 8px; }
|
|
248
|
+
.chip { padding: 4px 10px; }
|
|
249
|
+
}
|
|
250
|
+
</style>
|
|
251
|
+
</head>
|
|
252
|
+
<body>
|
|
253
|
+
<!-- Icons: Feather (feathericons.com, MIT license) -->
|
|
254
|
+
<svg width="0" height="0" style="position:absolute" aria-hidden="true">
|
|
255
|
+
<symbol id="i-gear" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></symbol>
|
|
256
|
+
<symbol id="i-power" viewBox="0 0 24 24"><path d="M18.36 6.64a9 9 0 1 1-12.73 0"/><line x1="12" y1="2" x2="12" y2="12"/></symbol>
|
|
257
|
+
<symbol id="i-mic" viewBox="0 0 24 24"><path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"/><path d="M19 10v2a7 7 0 0 1-14 0v-2"/><line x1="12" y1="19" x2="12" y2="23"/><line x1="8" y1="23" x2="16" y2="23"/></symbol>
|
|
258
|
+
<symbol id="i-smile" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><path d="M8 14s1.5 2 4 2 4-2 4-2"/><line x1="9" y1="9" x2="9.01" y2="9"/><line x1="15" y1="9" x2="15.01" y2="9"/></symbol>
|
|
259
|
+
<symbol id="i-camera" viewBox="0 0 24 24"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"/><circle cx="12" cy="13" r="4"/></symbol>
|
|
260
|
+
<symbol id="i-zap" viewBox="0 0 24 24"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></symbol>
|
|
261
|
+
<symbol id="i-menu" viewBox="0 0 24 24"><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="18" x2="21" y2="18"/></symbol>
|
|
262
|
+
<symbol id="i-image" viewBox="0 0 24 24"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></symbol>
|
|
263
|
+
<symbol id="i-film" viewBox="0 0 24 24"><rect x="2" y="2" width="20" height="20" rx="2.18" ry="2.18"/><line x1="7" y1="2" x2="7" y2="22"/><line x1="17" y1="2" x2="17" y2="22"/><line x1="2" y1="12" x2="22" y2="12"/><line x1="2" y1="7" x2="7" y2="7"/><line x1="2" y1="17" x2="7" y2="17"/><line x1="17" y1="17" x2="22" y2="17"/><line x1="17" y1="7" x2="22" y2="7"/></symbol>
|
|
264
|
+
<symbol id="i-battery" viewBox="0 0 24 24"><rect x="1" y="6" width="18" height="12" rx="2" ry="2"/><line x1="23" y1="13" x2="23" y2="11"/></symbol>
|
|
265
|
+
<symbol id="i-thermo" viewBox="0 0 24 24"><path d="M14 14.76V3.5a2.5 2.5 0 0 0-5 0v11.26a4.5 4.5 0 1 0 5 0z"/></symbol>
|
|
266
|
+
<symbol id="i-eye" viewBox="0 0 24 24"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></symbol>
|
|
267
|
+
<symbol id="i-headphones" viewBox="0 0 24 24"><path d="M3 18v-6a9 9 0 0 1 18 0v6"/><path d="M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z"/></symbol>
|
|
268
|
+
<symbol id="i-bluetooth" viewBox="0 0 24 24"><polyline points="6.5 6.5 17.5 17.5 12 23 12 1 17.5 6.5 6.5 17.5"/></symbol>
|
|
269
|
+
<symbol id="i-x" viewBox="0 0 24 24"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></symbol>
|
|
270
|
+
<symbol id="i-restart" viewBox="0 0 24 24"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></symbol>
|
|
271
|
+
<symbol id="i-trash" viewBox="0 0 24 24"><polyline points="3 6 5 6 21 6"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/><path d="M10 11v6M14 11v6M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/></symbol>
|
|
272
|
+
<symbol id="i-download" viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></symbol>
|
|
273
|
+
</svg>
|
|
274
|
+
|
|
275
|
+
<header class="top">
|
|
276
|
+
<div class="brand"><img src="/static/logo.png" alt="Chromapi"><span>Chromapi</span></div>
|
|
277
|
+
<div class="chips">
|
|
278
|
+
<button class="chip chip-btn" id="chip-batt" title="Battery">
|
|
279
|
+
<svg class="i" viewBox="0 0 24 24"><use href="#i-battery"/><rect id="batt-fill" x="3" y="8" width="0" height="8" rx="1" fill="currentColor" stroke="none"/></svg>
|
|
280
|
+
<span id="batt">--</span></button>
|
|
281
|
+
<span class="chip" id="chip-temp" title="Raspberry Pi temperature"><svg class="i"><use href="#i-thermo"/></svg><span id="temp">--</span></span>
|
|
282
|
+
<span class="chip" id="chip-link"><i class="dot"></i><svg class="i"><use href="#i-bluetooth"/></svg><span id="link">Offline</span></span>
|
|
283
|
+
<span class="chip" id="chip-role" hidden title="Another page drives the robot: you see the camera and its state">Watching</span>
|
|
284
|
+
<span class="chip" id="chip-viewers" hidden title="The camera is on: people watching it"><svg class="i"><use href="#i-eye"/></svg><span id="viewers">0</span></span>
|
|
285
|
+
</div>
|
|
286
|
+
<button class="round small" id="b-settings" aria-label="Settings"><svg class="i"><use href="#i-gear"/></svg></button>
|
|
287
|
+
<button class="round small danger" id="b-power" aria-label="Power"><svg class="i"><use href="#i-power"/></svg></button>
|
|
288
|
+
</header>
|
|
289
|
+
|
|
290
|
+
<main class="stage">
|
|
291
|
+
<div class="side" id="side-l">
|
|
292
|
+
<div class="buttons">
|
|
293
|
+
<button class="round" id="b-photo" aria-label="Take a photo"><svg class="i"><use href="#i-camera"/></svg></button>
|
|
294
|
+
<button class="round rec" id="b-rec" aria-label="Record a video"><span class="rec-dot"></span></button>
|
|
295
|
+
<button class="round torch" id="b-torch" aria-label="Flash light"><svg class="i"><use href="#i-zap"/></svg></button>
|
|
296
|
+
</div>
|
|
297
|
+
<div class="stick-wrap"><span class="lbl" id="lbl-l">Walk</span><div class="stick" id="stick-l"><div class="knob"></div></div></div>
|
|
298
|
+
</div>
|
|
299
|
+
|
|
300
|
+
<div class="video">
|
|
301
|
+
<img id="cam" alt="Chromapi's camera">
|
|
302
|
+
<div class="off" id="cam-off" hidden>No camera</div>
|
|
303
|
+
<div class="diag" id="diag" hidden>
|
|
304
|
+
<span>Link</span><b id="o-link">--</b>
|
|
305
|
+
<span>Battery</span><b id="o-batt">--</b>
|
|
306
|
+
<span>Servos</span><b id="o-servos">--</b>
|
|
307
|
+
<span>Hottest</span><b id="o-stemp">--</b>
|
|
308
|
+
<span>Pi</span><b id="o-cpu">--</b>
|
|
309
|
+
<span>Tilt</span><b id="o-tilt">--</b>
|
|
310
|
+
<span>Feet</span><b class="feet"><i id="o-f-tl"></i><i id="o-f-tr"></i><i id="o-f-bl"></i><i id="o-f-br"></i></b>
|
|
311
|
+
</div>
|
|
312
|
+
<div class="rec-badge" id="rec-badge">REC</div>
|
|
313
|
+
<div class="toast" id="toast"></div>
|
|
314
|
+
<div class="talkie" aria-label="Talkie-walkie">
|
|
315
|
+
<button class="round small" id="b-mic" title="Hold to talk through Chromapi" aria-label="Hold to talk through Chromapi"><svg class="i"><use href="#i-mic"/></svg></button>
|
|
316
|
+
<button class="round small" id="b-listen" title="Listen around Chromapi (its ring shows it)" aria-label="Listen through Chromapi" aria-pressed="false"><svg class="i"><use href="#i-headphones"/></svg></button>
|
|
317
|
+
</div>
|
|
318
|
+
<button class="pill" id="b-awake">Wake up</button>
|
|
319
|
+
</div>
|
|
320
|
+
<div class="quick">
|
|
321
|
+
<label class="q"><span class="lbl">Speed</span><input type="range" id="s-speed" min="0.25" max="1" step="0.05" value="1"><span id="s-speed-v" class="v">100%</span></label>
|
|
322
|
+
<label class="q"><span class="lbl">Height</span><input type="range" id="s-height" min="-40" max="20" step="2" value="0"><span id="s-height-v" class="v">+0 mm</span></label>
|
|
323
|
+
</div>
|
|
324
|
+
|
|
325
|
+
<div class="side" id="side-r">
|
|
326
|
+
<div class="buttons">
|
|
327
|
+
<button class="round" id="b-emotes" aria-label="Emotes"><svg class="i"><use href="#i-smile"/></svg></button>
|
|
328
|
+
<button class="round" id="b-menu" aria-label="Menu"><svg class="i"><use href="#i-menu"/></svg></button>
|
|
329
|
+
</div>
|
|
330
|
+
<div class="stick-wrap"><span class="lbl" id="lbl-r">Turn</span><div class="stick" id="stick-r"><div class="knob"></div></div></div>
|
|
331
|
+
</div>
|
|
332
|
+
|
|
333
|
+
</main>
|
|
334
|
+
|
|
335
|
+
<div class="scrim" id="scrim"></div>
|
|
336
|
+
|
|
337
|
+
<section class="sheet" id="sheet-emotes" aria-label="Emotes">
|
|
338
|
+
<div class="grab"></div>
|
|
339
|
+
<div class="head"><h2>Emotes</h2>
|
|
340
|
+
<button class="round small" data-close aria-label="Close"><svg class="i"><use href="#i-x"/></svg></button></div>
|
|
341
|
+
<h3>Moves</h3>
|
|
342
|
+
<div class="grid">
|
|
343
|
+
<button class="tile" data-emote="greet"><span class="emoji">👋</span>Greet</button>
|
|
344
|
+
<button class="tile" data-emote="kick_left"><span class="emoji">🦵</span>Kick left</button>
|
|
345
|
+
<button class="tile" data-emote="kick_right"><span class="emoji">🦵</span>Kick right</button>
|
|
346
|
+
</div>
|
|
347
|
+
<p class="hint" id="emote-hint"></p>
|
|
348
|
+
<h3>Moods</h3>
|
|
349
|
+
<div class="grid" id="moods" style="max-height: 40vh; overflow-y: auto"></div>
|
|
350
|
+
</section>
|
|
351
|
+
|
|
352
|
+
<section class="sheet" id="sheet-menu" aria-label="Menu">
|
|
353
|
+
<div class="grab"></div>
|
|
354
|
+
<div class="head"><h2>Menu</h2>
|
|
355
|
+
<button class="round small" data-close aria-label="Close"><svg class="i"><use href="#i-x"/></svg></button></div>
|
|
356
|
+
<div class="ctl">Mode <span class="seg"><button data-mode="turn">Turn</button><button data-mode="lean">Lean</button></span></div>
|
|
357
|
+
<div class="ctl">Diagnostics on the video <span class="seg"><button id="b-diag">Show</button></span></div>
|
|
358
|
+
<div class="ctl">Gait <span class="seg"><button data-gait="trot">Trot</button><button data-gait="crawl">Crawl</button></span></div>
|
|
359
|
+
<label class="ctl" id="ring-row">Ring <span class="group"><span class="seg"><button id="b-ring-idle">Idle</button><button id="b-ring-rainbow">Rainbow</button></span> <input type="range" id="s-ring" min="0" max="359" step="1" value="283" aria-label="Ring colour (hue)"></span></label>
|
|
360
|
+
<label class="ctl" id="fan-row" hidden>Fan <span class="group"><span class="seg"><button id="b-fan-auto">Auto</button></span> <input type="range" id="s-fan" min="0" max="100" step="5" value="100"> <span id="s-fan-v" class="v">100%</span></span></label>
|
|
361
|
+
<div class="stack" style="margin-top: 8px"><button class="btn" id="b-gallery"><svg class="i"><use href="#i-image"/></svg>Gallery</button></div>
|
|
362
|
+
</section>
|
|
363
|
+
|
|
364
|
+
<section class="panel" id="panel-gallery" aria-label="Gallery">
|
|
365
|
+
<div class="head"><h2>Gallery</h2>
|
|
366
|
+
<button class="round small" data-close aria-label="Close"><svg class="i"><use href="#i-x"/></svg></button></div>
|
|
367
|
+
<h3>Photos</h3><div class="media" id="g-photos"></div>
|
|
368
|
+
<h3>Videos</h3><div class="media" id="g-videos"></div>
|
|
369
|
+
</section>
|
|
370
|
+
|
|
371
|
+
<section class="panel" id="panel-settings" aria-label="Settings">
|
|
372
|
+
<div class="head"><h2>Settings</h2>
|
|
373
|
+
<button class="round small" data-close aria-label="Close"><svg class="i"><use href="#i-x"/></svg></button></div>
|
|
374
|
+
|
|
375
|
+
<h3>Maintenance</h3>
|
|
376
|
+
<div class="rows">
|
|
377
|
+
<a class="row" href="/report" download>Support report <svg class="i"><use href="#i-download"/></svg></a>
|
|
378
|
+
<button class="row" data-maint="update_firmware">Update the firmware <span class="v" id="m-update_firmware"></span></button>
|
|
379
|
+
<button class="row" data-maint="calibrate_servos">Calibrate the servos <span class="v" id="m-calibrate_servos"></span></button>
|
|
380
|
+
<button class="row" data-maint="calibrate_imu">Calibrate the IMU <span class="v" id="m-calibrate_imu"></span></button>
|
|
381
|
+
<button class="row" data-maint="assembly">Set up new servos <span class="v" id="m-assembly"></span></button>
|
|
382
|
+
</div>
|
|
383
|
+
<p class="hint" id="maint-hint"></p>
|
|
384
|
+
<button class="btn danger" id="maint-cancel" hidden>Cancel</button>
|
|
385
|
+
<pre class="hint log" id="maint-log" hidden></pre>
|
|
386
|
+
|
|
387
|
+
<h3>Controller</h3>
|
|
388
|
+
<div class="rows">
|
|
389
|
+
<div class="row">Gamepad <span class="v" id="d-gamepad">--</span></div>
|
|
390
|
+
<div class="row">Lean with the controller's tilt <span class="seg"><button id="b-pad-tilt">Off</button></span></div>
|
|
391
|
+
<button class="row" data-maint="pair_gamepad">Pair a controller <span class="v" id="m-pair_gamepad"></span></button>
|
|
392
|
+
</div>
|
|
393
|
+
|
|
394
|
+
<h3>Access</h3>
|
|
395
|
+
<div class="rows">
|
|
396
|
+
<button class="row" id="b-change-code">Change the access code <span class="v">signs out other devices</span></button>
|
|
397
|
+
</div>
|
|
398
|
+
|
|
399
|
+
<h3>Diagnostics</h3>
|
|
400
|
+
<div class="rows">
|
|
401
|
+
<div class="row">Motherboard <span class="v" id="d-link">--</span></div>
|
|
402
|
+
<div class="row">Battery <span class="v" id="d-batt">--</span></div>
|
|
403
|
+
<div class="row">Servos <span class="v" id="d-servos">--</span></div>
|
|
404
|
+
<div class="row">Hottest servo <span class="v" id="d-stemp">--</span></div>
|
|
405
|
+
<div class="row">Raspberry Pi <span class="v" id="d-cpu">--</span></div>
|
|
406
|
+
<div class="row">Tilt <span class="v" id="d-tilt">--</span></div>
|
|
407
|
+
<div class="row">Feet on the ground <span class="feet"><i id="f-tl"></i><i id="f-tr"></i><i id="f-bl"></i><i id="f-br"></i></span></div>
|
|
408
|
+
</div>
|
|
409
|
+
|
|
410
|
+
<h3>About</h3>
|
|
411
|
+
<div class="rows">
|
|
412
|
+
<div class="row">Name <span class="group"><span class="v" id="v-host">--</span><button class="btn small" id="b-identify">Identify</button></span></div>
|
|
413
|
+
<div class="row">SDK <span class="v" id="v-sdk">--</span></div>
|
|
414
|
+
<div class="row">Firmware <span class="v" id="v-fw">--</span></div>
|
|
415
|
+
</div>
|
|
416
|
+
</section>
|
|
417
|
+
|
|
418
|
+
<div class="modal" id="modal-maint" role="dialog" aria-label="Maintenance">
|
|
419
|
+
<h2 style="margin:0;font-weight:400" id="maint-title"></h2>
|
|
420
|
+
<p id="maint-text"></p>
|
|
421
|
+
<!-- pcbdraw render (600 dpi, 1000 px wide), placed with the mounting holes; connectors J5-J8 -->
|
|
422
|
+
<svg class="board" id="maint-board" viewBox="104 70.2 88.2 59.4" hidden aria-hidden="true">
|
|
423
|
+
<image href="/static/motherboard_front.png" x="103.06" y="69.21" width="90.13" height="61.38"/>
|
|
424
|
+
<g class="conn" data-conn="tr"><rect x="127.26" y="112.19" width="11.1" height="6.1" rx="0.8"/></g>
|
|
425
|
+
<g class="conn" data-conn="br"><rect x="138.25" y="112.19" width="11.1" height="6.1" rx="0.8"/></g>
|
|
426
|
+
<g class="conn" data-conn="tl"><rect x="127.26" y="118.18" width="11.1" height="6.1" rx="0.8"/></g>
|
|
427
|
+
<g class="conn" data-conn="bl"><rect x="138.25" y="118.18" width="11.1" height="6.1" rx="0.8"/></g>
|
|
428
|
+
</svg>
|
|
429
|
+
<div class="stack">
|
|
430
|
+
<button class="btn" id="maint-go">Start</button>
|
|
431
|
+
<button class="btn ghost" data-close>Cancel</button>
|
|
432
|
+
</div>
|
|
433
|
+
</div>
|
|
434
|
+
|
|
435
|
+
<div class="modal" id="modal-run" role="dialog" aria-label="Maintenance running">
|
|
436
|
+
<h2 style="margin:0;font-weight:400" id="run-title"></h2>
|
|
437
|
+
<p id="run-text"></p>
|
|
438
|
+
<div class="stack">
|
|
439
|
+
<button class="btn danger" id="run-cancel">Cancel</button>
|
|
440
|
+
<button class="btn ghost" data-close data-autofocus>Hide</button>
|
|
441
|
+
</div>
|
|
442
|
+
</div>
|
|
443
|
+
|
|
444
|
+
<div class="modal" id="modal-power" role="dialog" aria-label="Power">
|
|
445
|
+
<h2 style="margin:0;font-weight:400">Power</h2>
|
|
446
|
+
<p>Chromapi lies down first.</p>
|
|
447
|
+
<div class="stack">
|
|
448
|
+
<button class="btn" data-confirm="reboot"><svg class="i"><use href="#i-restart"/></svg>Restart</button>
|
|
449
|
+
<button class="btn danger" data-confirm="shutdown"><svg class="i"><use href="#i-power"/></svg>Power off</button>
|
|
450
|
+
<button class="btn dev" id="b-dev">Developer mode</button>
|
|
451
|
+
<button class="btn ghost" data-close data-autofocus>Cancel</button>
|
|
452
|
+
</div>
|
|
453
|
+
</div>
|
|
454
|
+
|
|
455
|
+
<div class="modal" id="modal-confirm" role="dialog" aria-labelledby="confirm-title">
|
|
456
|
+
<h2 style="margin:0;font-weight:400" id="confirm-title"></h2>
|
|
457
|
+
<p id="confirm-text"></p>
|
|
458
|
+
<div class="stack">
|
|
459
|
+
<button class="btn danger" id="confirm-go" data-power=""></button>
|
|
460
|
+
<button class="btn ghost" data-close data-autofocus>Cancel</button>
|
|
461
|
+
</div>
|
|
462
|
+
</div>
|
|
463
|
+
|
|
464
|
+
<div class="modal" id="modal-dev" role="dialog" aria-label="Developer mode">
|
|
465
|
+
<h2 style="margin:0;font-weight:400">Developer mode</h2>
|
|
466
|
+
<p>Chromapi lies down and the app stops, until it is switched off and on again. This page will no longer
|
|
467
|
+
answer: you can control Chromapi over SSH.</p>
|
|
468
|
+
<p style="color:var(--muted)">To restart the app without switching off, use: <code>sudo systemctl start chromapi@$USER</code></p>
|
|
469
|
+
<div class="stack">
|
|
470
|
+
<button class="btn danger" data-power="quit">Stop the app</button>
|
|
471
|
+
<button class="btn ghost" data-close data-autofocus>Cancel</button>
|
|
472
|
+
</div>
|
|
473
|
+
</div>
|
|
474
|
+
|
|
475
|
+
<div class="viewer" id="viewer">
|
|
476
|
+
<img id="viewer-img" alt="">
|
|
477
|
+
<p id="viewer-name"></p>
|
|
478
|
+
<div class="row-btns">
|
|
479
|
+
<button class="btn" id="viewer-dl"><svg class="i"><use href="#i-download"/></svg>Save</button>
|
|
480
|
+
<button class="btn danger" id="viewer-del"><svg class="i"><use href="#i-trash"/></svg>Delete</button>
|
|
481
|
+
<button class="btn ghost" id="viewer-close">Close</button>
|
|
482
|
+
</div>
|
|
483
|
+
</div>
|
|
484
|
+
|
|
485
|
+
<div class="gate" id="gate" hidden>
|
|
486
|
+
<form id="gate-form" novalidate>
|
|
487
|
+
<img src="/static/logo.png" alt="" width="72" style="align-self:center">
|
|
488
|
+
<h2 id="gate-title">Access code</h2>
|
|
489
|
+
<p id="gate-text"></p>
|
|
490
|
+
<input type="password" id="gate-current" aria-label="Current access code" placeholder="Current code" autocomplete="current-password">
|
|
491
|
+
<input type="password" id="gate-code" aria-label="Access code" autocomplete="current-password">
|
|
492
|
+
<input type="password" id="gate-confirm" aria-label="Access code, again" placeholder="Again" autocomplete="new-password">
|
|
493
|
+
<button class="btn" type="submit" id="gate-go">Continue</button>
|
|
494
|
+
<button class="btn ghost" type="button" id="gate-cancel">Cancel</button>
|
|
495
|
+
<p class="error" id="gate-error" role="alert"></p>
|
|
496
|
+
</form>
|
|
497
|
+
</div>
|
|
498
|
+
|
|
499
|
+
<div class="goodbye" id="goodbye"><div><img src="/static/logo.png" alt="" width="72"><h2 style="font-weight:400" id="goodbye-text">Powering off…</h2>
|
|
500
|
+
<p style="color:var(--muted)" id="goodbye-hint">You can close this page.</p></div></div>
|
|
501
|
+
|
|
502
|
+
<script>
|
|
503
|
+
const socket = io({autoConnect: false}); // connected by checkAccess
|
|
504
|
+
const $ = id => document.getElementById(id);
|
|
505
|
+
const axes = {lx: 0, ly: 0, rx: 0, ry: 0};
|
|
506
|
+
let state = {}, lastStatus = '', updateToasted = false;
|
|
507
|
+
|
|
508
|
+
// ---------- Overlays (one open at a time) ----------
|
|
509
|
+
// Closed overlays stay in the DOM: inert keeps the focus out
|
|
510
|
+
let open = null, opener = null;
|
|
511
|
+
const OVERLAYS = '.sheet, .panel, .modal, .viewer';
|
|
512
|
+
document.querySelectorAll(OVERLAYS).forEach(el => { el.inert = true; });
|
|
513
|
+
function show(el) {
|
|
514
|
+
hide(); open = el; opener = document.activeElement;
|
|
515
|
+
el.inert = false; el.classList.add('show'); $('scrim').classList.add('show');
|
|
516
|
+
const first = el.querySelector('[data-autofocus]') || el.querySelector('button:not([disabled]):not([hidden]), a[href], input');
|
|
517
|
+
if (first) first.focus({preventScroll: true});
|
|
518
|
+
}
|
|
519
|
+
function hide() {
|
|
520
|
+
if (open) { open.classList.remove('show'); open.inert = true; }
|
|
521
|
+
open = null; $('scrim').classList.remove('show');
|
|
522
|
+
if (opener && document.contains(opener)) opener.focus({preventScroll: true});
|
|
523
|
+
opener = null;
|
|
524
|
+
}
|
|
525
|
+
const showViewer = on => { $('viewer').classList.toggle('show', on); $('viewer').inert = !on; };
|
|
526
|
+
$('scrim').addEventListener('click', hide);
|
|
527
|
+
document.querySelectorAll('[data-close]').forEach(b => b.addEventListener('click', hide));
|
|
528
|
+
$('b-emotes').addEventListener('click', () => show($('sheet-emotes')));
|
|
529
|
+
$('b-settings').addEventListener('click', () => show($('panel-settings')));
|
|
530
|
+
$('b-power').addEventListener('click', () => show($('modal-power')));
|
|
531
|
+
$('b-dev').addEventListener('click', () => show($('modal-dev')));
|
|
532
|
+
$('b-identify').addEventListener('click', () => action('identify'));
|
|
533
|
+
// Restart and Power off ask again: [title, text, button]
|
|
534
|
+
const CONFIRM = {
|
|
535
|
+
reboot: ['Restart?', 'Chromapi lies down, then restarts. This page reconnects in about a minute.', 'Restart'],
|
|
536
|
+
shutdown: ['Power off?', 'Chromapi lies down, then switches off. To use it again, switch it on at its power switch.', 'Power off'],
|
|
537
|
+
};
|
|
538
|
+
document.querySelectorAll('[data-confirm]').forEach(b => b.addEventListener('click', () => {
|
|
539
|
+
const [title, text, go] = CONFIRM[b.dataset.confirm];
|
|
540
|
+
$('confirm-title').textContent = title; $('confirm-text').textContent = text;
|
|
541
|
+
$('confirm-go').textContent = go; $('confirm-go').dataset.power = b.dataset.confirm;
|
|
542
|
+
show($('modal-confirm'));
|
|
543
|
+
}));
|
|
544
|
+
$('b-menu').addEventListener('click', () => show($('sheet-menu')));
|
|
545
|
+
$('b-gallery').addEventListener('click', () => { loadGallery(); show($('panel-gallery')); });
|
|
546
|
+
|
|
547
|
+
let toastTimer = null;
|
|
548
|
+
function toast(text) {
|
|
549
|
+
$('toast').textContent = text; $('toast').classList.add('show');
|
|
550
|
+
clearTimeout(toastTimer); toastTimer = setTimeout(() => $('toast').classList.remove('show'), 3000);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// ---------- Joysticks (pointer events: touch and mouse) ----------
|
|
554
|
+
function makeStick(el, kx, ky) {
|
|
555
|
+
const knob = el.querySelector('.knob');
|
|
556
|
+
let pid = null;
|
|
557
|
+
function update(e) {
|
|
558
|
+
const r = el.getBoundingClientRect(), R = r.width / 2;
|
|
559
|
+
let dx = e.clientX - (r.left + R), dy = e.clientY - (r.top + R);
|
|
560
|
+
const d = Math.hypot(dx, dy);
|
|
561
|
+
if (d > R) { dx *= R / d; dy *= R / d; }
|
|
562
|
+
knob.style.transform = `translate(calc(-50% + ${dx}px), calc(-50% + ${dy}px))`;
|
|
563
|
+
axes[kx] = dx / R;
|
|
564
|
+
if (ky) axes[ky] = -dy / R; // y up-positive
|
|
565
|
+
}
|
|
566
|
+
function reset() { pid = null; knob.style.transform = ''; axes[kx] = 0; if (ky) axes[ky] = 0; }
|
|
567
|
+
el.addEventListener('pointerdown', e => { pid = e.pointerId; el.setPointerCapture(pid); update(e); });
|
|
568
|
+
el.addEventListener('pointermove', e => { if (e.pointerId === pid) update(e); });
|
|
569
|
+
el.addEventListener('pointerup', e => { if (e.pointerId === pid) reset(); });
|
|
570
|
+
el.addEventListener('pointercancel', e => { if (e.pointerId === pid) reset(); });
|
|
571
|
+
}
|
|
572
|
+
makeStick($('stick-l'), 'lx', 'ly');
|
|
573
|
+
makeStick($('stick-r'), 'rx', 'ry');
|
|
574
|
+
|
|
575
|
+
// Keyboard: WASD (physical keys) to walk, arrows to turn or lean, Enter to wake up
|
|
576
|
+
const keys = new Set();
|
|
577
|
+
const KEYMAP = {KeyW: ['ly', 1], KeyS: ['ly', -1], KeyA: ['lx', -1], KeyD: ['lx', 1],
|
|
578
|
+
ArrowLeft: ['rx', -1], ArrowRight: ['rx', 1], ArrowUp: ['ry', 1], ArrowDown: ['ry', -1]};
|
|
579
|
+
document.addEventListener('keydown', e => {
|
|
580
|
+
if (e.target.tagName === 'INPUT') return;
|
|
581
|
+
if (e.code === 'Escape') { hide(); showViewer(false); return; }
|
|
582
|
+
if (e.code === 'Enter' && !e.repeat && !open && document.activeElement === document.body) {
|
|
583
|
+
$('b-awake').click(); e.preventDefault(); return;
|
|
584
|
+
}
|
|
585
|
+
if (KEYMAP[e.code]) { keys.add(e.code); e.preventDefault(); }
|
|
586
|
+
});
|
|
587
|
+
document.addEventListener('keyup', e => keys.delete(e.code));
|
|
588
|
+
window.addEventListener('blur', () => keys.clear());
|
|
589
|
+
|
|
590
|
+
// Sticks at 20 Hz, also the deadman heartbeat
|
|
591
|
+
setInterval(() => {
|
|
592
|
+
if (!socket.connected || !pilot) return;
|
|
593
|
+
const out = {...axes};
|
|
594
|
+
keys.forEach(c => { const [a, v] = KEYMAP[c]; out[a] = Math.max(-1, Math.min(1, out[a] + v)); });
|
|
595
|
+
socket.volatile.emit('axes', out);
|
|
596
|
+
}, 50);
|
|
597
|
+
|
|
598
|
+
// ---------- Actions ----------
|
|
599
|
+
const action = name => socket.emit('action', {name});
|
|
600
|
+
$('b-awake').addEventListener('click', () => action(state.awake ? 'rest' : 'wake'));
|
|
601
|
+
document.querySelectorAll('[data-gait]').forEach(b => b.addEventListener('click', () => action(b.dataset.gait)));
|
|
602
|
+
document.querySelectorAll('[data-mode]').forEach(b => b.addEventListener('click', () => action(b.dataset.mode)));
|
|
603
|
+
$('b-torch').addEventListener('click', () => socket.emit('set_torch', {on: !state.torch}));
|
|
604
|
+
$('chip-batt').addEventListener('click', () => action('show_battery'));
|
|
605
|
+
let fanBusy = 0;
|
|
606
|
+
$('s-fan').addEventListener('input', e => {
|
|
607
|
+
fanBusy = Date.now() + 1500;
|
|
608
|
+
$('s-fan-v').textContent = e.target.value + '%';
|
|
609
|
+
socket.emit('set_fan', {percent: +e.target.value});
|
|
610
|
+
});
|
|
611
|
+
$('b-fan-auto').addEventListener('click', e => {
|
|
612
|
+
e.preventDefault(); // inside the label: do not focus the slider
|
|
613
|
+
socket.emit('set_fan', {auto: true});
|
|
614
|
+
});
|
|
615
|
+
// Ring colour, sent live
|
|
616
|
+
const RING_IDLE = '#b605fc';
|
|
617
|
+
let ringBusy = 0;
|
|
618
|
+
const hueRgb = h => [0, 8, 4].map(n => { const k = (n + h / 30) % 12; return Math.round(255 * (1 - Math.max(0, Math.min(k - 3, 9 - k, 1)))); });
|
|
619
|
+
const rgbHue = hex => {
|
|
620
|
+
const [r, g, b] = [1, 3, 5].map(i => parseInt(hex.slice(i, i + 2), 16)), mx = Math.max(r, g, b), d = mx - Math.min(r, g, b);
|
|
621
|
+
if (!d) return 0;
|
|
622
|
+
const h = mx === r ? (g - b) / d : mx === g ? 2 + (b - r) / d : 4 + (r - g) / d;
|
|
623
|
+
return Math.round((h * 60 + 360) % 360);
|
|
624
|
+
};
|
|
625
|
+
const showRing = hex => {
|
|
626
|
+
$('s-ring').style.setProperty('--ring', hex === 'rainbow' ? 'conic-gradient(#f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00)' : hex);
|
|
627
|
+
$('b-ring-idle').classList.toggle('active', hex === RING_IDLE);
|
|
628
|
+
$('b-ring-rainbow').classList.toggle('active', hex === 'rainbow');
|
|
629
|
+
};
|
|
630
|
+
$('s-ring').addEventListener('input', e => {
|
|
631
|
+
ringBusy = Date.now() + 1500;
|
|
632
|
+
const rgb = hueRgb(+e.target.value);
|
|
633
|
+
showRing('#' + rgb.map(c => c.toString(16).padStart(2, '0')).join(''));
|
|
634
|
+
socket.emit('set_ring_color', {rgb});
|
|
635
|
+
});
|
|
636
|
+
$('b-ring-idle').addEventListener('click', e => {
|
|
637
|
+
e.preventDefault(); // inside the label: do not focus the slider
|
|
638
|
+
ringBusy = 0;
|
|
639
|
+
socket.emit('set_ring_color', {});
|
|
640
|
+
});
|
|
641
|
+
$('b-ring-rainbow').addEventListener('click', e => {
|
|
642
|
+
e.preventDefault();
|
|
643
|
+
ringBusy = 0;
|
|
644
|
+
socket.emit('set_ring_color', {rainbow: true});
|
|
645
|
+
});
|
|
646
|
+
// New servos (ID 1): one job per servo, highest ID first
|
|
647
|
+
const servoSteps = []; // the setup_servo_<id> jobs, in order
|
|
648
|
+
let servoNext = 0;
|
|
649
|
+
const LEGS = {tl: 'front left', tr: 'front right', bl: 'back left', br: 'back right'}, PARTS = {1: 'coxa', 2: 'femur', 3: 'tibia'};
|
|
650
|
+
// Servo connector of each leg on the motherboard
|
|
651
|
+
const CONNS = {tl: 'TopLeft', tr: 'TopRight', bl: 'BotLeft', br: 'BotRight'};
|
|
652
|
+
const servoLeg = {}; // job -> leg
|
|
653
|
+
const loadServos = () => fetch('/servos').then(r => r.json()).then(d => d.servos.forEach((sv, k) => {
|
|
654
|
+
const [leg, part] = sv.joint.split('_'), job = 'setup_servo_' + sv.id, conn = CONNS[leg] || leg;
|
|
655
|
+
const newLeg = k > 0 && !d.servos[k - 1].joint.startsWith(leg + '_');
|
|
656
|
+
MAINT[job] = [`Servo ${k + 1}/${d.servos.length}: ${LEGS[leg] || leg} ${PARTS[part] || part} (ID ${sv.id})`,
|
|
657
|
+
(k === 0 ? `Chromapi off, plug only this new servo into the ${conn} connector, switch on, then start.`
|
|
658
|
+
: newLeg ? `New leg: plug this new servo into the ${conn} connector, keeping the other legs' servos plugged in, then start.`
|
|
659
|
+
: `Add this new servo to the chain on the ${conn} connector, keeping the ones already set up plugged in, then start.`)
|
|
660
|
+
+ ' One new servo at a time: two would end up with the same ID.'];
|
|
661
|
+
servoLeg[job] = leg;
|
|
662
|
+
servoSteps.push(job);
|
|
663
|
+
}));
|
|
664
|
+
const loadMoods = () => fetch('/moods').then(r => r.json()).then(d => d.moods.forEach(m => {
|
|
665
|
+
const b = document.createElement('button');
|
|
666
|
+
b.className = 'tile'; b.innerHTML = `<span class="emoji">${m.emoji}</span>${m.name}`;
|
|
667
|
+
b.addEventListener('click', () => { action('mood:' + m.name); hide(); });
|
|
668
|
+
$('moods').appendChild(b);
|
|
669
|
+
}));
|
|
670
|
+
document.querySelectorAll('[data-emote]').forEach(b => b.addEventListener('click', () => { action(b.dataset.emote); hide(); }));
|
|
671
|
+
const goodbye = power => {
|
|
672
|
+
hide();
|
|
673
|
+
$('goodbye-text').textContent = {reboot: 'Restarting…', shutdown: 'Powering off…', quit: 'Developer mode'}[power];
|
|
674
|
+
if (power === 'quit') {
|
|
675
|
+
$('goodbye-hint').textContent = 'The app is stopped until Chromapi restarts: its serial port is free for SSH. '
|
|
676
|
+
+ 'To start it again, use: sudo systemctl start chromapi@$USER';
|
|
677
|
+
}
|
|
678
|
+
$('goodbye').classList.add('show');
|
|
679
|
+
};
|
|
680
|
+
document.querySelectorAll('[data-power]').forEach(b => b.addEventListener('click', () => {
|
|
681
|
+
action(b.dataset.power);
|
|
682
|
+
goodbye(b.dataset.power);
|
|
683
|
+
}));
|
|
684
|
+
socket.on('goodbye', goodbye);
|
|
685
|
+
const MAINT = {
|
|
686
|
+
update_firmware: ['Update the firmware', 'Installs the firmware shipped with this app. The servos go limp: keep the robot lying down and switched on until it is done.'],
|
|
687
|
+
calibrate_servos: ['Calibrate the servos', 'Lift the robot so that no leg can touch anything: each joint sweeps its whole range, up to its mechanical stops. It takes a few minutes.'],
|
|
688
|
+
calibrate_imu: ['Calibrate the IMU', 'Put the robot on a level floor and do not touch it for 5 seconds.'],
|
|
689
|
+
pair_gamepad: ['Pair a controller', 'Hold the controller\'s pair button until its light flashes fast, then start. Once paired, it reconnects on its own.'],
|
|
690
|
+
};
|
|
691
|
+
let maintJob = null;
|
|
692
|
+
$('run-cancel').addEventListener('click', () => action('maintenance_cancel'));
|
|
693
|
+
$('maint-cancel').addEventListener('click', () => action('maintenance_cancel'));
|
|
694
|
+
// The running job's bubble, with Cancel; it closes when the job ends
|
|
695
|
+
let runShown = null; // the job whose bubble was shown
|
|
696
|
+
const showRun = job => {
|
|
697
|
+
runShown = job;
|
|
698
|
+
$('run-title').textContent = (MAINT[job] || [job])[0];
|
|
699
|
+
$('run-text').textContent = job === 'update_firmware' ? 'Running… do not switch the robot off.' : 'Running…';
|
|
700
|
+
$('run-cancel').hidden = job === 'update_firmware';
|
|
701
|
+
show($('modal-run'));
|
|
702
|
+
};
|
|
703
|
+
const showDiag = on => {
|
|
704
|
+
$('diag').hidden = !on; $('b-diag').classList.toggle('active', on); $('b-diag').textContent = on ? 'Shown' : 'Show';
|
|
705
|
+
try { localStorage.setItem('diag', on ? '1' : ''); } catch (e) {}
|
|
706
|
+
};
|
|
707
|
+
try { showDiag(!!localStorage.getItem('diag')); } catch (e) { showDiag(false); }
|
|
708
|
+
$('b-diag').addEventListener('click', () => showDiag($('diag').hidden));
|
|
709
|
+
$('b-pad-tilt').addEventListener('click', () => socket.emit('set_pad_tilt', {on: !$('b-pad-tilt').classList.contains('active')}));
|
|
710
|
+
const openMaint = (job, go = 'Start', note = '') => {
|
|
711
|
+
maintJob = job;
|
|
712
|
+
$('maint-title').textContent = MAINT[job][0];
|
|
713
|
+
$('maint-text').textContent = (note ? note + ' ' : '') + MAINT[job][1];
|
|
714
|
+
$('maint-go').textContent = go;
|
|
715
|
+
$('maint-board').toggleAttribute('hidden', !servoLeg[job]);
|
|
716
|
+
document.querySelectorAll('[data-conn]').forEach(g => g.classList.toggle('on', g.dataset.conn === servoLeg[job]));
|
|
717
|
+
show($('modal-maint'));
|
|
718
|
+
};
|
|
719
|
+
document.querySelectorAll('[data-maint]').forEach(b => b.addEventListener('click', () => {
|
|
720
|
+
const job = b.dataset.maint === 'assembly' ? servoSteps[servoNext] : b.dataset.maint;
|
|
721
|
+
if (job) openMaint(job);
|
|
722
|
+
}));
|
|
723
|
+
$('maint-go').addEventListener('click', () => { action(maintJob); hide(); });
|
|
724
|
+
let heightBusy = 0;
|
|
725
|
+
const mm = v => (v > 0 ? '+' : '') + v + ' mm';
|
|
726
|
+
$('s-height').addEventListener('input', e => {
|
|
727
|
+
heightBusy = Date.now() + 1500;
|
|
728
|
+
$('s-height-v').textContent = mm(+e.target.value);
|
|
729
|
+
socket.emit('set_height', {mm: +e.target.value});
|
|
730
|
+
});
|
|
731
|
+
let speedBusy = 0;
|
|
732
|
+
$('s-speed').addEventListener('input', e => {
|
|
733
|
+
speedBusy = Date.now() + 1500;
|
|
734
|
+
$('s-speed-v').textContent = Math.round(e.target.value * 100) + '%';
|
|
735
|
+
socket.emit('set_speed', {value: +e.target.value});
|
|
736
|
+
});
|
|
737
|
+
$('b-rec').addEventListener('click', () => socket.emit('camera_record', {on: !(state.cam_rec && state.cam_rec.on)}));
|
|
738
|
+
$('b-photo').addEventListener('click', async () => {
|
|
739
|
+
const reply = await fetch('/photo');
|
|
740
|
+
toast(reply.ok ? 'Photo saved to the gallery' : 'No camera image yet');
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
// ---------- Gallery ----------
|
|
744
|
+
async function loadGallery() {
|
|
745
|
+
const files = (await (await fetch('/gallery')).json()).files;
|
|
746
|
+
const photos = files.filter(f => f.kind === 'photo'), videos = files.filter(f => f.kind === 'video');
|
|
747
|
+
$('g-photos').innerHTML = photos.length ? '' : '<span class="empty-note">No photo yet.</span>';
|
|
748
|
+
$('g-videos').innerHTML = videos.length ? '' : '<span class="empty-note">No video yet.</span>';
|
|
749
|
+
for (const f of photos) {
|
|
750
|
+
const b = document.createElement('button');
|
|
751
|
+
b.innerHTML = `<img loading="lazy" src="/recordings/${f.name}" alt="">`;
|
|
752
|
+
b.addEventListener('click', () => openViewer(f));
|
|
753
|
+
$('g-photos').appendChild(b);
|
|
754
|
+
}
|
|
755
|
+
for (const f of videos) { // MJPG .avi: not playable in browsers
|
|
756
|
+
const b = document.createElement('button');
|
|
757
|
+
b.className = 'tile';
|
|
758
|
+
b.innerHTML = `<svg class="i"><use href="#i-film"/></svg>${f.name.slice(0, 15)}<br>${f.size_mb} MB`;
|
|
759
|
+
b.addEventListener('click', () => openViewer(f));
|
|
760
|
+
$('g-videos').appendChild(b);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
let viewing = null;
|
|
764
|
+
function openViewer(f) {
|
|
765
|
+
viewing = f;
|
|
766
|
+
$('viewer-img').hidden = f.kind !== 'photo';
|
|
767
|
+
$('viewer-img').src = f.kind === 'photo' ? '/recordings/' + f.name : '';
|
|
768
|
+
$('viewer-name').textContent = f.kind === 'photo' ? '' : `${f.name} · ${f.size_mb} MB`;
|
|
769
|
+
showViewer(true);
|
|
770
|
+
}
|
|
771
|
+
// Fetched by the page (the phone's download manager has neither the session nor the certificate); share sheet on phones
|
|
772
|
+
async function saveFile(name) {
|
|
773
|
+
const reply = await fetch('/recordings/' + encodeURIComponent(name));
|
|
774
|
+
if (!reply.ok) { toast('Cannot get ' + name); return; }
|
|
775
|
+
const blob = await reply.blob();
|
|
776
|
+
const file = new File([blob], name, {type: blob.type});
|
|
777
|
+
if (matchMedia('(pointer: coarse)').matches && navigator.canShare && navigator.canShare({files: [file]})) {
|
|
778
|
+
try { await navigator.share({files: [file]}); return; }
|
|
779
|
+
catch (e) { if (e.name === 'AbortError') return; } // NotAllowedError (tap too old): download
|
|
780
|
+
}
|
|
781
|
+
const a = document.createElement('a');
|
|
782
|
+
a.href = URL.createObjectURL(blob); a.download = name; a.click();
|
|
783
|
+
setTimeout(() => URL.revokeObjectURL(a.href), 60000);
|
|
784
|
+
}
|
|
785
|
+
$('viewer-dl').addEventListener('click', async () => {
|
|
786
|
+
$('viewer-dl').disabled = true;
|
|
787
|
+
try { await saveFile(viewing.name); } finally { $('viewer-dl').disabled = false; }
|
|
788
|
+
});
|
|
789
|
+
$('viewer-del').addEventListener('click', async () => {
|
|
790
|
+
if (!confirm(`Delete ${viewing.name} from the robot?`)) return;
|
|
791
|
+
const reply = await fetch('/recordings/' + encodeURIComponent(viewing.name), {method: 'DELETE'});
|
|
792
|
+
toast(reply.ok ? 'Deleted' : 'Cannot delete it');
|
|
793
|
+
showViewer(false); loadGallery();
|
|
794
|
+
});
|
|
795
|
+
$('viewer-close').addEventListener('click', () => showViewer(false));
|
|
796
|
+
|
|
797
|
+
// ---------- Talkie-walkie ----------
|
|
798
|
+
// Hold the mic button: the phone's microphone plays on Chromapi (16 kHz mono int16, HTTPS only)
|
|
799
|
+
const TALK_RATE = 16000;
|
|
800
|
+
let talk = null;
|
|
801
|
+
async function talkStart() {
|
|
802
|
+
if (talk) return;
|
|
803
|
+
const resume = !!listen; // listening resumes on release
|
|
804
|
+
listenStop(); // one way at a time
|
|
805
|
+
talk = {resume}; // asking: a release before the answer cancels
|
|
806
|
+
try {
|
|
807
|
+
const stream = await navigator.mediaDevices.getUserMedia(
|
|
808
|
+
{audio: {echoCancellation: true, noiseSuppression: true, autoGainControl: true, channelCount: 1}});
|
|
809
|
+
if (!talk) { stream.getTracks().forEach(t => t.stop()); return; }
|
|
810
|
+
const ctx = new AudioContext();
|
|
811
|
+
await ctx.resume(); // iOS starts it suspended
|
|
812
|
+
const src = ctx.createMediaStreamSource(stream);
|
|
813
|
+
const proc = ctx.createScriptProcessor(2048, 1, 1);
|
|
814
|
+
const ratio = ctx.sampleRate / TALK_RATE;
|
|
815
|
+
proc.onaudioprocess = e => {
|
|
816
|
+
const x = e.inputBuffer.getChannelData(0), n = Math.floor(x.length / ratio), out = new Int16Array(n);
|
|
817
|
+
for (let i = 0; i < n; i++) { // window mean before decimating
|
|
818
|
+
let sum = 0, a = Math.floor(i * ratio), b = Math.max(a + 1, Math.floor((i + 1) * ratio));
|
|
819
|
+
for (let j = a; j < b; j++) sum += x[j];
|
|
820
|
+
out[i] = Math.max(-1, Math.min(1, sum / (b - a))) * 32767;
|
|
821
|
+
}
|
|
822
|
+
if (socket.connected) socket.emit('talk', out.buffer);
|
|
823
|
+
};
|
|
824
|
+
src.connect(proc); proc.connect(ctx.destination);
|
|
825
|
+
talk = {stream, ctx, proc, src, resume};
|
|
826
|
+
$('b-mic').classList.add('talk');
|
|
827
|
+
} catch (err) {
|
|
828
|
+
talk = null;
|
|
829
|
+
toast(err.name === 'NotAllowedError' ? 'Microphone: permission refused' : 'Microphone unavailable');
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
function talkStop() {
|
|
833
|
+
const t = talk;
|
|
834
|
+
talk = null;
|
|
835
|
+
$('b-mic').classList.remove('talk');
|
|
836
|
+
if (!t) return;
|
|
837
|
+
if (t.stream) {
|
|
838
|
+
t.proc.disconnect(); t.src.disconnect(); t.ctx.close();
|
|
839
|
+
t.stream.getTracks().forEach(track => track.stop());
|
|
840
|
+
}
|
|
841
|
+
if (t.resume && pilot && !document.hidden) listenStart();
|
|
842
|
+
}
|
|
843
|
+
if (!window.isSecureContext || !navigator.mediaDevices) {
|
|
844
|
+
$('b-mic').disabled = true;
|
|
845
|
+
$('b-mic').title = 'Talkie-walkie: the browser gives the microphone to HTTPS pages only (chromapi run without --http)';
|
|
846
|
+
} else {
|
|
847
|
+
const mic = $('b-mic');
|
|
848
|
+
mic.addEventListener('pointerdown', e => { mic.setPointerCapture(e.pointerId); talkStart(); });
|
|
849
|
+
for (const ev of ['pointerup', 'pointercancel', 'lostpointercapture']) mic.addEventListener(ev, talkStop);
|
|
850
|
+
mic.addEventListener('keydown', e => { if ((e.code === 'Space' || e.code === 'Enter') && !e.repeat) { e.preventDefault(); talkStart(); } });
|
|
851
|
+
mic.addEventListener('keyup', e => { if (e.code === 'Space' || e.code === 'Enter') talkStop(); });
|
|
852
|
+
mic.addEventListener('contextmenu', e => e.preventDefault());
|
|
853
|
+
window.addEventListener('blur', talkStop);
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
// Headphones: Chromapi's microphone plays here, until hidden, talking or watching
|
|
857
|
+
const LISTEN_LEAD_S = 0.08;
|
|
858
|
+
let listen = null;
|
|
859
|
+
async function listenStart() {
|
|
860
|
+
if (listen) return;
|
|
861
|
+
talkStop();
|
|
862
|
+
const ctx = new AudioContext();
|
|
863
|
+
const l = {ctx, next: 0};
|
|
864
|
+
listen = l;
|
|
865
|
+
await ctx.resume();
|
|
866
|
+
if (listen !== l) return; // released meanwhile
|
|
867
|
+
socket.emit('listen_start');
|
|
868
|
+
$('b-listen').classList.add('talk'); $('b-listen').setAttribute('aria-pressed', 'true');
|
|
869
|
+
}
|
|
870
|
+
function listenStop() {
|
|
871
|
+
const l = listen;
|
|
872
|
+
listen = null;
|
|
873
|
+
$('b-listen').classList.remove('talk'); $('b-listen').setAttribute('aria-pressed', 'false');
|
|
874
|
+
if (!l) return;
|
|
875
|
+
socket.emit('listen_stop');
|
|
876
|
+
l.ctx.close();
|
|
877
|
+
}
|
|
878
|
+
socket.on('listen', data => {
|
|
879
|
+
if (!listen) return;
|
|
880
|
+
const pcm = new Int16Array(data), ctx = listen.ctx, buf = ctx.createBuffer(1, pcm.length, TALK_RATE), ch = buf.getChannelData(0);
|
|
881
|
+
for (let i = 0; i < pcm.length; i++) ch[i] = pcm[i] / 32768;
|
|
882
|
+
const src = ctx.createBufferSource();
|
|
883
|
+
src.buffer = buf; src.connect(ctx.destination);
|
|
884
|
+
const at = Math.max(ctx.currentTime + LISTEN_LEAD_S, listen.next);
|
|
885
|
+
src.start(at); listen.next = at + buf.duration;
|
|
886
|
+
});
|
|
887
|
+
$('b-listen').addEventListener('click', () => (listen ? listenStop() : listenStart()));
|
|
888
|
+
document.addEventListener('visibilitychange', () => { if (document.hidden) listenStop(); });
|
|
889
|
+
|
|
890
|
+
// ---------- One page drives ----------
|
|
891
|
+
// The first page connected drives, the others watch
|
|
892
|
+
const PILOT_ONLY = '#b-photo, #b-rec, #b-torch, #b-mic, #b-listen, #b-awake, #chip-batt, .stick, .quick, #b-emotes, ' +
|
|
893
|
+
'[data-mode], [data-gait], #fan-row, #ring-row, [data-maint], #b-power, #b-pad-tilt, #b-identify';
|
|
894
|
+
let pilot = true;
|
|
895
|
+
socket.on('role', r => {
|
|
896
|
+
if (r.pilot && !pilot) toast('You drive Chromapi now');
|
|
897
|
+
else if (!r.pilot && pilot) toast('Another pilot drives the Chromapi: you are watching');
|
|
898
|
+
pilot = r.pilot;
|
|
899
|
+
document.querySelectorAll(PILOT_ONLY).forEach(el => el.classList.toggle('off-pilot', !pilot));
|
|
900
|
+
$('chip-role').hidden = pilot;
|
|
901
|
+
if (!pilot) { talkStop(); listenStop(); hide(); }
|
|
902
|
+
});
|
|
903
|
+
|
|
904
|
+
// ---------- Access code ----------
|
|
905
|
+
// The first browser chooses the code, the others enter it once
|
|
906
|
+
const GATE = {
|
|
907
|
+
setup: ['Choose an access code', n => `Choose a code of at least ${n} characters. Anyone who wants to drive the robot or see its camera will need it.`, 'new-password'],
|
|
908
|
+
login: ['Access code', () => 'Enter the code chosen for this robot. Forgotten? Run chromapi access reset on the robot.', 'current-password'],
|
|
909
|
+
change: ['New access code', n => `At least ${n} characters. Every other device will have to enter the new password.`, 'new-password'],
|
|
910
|
+
};
|
|
911
|
+
let gateMode = null, minLength = 6, started = false;
|
|
912
|
+
function showGate(mode) {
|
|
913
|
+
gateMode = mode;
|
|
914
|
+
const [title, text, complete] = GATE[mode];
|
|
915
|
+
$('gate-title').textContent = title; $('gate-text').textContent = text(minLength);
|
|
916
|
+
$('gate-current').value = $('gate-code').value = $('gate-confirm').value = ''; $('gate-code').autocomplete = complete;
|
|
917
|
+
$('gate-current').hidden = mode !== 'change';
|
|
918
|
+
$('gate-code').placeholder = mode === 'change' ? 'New code' : '';
|
|
919
|
+
$('gate-confirm').hidden = mode === 'login'; $('gate-cancel').hidden = mode !== 'change';
|
|
920
|
+
$('gate-error').textContent = '';
|
|
921
|
+
hide(); $('gate').hidden = false; $(mode === 'change' ? 'gate-current' : 'gate-code').focus();
|
|
922
|
+
}
|
|
923
|
+
function start() {
|
|
924
|
+
$('gate').hidden = true;
|
|
925
|
+
$('cam').src = '/video_feed?' + Date.now();
|
|
926
|
+
socket.connect();
|
|
927
|
+
if (!started) { started = true; loadMoods(); loadServos(); }
|
|
928
|
+
}
|
|
929
|
+
let checking = false;
|
|
930
|
+
async function checkAccess() {
|
|
931
|
+
if (checking) return;
|
|
932
|
+
checking = true;
|
|
933
|
+
try {
|
|
934
|
+
const s = await (await fetch('/auth/state')).json();
|
|
935
|
+
minLength = s.min_length;
|
|
936
|
+
if (s.signed_in) { if (!socket.connected) start(); } else showGate(s.configured ? 'login' : 'setup');
|
|
937
|
+
} catch (e) { setTimeout(checkAccess, 3000); }
|
|
938
|
+
finally { checking = false; }
|
|
939
|
+
}
|
|
940
|
+
$('gate-form').addEventListener('submit', async e => {
|
|
941
|
+
e.preventDefault();
|
|
942
|
+
const code = $('gate-code').value;
|
|
943
|
+
if (gateMode !== 'login' && code.length < minLength) { $('gate-error').textContent = `At least ${minLength} characters.`; return; }
|
|
944
|
+
if (gateMode !== 'login' && code !== $('gate-confirm').value) { $('gate-error').textContent = 'The two codes differ.'; return; }
|
|
945
|
+
$('gate-go').disabled = true;
|
|
946
|
+
try {
|
|
947
|
+
const reply = await fetch('/auth/' + gateMode, {method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({code, current: $('gate-current').value})});
|
|
948
|
+
const d = await reply.json();
|
|
949
|
+
if (reply.status === 409) { showGate('login'); $('gate-error').textContent = d.error; return; }
|
|
950
|
+
if (!reply.ok) { $('gate-error').textContent = d.error; return; }
|
|
951
|
+
if (gateMode === 'change') { $('gate').hidden = true; toast('Access code changed: other devices must enter it'); }
|
|
952
|
+
else start();
|
|
953
|
+
} finally { $('gate-go').disabled = false; }
|
|
954
|
+
});
|
|
955
|
+
$('gate-cancel').addEventListener('click', () => { $('gate').hidden = true; });
|
|
956
|
+
$('b-change-code').addEventListener('click', () => showGate('change'));
|
|
957
|
+
socket.on('connect_error', checkAccess);
|
|
958
|
+
socket.on('disconnect', reason => { if (reason === 'io server disconnect') checkAccess(); });
|
|
959
|
+
checkAccess();
|
|
960
|
+
|
|
961
|
+
// ---------- Telemetry ----------
|
|
962
|
+
socket.on('disconnect', () => setLink('Offline', ''));
|
|
963
|
+
function setLink(text, cls) { $('link').textContent = text; $('chip-link').className = 'chip ' + cls; }
|
|
964
|
+
const fmt = (v, d, unit) => v == null ? '--' : v.toFixed(d) + unit.replace(' ', '\u00a0');
|
|
965
|
+
const LINK_TEXT = {'ok': 'connected', 'STM32 motherboard not answering': 'not answering', 'no serial port': 'not connected'};
|
|
966
|
+
let wasRecording = false;
|
|
967
|
+
|
|
968
|
+
socket.on('telemetry', d => {
|
|
969
|
+
state = d;
|
|
970
|
+
// Top chips: what a casual user needs.
|
|
971
|
+
const b = d.battery;
|
|
972
|
+
$('batt').textContent = b.percent == null ? '--' : Math.round(b.percent) + '%';
|
|
973
|
+
$('batt-fill').setAttribute('width', b.percent == null ? 0 : (14 * b.percent / 100).toFixed(1));
|
|
974
|
+
$('chip-viewers').hidden = !d.viewers; $('viewers').textContent = d.viewers;
|
|
975
|
+
const pad = d.gamepad;
|
|
976
|
+
$('d-gamepad').textContent = !pad ? 'none' : pad.battery == null ? 'connected' : `connected · ${pad.battery} %`;
|
|
977
|
+
$('b-pad-tilt').disabled = !pad || !pilot;
|
|
978
|
+
$('b-pad-tilt').classList.toggle('active', !!(pad && pad.tilt_lean));
|
|
979
|
+
$('b-pad-tilt').textContent = pad && pad.tilt_lean ? 'On' : 'Off';
|
|
980
|
+
$('chip-batt').className = 'chip chip-btn ' + (b.level || '');
|
|
981
|
+
$('chip-batt').title = b.percent == null ? 'Battery: not read yet' : 'Battery: show the charge on the LED ring';
|
|
982
|
+
$('temp').textContent = fmt(d.cpu_temp, 0, '°');
|
|
983
|
+
$('chip-temp').className = 'chip ' + (d.cpu_temp > 75 ? 'bad' : d.cpu_temp > 65 ? 'low' : '');
|
|
984
|
+
if (d.link !== 'ok') setLink(d.link === 'no serial port' ? 'No motherboard' : 'Motherboard silent', 'warn');
|
|
985
|
+
else if (d.simulation) setLink('Simulation', 'sim');
|
|
986
|
+
else if (d.gamepad) setLink('Bluetooth', 'bt');
|
|
987
|
+
else setLink('Live', 'live');
|
|
988
|
+
|
|
989
|
+
// Driving controls.
|
|
990
|
+
const awake = $('b-awake');
|
|
991
|
+
awake.textContent = d.awake ? 'Lie down' : 'Wake up';
|
|
992
|
+
awake.classList.toggle('awake', d.awake);
|
|
993
|
+
awake.disabled = d.link !== 'ok';
|
|
994
|
+
document.querySelectorAll('[data-gait]').forEach(g => g.classList.toggle('active', g.dataset.gait === d.gait));
|
|
995
|
+
document.querySelectorAll('[data-mode]').forEach(g => g.classList.toggle('active', g.dataset.mode === d.mode));
|
|
996
|
+
$('lbl-r').textContent = d.mode === 'lean' ? 'Lean' : 'Turn';
|
|
997
|
+
$('lbl-l').textContent = d.mode === 'lean' ? 'Shift' : 'Walk';
|
|
998
|
+
$('b-torch').classList.toggle('on', d.torch);
|
|
999
|
+
if (d.ring && Date.now() > ringBusy) { if (d.ring !== 'rainbow') $('s-ring').value = rgbHue(d.ring); showRing(d.ring); }
|
|
1000
|
+
$('fan-row').hidden = d.fan == null;
|
|
1001
|
+
$('b-fan-auto').classList.toggle('active', d.fan_auto);
|
|
1002
|
+
if (d.fan != null && Date.now() > fanBusy) { $('s-fan').value = d.fan; $('s-fan-v').textContent = Math.round(d.fan) + '%'; }
|
|
1003
|
+
const emoteBlock = !d.awake ? 'Wake Chromapi up first.' : d.mode !== 'turn' ? 'Switch back to Turn mode first.'
|
|
1004
|
+
: d.walking ? 'Stop walking first.' : d.emote ? 'An emote is playing.' : '';
|
|
1005
|
+
document.querySelectorAll('[data-emote]').forEach(e => e.disabled = !!emoteBlock);
|
|
1006
|
+
$('emote-hint').textContent = emoteBlock;
|
|
1007
|
+
$('s-speed').max = d.speed_max;
|
|
1008
|
+
if (Date.now() > heightBusy) { $('s-height').value = d.height_mm; $('s-height-v').textContent = mm(d.height_mm); }
|
|
1009
|
+
const m = d.maintenance || {};
|
|
1010
|
+
document.querySelectorAll('[data-maint]').forEach(b => {
|
|
1011
|
+
b.disabled = !!m.running || d.awake || d.simulation;
|
|
1012
|
+
$('m-' + b.dataset.maint).textContent = m.job === b.dataset.maint ? (m.running ? 'running…' : m.ok ? 'done' : 'failed') : '';
|
|
1013
|
+
});
|
|
1014
|
+
const step = servoSteps.indexOf(m.job);
|
|
1015
|
+
if (step >= 0) {
|
|
1016
|
+
servoNext = m.running || !m.ok ? step : (step + 1) % servoSteps.length;
|
|
1017
|
+
$('m-assembly').textContent = m.running ? `${step + 1}/${servoSteps.length}…`
|
|
1018
|
+
: !m.ok ? `${step + 1}/${servoSteps.length} failed` : step + 1 === servoSteps.length ? 'done' : `next: ${step + 2}/${servoSteps.length}`;
|
|
1019
|
+
}
|
|
1020
|
+
$('maint-hint').textContent = d.simulation ? 'Real robot only.' : m.running ? (m.cancelled ? 'Cancelling…' : 'Running: the robot does not answer meanwhile.')
|
|
1021
|
+
: d.awake ? 'Lay Chromapi down first.' : '';
|
|
1022
|
+
$('maint-log').hidden = !m.log; $('maint-log').textContent = m.log || '';
|
|
1023
|
+
if (m.running && runShown !== m.job) showRun(m.job);
|
|
1024
|
+
const cancellable = m.running && m.job !== 'update_firmware';
|
|
1025
|
+
$('maint-cancel').hidden = !cancellable || open === $('modal-run');
|
|
1026
|
+
for (const id of ['run-cancel', 'maint-cancel']) {
|
|
1027
|
+
$(id).disabled = !!m.cancelled; $(id).textContent = m.cancelled ? 'Cancelling…' : 'Cancel';
|
|
1028
|
+
}
|
|
1029
|
+
if (!m.running && runShown) {
|
|
1030
|
+
runShown = null;
|
|
1031
|
+
if (open === $('modal-run')) hide();
|
|
1032
|
+
// Servo assembly: next servo, or retry
|
|
1033
|
+
if (step >= 0 && !m.cancelled && pilot && !(m.ok && step + 1 === servoSteps.length)) {
|
|
1034
|
+
if (m.ok) openMaint(servoSteps[step + 1], 'Next servo', `Servo ${step + 1} done.`);
|
|
1035
|
+
else openMaint(m.job, 'Retry', `Failed: ${(m.log || '').trim().split('\n').pop()}`);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
if (Date.now() > speedBusy) { $('s-speed').value = d.speed_scale; $('s-speed-v').textContent = Math.round(d.speed_scale * 100) + '%'; }
|
|
1039
|
+
if (d.status !== lastStatus) { if (lastStatus) toast(d.status); lastStatus = d.status; }
|
|
1040
|
+
|
|
1041
|
+
// Camera.
|
|
1042
|
+
const r = d.cam_rec;
|
|
1043
|
+
$('cam').hidden = !r; $('cam-off').hidden = !!r;
|
|
1044
|
+
$('b-photo').disabled = $('b-rec').disabled = !r;
|
|
1045
|
+
if (r) {
|
|
1046
|
+
$('b-rec').classList.toggle('on', r.on);
|
|
1047
|
+
$('rec-badge').classList.toggle('on', r.on);
|
|
1048
|
+
$('rec-badge').textContent = 'REC ' + r.seconds.toFixed(0) + ' s';
|
|
1049
|
+
if (wasRecording && !r.on) toast('Video saved to the gallery');
|
|
1050
|
+
wasRecording = r.on;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// Same values in Settings (d-*) and on the video (o-*)
|
|
1054
|
+
const s = d.servos;
|
|
1055
|
+
const diag = {
|
|
1056
|
+
link: d.simulation ? 'simulated' : LINK_TEXT[d.link] || d.link,
|
|
1057
|
+
batt: d.voltage == null ? (b.percent == null ? 'not read yet' : '--')
|
|
1058
|
+
: `${Math.round(b.percent)}% · ${fmt(d.voltage, 2, ' V')} · ${fmt(d.current, 2, ' A')} · ${fmt(d.power, 1, ' W')}`,
|
|
1059
|
+
servos: s ? (s.missing.length ? 'not answering: ' + s.missing.join(', ') : 'all 12 answering') : '--',
|
|
1060
|
+
stemp: s ? fmt(s.max_temp, 0, ' °C') : '--',
|
|
1061
|
+
cpu: fmt(d.cpu_temp, 0, ' °C'),
|
|
1062
|
+
tilt: fmt(d.tilt_deg, 1, '°'),
|
|
1063
|
+
};
|
|
1064
|
+
for (const [key, text] of Object.entries(diag)) $('d-' + key).textContent = $('o-' + key).textContent = text;
|
|
1065
|
+
for (const leg of ['tl', 'tr', 'bl', 'br']) for (const p of ['f-', 'o-f-']) $(p + leg).classList.toggle('on', !!(d.contacts && d.contacts[leg]));
|
|
1066
|
+
const v = d.versions;
|
|
1067
|
+
if (!m.running && v.firmware_shipped && !d.simulation && d.link === 'ok') {
|
|
1068
|
+
$('m-update_firmware').textContent = v.firmware_update ? `${v.firmware || 'older'} → ${v.firmware_shipped}`
|
|
1069
|
+
: m.job === 'update_firmware' && !m.ok ? $('m-update_firmware').textContent : 'up to date';
|
|
1070
|
+
}
|
|
1071
|
+
$('b-settings').classList.toggle('badge', !!v.firmware_update);
|
|
1072
|
+
if (v.firmware_update && !updateToasted) { updateToasted = true; toast(`Firmware ${v.firmware_shipped} available: Settings › Maintenance`); }
|
|
1073
|
+
$('v-sdk').textContent = d.versions.sdk;
|
|
1074
|
+
if (d.host && $('v-host').textContent !== d.host) { $('v-host').textContent = d.host; document.title = d.host + ' · Chromapi'; }
|
|
1075
|
+
$('v-fw').textContent = d.versions.firmware || 'unknown';
|
|
1076
|
+
});
|
|
1077
|
+
</script>
|
|
1078
|
+
</body>
|
|
1079
|
+
</html>
|