Compare commits
22 Commits
0da30b6d6b
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6c9e06f33b | |||
| c1c3e5d71b | |||
| c64dd736f2 | |||
| cad0aa7e59 | |||
| 0ae39ab94b | |||
| 822d9d8e01 | |||
| 1db905eaae | |||
| 3d6ef5c7b4 | |||
| 78a4ce009c | |||
| 7ccab6fbc4 | |||
|
|
827eb97203 | ||
|
|
3cca0cffc5 | ||
|
|
d36828bde2 | ||
|
|
ed0048c795 | ||
|
|
b316edbaf9 | ||
| c1b0c41ef2 | |||
| 3bb75d49de | |||
| 3d77cb448a | |||
| 49383c0003 | |||
| 7d821b9c1c | |||
| 9b7e387ea6 | |||
| b4f0d1891e |
@@ -7,6 +7,8 @@ alwaysApply: true
|
||||
|
||||
1. When creating a new pattern under `led-driver/src/patterns/`, also add/update a corresponding test file in `led-driver/tests/patterns/`.
|
||||
|
||||
2. When adding a new pattern, ensure led-controller has `db/pattern.json`; if it does not exist, create it. Add the new pattern metadata and parameter mappings there.
|
||||
2. When adding a new pattern, ensure led-controller has `db/pattern.json`; if it does not exist, create it. Add the new pattern metadata and parameter mappings there. Optionally set **`supports_manual`** to `false` when the pattern is a poor fit for manual mode or audio beat triggers (smooth/blended animations); omit or `true` otherwise.
|
||||
|
||||
3. When adding a new pattern, add at least one test preset entry in `db/preset.json` in led-controller that uses the new pattern.
|
||||
|
||||
4. For any pattern that supports both auto and manual modes, keep behaviour parity unless explicitly requested otherwise: background colour handling, colour-cycling order, and parameter timing semantics (e.g. `n2`/`n3` meaning) must match between auto and manual paths.
|
||||
|
||||
18
.cursor/rules/submodules-led-driver-tool.mdc
Normal file
18
.cursor/rules/submodules-led-driver-tool.mdc
Normal file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
description: Keep led-driver and led-tool git submodules in sync when updating led-controller
|
||||
alwaysApply: true
|
||||
---
|
||||
|
||||
# Submodule pointers (`led-driver`, `led-tool`)
|
||||
|
||||
This repo tracks **`led-driver`** and **`led-tool`** as git submodules (see `.gitmodules`).
|
||||
|
||||
When you **update led-controller** work that should ship with matching firmware or CLI behaviour—or when you finish changes **inside** those submodule directories—**record the new submodule commits in the parent repo**:
|
||||
|
||||
1. In each submodule, commit and push on its remote if there are local commits (or ensure the checkout is the intended revision).
|
||||
2. From the **led-controller** root: `git add led-driver led-tool` after their HEADs point at the right commits.
|
||||
3. Include the parent-repo commit that bumps the gitlinks (so CI and clones get consistent trees).
|
||||
|
||||
**Do not** leave submodule directories dirty or forgotten while presenting the parent repo as “done”: either commit the submodule pointer update in led-controller, or leave an explicit note if the user must push submodule remotes first.
|
||||
|
||||
If the user only asked for a submodule bump with no code edits, a single `chore(submodules): bump led-driver and led-tool` style commit is appropriate (see commit rule).
|
||||
12
.gitignore
vendored
12
.gitignore
vendored
@@ -25,8 +25,20 @@ ENV/
|
||||
Thumbs.db
|
||||
|
||||
# Project specific
|
||||
scripts/.led-controller-venv
|
||||
docs/.help-print.html
|
||||
settings.json
|
||||
# Track shared JSON + preset binaries; ignore other db/*.json (e.g. device, zone) locally
|
||||
db/*
|
||||
!db/group.json
|
||||
!db/palette.json
|
||||
!db/pattern.json
|
||||
!db/preset.json
|
||||
!db/profile.json
|
||||
!db/scene.json
|
||||
!db/sequence.json
|
||||
!db/presets/
|
||||
!db/presets/*.bin
|
||||
*.log
|
||||
*.db
|
||||
*.sqlite
|
||||
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -4,3 +4,6 @@
|
||||
[submodule "led-tool"]
|
||||
path = led-tool
|
||||
url = git@git.technical.kiwi:technicalkiwi/led-tool.git
|
||||
[submodule "led-simulator"]
|
||||
path = led-simulator
|
||||
url = git@git.technical.kiwi:technicalkiwi/led-simulator.git
|
||||
|
||||
15
Pipfile
15
Pipfile
@@ -14,17 +14,20 @@ selenium = "*"
|
||||
adafruit-ampy = "*"
|
||||
microdot = "*"
|
||||
websockets = "*"
|
||||
numpy = "*"
|
||||
sounddevice = "*"
|
||||
|
||||
[dev-packages]
|
||||
pytest = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.12"
|
||||
python_version = "3.11"
|
||||
|
||||
[scripts]
|
||||
web = "python /home/pi/led-controller/tests/web.py"
|
||||
watch = "python -m watchfiles 'python tests/web.py' src tests"
|
||||
install = "pipenv install"
|
||||
web = "python tests/web.py"
|
||||
watch = "python -m watchfiles \"python tests/web.py\" src tests"
|
||||
run = "sh -c 'cd src && python main.py'"
|
||||
dev = "watchfiles \"sh -c 'cd src && python main.py'\" src"
|
||||
help-pdf = "sh scripts/build_help_pdf.sh"
|
||||
dev = "python -m watchfiles \"sh -c 'cd src && LED_CONTROLLER_LIVE_RELOAD=1 python main.py'\" src"
|
||||
test = "python -m pytest"
|
||||
test-browser = "sh -c 'python tests/web.py > /tmp/led-controller-web.log 2>&1 & pid=$!; trap \"kill $pid\" EXIT; sleep 2; LED_CONTROLLER_RUN_BROWSER_TESTS=1 LED_CONTROLLER_DEVICE_IP=http://127.0.0.1:5000 python -m pytest tests/test_browser.py'"
|
||||
test-browser-device = "sh -c 'LED_CONTROLLER_RUN_BROWSER_TESTS=1 python -m pytest tests/test_browser.py'"
|
||||
|
||||
243
Pipfile.lock
generated
243
Pipfile.lock
generated
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "18691f772c7660e4a087c90560c87a9217a09e9b6db97825d21c092a06d64b89"
|
||||
"sha256": "7975a888034cb3e0f68c7b866f7e69e5a1db7a5228fe1f02d6cb5f9c180de557"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.12"
|
||||
"python_version": "3.11"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
@@ -40,6 +40,13 @@
|
||||
"markers": "python_version >= '3.9'",
|
||||
"version": "==26.1.0"
|
||||
},
|
||||
"aubio": {
|
||||
"hashes": [
|
||||
"sha256:df1244f6c4cf5bea382c8c2d35aa43bc31f4cf631fe325ae3992c219546a4202"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==0.4.9"
|
||||
},
|
||||
"bitarray": {
|
||||
"hashes": [
|
||||
"sha256:0256d57e294414bfe4fec4f852fd1d9ae361228c71b082332bf81c8b8fc69f80",
|
||||
@@ -159,11 +166,11 @@
|
||||
},
|
||||
"certifi": {
|
||||
"hashes": [
|
||||
"sha256:027692e4402ad994f1c42e52a4997a9763c646b73e4096e4d5d6db8af1d6f0fa",
|
||||
"sha256:e887ab5cee78ea814d3472169153c2d12cd43b14bd03329a39a9c6e2e80bfba7"
|
||||
"sha256:3cb2210c8f88ba2318d29b0388d1023c8492ff72ecdde4ebdaddbb13a31b1c4a",
|
||||
"sha256:8d455352a37b71bf76a79caa83a3d6c25afee4a385d632127b6afb3963f1c580"
|
||||
],
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==2026.2.25"
|
||||
"version": "==2026.4.22"
|
||||
},
|
||||
"cffi": {
|
||||
"hashes": [
|
||||
@@ -252,7 +259,7 @@
|
||||
"sha256:fc7de24befaeae77ba923797c7c87834c73648a05a4bde34b3b7e5588973a453",
|
||||
"sha256:fe562eb1a64e67dd297ccc4f5addea2501664954f2692b69a76449ec7913ecbf"
|
||||
],
|
||||
"markers": "python_full_version >= '3.9' and platform_python_implementation != 'PyPy'",
|
||||
"markers": "python_version >= '3.9'",
|
||||
"version": "==2.0.0"
|
||||
},
|
||||
"charset-normalizer": {
|
||||
@@ -392,66 +399,66 @@
|
||||
},
|
||||
"click": {
|
||||
"hashes": [
|
||||
"sha256:14162b8b3b3550a7d479eafa77dfd3c38d9dc8951f6f69c78913a8f9a7540fd5",
|
||||
"sha256:1924d2c27c5653561cd2cae4548d1406039cb79b858b747cfea24924bbc1616d"
|
||||
"sha256:398329ad4837b2ff7cbe1dd166a4c0f8900c3ca3a218de04466f38f6497f18a2",
|
||||
"sha256:a2bf429bb3033c89fa4936ffb35d5cb471e3719e1f3c8a7c3fff0b8314305613"
|
||||
],
|
||||
"markers": "python_version >= '3.10'",
|
||||
"version": "==8.3.2"
|
||||
"version": "==8.3.3"
|
||||
},
|
||||
"cryptography": {
|
||||
"hashes": [
|
||||
"sha256:04959522f938493042d595a736e7dbdff6eb6cc2339c11465b3ff89343b65f65",
|
||||
"sha256:128c5edfe5e5938b86b03941e94fac9ee793a94452ad1365c9fc3f4f62216832",
|
||||
"sha256:1d25aee46d0c6f1a501adcddb2d2fee4b979381346a78558ed13e50aa8a59067",
|
||||
"sha256:24402210aa54baae71d99441d15bb5a1919c195398a87b563df84468160a65de",
|
||||
"sha256:258514877e15963bd43b558917bc9f54cf7cf866c38aa576ebf47a77ddbc43a4",
|
||||
"sha256:35719dc79d4730d30f1c2b6474bd6acda36ae2dfae1e3c16f2051f215df33ce0",
|
||||
"sha256:397655da831414d165029da9bc483bed2fe0e75dde6a1523ec2fe63f3c46046b",
|
||||
"sha256:3986ac1dee6def53797289999eabe84798ad7817f3e97779b5061a95b0ee4968",
|
||||
"sha256:420b1e4109cc95f0e5700eed79908cef9268265c773d3a66f7af1eef53d409ef",
|
||||
"sha256:42a1e5f98abb6391717978baf9f90dc28a743b7d9be7f0751a6f56a75d14065b",
|
||||
"sha256:462ad5cb1c148a22b2e3bcc5ad52504dff325d17daf5df8d88c17dda1f75f2a4",
|
||||
"sha256:506c4ff91eff4f82bdac7633318a526b1d1309fc07ca76a3ad182cb5b686d6d3",
|
||||
"sha256:5ad9ef796328c5e3c4ceed237a183f5d41d21150f972455a9d926593a1dcb308",
|
||||
"sha256:5d1c02a14ceb9148cc7816249f64f623fbfee39e8c03b3650d842ad3f34d637e",
|
||||
"sha256:5e51be372b26ef4ba3de3c167cd3d1022934bc838ae9eaad7e644986d2a3d163",
|
||||
"sha256:60627cf07e0d9274338521205899337c5d18249db56865f943cbe753aa96f40f",
|
||||
"sha256:65814c60f8cc400c63131584e3e1fad01235edba2614b61fbfbfa954082db0ee",
|
||||
"sha256:73510b83623e080a2c35c62c15298096e2a5dc8d51c3b4e1740211839d0dea77",
|
||||
"sha256:7bbc6ccf49d05ac8f7d7b5e2e2c33830d4fe2061def88210a126d130d7f71a85",
|
||||
"sha256:80406c3065e2c55d7f49a9550fe0c49b3f12e5bfff5dedb727e319e1afb9bf99",
|
||||
"sha256:84d4cced91f0f159a7ddacad249cc077e63195c36aac40b4150e7a57e84fffe7",
|
||||
"sha256:8a469028a86f12eb7d2fe97162d0634026d92a21f3ae0ac87ed1c4a447886c83",
|
||||
"sha256:91bbcb08347344f810cbe49065914fe048949648f6bd5c2519f34619142bbe85",
|
||||
"sha256:935ce7e3cfdb53e3536119a542b839bb94ec1ad081013e9ab9b7cfd478b05006",
|
||||
"sha256:9694078c5d44c157ef3162e3bf3946510b857df5a3955458381d1c7cfc143ddb",
|
||||
"sha256:a1529d614f44b863a7b480c6d000fe93b59acee9c82ffa027cfadc77521a9f5e",
|
||||
"sha256:abad9dac36cbf55de6eb49badd4016806b3165d396f64925bf2999bcb67837ba",
|
||||
"sha256:b36a4695e29fe69215d75960b22577197aca3f7a25b9cf9d165dcfe9d80bc325",
|
||||
"sha256:b7b412817be92117ec5ed95f880defe9cf18a832e8cafacf0a22337dc1981b4d",
|
||||
"sha256:c5b1ccd1239f48b7151a65bc6dd54bcfcc15e028c8ac126d3fada09db0e07ef1",
|
||||
"sha256:cbd5fb06b62bd0721e1170273d3f4d5a277044c47ca27ee257025146c34cbdd1",
|
||||
"sha256:cdf1a610ef82abb396451862739e3fc93b071c844399e15b90726ef7470eeaf2",
|
||||
"sha256:cdfbe22376065ffcf8be74dc9a909f032df19bc58a699456a21712d6e5eabfd0",
|
||||
"sha256:d02c738dacda7dc2a74d1b2b3177042009d5cab7c7079db74afc19e56ca1b455",
|
||||
"sha256:d151173275e1728cf7839aaa80c34fe550c04ddb27b34f48c232193df8db5842",
|
||||
"sha256:d23c8ca48e44ee015cd0a54aeccdf9f09004eba9fc96f38c911011d9ff1bd457",
|
||||
"sha256:d3b99c535a9de0adced13d159c5a9cf65c325601aa30f4be08afd680643e9c15",
|
||||
"sha256:d5f7520159cd9c2154eb61eb67548ca05c5774d39e9c2c4339fd793fe7d097b2",
|
||||
"sha256:db0f493b9181c7820c8134437eb8b0b4792085d37dbb24da050476ccb664e59c",
|
||||
"sha256:e06acf3c99be55aa3b516397fe42f5855597f430add9c17fa46bf2e0fb34c9bb",
|
||||
"sha256:e4cfd68c5f3e0bfdad0d38e023239b96a2fe84146481852dffbcca442c245aa5",
|
||||
"sha256:ea42cbe97209df307fdc3b155f1b6fa2577c0defa8f1f7d3be7d31d189108ad4",
|
||||
"sha256:ebd6daf519b9f189f85c479427bbd6e9c9037862cf8fe89ee35503bd209ed902",
|
||||
"sha256:f247c8c1a1fb45e12586afbb436ef21ff1e80670b2861a90353d9b025583d246",
|
||||
"sha256:fbfd0e5f273877695cb93baf14b185f4878128b250cc9f8e617ea0c025dfb022",
|
||||
"sha256:fc9ab8856ae6cf7c9358430e49b368f3108f050031442eaeb6b9d87e4dcf4e4f",
|
||||
"sha256:fcd8eac50d9138c1d7fc53a653ba60a2bee81a505f9f8850b6b2888555a45d0e",
|
||||
"sha256:fdd1736fed309b4300346f88f74cd120c27c56852c3838cab416e7a166f67298",
|
||||
"sha256:ffca7aa1d00cf7d6469b988c581598f2259e46215e0140af408966a24cf086ce"
|
||||
"sha256:0890f502ddf7d9c6426129c3f49f5c0a39278ed7cd6322c8755ffca6ee675a13",
|
||||
"sha256:0c558d2cdffd8f4bbb30fc7134c74d2ca9a476f830bb053074498fbc86f41ed6",
|
||||
"sha256:16cd65b9330583e4619939b3a3843eec1e6e789744bb01e7c7e2e62e33c239c8",
|
||||
"sha256:18349bbc56f4743c8b12dc32e2bccb2cf83ee8b69a3bba74ef8ae857e26b3d25",
|
||||
"sha256:1e2d54c8be6152856a36f0882ab231e70f8ec7f14e93cf87db8a2ed056bf160c",
|
||||
"sha256:22a5cb272895dce158b2cacdfdc3debd299019659f42947dbdac6f32d68fe832",
|
||||
"sha256:27241b1dc9962e056062a8eef1991d02c3a24569c95975bd2322a8a52c6e5e12",
|
||||
"sha256:2b4d59804e8408e2fea7d1fbaf218e5ec984325221db76e6a241a9abd6cdd95c",
|
||||
"sha256:2eb992bbd4661238c5a397594c83f5b4dc2bc5b848c365c8f991b6780efcc5c7",
|
||||
"sha256:369a6348999f94bbd53435c894377b20ab95f25a9065c283570e70150d8abc3c",
|
||||
"sha256:3cb07a3ed6431663cd321ea8a000a1314c74211f823e4177fefa2255e057d1ec",
|
||||
"sha256:40ba1f85eaa6959837b1d51c9767e230e14612eea4ef110ee8854ada22da1bf5",
|
||||
"sha256:4defde8685ae324a9eb9d818717e93b4638ef67070ac9bc15b8ca85f63048355",
|
||||
"sha256:55b7718303bf06a5753dcdccf2f3945cf18ad7bffde41b61226e4db31ab89a9c",
|
||||
"sha256:561215ea3879cb1cbbf272867e2efda62476f240fb58c64de6b393ae19246741",
|
||||
"sha256:58d00498e8933e4a194f3076aee1b4a97dfec1a6da444535755822fe5d8b0b86",
|
||||
"sha256:59baa2cb386c4f0b9905bd6eb4c2a79a69a128408fd31d32ca4d7102d4156321",
|
||||
"sha256:5a5ed8fde7a1d09376ca0b40e68cd59c69fe23b1f9768bd5824f54681626032a",
|
||||
"sha256:5b012212e08b8dd5edc78ef54da83dd9892fd9105323b3993eff6bea65dc21d7",
|
||||
"sha256:5c3932f4436d1cccb036cb0eaef46e6e2db91035166f1ad6505c3c9d5a635920",
|
||||
"sha256:614d0949f4790582d2cc25553abd09dd723025f0c0e7c67376a1d77196743d6e",
|
||||
"sha256:76341972e1eff8b4bea859f09c0d3e64b96ce931b084f9b9b7db8ef364c30eff",
|
||||
"sha256:77a2ccbbe917f6710e05ba9adaa25fb5075620bf3ea6fb751997875aff4ae4bd",
|
||||
"sha256:7995ef305d7165c3f11ae07f2517e5a4f1d5c18da1376a0a9ed496336b69e5f3",
|
||||
"sha256:7ce4bfae76319a532a2dc68f82cc32f5676ee792a983187dac07183690e5c66f",
|
||||
"sha256:7e8eac43dfca5c4cccc6dad9a80504436fca53bb9bc3100a2386d730fbe6b602",
|
||||
"sha256:84cf79f0dc8b36ac5da873481716e87aef31fcfa0444f9e1d8b4b2cece142855",
|
||||
"sha256:8c7378637d7d88016fa6791c159f698b3d3eed28ebf844ac36b9dc04a14dae18",
|
||||
"sha256:8cd666227ef7af430aa5914a9910e0ddd703e75f039cef0825cd0da71b6b711a",
|
||||
"sha256:906cbf0670286c6e0044156bc7d4af9cbb0ef6db9f73e52c3ec56ba6bdde5336",
|
||||
"sha256:9071196d81abc88b3516ac8cdfad32e2b66dd4a5393a8e68a961e9161ddc6239",
|
||||
"sha256:9249e3cd978541d665967ac2cb2787fd6a62bddf1e75b3e347a594d7dacf4f74",
|
||||
"sha256:984a20b0f62a26f48a3396c72e4bc34c66e356d356bf370053066b3b6d54634a",
|
||||
"sha256:9be5aafa5736574f8f15f262adc81b2a9869e2cfe9014d52a44633905b40d52c",
|
||||
"sha256:9c459db21422be75e2809370b829a87eb37f74cd785fc4aa9ea1e5f43b47cda4",
|
||||
"sha256:9ccdac7d40688ecb5a3b4a604b8a88c8002e3442d6c60aead1db2a89a041560c",
|
||||
"sha256:a0e692c683f4df67815a2d258b324e66f4738bd7a96a218c826dce4f4bd05d8f",
|
||||
"sha256:a5da777e32ffed6f85a7b2b3f7c5cbc88c146bfcd0a1d7baf5fcc6c52ee35dd4",
|
||||
"sha256:a64697c641c7b1b2178e573cbc31c7c6684cd56883a478d75143dbb7118036db",
|
||||
"sha256:ad64688338ed4bc1a6618076ba75fd7194a5f1797ac60b47afe926285adb3166",
|
||||
"sha256:bd72e68b06bb1e96913f97dd4901119bc17f39d4586a5adf2d3e47bc2b9d58b5",
|
||||
"sha256:c17dfe85494deaeddc5ce251aebd1d60bbe6afc8b62071bb0b469431a000124f",
|
||||
"sha256:c18684a7f0cc9a3cb60328f496b8e3372def7c5d2df39ac267878b05565aaaae",
|
||||
"sha256:cc90c0b39b2e3c65ef52c804b72e3c58f8a04ab2a1871272798e5f9572c17d20",
|
||||
"sha256:db63bf618e5dea46c07de12e900fe1cdd2541e6dc9dbae772a70b7d4d4765f6a",
|
||||
"sha256:ea8990436d914540a40ab24b6a77c0969695ed52f4a4874c5137ccf7045a7057",
|
||||
"sha256:ecde28a596bead48b0cfd2a1b4416c3d43074c2d785e3a398d7ec1fc4d0f7fbb",
|
||||
"sha256:f5333311663ea94f75dd408665686aaf426563556bb5283554a3539177e03b8c",
|
||||
"sha256:fdfef35d751d510fcef5252703621574364fec16418c4a1e5e1055248401054b"
|
||||
],
|
||||
"markers": "python_version >= '3.8' and python_full_version not in '3.9.0, 3.9.1'",
|
||||
"version": "==46.0.7"
|
||||
"markers": "python_version >= '3.9' and python_full_version not in '3.9.0, 3.9.1'",
|
||||
"version": "==48.0.0"
|
||||
},
|
||||
"esptool": {
|
||||
"hashes": [
|
||||
@@ -471,11 +478,11 @@
|
||||
},
|
||||
"idna": {
|
||||
"hashes": [
|
||||
"sha256:771a87f49d9defaf64091e6e6fe9c18d4833f140bd19464795bc32d966ca37ea",
|
||||
"sha256:795dafcc9c04ed0c1fb032c2aa73654d8e8c5023a7df64a53f39190ada629902"
|
||||
"sha256:585ea8fe5d69b9181ec1afba340451fba6ba764af97026f92a91d4eef164a242",
|
||||
"sha256:892ea0cde124a99ce773decba204c5552b69c3c67ffd5f232eb7696135bc8bb3"
|
||||
],
|
||||
"markers": "python_version >= '3.8'",
|
||||
"version": "==3.11"
|
||||
"version": "==3.13"
|
||||
},
|
||||
"intelhex": {
|
||||
"hashes": [
|
||||
@@ -486,11 +493,11 @@
|
||||
},
|
||||
"markdown-it-py": {
|
||||
"hashes": [
|
||||
"sha256:87327c59b172c5011896038353a81343b6754500a08cd7a4973bb48c6d578147",
|
||||
"sha256:cb0a2b4aa34f932c007117b194e945bd74e0ec24133ceb5bac59009cda1cb9f3"
|
||||
"sha256:04a21681d6fbb623de53f6f364d352309d4094dd4194040a10fd51833e418d49",
|
||||
"sha256:9f7ebbcd14fe59494226453aed97c1070d83f8d24b6fc3a3bcf9a38092641c4a"
|
||||
],
|
||||
"markers": "python_version >= '3.10'",
|
||||
"version": "==4.0.0"
|
||||
"version": "==4.2.0"
|
||||
},
|
||||
"mdurl": {
|
||||
"hashes": [
|
||||
@@ -502,12 +509,12 @@
|
||||
},
|
||||
"microdot": {
|
||||
"hashes": [
|
||||
"sha256:363e3ebfc80b7e0415779848c9332e4e7fb7bd365ee54d3620abffe42ed82946",
|
||||
"sha256:abfb82ca31cc430174e4761cc7356adc4bff00ea758d437c2b258883dc63f464"
|
||||
"sha256:3ba8bab39ae52bca08ee7024dfc71afb7cff089f0b6611d2a1f617abfcee749c",
|
||||
"sha256:d56824f4510e628dac711c86121957894ceaf833298e4d25f06c29d2b19a1721"
|
||||
],
|
||||
"index": "pypi",
|
||||
"markers": "python_version >= '3.8'",
|
||||
"version": "==2.6.0"
|
||||
"version": "==2.6.1"
|
||||
},
|
||||
"mpremote": {
|
||||
"hashes": [
|
||||
@@ -518,6 +525,85 @@
|
||||
"markers": "python_version >= '3.4'",
|
||||
"version": "==1.28.0"
|
||||
},
|
||||
"numpy": {
|
||||
"hashes": [
|
||||
"sha256:07077278157d02f65c43b1b26a3886bce886f95d20aabd11f87932750dfb14ed",
|
||||
"sha256:08f2e31ed5e6f04b118e49821397f12767934cfdd12a1ce86a058f91e004ee50",
|
||||
"sha256:0aec54fd785890ecca25a6003fd9a5aed47ad607bbac5cd64f836ad8666f4959",
|
||||
"sha256:0d35aea54ad1d420c812bfa0385c71cd7cc5bcf7c65fed95fc2cd02fe8c79827",
|
||||
"sha256:0d4e437e295f18ec29bc79daf55e8a47a9113df44d66f702f02a293d93a2d6dd",
|
||||
"sha256:0dfd3f9d3adbe2920b68b5cd3d51444e13a10792ec7154cd0a2f6e74d4ab3233",
|
||||
"sha256:1378871da56ca8943c2ba674530924bb8ca40cd228358a3b5f302ad60cf875fc",
|
||||
"sha256:15716cfef24d3a9762e3acdf87e27f58dc823d1348f765bbea6bef8c639bfa1b",
|
||||
"sha256:19710a9ca9992d7174e9c52f643d4272dcd1558c5f7af7f6f8190f633bd651a7",
|
||||
"sha256:23cbfd4c17357c81021f21540da84ee282b9c8fba38a03b7b9d09ba6b951421e",
|
||||
"sha256:2483e4584a1cb3092da4470b38866634bafb223cbcd551ee047633fd2584599a",
|
||||
"sha256:27a8d92cd10f1382a67d7cf4db7ce18341b66438bdd9f691d7b0e48d104c2a9d",
|
||||
"sha256:28a650663f7314afc3e6ec620f44f333c386aad9f6fc472030865dc0ebb26ee3",
|
||||
"sha256:2aa0613a5177c264ff5921051a5719d20095ea586ca88cc802c5c218d1c67d3e",
|
||||
"sha256:2c194dd721e54ecad9ad387c1d35e63dce5c4450c6dc7dd5611283dda239aabb",
|
||||
"sha256:2d19e6e2095506d1736b7d80595e0f252d76b89f5e715c35e06e937679ea7d7a",
|
||||
"sha256:2d390634c5182175533585cc89f3608a4682ccb173cc9bb940b2881c8d6f8fa0",
|
||||
"sha256:30caa73029a225b2d40d9fae193e008e24b2026b7ee1a867b7ee8d96ca1a448e",
|
||||
"sha256:42c16925aa5a02362f986765f9ebabf20de75cdefdca827d14315c568dcab113",
|
||||
"sha256:45dbed2ab436a9e826e302fcdcbe9133f9b0006e5af7168afb8963a6520da103",
|
||||
"sha256:4636de7fd195197b7535f231b5de9e4b36d2c440b6e566d2e4e4746e6af0ca93",
|
||||
"sha256:4a19d9dba1a76618dd86b164d608566f393f8ec6ac7c44f0cc879011c45e65af",
|
||||
"sha256:4bbc7f303d125971f60ec0aaad5e12c62d0d2c925f0ab1273debd0e4ba37aba5",
|
||||
"sha256:4d6d57903571f86180eb98f8f0c839fa9ebbfb031356d87f1361be91e433f5b7",
|
||||
"sha256:4e874c976154687c1f71715b034739b45c7711bec81db01914770373d125e392",
|
||||
"sha256:51fc224f7ca4d92656d5a5eb315f12eb5fe2c97a66249aa7b5f562528a3be38c",
|
||||
"sha256:58c8b5929fcb8287cbd6f0a3fae19c6e03a5c48402ae792962ac465224a629a4",
|
||||
"sha256:5a285b3b96f951841799528cd1f4f01cd70e7e0204b4abebac9463eecfcf2a40",
|
||||
"sha256:5c70f1cc1c4efbe316a572e2d8b9b9cc44e89b95f79ca3331553fbb63716e2bf",
|
||||
"sha256:62d6b0f03b694173f9fcb1fb317f7222fd0b0b103e784c6549f5e53a27718c44",
|
||||
"sha256:6a246d5914aa1c820c9443ddcee9c02bec3e203b0c080349533fae17727dfd1b",
|
||||
"sha256:6aa3236c78803afbcb255045fbef97a9e25a1f6c9888357d205ddc42f4d6eba5",
|
||||
"sha256:6bbe4eb67390b0a0265a2c25458f6b90a409d5d069f1041e6aff1e27e3d9a79e",
|
||||
"sha256:715d1c092715954784bc79e1174fc2a90093dc4dc84ea15eb14dad8abdcdeb74",
|
||||
"sha256:72944b19f2324114e9dc86a159787333b77874143efcf89a5167ef83cfee8af0",
|
||||
"sha256:81f4a14bee47aec54f883e0cad2d73986640c1590eb9bfaaba7ad17394481e6e",
|
||||
"sha256:846300f379b5b12cc769334464656bc882e0735d27d9726568bc932fdc49d5ec",
|
||||
"sha256:86b6f55f5a352b48d7fbfd2dbc3d5b780b2d79f4d3c121f33eb6efb22e9a2015",
|
||||
"sha256:874f200b2a981c647340f841730fc3a2b54c9d940566a3c4149099591e2c4c3d",
|
||||
"sha256:8a87ec22c87be071b6bdbd27920b129b94f2fc964358ce38f3822635a3e2e03d",
|
||||
"sha256:8b3b60bb7cba2c8c81837661c488637eee696f59a877788a396d33150c35d842",
|
||||
"sha256:8e3ed142f2728df44263aaf5fb1f5b0b99f4070c553a0d7f033be65338329150",
|
||||
"sha256:93e15038125dc1e5345d9b5b68aa7f996ec33b98118d18c6ca0d0b7d6198b7e8",
|
||||
"sha256:989824e9faf85f96ec9c7761cd8d29c531ad857bfa1daa930cba85baaecf1a9a",
|
||||
"sha256:99d838547ace2c4aace6c4f76e879ddfe02bb58a80c1549928477862b7a6d6ed",
|
||||
"sha256:9b2aec6af35c113b05695ebb5749a787acd63cafc83086a05771d1e1cd1e555f",
|
||||
"sha256:9c585a1790d5436a5374bac930dad6ed244c046ed91b2b2a3634eb2971d21008",
|
||||
"sha256:a7164afb23be6e37ad90b2f10426149fd75aee07ca55653d2aa41e66c4ef697e",
|
||||
"sha256:ac6b31e35612a26483e20750126d30d0941f949426974cace8e6b5c58a3657b0",
|
||||
"sha256:ad2e2ef14e0b04e544ea2fa0a36463f847f113d314aa02e5b402fdf910ef309e",
|
||||
"sha256:b268594bccac7d7cf5844c7732e3f20c50921d94e36d7ec9b79e9857694b1b2f",
|
||||
"sha256:b5f0362dc928a6ecd9db58868fca5e48485205e3855957bdedea308f8672ea4a",
|
||||
"sha256:ba1f4fc670ed79f876f70082eff4f9583c15fb9a4b89d6188412de4d18ae2f40",
|
||||
"sha256:ba203255017337d39f89bdd58417f03c4426f12beed0440cfd933cb15f8669c7",
|
||||
"sha256:c901b15172510173f5cb310eae652908340f8dede90fff9e3bf6c0d8dfd92f83",
|
||||
"sha256:c9b39d38a9bd2ae1becd7eac1303d031c5c110ad31f2b319c6e7d98b135c934d",
|
||||
"sha256:d2a8490669bfe99a233298348acc2d824d496dee0e66e31b66a6022c2ad74a5c",
|
||||
"sha256:dddbbd259598d7240b18c9d87c56a9d2fb3b02fe266f49a7c101532e78c1d871",
|
||||
"sha256:df3775294accfdd75f32c74ae39fcba920c9a378a2fc18a12b6820aa8c1fb502",
|
||||
"sha256:e44319a2953c738205bf3354537979eaa3998ed673395b964c1176083dd46252",
|
||||
"sha256:e4a010c27ff6f210ff4c6ef34394cd61470d01014439b192ec22552ee867f2a8",
|
||||
"sha256:e823b8b6edc81e747526f70f71a9c0a07ac4e7ad13020aa736bb7c9d67196115",
|
||||
"sha256:e892aff75639bbef0d2a2cfd55535510df26ff92f63c92cd84ef8d4ba5a5557f",
|
||||
"sha256:eea7ac5d2dce4189771cedb559c738a71512768210dc4e4753b107a2048b3d0e",
|
||||
"sha256:ef4059d6e5152fa1a39f888e344c73fdc926e1b2dd58c771d67b0acfbf2aa67d",
|
||||
"sha256:f169b9a863d34f5d11b8698ead99febeaa17a13ca044961aa8e2662a6c7766a0",
|
||||
"sha256:f2cf083b324a467e1ab358c105f6cad5ea950f50524668a80c486ff1db24e119",
|
||||
"sha256:f8474c4241bc18b750be2abea9d7a9ec84f46ef861dbacf86a4f6e043401f79e",
|
||||
"sha256:f983334aea213c99992053ede6168500e5f086ce74fbc4acc3f2b00f5762e9db",
|
||||
"sha256:f9e75681b59ddaa5e659898085ae0eaea229d054f2ac0c7e563a62205a700121",
|
||||
"sha256:fbc356aae7adf9e6336d336b9c8111d390a05df88f1805573ebb0807bd06fd1d",
|
||||
"sha256:fcfe2045fd2e8f3cb0ce9d4ba6dba6333b8fa05bb8a4939c908cd43322d14c7e"
|
||||
],
|
||||
"index": "pypi",
|
||||
"markers": "python_version >= '3.11'",
|
||||
"version": "==2.4.4"
|
||||
},
|
||||
"outcome": {
|
||||
"hashes": [
|
||||
"sha256:9dcf02e65f2971b80047b377468e72a268e15c0af3cf1238e6ff14f7f91143b8",
|
||||
@@ -718,6 +804,19 @@
|
||||
],
|
||||
"version": "==2.4.0"
|
||||
},
|
||||
"sounddevice": {
|
||||
"hashes": [
|
||||
"sha256:05eb9fd6c54c38d67741441c19164c0dae8ce80453af2d8c4ad2e7823d15b722",
|
||||
"sha256:1234cc9b4c9df97b6cbe748146ae0ec64dd7d6e44739e8e42eaa5b595313a103",
|
||||
"sha256:22487b65198cb5bf2208755105b524f78ad173e5ab6b445bdab1c989f6698df3",
|
||||
"sha256:30ff99f6c107f49d25ad16a45cacd8d91c25a1bcdd3e81a206b921a3a6405b1f",
|
||||
"sha256:3861901ddd8230d2e0e8ae62ac320cdd4c688d81df89da036dcb812f757bb3e6",
|
||||
"sha256:cfc6b2c49fb7f555591c78cb8ecf48d6a637fd5b6e1db5fec6ed9365d64b3519"
|
||||
],
|
||||
"index": "pypi",
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==0.5.5"
|
||||
},
|
||||
"tibs": {
|
||||
"hashes": [
|
||||
"sha256:01ea5258bdf942d21560dc07d532082cd04f07cfef65fedd58ae84f7d0d2562a",
|
||||
@@ -1002,11 +1101,11 @@
|
||||
},
|
||||
"packaging": {
|
||||
"hashes": [
|
||||
"sha256:00243ae351a257117b6a241061796684b084ed1c516a08c48a3f7e147a9d80b4",
|
||||
"sha256:b36f1fef9334a5588b4166f8bcd26a14e521f2b55e6b9de3aaa80d3ff7a37529"
|
||||
"sha256:5fc45236b9446107ff2415ce77c807cee2862cb6fac22b8a73826d0693b0980e",
|
||||
"sha256:ff452ff5a3e828ce110190feff1178bb1f2ea2281fa2075aadb987c2fb221661"
|
||||
],
|
||||
"markers": "python_version >= '3.8'",
|
||||
"version": "==26.0"
|
||||
"version": "==26.2"
|
||||
},
|
||||
"pluggy": {
|
||||
"hashes": [
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
{"188b0e1560a8": {"id": "188b0e1560a8", "name": "led-188b0e1560a8", "type": "led", "transport": "wifi", "address": "10.1.1.192", "default_pattern": null, "zones": []}, "f0f5bdfb9d30": {"id": "f0f5bdfb9d30", "name": "led-f0f5bdfb9d30", "type": "led", "transport": "wifi", "address": "10.1.1.232", "default_pattern": null, "zones": []}}
|
||||
@@ -1 +1 @@
|
||||
{"1": {"name": "Main Group", "devices": ["1", "2", "3"]}, "2": {"name": "Accent Group", "devices": ["4", "5"]}}
|
||||
{"1": {"name": "group1", "devices": ["e8f60a16fb00", "e8f60a170794"], "wifi_driver_display_name": "desk", "wifi_driver_num_leds": 59, "wifi_color_order": "rgb", "wifi_startup_mode": "default", "pattern": "on", "colors": ["000000", "FF0000"], "brightness": 100, "delay": 100, "step_offset": 0, "step_increment": 1, "n1": 0, "n2": 0, "n3": 0, "n4": 0, "n5": 0, "n6": 0, "n7": 0, "n8": 0, "output_brightness": 255}, "2": {"name": "group2", "devices": ["188b0e1560a8"], "wifi_driver_display_name": null, "wifi_driver_num_leds": null, "wifi_color_order": "rgb", "wifi_startup_mode": "default", "output_brightness": 255, "pattern": "on", "colors": ["000000", "FF0000"], "brightness": 100, "delay": 100, "step_offset": 0, "step_increment": 1, "n1": 0, "n2": 0, "n3": 0, "n4": 0, "n5": 0, "n6": 0, "n7": 0, "n8": 0}}
|
||||
292
db/pattern.json
292
db/pattern.json
@@ -1 +1,291 @@
|
||||
{"on": {"min_delay": 10, "max_delay": 10000, "max_colors": 1}, "off": {"min_delay": 10, "max_delay": 10000, "max_colors": 0}, "rainbow": {"n1": "Step Rate", "min_delay": 10, "max_delay": 10000, "max_colors": 0}, "colour_cycle": {"n1": "Step Rate", "min_delay": 10, "max_delay": 10000, "max_colors": 10}, "transition": {"min_delay": 10, "max_delay": 10000, "max_colors": 10}, "chase": {"n1": "Colour 1 Length", "n2": "Colour 2 Length", "n3": "Step 1", "n4": "Step 2", "min_delay": 10, "max_delay": 10000, "max_colors": 2}, "pulse": {"n1": "Attack", "n2": "Hold", "n3": "Decay", "min_delay": 10, "max_delay": 10000, "max_colors": 10}, "circle": {"n1": "Head Rate", "n2": "Max Length", "n3": "Tail Rate", "n4": "Min Length", "min_delay": 10, "max_delay": 10000, "max_colors": 2}, "blink": {"min_delay": 10, "max_delay": 10000, "max_colors": 10}, "flicker": {"n1": "Min brightness", "min_delay": 10, "max_delay": 10000, "max_colors": 10}, "flame": {"n1": "Min brightness", "n2": "Breath period (ms)", "n3": "Spark gap min (ms, 0=default 10\u201330 s, -1=off)", "n4": "Spark gap max (ms)", "min_delay": 10, "max_delay": 10000, "max_colors": 10}, "twinkle": {"n1": "Twinkle activity (1\u2013255, higher = more changes)", "n2": "Density (0\u2013255, higher = more of the strip lit)", "n3": "Min adjacent LEDs per twinkle (same as max for fixed length)", "n4": "Max adjacent LEDs per twinkle (same as min for fixed length)", "min_delay": 10, "max_delay": 10000, "max_colors": 10}, "radiate": {"n1": "Node spacing (LEDs)", "n2": "Out time (ms)", "n3": "In time (ms)", "min_delay": 10, "max_delay": 10000, "max_colors": 2}, "meteor_rain": {"n1": "Tail length", "n2": "Speed (LEDs per frame)", "n3": "Fade amount (1-255)", "min_delay": 10, "max_delay": 10000, "max_colors": 10}, "scanner": {"n1": "Eye width", "n2": "End pause (frames)", "min_delay": 10, "max_delay": 10000, "max_colors": 10}, "gradient_scroll": {"n1": "Scroll step rate", "min_delay": 10, "max_delay": 10000, "max_colors": 10}, "comet_dual": {"n1": "Tail length", "n2": "Speed", "n3": "Gap", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "sparkle_trail": {"n1": "Spark density", "n2": "Decay", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "wave": {"n1": "Wavelength", "n2": "Amplitude", "n3": "Drift speed", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "plasma": {"n1": "Scale", "n2": "Speed", "n3": "Contrast", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "segment_chase": {"n1": "Segment size", "n2": "Phase step", "n3": "Segment phase offset", "n4": "Gap per segment", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "bar_graph": {"n1": "Level percent", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "breathing_dual": {"n1": "Phase offset", "n2": "Ease", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "strobe_burst": {"n1": "Burst count", "n2": "Burst gap", "n3": "Cooldown", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "rain_drops": {"n1": "Drop rate", "n2": "Ripple width", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "fireflies": {"n1": "Count", "n2": "Twinkle speed", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "clock_sweep": {"n1": "Hand width", "n2": "Marker interval", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "marquee": {"n1": "On length", "n2": "Off length", "n3": "Step", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "aurora": {"n1": "Band count", "n2": "Shimmer", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "snowfall": {"n1": "Flake density", "n2": "Fall speed", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "heartbeat": {"n1": "Pulse 1 ms", "n2": "Pulse 2 ms", "n3": "Pause ms", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "orbit": {"n1": "Orbit count", "n2": "Base speed", "max_colors": 10, "min_delay": 10, "max_delay": 10000}, "palette_morph": {"n1": "Morph ms", "n2": "Warp rate", "n3": "Turbulence", "max_colors": 10, "min_delay": 10, "max_delay": 10000}}
|
||||
{
|
||||
"on": {
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"max_colors": 1,
|
||||
"supports_manual": true
|
||||
},
|
||||
"off": {
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"max_colors": 0,
|
||||
"supports_manual": true
|
||||
},
|
||||
"rainbow": {
|
||||
"n1": "Step Rate",
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"max_colors": 0,
|
||||
"supports_manual": true
|
||||
},
|
||||
"colour_cycle": {
|
||||
"n1": "Step Rate",
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"max_colors": 10,
|
||||
"supports_manual": true
|
||||
},
|
||||
"transition": {
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"max_colors": 10,
|
||||
"supports_manual": false
|
||||
},
|
||||
"chase": {
|
||||
"n1": "Colour 1 Length",
|
||||
"n2": "Colour 2 Length",
|
||||
"n3": "Step 1",
|
||||
"n4": "Step 2",
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"max_colors": 2,
|
||||
"has_background": true,
|
||||
"supports_manual": true
|
||||
},
|
||||
"pulse": {
|
||||
"n1": "Attack",
|
||||
"n2": "Hold",
|
||||
"n3": "Decay",
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"max_colors": 10,
|
||||
"has_background": true,
|
||||
"supports_manual": true
|
||||
},
|
||||
"circle": {
|
||||
"n1": "Head Rate",
|
||||
"n2": "Max Length",
|
||||
"n3": "Tail Rate",
|
||||
"n4": "Min Length",
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"max_colors": 2,
|
||||
"has_background": true,
|
||||
"supports_manual": false
|
||||
},
|
||||
"blink": {
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"max_colors": 10,
|
||||
"has_background": true,
|
||||
"supports_manual": false
|
||||
},
|
||||
"flicker": {
|
||||
"n1": "Min brightness",
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"max_colors": 10,
|
||||
"supports_manual": true
|
||||
},
|
||||
"flame": {
|
||||
"n1": "Min brightness",
|
||||
"n2": "Breath period (ms)",
|
||||
"n3": "Spark gap min (ms, 0=default 10–30 s, -1=off)",
|
||||
"n4": "Spark gap max (ms)",
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"max_colors": 10,
|
||||
"supports_manual": false
|
||||
},
|
||||
"twinkle": {
|
||||
"n1": "Twinkle activity (1–255, higher = more changes)",
|
||||
"n2": "Density (0–255, higher = more of the strip lit)",
|
||||
"n3": "Min adjacent LEDs per twinkle (same as max for fixed length)",
|
||||
"n4": "Max adjacent LEDs per twinkle (same as min for fixed length)",
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"max_colors": 10,
|
||||
"has_background": true,
|
||||
"supports_manual": true
|
||||
},
|
||||
"radiate": {
|
||||
"n1": "Node spacing (LEDs)",
|
||||
"n2": "Out time (ms)",
|
||||
"n3": "In time (ms)",
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"max_colors": 10,
|
||||
"has_background": true,
|
||||
"supports_manual": true
|
||||
},
|
||||
"meteor_rain": {
|
||||
"n1": "Tail length",
|
||||
"n2": "Speed (LEDs per frame)",
|
||||
"n3": "Fade amount (1-255)",
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"max_colors": 10,
|
||||
"supports_manual": true
|
||||
},
|
||||
"scanner": {
|
||||
"n1": "Eye width",
|
||||
"n2": "End pause (frames)",
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"max_colors": 10,
|
||||
"has_background": true,
|
||||
"supports_manual": true
|
||||
},
|
||||
"gradient_scroll": {
|
||||
"n1": "Scroll step rate",
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"max_colors": 10,
|
||||
"supports_manual": true
|
||||
},
|
||||
"comet_dual": {
|
||||
"n1": "Tail length",
|
||||
"n2": "Speed",
|
||||
"n3": "Gap",
|
||||
"max_colors": 10,
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"has_background": true,
|
||||
"supports_manual": true
|
||||
},
|
||||
"sparkle_trail": {
|
||||
"n1": "Spark density",
|
||||
"n2": "Decay",
|
||||
"max_colors": 10,
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"supports_manual": true
|
||||
},
|
||||
"wave": {
|
||||
"n1": "Wavelength",
|
||||
"n2": "Amplitude",
|
||||
"n3": "Drift speed",
|
||||
"max_colors": 10,
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"supports_manual": false
|
||||
},
|
||||
"plasma": {
|
||||
"n1": "Scale",
|
||||
"n2": "Speed",
|
||||
"n3": "Contrast",
|
||||
"max_colors": 10,
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"supports_manual": false
|
||||
},
|
||||
"segment_chase": {
|
||||
"n1": "Segment size",
|
||||
"n2": "Phase step",
|
||||
"n3": "Segment phase offset",
|
||||
"n4": "Gap per segment",
|
||||
"max_colors": 10,
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"has_background": true,
|
||||
"supports_manual": true
|
||||
},
|
||||
"bar_graph": {
|
||||
"n1": "Level percent",
|
||||
"max_colors": 10,
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"has_background": true,
|
||||
"supports_manual": false
|
||||
},
|
||||
"breathing_dual": {
|
||||
"n1": "Phase offset",
|
||||
"n2": "Ease",
|
||||
"max_colors": 10,
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"supports_manual": false
|
||||
},
|
||||
"strobe_burst": {
|
||||
"n1": "Burst count",
|
||||
"n2": "Burst gap",
|
||||
"n3": "Cooldown",
|
||||
"max_colors": 10,
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"has_background": true,
|
||||
"supports_manual": true
|
||||
},
|
||||
"rain_drops": {
|
||||
"n1": "Drop rate",
|
||||
"n2": "Ripple width",
|
||||
"max_colors": 10,
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"has_background": true,
|
||||
"supports_manual": true
|
||||
},
|
||||
"fireflies": {
|
||||
"n1": "Count",
|
||||
"n2": "Twinkle speed",
|
||||
"max_colors": 10,
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"has_background": true,
|
||||
"supports_manual": true
|
||||
},
|
||||
"clock_sweep": {
|
||||
"n1": "Hand width",
|
||||
"n2": "Marker interval",
|
||||
"max_colors": 10,
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"has_background": true,
|
||||
"supports_manual": true
|
||||
},
|
||||
"marquee": {
|
||||
"n1": "On length",
|
||||
"n2": "Off length",
|
||||
"n3": "Step",
|
||||
"max_colors": 10,
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"has_background": true,
|
||||
"supports_manual": true
|
||||
},
|
||||
"aurora": {
|
||||
"n1": "Band count",
|
||||
"n2": "Shimmer",
|
||||
"max_colors": 10,
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"supports_manual": false
|
||||
},
|
||||
"snowfall": {
|
||||
"n1": "Flake density",
|
||||
"n2": "Fall speed",
|
||||
"max_colors": 10,
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"has_background": true,
|
||||
"supports_manual": true
|
||||
},
|
||||
"heartbeat": {
|
||||
"n1": "Pulse 1 ms",
|
||||
"n2": "Pulse 2 ms",
|
||||
"n3": "Pause ms",
|
||||
"max_colors": 10,
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"has_background": true,
|
||||
"supports_manual": true
|
||||
},
|
||||
"orbit": {
|
||||
"n1": "Orbit count",
|
||||
"n2": "Base speed",
|
||||
"max_colors": 10,
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"has_background": true,
|
||||
"supports_manual": true
|
||||
},
|
||||
"palette_morph": {
|
||||
"n1": "Morph ms",
|
||||
"n2": "Warp rate",
|
||||
"n3": "Turbulence",
|
||||
"max_colors": 10,
|
||||
"min_delay": 10,
|
||||
"max_delay": 10000,
|
||||
"supports_manual": false
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
BIN
db/presets/1.bin
Normal file
BIN
db/presets/1.bin
Normal file
Binary file not shown.
3
db/presets/10.bin
Normal file
3
db/presets/10.bin
Normal file
@@ -0,0 +1,3 @@
|
||||
PRST1xœ%ÎÁ
|
||||
Â0Ð_‘ñšCSµJîæ'D$¶«
|
||||
ÄÝ’¦ˆˆÿntOovæ²opxz‘´zޱ¦P
|
||||
2
db/presets/11.bin
Normal file
2
db/presets/11.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1xњ%ОAВ …б»<·,J5\Е4
|
||||
К $84SX4Ж»‹eхеНlюШЅ B
|
||||
1
db/presets/12.bin
Normal file
1
db/presets/12.bin
Normal file
@@ -0,0 +1 @@
|
||||
PRST1xœ%ÎA л|·, ŠÐK˜ÆP;*
|
||||
2
db/presets/13.bin
Normal file
2
db/presets/13.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1xœEÎÁ
|
||||
Â0Ð_‘9ç`«Qɯˆ”Ô®ˆ»e“RDüwsðô˜™Ë¼ÁñIИx”uS²¬p˜c¤ü¬»J-ç‹Ã¨éþ¨LÅrï½ÃD9¾:¿uˆK„ª9pg¥Ñ#ØÂ»Æ¾á‡Æ±qú1«ÜR¦!Mö¡Ãç<0B><>1
|
||||
2
db/presets/14.bin
Normal file
2
db/presets/14.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1xœ=ÎÝ
|
||||
!†á[‰¯StK[¼€½‰ˆ°v*ÁTü!"º÷Ü¤Žžá<C5BE>9˜¼¹4bu™VÙ…¢)…’ÿåVÎÁ…”¡÷XO“RœãÀpJöz+žr[R2ÌäÌzäœÁÔ KªÄàE;àKõ´èÓæß¶Ð²£:»Îø%¦p±ŽŽvn? ¼?<3F>¨2ú
|
||||
BIN
db/presets/15.bin
Normal file
BIN
db/presets/15.bin
Normal file
Binary file not shown.
BIN
db/presets/2.bin
Normal file
BIN
db/presets/2.bin
Normal file
Binary file not shown.
2
db/presets/3.bin
Normal file
2
db/presets/3.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1xœUÎÁ
|
||||
Â0ЙsM5Uò+"²µ«â¦lSDÄwiNž³3‡ý@èɈPJ2–fª•Uþn×’‹.ˆ§³Ã¨éþ¨Â‹å>‡‰3½}×9ÐZbÕ•ÄÛÀè‘]cß<08>¡qh7f-·”ù’&ûÁãûF9/.
|
||||
2
db/presets/30.bin
Normal file
2
db/presets/30.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1xœEÎÁ
|
||||
Â0Ð_‘9ç`«Qɯˆ”Ô®ˆ»e“RDüwsðô˜™Ë¼ÁñIИx”uS²¬p˜c¤ü¬»J-ç‹Ã¨éþ¨LÅrï½ÃD9¾:¿uˆK„ª9pg¥Ñ#ØÂ»Æ¾á‡Æ±qú1«ÜR¦!Mö¡Çç<0B>“1
|
||||
BIN
db/presets/31.bin
Normal file
BIN
db/presets/31.bin
Normal file
Binary file not shown.
2
db/presets/32.bin
Normal file
2
db/presets/32.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1xœ%ͽÂ0àW©Ž5C~•&VÆ
|
||||
¡@<40>)uª4K…xwR<}ç»Á° —ks<DjÎ)¦…É•B™ë–¸ž¯µža;l¼×Ú{Üž9ïÂ4×ÁÐStl«kævÅ[a'ì…ƒpN¦œ|ˆô}ýmðý‡-‰
|
||||
1
db/presets/33.bin
Normal file
1
db/presets/33.bin
Normal file
@@ -0,0 +1 @@
|
||||
PRST1xœMÎ1!†á¿b¾[=5ÌNÎnÆô@I°\€Åÿ»Å.²<oÚ¼Aîéa±?,ŽÅQ<C385>-f‚ÂìZó…xÓþÇ·œr©°'!h~<´î-Õg…k‰÷G#_ùØ0ùä^Ü#7-a;FX ka6ÂVØý˜K1ùKœø_Ÿ/ÐM4y
|
||||
BIN
db/presets/34.bin
Normal file
BIN
db/presets/34.bin
Normal file
Binary file not shown.
2
db/presets/35.bin
Normal file
2
db/presets/35.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1xœ%ͽÂ0àW©Ž5C~•&VÆ
|
||||
¡@<40>)uª4K…xwR<}ç»Á° —ks<DjÎ)¦…É•B™ë–¸ž¯µža;l¼×Ú{Üž9ïÂ4×ÁÐStl«kævÅ[a'ì…ƒpN¦œ|ˆô}ýmðý‡-‰
|
||||
1
db/presets/36.bin
Normal file
1
db/presets/36.bin
Normal file
@@ -0,0 +1 @@
|
||||
PRST1xœMÎ1!†á¿b¾[=5ÌNÎnÆô@I°\€Åÿ»Å.²<oÚ¼Aîéa±?,ŽÅQ<C385>-f‚ÂìZó…xÓþÇ·œr©°'!h~<´î-Õg…k‰÷G#_ùØ0ùä^Ü#7-a;FX ka6ÂVØý˜K1ùKœø_Ÿ/ÐM4y
|
||||
BIN
db/presets/37.bin
Normal file
BIN
db/presets/37.bin
Normal file
Binary file not shown.
BIN
db/presets/38.bin
Normal file
BIN
db/presets/38.bin
Normal file
Binary file not shown.
3
db/presets/39.bin
Normal file
3
db/presets/39.bin
Normal file
@@ -0,0 +1,3 @@
|
||||
PRST1xœUÎÁ‚0„áw¯=¤jú*†<>
|
||||
[m\[²”ƒ1¾»…ž<}ÉÌåÿ ºÁÂsŸ$P˜]Î$ño'Y`¯88ÒÚ{ô
|
||||
7 ÷GŽ´”£5Fa"voX£Üšl–•bÛè2ÆvãXé*¦rªœ+—<>Y’LC˜JM³·1•ºAÈo5qeî¿?ªð9±
|
||||
BIN
db/presets/4.bin
Normal file
BIN
db/presets/4.bin
Normal file
Binary file not shown.
4
db/presets/40.bin
Normal file
4
db/presets/40.bin
Normal file
@@ -0,0 +1,4 @@
|
||||
PRST1xśMÎÁ‚0„áwŻ=$ű*†<>
|
||||
[%Y[RÚ1ľ»…^<}ÉĚĺ˙Ŕ™7<E284A2>`ĺPa51rpËäŇ
|
||||
tÇĹÚ©×<1A>Â#,ĎWtĽĺŁŞ{…™Ĺě V+<2B>=(†Ä
|
||||
®5m¶ŐťÎŻk@×B[č
|
||||
2
db/presets/41.bin
Normal file
2
db/presets/41.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1xśmŹÁ‚0†ßĄ\wČ`ŮMQ^Â2ĄčâÜČ1ĆřînĚ‹‰—~í—?Mű#ďüC™›F 0IďŃ™w¶ÚşÄ˛š7Ľm<C4BD>ËĺMęveýuUąo<v[şć:'§.Wop
|
||||
ƨĺDN)ąx» <09><H¤)B2r"˘Śá@–Ć*ˇNŕ+&gGĄ±WC8<_ßĐéŽńpłhMţ”îýŹ!I°
|
||||
2
db/presets/42.bin
Normal file
2
db/presets/42.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1xњUЋ;В0птТєp>°WAQґђ5X2Nд8BЬ;©hv¤·SМЃ_BдЙq(,њ’Др·Эg?ЗtEЕЅЦЦжТZіf
|
||||
·иПdНJcЊВ$ћЯ “ЮТJq…PѓЪј…t)ПР‚є]ЁАињњw,q¶ОЛи¦\Wп^rнЕ–є°yЇКѕ?Эh>Ў
|
||||
BIN
db/presets/43.bin
Normal file
BIN
db/presets/43.bin
Normal file
Binary file not shown.
2
db/presets/44.bin
Normal file
2
db/presets/44.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1xœEÎM
|
||||
Â0à«Ès›Eÿ¢’ôE$¶£â¤$Ó…ˆww0góÁ{o1o°„ŠìÊì™)Ã`õ"”Y‹6§˜r<CB9C>›°ÇFgƒk÷‡0-:k
|
||||
3
db/presets/45.bin
Normal file
3
db/presets/45.bin
Normal file
@@ -0,0 +1,3 @@
|
||||
PRST1xœ=ŽA‚0E¯B>Û.
|
||||
*š€KC*ŒØ¤¶¤Æxw<1B>Í{™7‹y!ØÁ€)s5';9
|
||||
\å1Eï¡°XfJA~mø·1ú˜2ÌußkÙÕZo^ls\®ÉÍw”å¸mµÂDÞ>a:Q»r„á´’Bh¤Z)aW°/8tÇ‚ÓKŠ7çip“üÙàý)<¡
|
||||
3
db/presets/46.bin
Normal file
3
db/presets/46.bin
Normal file
@@ -0,0 +1,3 @@
|
||||
PRST1xś-ÎÁ‚0Đ_!õ‡Šdo˝ô'Ś!Ş’”–”ĺ`Ś˙î<˝ÍĚö<>čfű•‹!Íž‹qs
|
||||
‹cö9J·Çý?RHy]QZkŚÖ’•Zc-n
|
||||
÷<=_ý*“Zk…Ń÷µrşŤ<13>óćbę„T
|
||||
2
db/presets/47.bin
Normal file
2
db/presets/47.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1x<EFBFBD>5־A‚0…ב«<D791>ַ¶@Dׂ- —0ֶT©<54>X[2ֶxwG׳ש&»˜‚yXh°M\₪<>׀<EFBFBD><D780>‚ֹ8…<>0[
|
||||
’ור/חט#%ט=ֺ¾†q”·r\…¹כ<C2B9>ƒMע¥©*…ֹzף„מd5Gh¦ֵ*„Zz+6b-1l ¿´™m¦ֻל2ֺLסגה"7ֹy5<79>־ד:G
|
||||
2
db/presets/48.bin
Normal file
2
db/presets/48.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1xœ-ÎÁ Ð_1ã•ÔZŽúÆ´«’ 4°Õã¿»Š§7;sÙ¢»,˜
|
||||
/îNP˜3å(í¿8¥<38>r<EFBFBD>Ýa©õ¶ìŽÙ_®©ÈÐh0RpOØN¢›9ÁržI!XÓˆ<C393>ØËW„ö{+]eSéL9<4C>} ƒåƒ÷ªù0¿
|
||||
2
db/presets/49.bin
Normal file
2
db/presets/49.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1x<EFBFBD>=ЮA
|
||||
Т0аЋШw<D0A8>EZ5JаK<14>б<EFBFBD>ZH<5A><48>L"онС<D0BD>Ћ7ќџѓFЄ<46>с!\e<>е<>`<60>I<EFBFBD>KдќнRHЅТ<D085>и<0E>ЕЮсlp-ѓу)<29>ЋНЕzС;=i<>/ee<65>иiІє:Sv<53>=МютЁсЧЦщG.щ>ОЬ<D09E>Овсѓ,<2C>1И
|
||||
BIN
db/presets/5.bin
Normal file
BIN
db/presets/5.bin
Normal file
Binary file not shown.
2
db/presets/50.bin
Normal file
2
db/presets/50.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1xœ5ÎA‚0Ы<C390>϶‹‚ˆ¦è%Œ!F <20>–´ÃÂïîhu6o2ÿ/æ ïV‚Sâ"Ѹ’碟\"(lŽ™¢—ø—tÿ¤Kˆ æ‚ÒZ-#·ò£µ¸*Üâ<Nì)I¥ÖZa Å=`ZYÝΆãN
|
||||
¾‚i„¦0RðMæ˜i3§ÌùËÃ}^¨›ùÂë
|
||||
BIN
db/presets/51.bin
Normal file
BIN
db/presets/51.bin
Normal file
Binary file not shown.
BIN
db/presets/52.bin
Normal file
BIN
db/presets/52.bin
Normal file
Binary file not shown.
2
db/presets/53.bin
Normal file
2
db/presets/53.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1xœ5Î=Â0†á«Tk†þQ<C3BE>À%*T%Ô@¥’TŽ; ÄÝIáå±ôzðÞ¾å¨ET Ž·JT,V•ŧšÃð·0‰ ‡Ë>¸8™OõS¨ËÒ`äÙ¾A]Zíª¤²²<C2B2>¯@M¢ÎÉ7 v;÷-hã˜é2§Ìyg‘pŸf¦1ýTáû^
|
||||
7˜
|
||||
3
db/presets/54.bin
Normal file
3
db/presets/54.bin
Normal file
@@ -0,0 +1,3 @@
|
||||
PRST1x<EFBFBD>5ΞΝ
|
||||
Β0ΰW)γ5‡ώhΉϊ"%ΪU5)›νAΔww5xϊ–™9μΑ=BI
|
||||
v>Η%Α`q"ΔA»o<ώγK<CEB3>#'Ψ#6‡²ο†'ƒ3ϋΫ]%-κ²4<C2B2>hvOΨVO·J„^Ι T°MΦ<C2AD><CEA6>ΐκ"l3»L›ΩgΊΗ«<CE97>iτ“ώSαύ<01><>5%
|
||||
4
db/presets/55.bin
Normal file
4
db/presets/55.bin
Normal file
@@ -0,0 +1,4 @@
|
||||
PRST1xœMαÂ0Ð_A×5CZ ´™Q~!¨‘BR%î€ÿŽE¦gÝÝà7¢{˜
|
||||
ofŸiž
|
||||
ÇL9JõŸÞRH¹ÀœÐX{Ô½–¬µµ£ÆYášýýÁ‘ŠL:&
|
||||
îÓËéVN0œWRˆdB3[Ä]e_é+‡ÊðcÉiö<69>.~’¿Z|¾¡ 61
|
||||
1
db/presets/56.bin
Normal file
1
db/presets/56.bin
Normal file
@@ -0,0 +1 @@
|
||||
PRST1xœ5ŽAƒ E¯b¾[¨U+WiŒ¡2¶¦`š¦éÝ’nxÌ›Y¼Œ|ùPÌÚÎ<C39A>¿ˆ60l2r&.?ýýlµuâ‚Rõ|àCt%Wuß5®n½Ýƒ!OjÎiùN¹ÜN¦‚¨¢35DÑ@¤é”Ñft}ÆùÀæì²jšVÓª#TSL<53>-)ËìZ³ôŒßQ•AÓ
|
||||
1
db/presets/57.bin
Normal file
1
db/presets/57.bin
Normal file
@@ -0,0 +1 @@
|
||||
PRST1xњEО1В0Р« ПљЎiЎ ЂK „5)MЪФвоXНЂ—gщяБD72В‹lF—зВѓЙ‰pЋьoчR^@glOлаbpЛющ’И‹mУЬФлкЉ$ђдВС‚:ҐХљТЃ¬Іi/о+}еP9®L9=|а«ф‹пжg2д
|
||||
2
db/presets/58.bin
Normal file
2
db/presets/58.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1xœ=ÎÍ
|
||||
Â0àW‘é5‡ô?ìM"} ‰vÕBMJ’D|wSž¾afû†5O!rˆ;³zç
|
||||
3
db/presets/59.bin
Normal file
3
db/presets/59.bin
Normal file
@@ -0,0 +1,3 @@
|
||||
PRST1x°Mна
|
||||
б0ЮW▒вз╘SzTЯ%D╓╨L╣m├┬ЬНfКе\╬ДOЫ ╦'а┌)С"┤ЬЙ°ВP3╔ ⌡©П}LЖ└Й8≈dуNЖр²╝╘©?8P√⌠Zk┘√╪{ц6р╨▒#,╖▒┌≥Жb
|
||||
k└%Л4╜
|
||||
2
db/presets/6.bin
Normal file
2
db/presets/6.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1xœMÎK
|
||||
Â0…á½§ÜT£’tR$Ú«âMÉc âÞm<C39E>ˆ£þ39Oˆ»3,¦2Car¥p’¿rŽ!¦{ÀЍï‰0(œ’¿ÞŠpž‡Î…‘ƒ{À"WK„-©²‚hXMK•î;Ëú—6°¦±mìûSŠøèÇù’Æë
|
||||
4
db/presets/60.bin
Normal file
4
db/presets/60.bin
Normal file
@@ -0,0 +1,4 @@
|
||||
PRST1xœMÎA‚0Ы˜ï¶‹RÉ€KcŠŒBR[Òc¼»l\½Éÿùɼáí“ANr˜ÙFÙ
|
||||
V+ÂÑçê?½b
|
||||
8ö½éj<EFBFBD>‹Â—Ç,žS.ŒÖ
|
||||
;ûµù´›<04>Ä<EFBFBD>|ªL½uŨ)_ƒ
|
||||
BIN
db/presets/61.bin
Normal file
BIN
db/presets/61.bin
Normal file
Binary file not shown.
3
db/presets/62.bin
Normal file
3
db/presets/62.bin
Normal file
@@ -0,0 +1,3 @@
|
||||
PRST1xœ5ŽA‚0E¯B>Û.
|
||||
*š€KCªŒBRÚ¦c¼»ÅÙ¼7óÿb>ðv"0Í\D눙Š)¤8@!ZÙ’—xOºò.¤æŠ²mµŒÜJW϶:n
|
||||
÷4¾ö4K¹ÖZ¡'gß0<C39F>¨]8ÀpZHÁW0ÕVðõÞô˜ÇŒSF“qθlˆ)<GGÝØË«¾?ð¹<
|
||||
3
db/presets/7.bin
Normal file
3
db/presets/7.bin
Normal file
@@ -0,0 +1,3 @@
|
||||
PRST1xœMŽ1Â0Eïò»fp
|
||||
<EFBFBD>(K/<2F>
|
||||
<EFBFBD>H!©Òt@ˆ»cÈÂô¾Ÿ¿%¿<>üƒá0†2F†Âìkå’þÕ˜c.ÜÝ0‘¸Î‘%œ.%Üî5ñ"•Þ…‰£J&RðkÍpµ¬¬<C2AC>´HA§e•6mÜÂÉQ2p_¹kØ7Øæ’¯!ò9Lò–Æû¼Ã1ó
|
||||
BIN
db/presets/8.bin
Normal file
BIN
db/presets/8.bin
Normal file
Binary file not shown.
2
db/presets/9.bin
Normal file
2
db/presets/9.bin
Normal file
@@ -0,0 +1,2 @@
|
||||
PRST1xœ%ÎK
|
||||
Ã0Ы”éÖ‹$ýâ«”ÜFnŽ›PJï^ÇÖæI£Í|Áf&hlFæÃ6¹HPXLŒ$œãÀù|d…~àhË WxŠ{O‘iÍ<69>®iFòæÝî»I1@GI¤À-tޏ«œ*çÊ¥rÜ*÷Â"Á:Oƒs<>¶´ò”{
|
||||
@@ -1 +1 @@
|
||||
{"1": {"group_name": "Main Group", "presets": ["1", "2"], "sequence_duration": 3000, "sequence_transition": 500, "sequence_loop": true, "sequence_repeat_count": 0, "sequence_active": false, "sequence_index": 0, "sequence_start_time": 0}, "2": {"group_name": "Accent Group", "presets": ["2", "3"], "sequence_duration": 2000, "sequence_transition": 300, "sequence_loop": true, "sequence_repeat_count": 0, "sequence_active": false, "sequence_index": 0, "sequence_start_time": 0}}
|
||||
{"1": {"group_name": "Main Group", "presets": ["1", "2"], "sequence_duration": 3000, "sequence_transition": 500, "sequence_loop": true, "sequence_repeat_count": 0, "sequence_active": false, "sequence_index": 0, "sequence_start_time": 0, "steps": [], "step_duration_ms": 3000, "loop": true, "name": "Main Group", "profile_id": "1", "lanes": [[{"preset_id": "42", "beats": 6}, {"preset_id": "5", "beats": 2}], [{"preset_id": "6", "beats": 1}]], "group_ids": ["1"], "advance_mode": "beats", "lanes_group_ids": [["1"], ["2"]]}, "2": {"group_name": "Accent Group", "presets": ["2", "3"], "sequence_duration": 2000, "sequence_transition": 300, "sequence_loop": true, "sequence_repeat_count": 0, "sequence_active": false, "sequence_index": 0, "sequence_start_time": 0, "steps": [{"preset_id": "2", "group_ids": [], "beats": 1}, {"preset_id": "3", "group_ids": [], "beats": 1}], "step_duration_ms": 2000, "loop": true, "name": "Accent Group", "profile_id": "1", "lanes": [[{"preset_id": "2", "group_ids": [], "beats": 1}, {"preset_id": "3", "group_ids": [], "beats": 1}]], "group_ids": [], "advance_mode": "time", "lanes_group_ids": [[]]}}
|
||||
@@ -1 +0,0 @@
|
||||
{"1": {"name": "default", "names": ["led-188b0e1560a8", "led-f0f5bdfb9d30"], "presets": [["4", "2", "7"], ["3", "14", "5"], ["8", "9", "1"], ["6", "38", "42"], ["39", "40", "41"], ["43", "44", "45"], ["46", "47", "48"], ["49", "50", "51"], ["52", "53", "54"], ["55", "56", "57"], ["58", "59", "60"], ["61", "62"]], "presets_flat": ["4", "2", "7", "3", "14", "5", "8", "9", "1", "6", "38", "42", "39", "40", "41", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62"], "default_preset": "41"}, "2": {"name": "default", "names": ["1", "2", "3", "4", "5", "6", "7", "8", "0", "a"], "presets": [["16", "17", "18"], ["19", "20", "21"], ["22", "23", "24"], ["25", "26", "27"], ["28", "29", "30"]], "presets_flat": ["16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30"]}, "3": {"name": "default", "names": ["1"], "presets": [], "default_preset": null}, "4": {"name": "default", "names": ["1"], "presets": [], "default_preset": null}, "5": {"name": "dj", "names": ["dj"], "presets": [["31", "32", "33"]], "default_preset": "31", "presets_flat": ["31", "32", "33"]}, "6": {"name": "default", "names": ["1"], "presets": [], "default_preset": null, "presets_flat": []}, "7": {"name": "dj", "names": ["dj"], "presets": [["34", "35", "36"]], "default_preset": "34", "presets_flat": ["34", "35", "36"]}, "8": {"name": "test", "names": ["led-188b0e1560a8"], "presets": [["1", "2", "3"], ["4", "5"]], "default_preset": "1", "presets_flat": ["1", "2", "3", "4", "5"]}}
|
||||
@@ -42,7 +42,7 @@ Profiles are selected with **`POST /profiles/<id>/apply`**, which sets `current_
|
||||
| Method | Path | Description |
|
||||
|--------|------|-------------|
|
||||
| GET | `/` | Main UI (`templates/index.html`) |
|
||||
| GET | `/settings` | Settings page (`templates/settings.html`) |
|
||||
| GET | `/settings/page` | Standalone settings page (`templates/settings.html`) |
|
||||
| GET | `/favicon.ico` | Empty response (204) |
|
||||
| GET | `/static/<path>` | Static files under `src/static/` |
|
||||
|
||||
@@ -72,7 +72,7 @@ Below, `<id>` values are string identifiers used by the JSON stores (numeric str
|
||||
| PUT | `/settings/settings` | Merge keys into settings and save. Returns `{"message": "Settings updated successfully"}`. |
|
||||
| GET | `/settings/wifi/ap` | Saved Wi‑Fi AP fields: `saved_ssid`, `saved_password`, `saved_channel`, `active` (Pi: `active` is always false). |
|
||||
| POST | `/settings/wifi/ap` | Body: `ssid` (required), `password`, `channel` (1–11). Persists AP-related settings. |
|
||||
| GET | `/settings/page` | Serves `templates/settings.html` (same page as `GET /settings` from the root app, for convenience). |
|
||||
| GET | `/settings/page` | Serves `templates/settings.html`. |
|
||||
|
||||
### Devices — `/devices`
|
||||
|
||||
|
||||
7
espnow-sender/README.md
Normal file
7
espnow-sender/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# espnow-sender
|
||||
|
||||
Minimal MicroPython project for receiving JSON over Microdot WebSocket.
|
||||
|
||||
- WebSocket endpoint: `/ws`
|
||||
- Entry point: `main.py`
|
||||
- Message template: `msg.json`
|
||||
120
espnow-sender/main.py
Normal file
120
espnow-sender/main.py
Normal file
@@ -0,0 +1,120 @@
|
||||
import asyncio
|
||||
import json
|
||||
|
||||
from microdot import Microdot
|
||||
from microdot.websocket import WebSocketError, with_websocket
|
||||
|
||||
import espnow
|
||||
import network
|
||||
from util import format_mac, parse_mac
|
||||
|
||||
|
||||
app = Microdot()
|
||||
_esp = None
|
||||
_known_peers = set()
|
||||
_ws_clients = set()
|
||||
|
||||
|
||||
def _init_espnow():
|
||||
global _esp
|
||||
sta = network.WLAN(network.STA_IF)
|
||||
sta.active(True)
|
||||
_esp = espnow.ESPNow()
|
||||
_esp.active(True)
|
||||
|
||||
|
||||
def _validate_envelope(obj):
|
||||
if obj.get("v") != "1":
|
||||
raise ValueError("message.v must be '1'")
|
||||
devices = obj["devices"]
|
||||
for address in devices.keys():
|
||||
parse_mac(address)
|
||||
return obj
|
||||
|
||||
|
||||
def _send_espnow(address, payload):
|
||||
if _esp is None:
|
||||
raise ValueError("espnow is not initialized")
|
||||
mac = parse_mac(address)
|
||||
msg = json.dumps(payload, separators=(",", ":")).encode("utf-8")
|
||||
if mac not in _known_peers:
|
||||
_esp.add_peer(mac)
|
||||
_known_peers.add(mac)
|
||||
_esp.send(mac, msg)
|
||||
return mac, len(msg)
|
||||
|
||||
|
||||
async def _broadcast_ws(obj):
|
||||
text = json.dumps(obj)
|
||||
dead = []
|
||||
for client in list(_ws_clients):
|
||||
try:
|
||||
await client.send(text)
|
||||
except Exception:
|
||||
dead.append(client)
|
||||
for client in dead:
|
||||
_ws_clients.discard(client)
|
||||
|
||||
|
||||
async def _espnow_receive_loop():
|
||||
while True:
|
||||
host, msg = _esp.recv(0)
|
||||
if not host:
|
||||
await asyncio.sleep(0.01)
|
||||
continue
|
||||
await _broadcast_ws(
|
||||
{
|
||||
"from": format_mac(host),
|
||||
"payload": msg.decode("utf-8"),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@app.route("/ws")
|
||||
@with_websocket
|
||||
async def ws(request, ws):
|
||||
_ws_clients.add(ws)
|
||||
while True:
|
||||
try:
|
||||
raw = await ws.receive()
|
||||
except WebSocketError:
|
||||
break
|
||||
|
||||
if not raw:
|
||||
break
|
||||
|
||||
try:
|
||||
parsed = json.loads(raw)
|
||||
env = _validate_envelope(parsed)
|
||||
sent = []
|
||||
for address, payload in env["devices"].items():
|
||||
mac, payload_size = _send_espnow(address, payload)
|
||||
sent.append(
|
||||
{
|
||||
"address": format_mac(mac),
|
||||
"bytes": payload_size,
|
||||
}
|
||||
)
|
||||
except (ValueError, TypeError) as e:
|
||||
await ws.send(json.dumps({"ok": False, "error": str(e)}))
|
||||
continue
|
||||
|
||||
await ws.send(
|
||||
json.dumps(
|
||||
{
|
||||
"ok": True,
|
||||
"sent": sent,
|
||||
}
|
||||
)
|
||||
)
|
||||
_ws_clients.discard(ws)
|
||||
|
||||
|
||||
async def main(port=80):
|
||||
_init_espnow()
|
||||
asyncio.create_task(_espnow_receive_loop())
|
||||
await app.start_server(host="0.0.0.0", port=port)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main(port=80))
|
||||
24
espnow-sender/msg.json
Normal file
24
espnow-sender/msg.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"v": "1",
|
||||
"devices": {
|
||||
"ff:ff:ff:ff:ff:ff": {
|
||||
"presets": {
|
||||
"preset_id": {
|
||||
"pattern": "on",
|
||||
"colors": ["#FF0000"],
|
||||
"delay": 100,
|
||||
"brightness": 255,
|
||||
"auto": true
|
||||
}
|
||||
},
|
||||
"select": {
|
||||
"preset": "preset_id",
|
||||
"step": 0
|
||||
},
|
||||
"save": true,
|
||||
"default": "preset_id",
|
||||
"b": 255
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
espnow-sender/util.py
Normal file
12
espnow-sender/util.py
Normal file
@@ -0,0 +1,12 @@
|
||||
def parse_mac(value):
|
||||
raw = value.strip().lower().replace(":", "").replace("-", "")
|
||||
if len(raw) != 12:
|
||||
raise ValueError("address must be 12 hex chars or aa:bb:cc:dd:ee:ff")
|
||||
try:
|
||||
return bytes.fromhex(raw)
|
||||
except ValueError:
|
||||
raise ValueError("address contains non-hex characters")
|
||||
|
||||
|
||||
def format_mac(mac_bytes):
|
||||
return ":".join("{:02x}".format(b) for b in mac_bytes)
|
||||
Submodule led-driver updated: 4575ef16ad...2a768376d0
Submodule led-simulator updated: 7ce56b64df...42c14361e8
2
led-tool
2
led-tool
Submodule led-tool updated: eee9327e15...580fd11aca
123
led_bar_vertical_stand.scad
Normal file
123
led_bar_vertical_stand.scad
Normal file
@@ -0,0 +1,123 @@
|
||||
// Parametric LED bar vertical stand socket
|
||||
// For a bar nominally 14 x 17 mm, 2 m long.
|
||||
// This part is intended to be screwed to an MDF base.
|
||||
|
||||
// -------------------------
|
||||
// User parameters
|
||||
// -------------------------
|
||||
bar_w = 14; // Bar width (mm)
|
||||
bar_d = 17; // Bar depth (mm)
|
||||
clearance = 0.4; // Total clearance added to each axis (mm)
|
||||
|
||||
socket_height = 36; // Height of printed socket body (mm)
|
||||
wall = 3.2; // Socket wall thickness (mm)
|
||||
base_thickness = 5; // Printed bottom plate thickness (mm)
|
||||
|
||||
// USB cable/connector side opening
|
||||
usb_notch_enable = true;
|
||||
usb_notch_w = 11;
|
||||
usb_notch_h = 9;
|
||||
usb_notch_from_bottom = 6;
|
||||
usb_notch_side = "right"; // "right" or "left"
|
||||
|
||||
// Mounting ears for MDF screws
|
||||
ear_enable = true;
|
||||
ear_len = 16;
|
||||
ear_w = 16;
|
||||
ear_thickness = base_thickness;
|
||||
screw_hole_d = 4.2; // M4 clearance. Use 3.4 for M3.
|
||||
screw_hole_edge = 5.5; // Hole center offset from ear outer corner
|
||||
|
||||
// Optional clamp lip at top to reduce wobble
|
||||
top_lip_enable = true;
|
||||
top_lip_depth = 2.0; // Intrudes into opening on each side
|
||||
top_lip_height = 3.0;
|
||||
|
||||
$fn = 48;
|
||||
|
||||
// -------------------------
|
||||
// Derived
|
||||
// -------------------------
|
||||
inner_w = bar_w + clearance;
|
||||
inner_d = bar_d + clearance;
|
||||
|
||||
outer_w = inner_w + wall * 2;
|
||||
outer_d = inner_d + wall * 2;
|
||||
outer_h = socket_height;
|
||||
|
||||
module screw_hole() {
|
||||
cylinder(h = ear_thickness + 0.2, d = screw_hole_d);
|
||||
}
|
||||
|
||||
module mounting_ear(sign_y = 1) {
|
||||
translate([outer_w / 2, sign_y * (outer_d / 2), 0])
|
||||
cube([ear_len, ear_w, ear_thickness], center = false);
|
||||
}
|
||||
|
||||
module top_lip() {
|
||||
if (top_lip_enable) {
|
||||
// Front and back lips at the top of the socket.
|
||||
translate([wall, wall, outer_h - top_lip_height])
|
||||
cube([top_lip_depth, inner_d, top_lip_height]);
|
||||
|
||||
translate([outer_w - wall - top_lip_depth, wall, outer_h - top_lip_height])
|
||||
cube([top_lip_depth, inner_d, top_lip_height]);
|
||||
}
|
||||
}
|
||||
|
||||
difference() {
|
||||
union() {
|
||||
// Main body
|
||||
cube([outer_w, outer_d, outer_h], center = false);
|
||||
|
||||
// Base plate under socket for stiffness
|
||||
translate([0, 0, -base_thickness])
|
||||
cube([outer_w, outer_d, base_thickness], center = false);
|
||||
|
||||
// Mounting ears
|
||||
if (ear_enable) {
|
||||
translate([0, 0, -ear_thickness]) {
|
||||
mounting_ear(1);
|
||||
mounting_ear(-1);
|
||||
}
|
||||
}
|
||||
|
||||
top_lip();
|
||||
}
|
||||
|
||||
// Main bar cavity
|
||||
translate([wall, wall, 0])
|
||||
cube([inner_w, inner_d, outer_h + 0.2], center = false);
|
||||
|
||||
// USB side notch
|
||||
if (usb_notch_enable) {
|
||||
if (usb_notch_side == "right") {
|
||||
translate([outer_w - wall - 0.1, (outer_d - usb_notch_w) / 2, usb_notch_from_bottom])
|
||||
cube([wall + 0.3, usb_notch_w, usb_notch_h], center = false);
|
||||
} else {
|
||||
translate([-0.2, (outer_d - usb_notch_w) / 2, usb_notch_from_bottom])
|
||||
cube([wall + 0.3, usb_notch_w, usb_notch_h], center = false);
|
||||
}
|
||||
}
|
||||
|
||||
// Screw holes in ears
|
||||
if (ear_enable) {
|
||||
// Upper ear hole
|
||||
translate([
|
||||
outer_w / 2 + ear_len - screw_hole_edge,
|
||||
outer_d / 2 + ear_w - screw_hole_edge,
|
||||
-ear_thickness - 0.05
|
||||
]) screw_hole();
|
||||
|
||||
// Lower ear hole
|
||||
translate([
|
||||
outer_w / 2 + ear_len - screw_hole_edge,
|
||||
-outer_d / 2 + screw_hole_edge,
|
||||
-ear_thickness - 0.05
|
||||
]) screw_hole();
|
||||
}
|
||||
}
|
||||
|
||||
// Print orientation helper:
|
||||
// Keep the base/ears on the bed.
|
||||
// If fit is tight, increase clearance to 0.5 or 0.6.
|
||||
16
scripts/dev-run.sh
Normal file
16
scripts/dev-run.sh
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
PORT="${PORT:-80}"
|
||||
|
||||
# On watchfiles restarts the previous process can linger briefly.
|
||||
# Proactively terminate any listener on the target port before boot.
|
||||
pids="$(ss -ltnp "sport = :$PORT" 2>/dev/null | sed -n 's/.*pid=\([0-9]\+\).*/\1/p' | sort -u)"
|
||||
if [ -n "${pids}" ]; then
|
||||
kill -TERM ${pids} 2>/dev/null || true
|
||||
sleep 0.3
|
||||
fi
|
||||
|
||||
cd "$ROOT_DIR/src"
|
||||
exec python main.py
|
||||
@@ -10,6 +10,18 @@ if [ ! -f "scripts/led-controller.service" ]; then
|
||||
echo "Run this script from the repo root."
|
||||
exit 1
|
||||
fi
|
||||
export PIPENV_VENV_IN_PROJECT="${PIPENV_VENV_IN_PROJECT:-1}"
|
||||
if command -v pipenv >/dev/null 2>&1; then
|
||||
PY="$(command -v python3)"
|
||||
if [ -z "$PY" ]; then
|
||||
echo "python3 not found; install python3." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Ensuring Pipenv deps with $PY (venv in project: .venv when PIPENV_VENV_IN_PROJECT=1)…"
|
||||
# --skip-lock: install from Pipfile only (avoids lock/Python hash mismatches on device).
|
||||
pipenv install --quiet --skip-lock --python "$PY"
|
||||
pipenv --venv > scripts/.led-controller-venv
|
||||
fi
|
||||
chmod +x scripts/start.sh
|
||||
sudo cp "scripts/led-controller.service" "$UNIT_PATH"
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
[Unit]
|
||||
Description=LED Controller web server
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
# Use network.target only. Ordering after network-online.target can block `systemctl start`
|
||||
# until wait-online finishes; Wi‑Fi/DHCP delays then look like a hung start job.
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
@@ -12,6 +13,8 @@ Environment=PATH=/home/pi/.local/bin:/usr/local/bin:/usr/bin:/bin
|
||||
ExecStart=/bin/bash /home/pi/led-controller/scripts/start.sh
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
# pipenv/first bind can be slow; avoid misleading "activating" forever if misconfigured
|
||||
TimeoutStartSec=120
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
253
scripts/pi-eth-lan-router.sh
Executable file
253
scripts/pi-eth-lan-router.sh
Executable file
@@ -0,0 +1,253 @@
|
||||
#!/usr/bin/env bash
|
||||
# Configure Raspberry Pi OS: Wi-Fi client on IF_WAN (default wlan0), Ethernet IF_LAN
|
||||
# (default eth0) toward an external AP. Static LAN IP, DHCP via dnsmasq, NAT masquerade.
|
||||
#
|
||||
# Usage:
|
||||
# sudo ./pi-eth-lan-router.sh install
|
||||
# sudo ./pi-eth-lan-router.sh remove
|
||||
#
|
||||
# Environment overrides (optional):
|
||||
# IF_WAN=wlan0 IF_LAN=eth0 LAN_IP=192.168.4.1 LAN_PREFIX=24 \
|
||||
# DHCP_START=192.168.4.100 DHCP_END=192.168.4.200 \
|
||||
# DNSMASQ_DNS=1.1.1.1,8.8.8.8 \
|
||||
# sudo ./pi-eth-lan-router.sh install
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
IF_WAN="${IF_WAN:-wlan0}"
|
||||
IF_LAN="${IF_LAN:-eth0}"
|
||||
LAN_IP="${LAN_IP:-192.168.4.1}"
|
||||
LAN_PREFIX="${LAN_PREFIX:-24}"
|
||||
DHCP_START="${DHCP_START:-192.168.4.100}"
|
||||
DHCP_END="${DHCP_END:-192.168.4.200}"
|
||||
# Comma-separated DNS for DHCP clients (Pi does not need to run a resolver).
|
||||
DNSMASQ_DNS="${DNSMASQ_DNS:-1.1.1.1,8.8.8.8}"
|
||||
|
||||
NM_CON_NAME="pi-eth-lan-router"
|
||||
MARK_BEGIN="# BEGIN pi-eth-lan-router (scripts/pi-eth-lan-router.sh)"
|
||||
MARK_END="# END pi-eth-lan-router"
|
||||
SYSCTL_FILE="/etc/sysctl.d/99-pi-eth-lan-router.conf"
|
||||
DNSMASQ_SNIPPET="/etc/dnsmasq.d/pi-eth-lan-router.conf"
|
||||
NFT_SNIPPET="/etc/nftables.d/50-pi-eth-lan-router.nft"
|
||||
NFT_INCLUDE='include "/etc/nftables.d/50-pi-eth-lan-router.nft"'
|
||||
NFTABLES_CONF="/etc/nftables.conf"
|
||||
DHCPCD_CONF="/etc/dhcpcd.conf"
|
||||
|
||||
die() { echo "error: $*" >&2; exit 1; }
|
||||
log() { echo "$*"; }
|
||||
|
||||
need_root() {
|
||||
[[ "${EUID:-0}" -eq 0 ]] || die "run as root (sudo)"
|
||||
}
|
||||
|
||||
have_cmd() { command -v "$1" >/dev/null 2>&1; }
|
||||
|
||||
apt_install() {
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get update -qq
|
||||
apt-get install -y -qq dnsmasq nftables
|
||||
}
|
||||
|
||||
write_sysctl() {
|
||||
cat >"$SYSCTL_FILE" <<EOF
|
||||
# Managed by scripts/pi-eth-lan-router.sh
|
||||
net.ipv4.ip_forward=1
|
||||
EOF
|
||||
sysctl --system -q 2>/dev/null || sysctl -p "$SYSCTL_FILE" || true
|
||||
}
|
||||
|
||||
remove_sysctl() {
|
||||
rm -f "$SYSCTL_FILE"
|
||||
sysctl --system -q 2>/dev/null || true
|
||||
}
|
||||
|
||||
write_dnsmasq() {
|
||||
local mask="255.255.255.0"
|
||||
if [[ "$LAN_PREFIX" != "24" ]]; then
|
||||
die "only LAN_PREFIX=24 is supported by this script (extend dnsmasq netmask manually)"
|
||||
fi
|
||||
cat >"$DNSMASQ_SNIPPET" <<EOF
|
||||
# Managed by scripts/pi-eth-lan-router.sh
|
||||
interface=$IF_LAN
|
||||
bind-interfaces
|
||||
dhcp-range=$DHCP_START,$DHCP_END,$mask,24h
|
||||
dhcp-option=option:router,$LAN_IP
|
||||
dhcp-option=option:dns-server,$DNSMASQ_DNS
|
||||
EOF
|
||||
}
|
||||
|
||||
remove_dnsmasq() {
|
||||
rm -f "$DNSMASQ_SNIPPET"
|
||||
}
|
||||
|
||||
write_nft() {
|
||||
mkdir -p /etc/nftables.d
|
||||
cat >"$NFT_SNIPPET" <<EOF
|
||||
# Managed by scripts/pi-eth-lan-router.sh
|
||||
table ip pi_eth_wlan_nat {
|
||||
chain postrouting {
|
||||
type nat hook postrouting priority 100; policy accept;
|
||||
oifname "$IF_WAN" masquerade
|
||||
}
|
||||
}
|
||||
EOF
|
||||
if [[ -f "$NFTABLES_CONF" ]] && ! grep -qF '50-pi-eth-lan-router.nft' "$NFTABLES_CONF" 2>/dev/null; then
|
||||
printf '\n# pi-eth-lan-router\n%s\n' "$NFT_INCLUDE" >>"$NFTABLES_CONF"
|
||||
elif [[ ! -f "$NFTABLES_CONF" ]]; then
|
||||
log "warning: $NFTABLES_CONF missing; NAT was not added for boot persistence. Install/configure nftables, or add: $NFT_INCLUDE"
|
||||
fi
|
||||
}
|
||||
|
||||
remove_nft() {
|
||||
rm -f "$NFT_SNIPPET"
|
||||
if [[ -f "$NFTABLES_CONF" ]]; then
|
||||
sed -i '/# pi-eth-lan-router/d;/50-pi-eth-lan-router\.nft/d' "$NFTABLES_CONF" || true
|
||||
fi
|
||||
nft delete table ip pi_eth_wlan_nat 2>/dev/null || true
|
||||
}
|
||||
|
||||
apply_nft() {
|
||||
if have_cmd nft; then
|
||||
nft delete table ip pi_eth_wlan_nat 2>/dev/null || true
|
||||
nft -f "$NFT_SNIPPET"
|
||||
fi
|
||||
}
|
||||
|
||||
configure_nm_eth() {
|
||||
have_cmd nmcli || return 1
|
||||
systemctl is-active --quiet NetworkManager 2>/dev/null || return 1
|
||||
|
||||
if nmcli -t -f NAME con show --active 2>/dev/null | grep -qxF "$NM_CON_NAME"; then
|
||||
nmcli con down "$NM_CON_NAME" || true
|
||||
fi
|
||||
if nmcli -t -f NAME con show 2>/dev/null | grep -qxF "$NM_CON_NAME"; then
|
||||
nmcli con mod "$NM_CON_NAME" \
|
||||
connection.interface-name "$IF_LAN" \
|
||||
ipv4.method manual \
|
||||
ipv4.addresses "${LAN_IP}/${LAN_PREFIX}" \
|
||||
ipv4.gateway "" \
|
||||
ipv4.dns "" \
|
||||
ipv4.never-default yes \
|
||||
ipv6.method ignore
|
||||
else
|
||||
nmcli con add type ethernet con-name "$NM_CON_NAME" ifname "$IF_LAN" \
|
||||
ipv4.method manual \
|
||||
ipv4.addresses "${LAN_IP}/${LAN_PREFIX}" \
|
||||
ipv4.gateway "" \
|
||||
ipv4.dns "" \
|
||||
ipv4.never-default yes \
|
||||
ipv6.method ignore
|
||||
fi
|
||||
if ! nmcli con up "$NM_CON_NAME"; then
|
||||
log "warning: could not activate '$NM_CON_NAME' (is $IF_LAN connected?); profile saved for next boot."
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
remove_nm_eth() {
|
||||
have_cmd nmcli || return 0
|
||||
if nmcli -t -f NAME con show 2>/dev/null | grep -qxF "$NM_CON_NAME"; then
|
||||
nmcli con delete "$NM_CON_NAME" || true
|
||||
fi
|
||||
}
|
||||
|
||||
configure_dhcpcd_eth() {
|
||||
[[ -f "$DHCPCD_CONF" ]] || return 1
|
||||
if grep -qF "$MARK_BEGIN" "$DHCPCD_CONF" 2>/dev/null; then
|
||||
sed -i "/$MARK_BEGIN/,/$MARK_END/d" "$DHCPCD_CONF" || true
|
||||
fi
|
||||
{
|
||||
echo "$MARK_BEGIN"
|
||||
echo "interface $IF_LAN"
|
||||
echo "static ip_address=${LAN_IP}/${LAN_PREFIX}"
|
||||
echo "nohook wpa_supplicant"
|
||||
echo "$MARK_END"
|
||||
} >>"$DHCPCD_CONF"
|
||||
systemctl restart dhcpcd 2>/dev/null || true
|
||||
return 0
|
||||
}
|
||||
|
||||
remove_dhcpcd_block() {
|
||||
[[ -f "$DHCPCD_CONF" ]] || return 0
|
||||
if grep -qF "$MARK_BEGIN" "$DHCPCD_CONF" 2>/dev/null; then
|
||||
sed -i "/$MARK_BEGIN/,/$MARK_END/d" "$DHCPCD_CONF" || true
|
||||
systemctl restart dhcpcd 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
|
||||
configure_eth_static() {
|
||||
if configure_nm_eth; then
|
||||
log "configured $IF_LAN via NetworkManager profile '$NM_CON_NAME'"
|
||||
return 0
|
||||
fi
|
||||
if configure_dhcpcd_eth; then
|
||||
log "configured $IF_LAN via dhcpcd ($DHCPCD_CONF)"
|
||||
return 0
|
||||
fi
|
||||
die "neither NetworkManager (active) nor $DHCPCD_CONF found; set $IF_LAN to ${LAN_IP}/${LAN_PREFIX} manually"
|
||||
}
|
||||
|
||||
remove_eth_static() {
|
||||
remove_nm_eth
|
||||
remove_dhcpcd_block
|
||||
}
|
||||
|
||||
do_install() {
|
||||
need_root
|
||||
log "installing packages (dnsmasq, nftables)…"
|
||||
apt_install
|
||||
|
||||
log "writing sysctl, dnsmasq, nftables snippets…"
|
||||
write_sysctl
|
||||
write_dnsmasq
|
||||
write_nft
|
||||
|
||||
log "setting static IP on $IF_LAN…"
|
||||
configure_eth_static
|
||||
|
||||
log "restarting dnsmasq…"
|
||||
systemctl enable dnsmasq
|
||||
systemctl restart dnsmasq
|
||||
|
||||
log "loading NAT rules and enabling nftables…"
|
||||
apply_nft
|
||||
systemctl enable nftables 2>/dev/null || true
|
||||
systemctl restart nftables 2>/dev/null || true
|
||||
|
||||
log "done. Connect $IF_LAN to the external AP (DHCP off on the AP)."
|
||||
log "Join Wi-Fi on $IF_WAN to the uplink network and complete any captive portal on the Pi."
|
||||
}
|
||||
|
||||
do_remove() {
|
||||
need_root
|
||||
remove_eth_static
|
||||
remove_dnsmasq
|
||||
systemctl restart dnsmasq 2>/dev/null || true
|
||||
|
||||
remove_nft
|
||||
systemctl restart nftables 2>/dev/null || true
|
||||
|
||||
remove_sysctl
|
||||
sysctl -w net.ipv4.ip_forward=0 2>/dev/null || true
|
||||
|
||||
log "removed pi-eth-lan-router configuration snippets and NM profile '$NM_CON_NAME' (if present)."
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: sudo $0 install|remove
|
||||
|
||||
WAN (Wi-Fi client): $IF_WAN
|
||||
LAN (Ethernet to AP): $IF_LAN
|
||||
LAN address: ${LAN_IP}/${LAN_PREFIX}
|
||||
DHCP range: $DHCP_START – $DHCP_END
|
||||
|
||||
Override with environment variables (see script header).
|
||||
EOF
|
||||
}
|
||||
|
||||
case "${1:-}" in
|
||||
install) do_install ;;
|
||||
remove) do_remove ;;
|
||||
*) usage; exit 1 ;;
|
||||
esac
|
||||
@@ -1,5 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
# Start the LED controller web server (port 80 by default).
|
||||
cd "$(dirname "$0")/.."
|
||||
# Avoid `pipenv run` on the hot path — it re-resolves the env every time and is slow on a Pi.
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
export PORT="${PORT:-80}"
|
||||
pipenv run run
|
||||
export PIPENV_VENV_IN_PROJECT="${PIPENV_VENV_IN_PROJECT:-1}"
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
CACHE="$SCRIPT_DIR/.led-controller-venv"
|
||||
PYTHON=""
|
||||
|
||||
if [ -x "$ROOT/.venv/bin/python" ]; then
|
||||
PYTHON="$ROOT/.venv/bin/python"
|
||||
elif [ -f "$CACHE" ]; then
|
||||
_v="$(tr -d '\r\n' < "$CACHE")"
|
||||
if [ -n "$_v" ] && [ -x "$_v/bin/python" ]; then
|
||||
PYTHON="$_v/bin/python"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$PYTHON" ] && command -v pipenv >/dev/null 2>&1; then
|
||||
_v="$(cd "$ROOT" && pipenv --venv 2>/dev/null || true)"
|
||||
if [ -n "${_v:-}" ] && [ -x "$_v/bin/python" ]; then
|
||||
PYTHON="$_v/bin/python"
|
||||
printf '%s\n' "$_v" > "$CACHE" || true
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$PYTHON" ]; then
|
||||
echo 'led-controller: no venv resolved; using pipenv run (slow). Run: cd '"$ROOT"' && PIPENV_VENV_IN_PROJECT=1 pipenv install --skip-lock --python "$(command -v python3)"' >&2
|
||||
exec pipenv run run
|
||||
fi
|
||||
|
||||
cd "$ROOT/src"
|
||||
exec "$PYTHON" -u main.py
|
||||
|
||||
@@ -2,10 +2,14 @@ from microdot import Microdot
|
||||
from models.device import (
|
||||
Device,
|
||||
derive_device_mac,
|
||||
normalize_mac,
|
||||
validate_device_transport,
|
||||
validate_device_type,
|
||||
)
|
||||
from models.group import Group
|
||||
from models.transport import get_current_sender
|
||||
from settings import Settings
|
||||
from util.brightness_combine import effective_brightness_for_mac
|
||||
from models.wifi_ws_clients import (
|
||||
normalize_tcp_peer_ip,
|
||||
send_json_line_to_ip,
|
||||
@@ -52,8 +56,28 @@ def _compact_v1_json(*, presets=None, select=None, save=False):
|
||||
# Seconds after identify blink before selecting built-in ``off`` (tests may monkeypatch).
|
||||
IDENTIFY_OFF_DELAY_S = 2.0
|
||||
|
||||
|
||||
def _validate_output_brightness(value):
|
||||
if value is None:
|
||||
return None
|
||||
try:
|
||||
b = int(value)
|
||||
except (TypeError, ValueError):
|
||||
raise ValueError("output_brightness must be an integer 0–255")
|
||||
if b < 0 or b > 255:
|
||||
raise ValueError("output_brightness must be between 0 and 255")
|
||||
return b
|
||||
|
||||
|
||||
def _brightness_save_message_json(b_val: int) -> str:
|
||||
b_val = max(0, min(255, int(b_val)))
|
||||
return json.dumps({"v": "1", "b": b_val, "save": True}, separators=(",", ":"))
|
||||
|
||||
|
||||
controller = Microdot()
|
||||
devices = Device()
|
||||
_group_registry = Group()
|
||||
_pi_settings = Settings()
|
||||
|
||||
|
||||
def _device_live_connected(dev_dict):
|
||||
@@ -143,6 +167,107 @@ async def _identify_send_off_after_delay(sender, transport, wifi_ip, dev_id, nam
|
||||
pass
|
||||
|
||||
|
||||
async def send_identify_to_device(dev_id: str) -> tuple[int, str]:
|
||||
"""
|
||||
Send the same identify blink as ``POST /devices/<id>/identify``.
|
||||
|
||||
Returns ``(http_status, "")`` on success, or ``(status, error_message)`` on failure
|
||||
(status matches the single-device route).
|
||||
"""
|
||||
dev = devices.read(dev_id)
|
||||
if not dev:
|
||||
return 404, "Device not found"
|
||||
sender = get_current_sender()
|
||||
if not sender:
|
||||
return 503, "Transport not configured"
|
||||
name = str(dev.get("name") or "").strip()
|
||||
if not name:
|
||||
return 400, "Device must have a name to identify"
|
||||
|
||||
transport = dev.get("transport") or "espnow"
|
||||
wifi_ip = None
|
||||
if transport == "wifi":
|
||||
wifi_ip = dev.get("address")
|
||||
if not wifi_ip:
|
||||
return 400, "Device has no IP address"
|
||||
|
||||
try:
|
||||
msg = _compact_v1_json(
|
||||
presets={_IDENTIFY_PRESET_KEY: dict(_IDENTIFY_DRIVER_PRESET)},
|
||||
select={name: [_IDENTIFY_PRESET_KEY]},
|
||||
)
|
||||
if transport == "wifi":
|
||||
ok = await send_json_line_to_ip(wifi_ip, msg)
|
||||
if not ok:
|
||||
return 503, "Wi-Fi driver not connected"
|
||||
else:
|
||||
await sender.send(msg, addr=dev_id)
|
||||
|
||||
asyncio.create_task(
|
||||
_identify_send_off_after_delay(sender, transport, wifi_ip, dev_id, name)
|
||||
)
|
||||
except Exception as e:
|
||||
return 503, str(e)
|
||||
return 200, ""
|
||||
|
||||
|
||||
async def send_identify_to_group_devices(macs: list[str]) -> tuple[int, list[dict]]:
|
||||
"""
|
||||
Identify every listed registry MAC in one delivery round: merged ``select`` and a single
|
||||
ESP-NOW split envelope when multiple peers share the serial bridge (avoids per-device
|
||||
``SerialSender`` lock serialisation). Wi-Fi peers are sent in parallel as in
|
||||
``deliver_json_messages``.
|
||||
"""
|
||||
from util.driver_delivery import deliver_json_messages
|
||||
|
||||
errors: list[dict] = []
|
||||
sender = get_current_sender()
|
||||
if not sender:
|
||||
return 0, [{"mac": "*", "error": "Transport not configured"}]
|
||||
|
||||
merged_select: dict[str, list[str]] = {}
|
||||
valid_macs: list[str] = []
|
||||
for dev_id in macs:
|
||||
dev = devices.read(dev_id)
|
||||
if not dev:
|
||||
errors.append({"mac": dev_id, "error": "Device not found"})
|
||||
continue
|
||||
name = str(dev.get("name") or "").strip()
|
||||
if not name:
|
||||
errors.append({"mac": dev_id, "error": "Device must have a name to identify"})
|
||||
continue
|
||||
transport = (dev.get("transport") or "espnow").strip().lower()
|
||||
if transport == "wifi":
|
||||
if not dev.get("address"):
|
||||
errors.append({"mac": dev_id, "error": "Device has no IP address"})
|
||||
continue
|
||||
merged_select[name] = [_IDENTIFY_PRESET_KEY]
|
||||
valid_macs.append(dev_id)
|
||||
|
||||
if not merged_select:
|
||||
return 0, errors
|
||||
|
||||
try:
|
||||
msg = _compact_v1_json(
|
||||
presets={_IDENTIFY_PRESET_KEY: dict(_IDENTIFY_DRIVER_PRESET)},
|
||||
select=merged_select,
|
||||
)
|
||||
await deliver_json_messages(sender, [msg], valid_macs, devices, delay_s=0)
|
||||
except Exception as e:
|
||||
return 0, errors + [{"mac": "*", "error": str(e)}]
|
||||
|
||||
for dev_id in valid_macs:
|
||||
dev = devices.read(dev_id) or {}
|
||||
name = str(dev.get("name") or "").strip()
|
||||
transport = (dev.get("transport") or "espnow").strip().lower()
|
||||
wifi_ip = dev.get("address") if transport == "wifi" else None
|
||||
asyncio.create_task(
|
||||
_identify_send_off_after_delay(sender, transport, wifi_ip, dev_id, name)
|
||||
)
|
||||
|
||||
return len(valid_macs), errors
|
||||
|
||||
|
||||
@controller.get("")
|
||||
async def list_devices(request):
|
||||
"""List all devices (includes ``connected`` for live Wi-Fi WebSocket presence)."""
|
||||
@@ -154,6 +279,42 @@ async def list_devices(request):
|
||||
return json.dumps(devices_data), 200, {"Content-Type": "application/json"}
|
||||
|
||||
|
||||
@controller.post("/resolve-brightness")
|
||||
async def resolve_brightness_batch(request):
|
||||
"""
|
||||
POST JSON ``{ \"macs\": [\"..\"], \"zone_brightness\": optional 0–255 }``.
|
||||
Returns ``{ \"values\": { mac: combined_int } }`` — global × group(s) × device × zone (optional).
|
||||
"""
|
||||
try:
|
||||
data = request.json or {}
|
||||
except Exception:
|
||||
data = {}
|
||||
macs = data.get("macs")
|
||||
if not isinstance(macs, list):
|
||||
return json.dumps({"error": "macs must be an array"}), 400, {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
zb = None
|
||||
if isinstance(data, dict) and data.get("zone_brightness") is not None:
|
||||
try:
|
||||
zb = _validate_output_brightness(data.get("zone_brightness"))
|
||||
except ValueError as e:
|
||||
return json.dumps({"error": str(e)}), 400, {"Content-Type": "application/json"}
|
||||
values = {}
|
||||
for raw in macs:
|
||||
m = normalize_mac(str(raw))
|
||||
if not m:
|
||||
continue
|
||||
values[m] = effective_brightness_for_mac(
|
||||
_pi_settings,
|
||||
_group_registry,
|
||||
devices,
|
||||
m,
|
||||
zone_brightness=zb,
|
||||
)
|
||||
return json.dumps({"values": values}), 200, {"Content-Type": "application/json"}
|
||||
|
||||
|
||||
@controller.get("/<id>")
|
||||
async def get_device(request, id):
|
||||
"""Get a device by ID (includes ``connected`` for live Wi-Fi WebSocket presence)."""
|
||||
@@ -239,7 +400,17 @@ async def update_device(request, id):
|
||||
data["transport"] = validate_device_transport(data.get("transport"))
|
||||
if "zones" in data and isinstance(data["zones"], list):
|
||||
data["zones"] = [str(t) for t in data["zones"]]
|
||||
if "output_brightness" in data:
|
||||
data["output_brightness"] = _validate_output_brightness(data.get("output_brightness"))
|
||||
prev_doc = devices.read(id)
|
||||
if devices.update(id, data):
|
||||
if prev_doc and "name" in data:
|
||||
on = str(prev_doc.get("name") or "").strip()
|
||||
nn = str(data.get("name") or "").strip()
|
||||
if on and nn and on != nn:
|
||||
from util.beat_driver_route import remap_beat_route_device_name
|
||||
|
||||
remap_beat_route_device_name(on, nn)
|
||||
return json.dumps(devices.read(id)), 200, {"Content-Type": "application/json"}
|
||||
return json.dumps({"error": "Device not found"}), 404, {
|
||||
"Content-Type": "application/json",
|
||||
@@ -271,51 +442,124 @@ async def identify_device(request, id):
|
||||
this device name — same combined shape as profile sends the driver already accepts over TCP
|
||||
/ ESP-NOW. No ``save``. After ``IDENTIFY_OFF_DELAY_S``, a background task selects ``off``.
|
||||
"""
|
||||
status, err = await send_identify_to_device(id)
|
||||
if status == 200:
|
||||
return json.dumps({"message": "Identify sent"}), 200, {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
return json.dumps({"error": err}), status, {"Content-Type": "application/json"}
|
||||
|
||||
|
||||
@controller.post("/<id>/brightness")
|
||||
async def push_device_output_brightness(request, id):
|
||||
"""
|
||||
Push combined brightness to the driver: global × group(s) × device × optional ``zone_brightness``
|
||||
in JSON body — single ``b`` (``v``/``b``/``save``). Wi‑Fi or ESP‑NOW.
|
||||
"""
|
||||
dev = devices.read(id)
|
||||
if not dev:
|
||||
return json.dumps({"error": "Device not found"}), 404, {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
sender = get_current_sender()
|
||||
if not sender:
|
||||
return json.dumps({"error": "Transport not configured"}), 503, {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
name = str(dev.get("name") or "").strip()
|
||||
if not name:
|
||||
return json.dumps({"error": "Device must have a name to identify"}), 400, {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
body = request.json or {}
|
||||
zb = None
|
||||
if isinstance(body, dict) and body.get("zone_brightness") is not None:
|
||||
try:
|
||||
zb = _validate_output_brightness(body.get("zone_brightness"))
|
||||
except ValueError as e:
|
||||
return json.dumps({"error": str(e)}), 400, {"Content-Type": "application/json"}
|
||||
b_val = effective_brightness_for_mac(
|
||||
_pi_settings,
|
||||
_group_registry,
|
||||
devices,
|
||||
id,
|
||||
zone_brightness=zb,
|
||||
)
|
||||
|
||||
msg = _brightness_save_message_json(b_val)
|
||||
transport = (dev.get("transport") or "espnow").strip().lower()
|
||||
|
||||
transport = dev.get("transport") or "espnow"
|
||||
wifi_ip = None
|
||||
if transport == "wifi":
|
||||
wifi_ip = dev.get("address")
|
||||
if not wifi_ip:
|
||||
ip = normalize_tcp_peer_ip(str(dev.get("address") or ""))
|
||||
if not ip:
|
||||
return json.dumps({"error": "Device has no IP address"}), 400, {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
try:
|
||||
msg = _compact_v1_json(
|
||||
presets={_IDENTIFY_PRESET_KEY: dict(_IDENTIFY_DRIVER_PRESET)},
|
||||
select={name: [_IDENTIFY_PRESET_KEY]},
|
||||
)
|
||||
if transport == "wifi":
|
||||
ok = await send_json_line_to_ip(wifi_ip, msg)
|
||||
if not ok:
|
||||
return json.dumps({"error": "Wi-Fi driver not connected"}), 503, {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
else:
|
||||
ok = await send_json_line_to_ip(ip, msg)
|
||||
if not ok:
|
||||
return json.dumps({"error": "Wi-Fi driver not connected"}), 503, {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
else:
|
||||
sender = get_current_sender()
|
||||
if not sender:
|
||||
return json.dumps({"error": "Transport not configured"}), 503, {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
try:
|
||||
await sender.send(msg, addr=id)
|
||||
except Exception as e:
|
||||
return json.dumps({"error": str(e)}), 503, {"Content-Type": "application/json"}
|
||||
|
||||
asyncio.create_task(
|
||||
_identify_send_off_after_delay(sender, transport, wifi_ip, id, name)
|
||||
)
|
||||
except Exception as e:
|
||||
return json.dumps({"error": str(e)}), 503, {"Content-Type": "application/json"}
|
||||
return json.dumps({"message": "Identify sent"}), 200, {
|
||||
return json.dumps({"message": "brightness sent", "brightness": b_val}), 200, {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
|
||||
@controller.post("/<id>/driver-config")
|
||||
async def push_driver_config(request, id):
|
||||
"""
|
||||
Push ``device_config`` to a Wi‑Fi LED driver over WebSocket.
|
||||
Body JSON: optional ``name``, ``num_leds``, ``color_order``, ``startup_mode`` (default|last|off).
|
||||
"""
|
||||
dev = devices.read(id)
|
||||
if not dev:
|
||||
return json.dumps({"error": "Device not found"}), 404, {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
if (dev.get("transport") or "").lower() != "wifi":
|
||||
return json.dumps({"error": "driver-config is only for Wi-Fi devices"}), 400, {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
wifi_ip = str(dev.get("address") or "").strip()
|
||||
if not wifi_ip:
|
||||
return json.dumps({"error": "Device has no IP address"}), 400, {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
body = request.json or {}
|
||||
dc = {}
|
||||
if isinstance(body.get("name"), str) and body["name"].strip():
|
||||
dc["name"] = body["name"].strip()
|
||||
if "num_leds" in body:
|
||||
try:
|
||||
n = int(body["num_leds"])
|
||||
if 1 <= n <= 2048:
|
||||
dc["num_leds"] = n
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
if isinstance(body.get("color_order"), str):
|
||||
co = body["color_order"].strip().lower()
|
||||
if co in ("rgb", "rbg", "grb", "gbr", "brg", "bgr"):
|
||||
dc["color_order"] = co
|
||||
if isinstance(body.get("startup_mode"), str):
|
||||
sm = body["startup_mode"].strip().lower()
|
||||
if sm in ("default", "last", "off"):
|
||||
dc["startup_mode"] = sm
|
||||
if not dc:
|
||||
return json.dumps(
|
||||
{
|
||||
"error": "Provide at least one of name, num_leds, color_order, startup_mode"
|
||||
}
|
||||
), 400, {"Content-Type": "application/json"}
|
||||
msg = json.dumps(
|
||||
{"v": "1", "device_config": dc, "save": True}, separators=(",", ":")
|
||||
)
|
||||
ok = await send_json_line_to_ip(wifi_ip, msg)
|
||||
if not ok:
|
||||
return json.dumps({"error": "Wi-Fi driver not connected"}), 503, {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
return json.dumps({"message": "driver-config sent"}), 200, {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
|
||||
@@ -1,50 +1,359 @@
|
||||
from microdot import Microdot
|
||||
from microdot.session import with_session
|
||||
import asyncio
|
||||
from models.group import Group
|
||||
from models.device import Device
|
||||
from models.transport import get_current_sender
|
||||
from models.wifi_ws_clients import normalize_tcp_peer_ip, send_json_line_to_ip
|
||||
from settings import Settings
|
||||
from util.brightness_combine import effective_brightness_for_mac
|
||||
import json
|
||||
|
||||
controller = Microdot()
|
||||
groups = Group()
|
||||
devices = Device()
|
||||
_pi_settings = Settings()
|
||||
|
||||
@controller.get('')
|
||||
async def list_groups(request):
|
||||
"""List all groups."""
|
||||
return json.dumps(groups), 200, {'Content-Type': 'application/json'}
|
||||
|
||||
@controller.get('/<id>')
|
||||
async def get_group(request, id):
|
||||
"""Get a specific group by ID."""
|
||||
def _group_doc_visible_for_profile(doc, profile_id):
|
||||
if not isinstance(doc, dict):
|
||||
return False
|
||||
scoped = doc.get("profile_id")
|
||||
if scoped is None:
|
||||
scoped = doc.get("profileId")
|
||||
if scoped is None or str(scoped).strip() == "":
|
||||
return True
|
||||
if not profile_id:
|
||||
return False
|
||||
return str(scoped).strip() == str(profile_id).strip()
|
||||
|
||||
|
||||
def _filtered_groups_dict(session):
|
||||
from controllers.zone import get_current_profile_id
|
||||
|
||||
pid = get_current_profile_id(session)
|
||||
out = {}
|
||||
for gid, doc in groups.items():
|
||||
if not isinstance(doc, dict):
|
||||
continue
|
||||
if _group_doc_visible_for_profile(doc, pid):
|
||||
out[str(gid)] = doc
|
||||
return out
|
||||
|
||||
|
||||
@controller.get("")
|
||||
@with_session
|
||||
async def list_groups(request, session):
|
||||
"""List groups visible for the current profile (shared + profile-scoped)."""
|
||||
return json.dumps(_filtered_groups_dict(session)), 200, {"Content-Type": "application/json"}
|
||||
|
||||
|
||||
@controller.get("/<id>")
|
||||
@with_session
|
||||
async def get_group(request, session, id):
|
||||
"""Get a specific group by ID (404 if scoped to another profile)."""
|
||||
group = groups.read(id)
|
||||
if group:
|
||||
return json.dumps(group), 200, {'Content-Type': 'application/json'}
|
||||
return json.dumps({"error": "Group not found"}), 404
|
||||
if not group or not isinstance(group, dict):
|
||||
return json.dumps({"error": "Group not found"}), 404
|
||||
from controllers.zone import get_current_profile_id
|
||||
|
||||
@controller.post('')
|
||||
async def create_group(request):
|
||||
"""Create a new group."""
|
||||
if not _group_doc_visible_for_profile(group, get_current_profile_id(session)):
|
||||
return json.dumps({"error": "Group not found"}), 404
|
||||
return json.dumps(group), 200, {"Content-Type": "application/json"}
|
||||
|
||||
|
||||
def _sanitize_group_profile_id_write(data, session):
|
||||
"""Allow ``profile_id`` only for the active profile, or null to share across profiles."""
|
||||
if not isinstance(data, dict):
|
||||
return
|
||||
from controllers.zone import get_current_profile_id
|
||||
|
||||
cur = get_current_profile_id(session)
|
||||
if "profile_id" not in data and "profileId" not in data:
|
||||
return
|
||||
raw = data.get("profile_id")
|
||||
if raw is None and "profileId" in data:
|
||||
raw = data.get("profileId")
|
||||
if raw is None or raw == "":
|
||||
data.pop("profileId", None)
|
||||
data["profile_id"] = None
|
||||
return
|
||||
if not cur or str(raw).strip() != str(cur).strip():
|
||||
data.pop("profileId", None)
|
||||
data.pop("profile_id", None)
|
||||
|
||||
|
||||
@controller.post("")
|
||||
@with_session
|
||||
async def create_group(request, session):
|
||||
"""Create a new group (omit ``profile_id`` for shared; or ``profile_scoped``: true for this profile only)."""
|
||||
try:
|
||||
data = request.json or {}
|
||||
data = dict(request.json or {})
|
||||
name = data.get("name", "")
|
||||
profile_scoped = bool(data.pop("profile_scoped", False))
|
||||
_sanitize_group_profile_id_write(data, session)
|
||||
group_id = groups.create(name)
|
||||
if data:
|
||||
groups.update(group_id, data)
|
||||
return json.dumps(groups.read(group_id)), 201, {'Content-Type': 'application/json'}
|
||||
if profile_scoped:
|
||||
from controllers.zone import get_current_profile_id
|
||||
|
||||
cur = get_current_profile_id(session)
|
||||
if cur:
|
||||
groups.update(group_id, {"profile_id": str(cur)})
|
||||
return json.dumps(groups.read(group_id)), 201, {"Content-Type": "application/json"}
|
||||
except Exception as e:
|
||||
return json.dumps({"error": str(e)}), 400
|
||||
|
||||
@controller.put('/<id>')
|
||||
async def update_group(request, id):
|
||||
|
||||
@controller.put("/<id>")
|
||||
@with_session
|
||||
async def update_group(request, session, id):
|
||||
"""Update an existing group."""
|
||||
try:
|
||||
data = request.json
|
||||
if not isinstance(data, dict):
|
||||
return json.dumps({"error": "Invalid JSON"}), 400, {"Content-Type": "application/json"}
|
||||
data = dict(data)
|
||||
_sanitize_group_profile_id_write(data, session)
|
||||
if groups.update(id, data):
|
||||
return json.dumps(groups.read(id)), 200, {'Content-Type': 'application/json'}
|
||||
g = groups.read(id)
|
||||
if g:
|
||||
return json.dumps(g), 200, {"Content-Type": "application/json"}
|
||||
return json.dumps({"error": "Group not found"}), 404
|
||||
except Exception as e:
|
||||
return json.dumps({"error": str(e)}), 400
|
||||
|
||||
@controller.delete('/<id>')
|
||||
async def delete_group(request, id):
|
||||
"""Delete a group."""
|
||||
@controller.delete("/<id>")
|
||||
@with_session
|
||||
async def delete_group(request, session, id):
|
||||
"""Delete a group (not allowed for another profile's scoped group)."""
|
||||
g = groups.read(id)
|
||||
if not g or not isinstance(g, dict):
|
||||
return json.dumps({"error": "Group not found"}), 404
|
||||
from controllers.zone import get_current_profile_id
|
||||
|
||||
if not _group_doc_visible_for_profile(g, get_current_profile_id(session)):
|
||||
return json.dumps({"error": "Group not found"}), 404
|
||||
if groups.delete(id):
|
||||
return json.dumps({"message": "Group deleted successfully"}), 200
|
||||
return json.dumps({"error": "Group not found"}), 404
|
||||
|
||||
|
||||
def _group_driver_config_payload(doc):
|
||||
"""Build ``device_config`` dict from stored group Wi‑Fi defaults (non-empty only)."""
|
||||
dc = {}
|
||||
if not isinstance(doc, dict):
|
||||
return dc
|
||||
nm = doc.get("wifi_driver_display_name")
|
||||
if isinstance(nm, str) and nm.strip():
|
||||
dc["name"] = nm.strip()
|
||||
nled = doc.get("wifi_driver_num_leds")
|
||||
if nled is not None:
|
||||
try:
|
||||
n = int(nled)
|
||||
if 1 <= n <= 2048:
|
||||
dc["num_leds"] = n
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
co = doc.get("wifi_color_order")
|
||||
if isinstance(co, str):
|
||||
c = co.strip().lower()
|
||||
if c in ("rgb", "rbg", "grb", "gbr", "brg", "bgr"):
|
||||
dc["color_order"] = c
|
||||
sm = doc.get("wifi_startup_mode")
|
||||
if isinstance(sm, str):
|
||||
s = sm.strip().lower()
|
||||
if s in ("default", "last", "off"):
|
||||
dc["startup_mode"] = s
|
||||
return dc
|
||||
|
||||
|
||||
def _read_group_for_session(session, id):
|
||||
g = groups.read(id)
|
||||
if not g or not isinstance(g, dict):
|
||||
return None
|
||||
from controllers.zone import get_current_profile_id
|
||||
|
||||
if not _group_doc_visible_for_profile(g, get_current_profile_id(session)):
|
||||
return None
|
||||
return g
|
||||
|
||||
|
||||
@controller.post("/<id>/driver-config")
|
||||
@with_session
|
||||
async def push_group_driver_config(request, session, id):
|
||||
"""
|
||||
Push group Wi‑Fi defaults to every Wi‑Fi device listed in the group (TCP WebSocket).
|
||||
Uses stored ``wifi_*`` fields on the group; optional JSON body may override for this send only.
|
||||
"""
|
||||
gdoc = _read_group_for_session(session, id)
|
||||
if not gdoc:
|
||||
return json.dumps({"error": "Group not found"}), 404
|
||||
|
||||
body = request.json or {}
|
||||
merged = dict(gdoc)
|
||||
if isinstance(body, dict):
|
||||
for k in (
|
||||
"wifi_driver_display_name",
|
||||
"wifi_driver_num_leds",
|
||||
"wifi_color_order",
|
||||
"wifi_startup_mode",
|
||||
):
|
||||
if k in body:
|
||||
merged[k] = body[k]
|
||||
dc = _group_driver_config_payload(merged)
|
||||
if not dc:
|
||||
return json.dumps(
|
||||
{"error": "No driver defaults on this group (set display name, LEDs, colour order, or power-on pattern)"}
|
||||
), 400, {"Content-Type": "application/json"}
|
||||
|
||||
mac_list = gdoc.get("devices") if isinstance(gdoc.get("devices"), list) else []
|
||||
sent = 0
|
||||
errors = []
|
||||
msg = json.dumps(
|
||||
{"v": "1", "device_config": dc, "save": True}, separators=(",", ":")
|
||||
)
|
||||
tasks = []
|
||||
meta_macs = []
|
||||
for mac in mac_list:
|
||||
m = str(mac).strip().lower().replace(":", "").replace("-", "")
|
||||
if len(m) != 12:
|
||||
continue
|
||||
dev = devices.read(m)
|
||||
if not dev:
|
||||
errors.append({"mac": m, "error": "not in registry"})
|
||||
continue
|
||||
if (dev.get("transport") or "").lower() != "wifi":
|
||||
continue
|
||||
ip = normalize_tcp_peer_ip(str(dev.get("address") or ""))
|
||||
if not ip:
|
||||
errors.append({"mac": m, "error": "no IP"})
|
||||
continue
|
||||
tasks.append(send_json_line_to_ip(ip, msg))
|
||||
meta_macs.append(m)
|
||||
if tasks:
|
||||
results = await asyncio.gather(*tasks, return_exceptions=True)
|
||||
for m, r in zip(meta_macs, results):
|
||||
if r is True:
|
||||
sent += 1
|
||||
elif isinstance(r, Exception):
|
||||
errors.append({"mac": m, "error": str(r)})
|
||||
else:
|
||||
errors.append({"mac": m, "error": "driver not connected"})
|
||||
|
||||
return json.dumps(
|
||||
{"message": "driver-config sent", "sent": sent, "errors": errors}
|
||||
), 200, {"Content-Type": "application/json"}
|
||||
|
||||
|
||||
def _brightness_save_message_json(b_val: int) -> str:
|
||||
b_val = max(0, min(255, int(b_val)))
|
||||
return json.dumps({"v": "1", "b": b_val, "save": True}, separators=(",", ":"))
|
||||
|
||||
|
||||
@controller.post("/<id>/brightness")
|
||||
@with_session
|
||||
async def push_group_output_brightness(request, session, id):
|
||||
"""
|
||||
Push combined brightness (global × group(s) × device) to each member — one ``b`` per device.
|
||||
"""
|
||||
gdoc = _read_group_for_session(session, id)
|
||||
if not gdoc:
|
||||
return json.dumps({"error": "Group not found"}), 404
|
||||
|
||||
mac_list = gdoc.get("devices") if isinstance(gdoc.get("devices"), list) else []
|
||||
sent = 0
|
||||
errors = []
|
||||
sender = get_current_sender()
|
||||
|
||||
async def _push_brightness_one(m: str, dev: dict) -> tuple[str, bool, str | None]:
|
||||
b_val = effective_brightness_for_mac(
|
||||
_pi_settings,
|
||||
groups,
|
||||
devices,
|
||||
m,
|
||||
zone_brightness=None,
|
||||
)
|
||||
msg = _brightness_save_message_json(b_val)
|
||||
transport = (dev.get("transport") or "espnow").strip().lower()
|
||||
if transport == "wifi":
|
||||
ip = normalize_tcp_peer_ip(str(dev.get("address") or ""))
|
||||
if not ip:
|
||||
return m, False, "no IP"
|
||||
ok = await send_json_line_to_ip(ip, msg)
|
||||
return m, bool(ok), None if ok else "driver not connected"
|
||||
if not sender:
|
||||
return m, False, "transport not configured"
|
||||
try:
|
||||
await sender.send(msg, addr=m)
|
||||
return m, True, None
|
||||
except Exception as e:
|
||||
return m, False, str(e)
|
||||
|
||||
tasks: list = []
|
||||
for mac in mac_list:
|
||||
m = str(mac).strip().lower().replace(":", "").replace("-", "")
|
||||
if len(m) != 12:
|
||||
continue
|
||||
dev = devices.read(m)
|
||||
if not dev:
|
||||
errors.append({"mac": m, "error": "not in registry"})
|
||||
continue
|
||||
tasks.append(_push_brightness_one(m, dev))
|
||||
|
||||
if tasks:
|
||||
results = await asyncio.gather(*tasks, return_exceptions=True)
|
||||
for r in results:
|
||||
if isinstance(r, Exception):
|
||||
errors.append({"mac": "*", "error": str(r)})
|
||||
continue
|
||||
m, ok, err = r
|
||||
if ok:
|
||||
sent += 1
|
||||
elif err:
|
||||
errors.append({"mac": m, "error": err})
|
||||
|
||||
return json.dumps(
|
||||
{"message": "brightness sent", "sent": sent, "errors": errors}
|
||||
), 200, {"Content-Type": "application/json"}
|
||||
|
||||
|
||||
@controller.post("/<id>/identify")
|
||||
@with_session
|
||||
async def identify_group_devices(request, session, id):
|
||||
"""
|
||||
Run the same identify blink as ``POST /devices/<id>/identify`` for every registry member
|
||||
in parallel so all drivers in the group blink together.
|
||||
"""
|
||||
_ = request
|
||||
gdoc = _read_group_for_session(session, id)
|
||||
if not gdoc:
|
||||
return json.dumps({"error": "Group not found"}), 404, {"Content-Type": "application/json"}
|
||||
|
||||
mac_list = gdoc.get("devices") if isinstance(gdoc.get("devices"), list) else []
|
||||
if not mac_list:
|
||||
return json.dumps({"error": "Group has no devices"}), 400, {"Content-Type": "application/json"}
|
||||
|
||||
from controllers.device import send_identify_to_group_devices
|
||||
|
||||
normalized: list[str] = []
|
||||
errors: list[dict] = []
|
||||
for mac in mac_list:
|
||||
m = str(mac).strip().lower().replace(":", "").replace("-", "")
|
||||
if len(m) != 12:
|
||||
errors.append({"mac": str(mac), "error": "invalid MAC"})
|
||||
continue
|
||||
normalized.append(m)
|
||||
|
||||
if not normalized:
|
||||
return json.dumps(
|
||||
{"message": "identify group done", "sent": 0, "errors": errors}
|
||||
), 200, {"Content-Type": "application/json"}
|
||||
|
||||
sent, batch_errors = await send_identify_to_group_devices(normalized)
|
||||
errors.extend(batch_errors)
|
||||
|
||||
return json.dumps(
|
||||
{"message": "identify group done", "sent": sent, "errors": errors}
|
||||
), 200, {"Content-Type": "application/json"}
|
||||
|
||||
@@ -367,6 +367,8 @@ async def create_driver_pattern(request):
|
||||
Body JSON:
|
||||
name, code (required),
|
||||
min_delay, max_delay, max_colors (optional numbers),
|
||||
has_background (optional bool),
|
||||
supports_manual (optional bool, default true if omitted in db),
|
||||
n1..n8 (optional string labels),
|
||||
overwrite (optional, default true).
|
||||
"""
|
||||
@@ -409,6 +411,12 @@ async def create_driver_pattern(request):
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
if "has_background" in data:
|
||||
meta["has_background"] = bool(data.get("has_background"))
|
||||
|
||||
if "supports_manual" in data:
|
||||
meta["supports_manual"] = bool(data.get("supports_manual"))
|
||||
|
||||
for i in range(1, 9):
|
||||
nk = "n%d" % i
|
||||
if nk not in data:
|
||||
|
||||
@@ -2,6 +2,7 @@ from microdot import Microdot
|
||||
from microdot.session import with_session
|
||||
from models.preset import Preset
|
||||
from models.profile import Profile
|
||||
from models.pallet import Palette
|
||||
from models.device import Device, normalize_mac
|
||||
from models.transport import get_current_sender
|
||||
from util.driver_delivery import deliver_json_messages, deliver_preset_broadcast_then_per_device
|
||||
@@ -12,6 +13,18 @@ controller = Microdot()
|
||||
presets = Preset()
|
||||
profiles = Profile()
|
||||
|
||||
|
||||
def _palette_colors_for_profile(profile_id):
|
||||
prof = profiles.read(str(profile_id))
|
||||
if not isinstance(prof, dict):
|
||||
return None
|
||||
pid = prof.get("palette_id") or prof.get("paletteId")
|
||||
if not pid:
|
||||
return None
|
||||
cols = Palette().read(str(pid))
|
||||
return cols if isinstance(cols, list) else None
|
||||
|
||||
|
||||
def get_current_profile_id(session=None):
|
||||
"""Get the current active profile ID from session or fallback to first."""
|
||||
profile_list = profiles.list()
|
||||
@@ -153,6 +166,7 @@ async def send_presets(request, session):
|
||||
|
||||
# Build API-compliant preset map keyed by preset ID, include name
|
||||
current_profile_id = get_current_profile_id(session)
|
||||
palette_colors = _palette_colors_for_profile(current_profile_id)
|
||||
presets_by_name = {}
|
||||
for pid in preset_ids:
|
||||
preset_data = presets.read(str(pid))
|
||||
@@ -161,7 +175,7 @@ async def send_presets(request, session):
|
||||
if str(preset_data.get("profile_id")) != str(current_profile_id):
|
||||
continue
|
||||
preset_key = str(pid)
|
||||
preset_payload = build_preset_dict(preset_data)
|
||||
preset_payload = build_preset_dict(preset_data, palette_colors)
|
||||
preset_payload["name"] = preset_data.get("name", "")
|
||||
presets_by_name[preset_key] = preset_payload
|
||||
|
||||
@@ -315,6 +329,17 @@ async def push_driver_messages(request, session):
|
||||
except Exception:
|
||||
return json.dumps({"error": "Send failed"}), 503, {'Content-Type': 'application/json'}
|
||||
|
||||
try:
|
||||
from util import sequence_playback as seq_pb
|
||||
from util.beat_driver_route import sync_beat_route_from_push_sequence
|
||||
|
||||
preserve = bool(seq_pb.playback_status().get("active"))
|
||||
sync_beat_route_from_push_sequence(
|
||||
seq, target_macs=target_list, preserve_parallel_lane_routes=preserve
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return json.dumps({
|
||||
"message": "Delivered",
|
||||
"deliveries": deliveries,
|
||||
|
||||
@@ -1,51 +1,207 @@
|
||||
from microdot import Microdot
|
||||
from models.squence import Sequence
|
||||
from microdot.session import with_session
|
||||
from models.sequence import Sequence
|
||||
from models.profile import Profile
|
||||
from models.transport import get_current_sender
|
||||
import json
|
||||
|
||||
controller = Microdot()
|
||||
sequences = Sequence()
|
||||
profiles = Profile()
|
||||
|
||||
@controller.get('')
|
||||
async def list_sequences(request):
|
||||
"""List all sequences."""
|
||||
return json.dumps(sequences), 200, {'Content-Type': 'application/json'}
|
||||
|
||||
@controller.get('/<id>')
|
||||
async def get_sequence(request, id):
|
||||
"""Get a specific sequence by ID."""
|
||||
sequence = sequences.read(id)
|
||||
if sequence:
|
||||
return json.dumps(sequence), 200, {'Content-Type': 'application/json'}
|
||||
def get_current_profile_id(session=None):
|
||||
"""Get the current active profile ID from session or fallback to first."""
|
||||
profile_list = profiles.list()
|
||||
session_profile = None
|
||||
if session is not None:
|
||||
session_profile = session.get("current_profile")
|
||||
if session_profile and session_profile in profile_list:
|
||||
return session_profile
|
||||
if profile_list:
|
||||
return profile_list[0]
|
||||
return None
|
||||
|
||||
|
||||
@controller.get("")
|
||||
@with_session
|
||||
async def list_sequences(request, session):
|
||||
"""List sequences for the current profile."""
|
||||
current_profile_id = get_current_profile_id(session)
|
||||
if not current_profile_id:
|
||||
return json.dumps({}), 200, {"Content-Type": "application/json"}
|
||||
scoped = {
|
||||
sid: sdata
|
||||
for sid, sdata in sequences.items()
|
||||
if isinstance(sdata, dict)
|
||||
and str(sdata.get("profile_id")) == str(current_profile_id)
|
||||
}
|
||||
return json.dumps(scoped), 200, {"Content-Type": "application/json"}
|
||||
|
||||
|
||||
@controller.get("/<id>")
|
||||
@with_session
|
||||
async def get_sequence(request, session, id):
|
||||
"""Get a specific sequence by ID (current profile only)."""
|
||||
current_profile_id = get_current_profile_id(session)
|
||||
seq = sequences.read(id)
|
||||
if (
|
||||
seq
|
||||
and current_profile_id
|
||||
and str(seq.get("profile_id")) == str(current_profile_id)
|
||||
):
|
||||
return json.dumps(seq), 200, {"Content-Type": "application/json"}
|
||||
return json.dumps({"error": "Sequence not found"}), 404
|
||||
|
||||
@controller.post('')
|
||||
async def create_sequence(request):
|
||||
"""Create a new sequence."""
|
||||
try:
|
||||
data = request.json or {}
|
||||
group_name = data.get("group_name", "")
|
||||
preset_names = data.get("presets", None)
|
||||
sequence_id = sequences.create(group_name, preset_names)
|
||||
if data:
|
||||
sequences.update(sequence_id, data)
|
||||
return json.dumps(sequences.read(sequence_id)), 201, {'Content-Type': 'application/json'}
|
||||
except Exception as e:
|
||||
return json.dumps({"error": str(e)}), 400
|
||||
|
||||
@controller.put('/<id>')
|
||||
async def update_sequence(request, id):
|
||||
"""Update an existing sequence."""
|
||||
@controller.post("")
|
||||
@with_session
|
||||
async def create_sequence(request, session):
|
||||
"""Create a new sequence for the current profile."""
|
||||
try:
|
||||
try:
|
||||
data = request.json or {}
|
||||
except Exception:
|
||||
return (
|
||||
json.dumps({"error": "Invalid JSON"}),
|
||||
400,
|
||||
{"Content-Type": "application/json"},
|
||||
)
|
||||
current_profile_id = get_current_profile_id(session)
|
||||
if not current_profile_id:
|
||||
return (
|
||||
json.dumps({"error": "No profile available"}),
|
||||
404,
|
||||
{"Content-Type": "application/json"},
|
||||
)
|
||||
sequence_id = sequences.create(current_profile_id)
|
||||
if not isinstance(data, dict):
|
||||
data = {}
|
||||
data = dict(data)
|
||||
data["profile_id"] = str(current_profile_id)
|
||||
if sequences.update(sequence_id, data):
|
||||
seq_data = sequences.read(sequence_id)
|
||||
return (
|
||||
json.dumps({sequence_id: seq_data}),
|
||||
201,
|
||||
{"Content-Type": "application/json"},
|
||||
)
|
||||
return (
|
||||
json.dumps({"error": "Failed to create sequence"}),
|
||||
400,
|
||||
{"Content-Type": "application/json"},
|
||||
)
|
||||
except Exception as e:
|
||||
return json.dumps({"error": str(e)}), 400, {"Content-Type": "application/json"}
|
||||
|
||||
|
||||
@controller.put("/<id>")
|
||||
@with_session
|
||||
async def update_sequence(request, session, id):
|
||||
"""Update an existing sequence (current profile only)."""
|
||||
try:
|
||||
current_profile_id = get_current_profile_id(session)
|
||||
seq = sequences.read(id)
|
||||
if not seq or str(seq.get("profile_id")) != str(current_profile_id):
|
||||
return json.dumps({"error": "Sequence not found"}), 404
|
||||
data = request.json
|
||||
if not isinstance(data, dict):
|
||||
return (
|
||||
json.dumps({"error": "Invalid JSON"}),
|
||||
400,
|
||||
{"Content-Type": "application/json"},
|
||||
)
|
||||
data = dict(data)
|
||||
data["profile_id"] = str(current_profile_id)
|
||||
if sequences.update(id, data):
|
||||
return json.dumps(sequences.read(id)), 200, {'Content-Type': 'application/json'}
|
||||
try:
|
||||
from util.sequence_playback import stop_if_playing_sequence
|
||||
|
||||
stop_if_playing_sequence(str(id))
|
||||
except Exception:
|
||||
pass
|
||||
return json.dumps(sequences.read(id)), 200, {"Content-Type": "application/json"}
|
||||
return json.dumps({"error": "Sequence not found"}), 404
|
||||
except Exception as e:
|
||||
return json.dumps({"error": str(e)}), 400
|
||||
return json.dumps({"error": str(e)}), 400, {"Content-Type": "application/json"}
|
||||
|
||||
@controller.delete('/<id>')
|
||||
async def delete_sequence(request, id):
|
||||
"""Delete a sequence."""
|
||||
|
||||
@controller.delete("/<id>")
|
||||
@with_session
|
||||
async def delete_sequence(request, session, id):
|
||||
"""Delete a sequence (current profile only)."""
|
||||
current_profile_id = get_current_profile_id(session)
|
||||
seq = sequences.read(id)
|
||||
if not seq or str(seq.get("profile_id")) != str(current_profile_id):
|
||||
return json.dumps({"error": "Sequence not found"}), 404
|
||||
try:
|
||||
from util.sequence_playback import stop_if_playing_sequence
|
||||
|
||||
stop_if_playing_sequence(str(id))
|
||||
except Exception:
|
||||
pass
|
||||
if sequences.delete(id):
|
||||
return json.dumps({"message": "Sequence deleted successfully"}), 200
|
||||
return (
|
||||
json.dumps({"message": "Sequence deleted successfully"}),
|
||||
200,
|
||||
{"Content-Type": "application/json"},
|
||||
)
|
||||
return json.dumps({"error": "Sequence not found"}), 404
|
||||
|
||||
|
||||
@controller.post("/stop")
|
||||
@with_session
|
||||
async def stop_sequence_playback(request, session):
|
||||
"""Stop server-driven zone sequence playback."""
|
||||
_ = request
|
||||
try:
|
||||
from util.sequence_playback import stop
|
||||
|
||||
stop()
|
||||
return json.dumps({"ok": True}), 200, {"Content-Type": "application/json"}
|
||||
except Exception as e:
|
||||
return json.dumps({"error": str(e)}), 500, {"Content-Type": "application/json"}
|
||||
|
||||
|
||||
@controller.post("/<id>/play")
|
||||
@with_session
|
||||
async def play_sequence(request, session, id):
|
||||
"""Start server-driven playback for a sequence in a zone (body: {\"zone_id\": \"...\"})."""
|
||||
if not get_current_sender():
|
||||
return (
|
||||
json.dumps({"error": "Transport not configured"}),
|
||||
503,
|
||||
{"Content-Type": "application/json"},
|
||||
)
|
||||
current_profile_id = get_current_profile_id(session)
|
||||
if not current_profile_id:
|
||||
return (
|
||||
json.dumps({"error": "No profile available"}),
|
||||
404,
|
||||
{"Content-Type": "application/json"},
|
||||
)
|
||||
try:
|
||||
data = request.json or {}
|
||||
except Exception:
|
||||
data = {}
|
||||
if not isinstance(data, dict):
|
||||
data = {}
|
||||
zone_id = data.get("zone_id") or data.get("zoneId")
|
||||
if zone_id is None or str(zone_id).strip() == "":
|
||||
return (
|
||||
json.dumps({"error": "zone_id required"}),
|
||||
400,
|
||||
{"Content-Type": "application/json"},
|
||||
)
|
||||
zone_id = str(zone_id).strip()
|
||||
try:
|
||||
from util.sequence_playback import start
|
||||
|
||||
await start(zone_id, str(id), str(current_profile_id), data if isinstance(data, dict) else None)
|
||||
return json.dumps({"ok": True}), 200, {"Content-Type": "application/json"}
|
||||
except ValueError as e:
|
||||
return json.dumps({"error": str(e)}), 400, {"Content-Type": "application/json"}
|
||||
except RuntimeError as e:
|
||||
return json.dumps({"error": str(e)}), 503, {"Content-Type": "application/json"}
|
||||
except Exception as e:
|
||||
return json.dumps({"error": str(e)}), 500, {"Content-Type": "application/json"}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
from microdot import Microdot, send_file
|
||||
from settings import Settings
|
||||
import asyncio
|
||||
import json
|
||||
|
||||
from microdot import Microdot, send_file
|
||||
|
||||
from models import wifi_ws_clients
|
||||
from settings import Settings
|
||||
|
||||
controller = Microdot()
|
||||
settings = Settings()
|
||||
|
||||
@@ -63,17 +67,36 @@ def _validate_wifi_channel(value):
|
||||
return ch
|
||||
|
||||
|
||||
def _validate_global_brightness(value):
|
||||
"""Return int 0–255 or raise ValueError."""
|
||||
v = int(value)
|
||||
if v < 0 or v > 255:
|
||||
raise ValueError("global_brightness must be between 0 and 255")
|
||||
return v
|
||||
|
||||
|
||||
@controller.put('/settings')
|
||||
async def update_settings(request):
|
||||
"""Update general settings."""
|
||||
try:
|
||||
data = request.json
|
||||
global_brightness_changed = False
|
||||
for key, value in data.items():
|
||||
if key == 'wifi_channel' and value is not None:
|
||||
settings[key] = _validate_wifi_channel(value)
|
||||
elif key == 'global_brightness' and value is not None:
|
||||
settings[key] = _validate_global_brightness(value)
|
||||
global_brightness_changed = True
|
||||
else:
|
||||
settings[key] = value
|
||||
settings.save()
|
||||
if global_brightness_changed:
|
||||
try:
|
||||
asyncio.get_running_loop().create_task(
|
||||
wifi_ws_clients.broadcast_global_brightness_to_tcp_drivers()
|
||||
)
|
||||
except RuntimeError:
|
||||
pass
|
||||
return json.dumps({"message": "Settings updated successfully"}), 200, {'Content-Type': 'application/json'}
|
||||
except ValueError as e:
|
||||
return json.dumps({"error": str(e)}), 400
|
||||
|
||||
@@ -290,6 +290,8 @@ async def create_zone(request, session):
|
||||
ids_str = request.form.get("ids", "1").strip()
|
||||
names = [i.strip() for i in ids_str.split(",") if i.strip()]
|
||||
preset_ids = None
|
||||
group_ids = []
|
||||
content_kind = None
|
||||
else:
|
||||
data = request.json or {}
|
||||
name = data.get("name", "")
|
||||
@@ -297,11 +299,20 @@ async def create_zone(request, session):
|
||||
if names is None:
|
||||
names = data.get("ids")
|
||||
preset_ids = data.get("presets", None)
|
||||
group_ids = data.get("group_ids")
|
||||
if group_ids is None:
|
||||
group_ids = []
|
||||
if isinstance(group_ids, list):
|
||||
group_ids = [str(x) for x in group_ids if x is not None]
|
||||
else:
|
||||
group_ids = []
|
||||
raw_kind = data.get("content_kind")
|
||||
content_kind = raw_kind if raw_kind in ("presets", "sequences") else None
|
||||
|
||||
if not name:
|
||||
return json.dumps({"error": "Zone name cannot be empty"}), 400
|
||||
|
||||
zid = zones.create(name, names, preset_ids)
|
||||
zid = zones.create(name, names, preset_ids, group_ids, content_kind)
|
||||
|
||||
profile_id = get_current_profile_id(session)
|
||||
if profile_id:
|
||||
@@ -333,7 +344,12 @@ async def clone_zone(request, session, id):
|
||||
data = request.json or {}
|
||||
source_name = source.get("name") or f"Zone {id}"
|
||||
new_name = data.get("name") or f"{source_name} Copy"
|
||||
clone_id = zones.create(new_name, source.get("names"), source.get("presets"))
|
||||
clone_id = zones.create(
|
||||
new_name,
|
||||
source.get("names"),
|
||||
source.get("presets"),
|
||||
source.get("group_ids"),
|
||||
)
|
||||
extra = {k: v for k, v in source.items() if k not in ("name", "names", "presets")}
|
||||
if extra:
|
||||
zones.update(clone_id, extra)
|
||||
|
||||
156
src/main.py
156
src/main.py
@@ -2,6 +2,7 @@ import asyncio
|
||||
import errno
|
||||
import json
|
||||
import os
|
||||
import secrets
|
||||
import signal
|
||||
import socket
|
||||
import threading
|
||||
@@ -31,12 +32,18 @@ from util.device_status_broadcaster import (
|
||||
register_device_status_ws,
|
||||
unregister_device_status_ws,
|
||||
)
|
||||
from util.audio_detector import AudioBeatDetector
|
||||
|
||||
_tcp_device_lock = threading.Lock()
|
||||
|
||||
DISCOVERY_UDP_PORT = 8766
|
||||
|
||||
|
||||
def _live_reload_enabled() -> bool:
|
||||
v = os.environ.get("LED_CONTROLLER_LIVE_RELOAD", "").strip().lower()
|
||||
return v not in ("", "0", "false", "no")
|
||||
|
||||
|
||||
def _register_udp_device_sync(
|
||||
device_name: str, peer_ip: str, mac, device_type=None
|
||||
) -> None:
|
||||
@@ -246,6 +253,29 @@ async def main(port=80):
|
||||
set_sender(sender)
|
||||
|
||||
app = Microdot()
|
||||
audio_detector = AudioBeatDetector()
|
||||
try:
|
||||
from util import audio_detector as audio_detector_module
|
||||
|
||||
audio_detector_module.set_shared_beat_detector(audio_detector)
|
||||
except Exception as e:
|
||||
print(f"[startup] audio detector shared registration skipped: {e!r}")
|
||||
try:
|
||||
from util.audio_run_persist import coerce_audio_device, read_audio_run_state
|
||||
|
||||
persisted = read_audio_run_state()
|
||||
if persisted.get("enabled"):
|
||||
dev = coerce_audio_device(persisted.get("device"))
|
||||
audio_detector.start(device=dev)
|
||||
print("[startup] audio beat detector started from saved run state")
|
||||
except Exception as e:
|
||||
print(f"[startup] audio auto-start skipped: {e!r}")
|
||||
from util import beat_driver_route
|
||||
|
||||
beat_driver_route.set_beat_route_main_loop(asyncio.get_running_loop())
|
||||
from util import sequence_playback as seq_pb
|
||||
|
||||
seq_pb.ensure_beat_consumer_started()
|
||||
|
||||
# Initialize sessions with a secret key from settings
|
||||
secret_key = settings.get('session_secret_key', 'led-controller-secret-key-change-in-production')
|
||||
@@ -279,23 +309,125 @@ async def main(port=80):
|
||||
tcp_client_registry.set_settings(settings)
|
||||
tcp_client_registry.set_tcp_status_broadcaster(broadcast_device_tcp_status)
|
||||
|
||||
live_reload = _live_reload_enabled()
|
||||
dev_build_id = secrets.token_hex(12) if live_reload else None
|
||||
if live_reload:
|
||||
print(
|
||||
"[dev] LED_CONTROLLER_LIVE_RELOAD: browser refreshes when the server process restarts"
|
||||
)
|
||||
|
||||
if dev_build_id:
|
||||
|
||||
@app.route("/__dev/build-id")
|
||||
def dev_build_id_route(request):
|
||||
_ = request
|
||||
return (
|
||||
dev_build_id,
|
||||
200,
|
||||
{
|
||||
"Content-Type": "text/plain; charset=utf-8",
|
||||
"Cache-Control": "no-store",
|
||||
},
|
||||
)
|
||||
|
||||
# Serve index.html at root (cwd is src/ when run via pipenv run run)
|
||||
@app.route('/')
|
||||
@app.route("/")
|
||||
def index(request):
|
||||
"""Serve the main web UI."""
|
||||
return send_file('templates/index.html')
|
||||
|
||||
# Serve settings page
|
||||
@app.route('/settings')
|
||||
def settings_page(request):
|
||||
"""Serve the settings page."""
|
||||
return send_file('templates/settings.html')
|
||||
if dev_build_id:
|
||||
try:
|
||||
with open("templates/index.html", encoding="utf-8") as f:
|
||||
html = f.read()
|
||||
tag = '<script src="/static/dev-live-reload.js" defer></script>'
|
||||
if "</body>" in html:
|
||||
html = html.replace("</body>", tag + "\n</body>", 1)
|
||||
return html, 200, {"Content-Type": "text/html; charset=utf-8"}
|
||||
except OSError:
|
||||
pass
|
||||
return send_file("templates/index.html")
|
||||
|
||||
# Favicon: avoid 404 in browser console (no file needed)
|
||||
@app.route('/favicon.ico')
|
||||
def favicon(request):
|
||||
return '', 204
|
||||
|
||||
@app.route('/api/audio/devices')
|
||||
async def audio_devices(request):
|
||||
_ = request
|
||||
try:
|
||||
return {
|
||||
"devices": audio_detector.list_input_devices(),
|
||||
"diagnostics": audio_detector.diagnostics(),
|
||||
}
|
||||
except Exception as e:
|
||||
return {"error": str(e)}, 500
|
||||
|
||||
@app.route('/api/audio/start', methods=['POST'])
|
||||
async def audio_start(request):
|
||||
payload = request.json if isinstance(request.json, dict) else {}
|
||||
device = payload.get("device", None)
|
||||
if device in ("", None):
|
||||
device = None
|
||||
else:
|
||||
try:
|
||||
device = int(device)
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
try:
|
||||
audio_detector.start(device=device)
|
||||
from util.audio_run_persist import write_audio_run_state
|
||||
|
||||
write_audio_run_state(enabled=True, device=device)
|
||||
return {"ok": True, "status": audio_detector.status()}
|
||||
except Exception as e:
|
||||
return {"ok": False, "error": str(e)}, 500
|
||||
|
||||
@app.route('/api/audio/stop', methods=['POST'])
|
||||
async def audio_stop(request):
|
||||
_ = request
|
||||
audio_detector.stop()
|
||||
from util.audio_run_persist import write_audio_run_state
|
||||
|
||||
write_audio_run_state(enabled=False)
|
||||
return {"ok": True, "status": audio_detector.status()}
|
||||
|
||||
@app.route('/api/audio/status')
|
||||
async def audio_status(request):
|
||||
_ = request
|
||||
from util import beat_driver_route
|
||||
from util import sequence_playback
|
||||
|
||||
st = audio_detector.status()
|
||||
st["sequence"] = sequence_playback.playback_status()
|
||||
st["manual_beat_stride"] = beat_driver_route.manual_beat_stride_status()
|
||||
seq = st.get("sequence")
|
||||
beat_readout = ""
|
||||
if isinstance(seq, dict) and str(seq.get("beat_readout") or "").strip():
|
||||
beat_readout = str(seq.get("beat_readout") or "").strip()
|
||||
elif st.get("running"):
|
||||
mb = st.get("manual_beat_stride")
|
||||
if isinstance(mb, dict) and mb.get("active"):
|
||||
try:
|
||||
n = int(mb.get("stride_n") or 1)
|
||||
except (TypeError, ValueError):
|
||||
n = 1
|
||||
n = max(1, min(64, n))
|
||||
try:
|
||||
bi = int(mb.get("beat_in_stride") or 1)
|
||||
except (TypeError, ValueError):
|
||||
bi = 1
|
||||
pos = min(n, max(1, bi))
|
||||
beat_readout = f"{pos}/{n}"
|
||||
else:
|
||||
try:
|
||||
bs = int(st.get("beat_seq") or 0)
|
||||
except (TypeError, ValueError):
|
||||
bs = 0
|
||||
if bs > 0:
|
||||
beat_readout = str(bs)
|
||||
st["beat_readout"] = beat_readout
|
||||
return {"status": st}
|
||||
|
||||
# Static file route
|
||||
@app.route("/static/<path:path>")
|
||||
def static_handler(request, path):
|
||||
@@ -354,6 +486,10 @@ async def main(port=80):
|
||||
def _graceful_shutdown(*_args):
|
||||
print("[server] shutting down...")
|
||||
udp_holder["closing"] = True
|
||||
try:
|
||||
audio_detector.stop()
|
||||
except Exception:
|
||||
pass
|
||||
u = udp_holder.get("sock")
|
||||
if u is not None:
|
||||
try:
|
||||
@@ -389,6 +525,10 @@ async def main(port=80):
|
||||
)
|
||||
raise
|
||||
finally:
|
||||
try:
|
||||
audio_detector.stop()
|
||||
except Exception:
|
||||
pass
|
||||
srv = getattr(app, "server", None)
|
||||
if srv is not None:
|
||||
try:
|
||||
|
||||
@@ -38,6 +38,29 @@ def normalize_mac(mac):
|
||||
return None
|
||||
|
||||
|
||||
def resolve_device_mac_for_select_routing(devices, name_key):
|
||||
"""
|
||||
Map a v1 ``select`` map key to device storage id (MAC).
|
||||
|
||||
Matches the registry **name**, or ``led-<12hex>`` as a MAC hint (default driver
|
||||
name form) so routing still works after the device is renamed in the registry.
|
||||
"""
|
||||
k = str(name_key or "").strip()
|
||||
if not k:
|
||||
return None
|
||||
for did in devices.list():
|
||||
doc = devices.read(did) or {}
|
||||
if str(doc.get("name") or "").strip() == k:
|
||||
m = normalize_mac(did)
|
||||
if m:
|
||||
return m
|
||||
if k.startswith("led-"):
|
||||
m = normalize_mac(k[4:])
|
||||
if m and devices.read(m):
|
||||
return m
|
||||
return None
|
||||
|
||||
|
||||
def derive_device_mac(mac=None, address=None, transport="espnow"):
|
||||
"""
|
||||
Resolve the device MAC used as storage id.
|
||||
|
||||
@@ -1,14 +1,71 @@
|
||||
from models.model import Model
|
||||
|
||||
|
||||
class Group(Model):
|
||||
"""Device groups (members + optional Wi‑Fi driver defaults); also pattern fields for sequences.
|
||||
|
||||
Omit ``profile_id`` (or set it null) for a **shared** group: every profile can attach it to
|
||||
zones and sequences. Set ``profile_id`` to a profile id to show the group only when that
|
||||
profile is active (still one global record in ``group.json``).
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def load(self):
|
||||
super().load()
|
||||
changed = False
|
||||
for gid, doc in list(self.items()):
|
||||
if not isinstance(doc, dict):
|
||||
continue
|
||||
if self._migrate_record(doc):
|
||||
changed = True
|
||||
if changed:
|
||||
self.save()
|
||||
|
||||
def _migrate_record(self, doc):
|
||||
changed = False
|
||||
raw_dev = doc.get("devices")
|
||||
if raw_dev is None:
|
||||
doc["devices"] = []
|
||||
changed = True
|
||||
elif isinstance(raw_dev, list):
|
||||
norm = []
|
||||
for x in raw_dev:
|
||||
if x is None:
|
||||
continue
|
||||
s = str(x).strip().lower().replace(":", "").replace("-", "")
|
||||
if len(s) == 12 and all(c in "0123456789abcdef" for c in s):
|
||||
norm.append(s)
|
||||
else:
|
||||
norm.append(str(x).strip())
|
||||
if norm != raw_dev:
|
||||
doc["devices"] = norm
|
||||
changed = True
|
||||
for key in (
|
||||
"wifi_driver_display_name",
|
||||
"wifi_driver_num_leds",
|
||||
"wifi_color_order",
|
||||
"wifi_startup_mode",
|
||||
):
|
||||
if key not in doc:
|
||||
doc[key] = None
|
||||
changed = True
|
||||
if "output_brightness" not in doc:
|
||||
doc["output_brightness"] = 255
|
||||
changed = True
|
||||
return changed
|
||||
|
||||
def create(self, name=""):
|
||||
next_id = self.get_next_id()
|
||||
self[next_id] = {
|
||||
"name": name,
|
||||
"devices": [],
|
||||
"wifi_driver_display_name": None,
|
||||
"wifi_driver_num_leds": None,
|
||||
"wifi_color_order": None,
|
||||
"wifi_startup_mode": None,
|
||||
"output_brightness": 255,
|
||||
"pattern": "on",
|
||||
"colors": ["000000", "FF0000"],
|
||||
"brightness": 100,
|
||||
@@ -22,7 +79,7 @@ class Group(Model):
|
||||
"n5": 0,
|
||||
"n6": 0,
|
||||
"n7": 0,
|
||||
"n8": 0
|
||||
"n8": 0,
|
||||
}
|
||||
self.save()
|
||||
return next_id
|
||||
|
||||
@@ -15,6 +15,9 @@ class Preset(Model):
|
||||
if default_profile_id is not None:
|
||||
preset_data["profile_id"] = str(default_profile_id)
|
||||
changed = True
|
||||
if isinstance(preset_data, dict) and "group_ids" in preset_data:
|
||||
preset_data.pop("group_ids", None)
|
||||
changed = True
|
||||
if changed:
|
||||
self.save()
|
||||
except Exception:
|
||||
@@ -26,6 +29,7 @@ class Preset(Model):
|
||||
"name": "",
|
||||
"pattern": "",
|
||||
"colors": [],
|
||||
"background": "#000000",
|
||||
"brightness": 0,
|
||||
"delay": 0,
|
||||
"n1": 0,
|
||||
@@ -36,6 +40,7 @@ class Preset(Model):
|
||||
"n6": 0,
|
||||
"n7": 0,
|
||||
"n8": 0,
|
||||
"manual_beat_n": 1,
|
||||
"profile_id": str(profile_id) if profile_id is not None else None,
|
||||
}
|
||||
self.save()
|
||||
|
||||
159
src/models/sequence.py
Normal file
159
src/models/sequence.py
Normal file
@@ -0,0 +1,159 @@
|
||||
from models.model import Model
|
||||
|
||||
|
||||
class Sequence(Model):
|
||||
def load(self):
|
||||
super().load()
|
||||
self._migrate_after_load()
|
||||
|
||||
def _migrate_after_load(self):
|
||||
try:
|
||||
from models.profile import Profile
|
||||
|
||||
profiles = Profile()
|
||||
profile_list = profiles.list()
|
||||
default_profile_id = profile_list[0] if profile_list else None
|
||||
except Exception:
|
||||
default_profile_id = None
|
||||
|
||||
changed = False
|
||||
for _sid, doc in list(self.items()):
|
||||
if not isinstance(doc, dict):
|
||||
continue
|
||||
if not isinstance(doc.get("steps"), list):
|
||||
presets = doc.get("presets")
|
||||
if isinstance(presets, list) and presets:
|
||||
doc["steps"] = [
|
||||
{"preset_id": str(p), "group_ids": []} for p in presets
|
||||
]
|
||||
else:
|
||||
doc["steps"] = []
|
||||
changed = True
|
||||
if "step_duration_ms" not in doc:
|
||||
dur = doc.get("sequence_duration")
|
||||
doc["step_duration_ms"] = (
|
||||
int(dur) if isinstance(dur, (int, float)) else 3000
|
||||
)
|
||||
changed = True
|
||||
if "loop" not in doc:
|
||||
doc["loop"] = bool(doc.get("sequence_loop", False))
|
||||
changed = True
|
||||
if "name" not in doc:
|
||||
doc["name"] = str(doc.get("group_name") or "")
|
||||
changed = True
|
||||
if "profile_id" not in doc and default_profile_id is not None:
|
||||
doc["profile_id"] = str(default_profile_id)
|
||||
changed = True
|
||||
if not isinstance(doc.get("lanes"), list):
|
||||
steps = doc.get("steps")
|
||||
if isinstance(steps, list) and steps:
|
||||
doc["lanes"] = [list(steps)]
|
||||
else:
|
||||
doc["lanes"] = [[]]
|
||||
changed = True
|
||||
if "group_ids" not in doc or not isinstance(doc.get("group_ids"), list):
|
||||
doc["group_ids"] = []
|
||||
changed = True
|
||||
if doc.get("advance_mode") != "beats":
|
||||
doc["advance_mode"] = "beats"
|
||||
changed = True
|
||||
if "simulated_bpm" not in doc:
|
||||
doc["simulated_bpm"] = 120
|
||||
changed = True
|
||||
else:
|
||||
try:
|
||||
sb = int(float(doc["simulated_bpm"]))
|
||||
doc["simulated_bpm"] = max(30, min(300, sb))
|
||||
except (TypeError, ValueError):
|
||||
doc["simulated_bpm"] = 120
|
||||
changed = True
|
||||
if "sequence_transition" not in doc:
|
||||
doc["sequence_transition"] = 500
|
||||
changed = True
|
||||
# Ensure each step has beats (beat-based advance); default 1
|
||||
for lane in doc.get("lanes") or []:
|
||||
if not isinstance(lane, list):
|
||||
continue
|
||||
for step in lane:
|
||||
if not isinstance(step, dict):
|
||||
continue
|
||||
if "beats" not in step:
|
||||
step["beats"] = 1
|
||||
changed = True
|
||||
# Per-lane group ids (parallel to ``lanes``)
|
||||
lanes_list = [x for x in (doc.get("lanes") or []) if isinstance(x, list)]
|
||||
n_lanes = len(lanes_list)
|
||||
lg = doc.get("lanes_group_ids")
|
||||
if n_lanes and (not isinstance(lg, list) or len(lg) != n_lanes):
|
||||
shared = doc.get("group_ids") if isinstance(doc.get("group_ids"), list) else []
|
||||
shared_s = [str(x).strip() for x in shared if x is not None and str(x).strip()]
|
||||
if n_lanes == 1 and lanes_list[0]:
|
||||
first = lanes_list[0][0] if isinstance(lanes_list[0][0], dict) else {}
|
||||
step_g = (
|
||||
first.get("group_ids")
|
||||
if isinstance(first.get("group_ids"), list)
|
||||
else []
|
||||
)
|
||||
step_s = [
|
||||
str(x).strip() for x in step_g if x is not None and str(x).strip()
|
||||
]
|
||||
doc["lanes_group_ids"] = [step_s if step_s else list(shared_s)]
|
||||
else:
|
||||
doc["lanes_group_ids"] = [list(shared_s) for _ in range(n_lanes)]
|
||||
changed = True
|
||||
if changed:
|
||||
self.save()
|
||||
|
||||
def create(self, profile_id=None):
|
||||
next_id = self.get_next_id()
|
||||
self[next_id] = {
|
||||
"name": "",
|
||||
"profile_id": str(profile_id) if profile_id is not None else None,
|
||||
"group_ids": [],
|
||||
"lanes": [[]],
|
||||
"lanes_group_ids": [[]],
|
||||
"advance_mode": "beats",
|
||||
"steps": [],
|
||||
"step_duration_ms": 3000,
|
||||
"simulated_bpm": 120,
|
||||
"sequence_transition": 500,
|
||||
"loop": True,
|
||||
}
|
||||
self.save()
|
||||
return next_id
|
||||
|
||||
def read(self, id):
|
||||
id_str = str(id)
|
||||
return self.get(id_str, None)
|
||||
|
||||
def update(self, id, data):
|
||||
id_str = str(id)
|
||||
if id_str not in self:
|
||||
return False
|
||||
if not isinstance(data, dict):
|
||||
return False
|
||||
data = dict(data)
|
||||
steps = data.get("steps")
|
||||
lanes = data.get("lanes")
|
||||
if isinstance(steps, list) and steps:
|
||||
lanes_ok = (
|
||||
isinstance(lanes, list)
|
||||
and lanes
|
||||
and any(isinstance(x, list) and len(x) > 0 for x in lanes)
|
||||
)
|
||||
if not lanes_ok:
|
||||
data["lanes"] = [list(steps)]
|
||||
self[id_str].update(data)
|
||||
self.save()
|
||||
return True
|
||||
|
||||
def delete(self, id):
|
||||
id_str = str(id)
|
||||
if id_str not in self:
|
||||
return False
|
||||
self.pop(id_str)
|
||||
self.save()
|
||||
return True
|
||||
|
||||
def list(self):
|
||||
return list(self.keys())
|
||||
@@ -1,44 +0,0 @@
|
||||
from models.model import Model
|
||||
|
||||
class Sequence(Model):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def create(self, group_name="", preset_names=None):
|
||||
next_id = self.get_next_id()
|
||||
self[next_id] = {
|
||||
"group_name": group_name,
|
||||
"presets": preset_names if preset_names else [],
|
||||
"sequence_duration": 3000, # Duration per preset in ms
|
||||
"sequence_transition": 500, # Transition time in ms
|
||||
"sequence_loop": False,
|
||||
"sequence_repeat_count": 0, # 0 = infinite
|
||||
"sequence_active": False,
|
||||
"sequence_index": 0,
|
||||
"sequence_start_time": 0
|
||||
}
|
||||
self.save()
|
||||
return next_id
|
||||
|
||||
def read(self, id):
|
||||
id_str = str(id)
|
||||
return self.get(id_str, None)
|
||||
|
||||
def update(self, id, data):
|
||||
id_str = str(id)
|
||||
if id_str not in self:
|
||||
return False
|
||||
self[id_str].update(data)
|
||||
self.save()
|
||||
return True
|
||||
|
||||
def delete(self, id):
|
||||
id_str = str(id)
|
||||
if id_str not in self:
|
||||
return False
|
||||
self.pop(id_str)
|
||||
self.save()
|
||||
return True
|
||||
|
||||
def list(self):
|
||||
return list(self.keys())
|
||||
@@ -33,6 +33,13 @@ async def _to_thread(func, *args):
|
||||
return await loop.run_in_executor(None, func, *args)
|
||||
|
||||
|
||||
class NullSender:
|
||||
"""Used when no ESP-NOW UART bridge is configured or the port cannot be opened."""
|
||||
|
||||
async def send(self, data, addr=None):
|
||||
return True
|
||||
|
||||
|
||||
class SerialSender:
|
||||
def __init__(self, port, baudrate, default_addr=None):
|
||||
import serial
|
||||
@@ -62,7 +69,22 @@ def get_current_sender():
|
||||
|
||||
|
||||
def get_sender(settings):
|
||||
# Serial ESP-NOW bridge is opt-in (serial_enabled true); default off for dev / Wi-Fi-only.
|
||||
if not settings.get("serial_enabled"):
|
||||
print("[startup] serial bridge disabled (set serial_enabled true in settings.json to enable)")
|
||||
return NullSender()
|
||||
port = settings.get("serial_port", "/dev/ttyS0")
|
||||
raw_port = str(port).strip() if port is not None else ""
|
||||
if not raw_port or raw_port.lower() in ("none", "off"):
|
||||
print("[startup] serial bridge disabled (empty serial_port)")
|
||||
return NullSender()
|
||||
baudrate = settings.get("serial_baudrate", 912000)
|
||||
default_addr = settings.get("serial_destination_mac", "ffffffffffff")
|
||||
return SerialSender(port, baudrate, default_addr=default_addr)
|
||||
try:
|
||||
return SerialSender(raw_port, baudrate, default_addr=default_addr)
|
||||
except Exception as e:
|
||||
print(
|
||||
f"[startup] serial open failed ({raw_port!r}): {e}; "
|
||||
"continuing without ESP-NOW bridge (Wi-Fi drivers unchanged)"
|
||||
)
|
||||
return NullSender()
|
||||
|
||||
@@ -84,6 +84,36 @@ def prune_stale_tcp_writers() -> None:
|
||||
_schedule_status_broadcast(ip, False)
|
||||
|
||||
|
||||
def _global_brightness_message_text() -> str | None:
|
||||
"""v1 JSON line for saved zone UI brightness; works with shipping driver firmware (applies ``b`` in RAM)."""
|
||||
global _settings
|
||||
if _settings is None:
|
||||
return None
|
||||
try:
|
||||
b = int(_settings.get("global_brightness", 255))
|
||||
except (TypeError, ValueError):
|
||||
b = 255
|
||||
b = max(0, min(255, b))
|
||||
return json.dumps({"v": "1", "b": b})
|
||||
|
||||
|
||||
async def sync_global_brightness_to_driver(ip: str) -> bool:
|
||||
"""Push Pi-stored global brightness to one Wi-Fi driver over the outbound WebSocket."""
|
||||
text = _global_brightness_message_text()
|
||||
if not text:
|
||||
return False
|
||||
return await send_json_line_to_ip(ip, text)
|
||||
|
||||
|
||||
async def broadcast_global_brightness_to_tcp_drivers() -> None:
|
||||
"""Push saved global brightness to every connected Wi-Fi driver."""
|
||||
text = _global_brightness_message_text()
|
||||
if not text:
|
||||
return
|
||||
for ip in list_connected_ips():
|
||||
await send_json_line_to_ip(ip, text)
|
||||
|
||||
|
||||
def _register_ws(ip: str, ws) -> None:
|
||||
key = normalize_tcp_peer_ip(ip)
|
||||
if not key:
|
||||
@@ -195,6 +225,27 @@ async def _recv_forward_loop(ip: str, ws) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def _stagger_delay_s_for_ip(ip: str) -> float:
|
||||
"""0 .. wifi_driver_connect_stagger_max_s based on last IPv4 octet (deterministic spread)."""
|
||||
global _settings
|
||||
if _settings is None:
|
||||
return 0.0
|
||||
try:
|
||||
max_s = float(_settings.get("wifi_driver_connect_stagger_max_s", 2.5))
|
||||
except (TypeError, ValueError):
|
||||
max_s = 2.5
|
||||
if max_s <= 0:
|
||||
return 0.0
|
||||
parts = str(ip).strip().split(".")
|
||||
if len(parts) != 4:
|
||||
return 0.0
|
||||
try:
|
||||
last = int(parts[3]) % 256
|
||||
except ValueError:
|
||||
return 0.0
|
||||
return (last / 255.0) * max_s
|
||||
|
||||
|
||||
async def _driver_connection_loop(ip: str) -> None:
|
||||
global _settings
|
||||
if _settings is None:
|
||||
@@ -204,26 +255,48 @@ async def _driver_connection_loop(ip: str) -> None:
|
||||
if not path.startswith("/"):
|
||||
path = "/" + path
|
||||
uri = f"ws://{ip}:{port}{path}"
|
||||
retry_interval_s = 2.0
|
||||
retry_window_s = 30.0
|
||||
deadline = asyncio.get_running_loop().time() + retry_window_s
|
||||
try:
|
||||
retry_interval_s = float(_settings.get("wifi_driver_connect_retry_interval_s", 2.0))
|
||||
except (TypeError, ValueError):
|
||||
retry_interval_s = 2.0
|
||||
retry_interval_s = max(0.2, retry_interval_s)
|
||||
try:
|
||||
max_boot_attempts = int(_settings.get("wifi_driver_initial_connect_attempts", 4))
|
||||
except (TypeError, ValueError):
|
||||
max_boot_attempts = 4
|
||||
max_boot_attempts = max(1, max_boot_attempts)
|
||||
try:
|
||||
open_timeout = float(_settings.get("wifi_driver_ws_open_timeout", 45.0))
|
||||
except (TypeError, ValueError):
|
||||
open_timeout = 45.0
|
||||
open_timeout = max(5.0, open_timeout)
|
||||
|
||||
stagger = _stagger_delay_s_for_ip(ip)
|
||||
if stagger > 0:
|
||||
await asyncio.sleep(stagger)
|
||||
|
||||
# Only bound boot-time: after we have connected once, keep retrying (Wi-Fi drops, reboots).
|
||||
connected_once = False
|
||||
boot_attempts = 0
|
||||
try:
|
||||
while True:
|
||||
now = asyncio.get_running_loop().time()
|
||||
if now >= deadline:
|
||||
print(
|
||||
f"[WS] driver {ip} still unreachable after {int(retry_window_s)}s; "
|
||||
"stopping retries until next hello"
|
||||
)
|
||||
break
|
||||
if not connected_once:
|
||||
if boot_attempts >= max_boot_attempts:
|
||||
print(
|
||||
f"[WS] driver {ip} still unreachable after {max_boot_attempts} "
|
||||
f"initial dial attempt(s); stopping until next UDP hello / registry prime"
|
||||
)
|
||||
break
|
||||
boot_attempts += 1
|
||||
try:
|
||||
print(f"[WS] connecting to {uri!r}")
|
||||
async with websockets.connect(
|
||||
uri,
|
||||
ping_interval=20,
|
||||
ping_timeout=15,
|
||||
open_timeout=30,
|
||||
open_timeout=open_timeout,
|
||||
) as ws:
|
||||
connected_once = True
|
||||
_register_ws(ip, ws)
|
||||
try:
|
||||
await _recv_forward_loop(ip, ws)
|
||||
@@ -239,7 +312,9 @@ async def _driver_connection_loop(ip: str) -> None:
|
||||
n = _unreachable_counts.get(ip, 0) + 1
|
||||
_unreachable_counts[ip] = n
|
||||
if n == 1 or (n % 30) == 0:
|
||||
print(f"[WS] driver {ip} unreachable, retry in 2s: {e} (x{n})")
|
||||
print(
|
||||
f"[WS] driver {ip} unreachable, retry in {retry_interval_s}s: {e} (x{n})"
|
||||
)
|
||||
else:
|
||||
print(f"[WS] driver {ip} session error: {e!r}")
|
||||
traceback.print_exception(type(e), e, e.__traceback__)
|
||||
|
||||
@@ -19,7 +19,11 @@ def _maybe_migrate_tab_json_to_zone():
|
||||
|
||||
|
||||
class Zone(Model):
|
||||
"""Preset layout row (stored in ``db/zone.json``); legacy storage was ``tab.json`` / Tab."""
|
||||
"""Preset layout row (stored in ``db/zone.json``); legacy storage was ``tab.json`` / Tab.
|
||||
|
||||
Optional ``content_kind`` on a row: ``\"presets\"`` (preset tiles only) or ``\"sequences\"``
|
||||
(sequence tiles only). Omitted or unknown => both (legacy behaviour).
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
if not getattr(Zone, "_migration_checked", False):
|
||||
@@ -27,14 +31,38 @@ class Zone(Model):
|
||||
Zone._migration_checked = True
|
||||
super().__init__()
|
||||
|
||||
def create(self, name="", names=None, presets=None):
|
||||
def load(self):
|
||||
super().load()
|
||||
changed = False
|
||||
for zid, doc in list(self.items()):
|
||||
if not isinstance(doc, dict):
|
||||
continue
|
||||
if "group_ids" not in doc:
|
||||
doc["group_ids"] = []
|
||||
changed = True
|
||||
if "preset_group_ids" not in doc or not isinstance(doc.get("preset_group_ids"), dict):
|
||||
doc["preset_group_ids"] = {}
|
||||
changed = True
|
||||
if changed:
|
||||
self.save()
|
||||
|
||||
def create(self, name="", names=None, presets=None, group_ids=None, content_kind=None):
|
||||
next_id = self.get_next_id()
|
||||
self[next_id] = {
|
||||
gid_list = []
|
||||
if isinstance(group_ids, list):
|
||||
gid_list = [str(x).strip() for x in group_ids if x is not None and str(x).strip()]
|
||||
doc = {
|
||||
"name": name,
|
||||
"names": names if names else [],
|
||||
"group_ids": gid_list,
|
||||
"preset_group_ids": {},
|
||||
"presets": presets if presets else [],
|
||||
"default_preset": None,
|
||||
"brightness": 255,
|
||||
}
|
||||
if content_kind in ("presets", "sequences"):
|
||||
doc["content_kind"] = content_kind
|
||||
self[next_id] = doc
|
||||
self.save()
|
||||
return next_id
|
||||
|
||||
|
||||
@@ -57,6 +57,28 @@ class Settings(dict):
|
||||
# down (0 disables). Helps drivers that reconnect after seeing traffic on 8766.
|
||||
if 'wifi_driver_hello_interval_s' not in self:
|
||||
self['wifi_driver_hello_interval_s'] = 10.0
|
||||
# Legacy key (no longer read): initial outbound dial limit uses
|
||||
# wifi_driver_initial_connect_attempts instead.
|
||||
if 'wifi_driver_connect_retry_window_s' not in self:
|
||||
self['wifi_driver_connect_retry_window_s'] = 120.0
|
||||
# Spread outbound dials 0..N s by device IP so six+ drivers do not all hit the AP at once.
|
||||
if 'wifi_driver_connect_stagger_max_s' not in self:
|
||||
self['wifi_driver_connect_stagger_max_s'] = 2.5
|
||||
# TCP/WebSocket open timeout per attempt (seconds).
|
||||
if 'wifi_driver_ws_open_timeout' not in self:
|
||||
self['wifi_driver_ws_open_timeout'] = 45.0
|
||||
# Pause between outbound WebSocket dial attempts (seconds).
|
||||
if 'wifi_driver_connect_retry_interval_s' not in self:
|
||||
self['wifi_driver_connect_retry_interval_s'] = 2.0
|
||||
# Outbound dial attempts to the saved driver IP before first success; then wait for UDP discovery.
|
||||
if 'wifi_driver_initial_connect_attempts' not in self:
|
||||
self['wifi_driver_initial_connect_attempts'] = 4
|
||||
# UART to ESP32 ESP-NOW bridge; default off (Wi-Fi drivers need no serial).
|
||||
if 'serial_enabled' not in self:
|
||||
self['serial_enabled'] = False
|
||||
# Zone UI global brightness (0–255); shared across browsers/devices.
|
||||
if 'global_brightness' not in self:
|
||||
self['global_brightness'] = 255
|
||||
|
||||
def save(self):
|
||||
try:
|
||||
|
||||
477
src/static/audio.js
Normal file
477
src/static/audio.js
Normal file
@@ -0,0 +1,477 @@
|
||||
(() => {
|
||||
let pollTimer = null;
|
||||
let lastBeatSeq = 0;
|
||||
let lastLoggedSequenceBeatFractions = "";
|
||||
/** Prior poll had server zone sequence playback active (`status.sequence.active === true`). */
|
||||
let prevZoneSequencePlaybackActive = false;
|
||||
/**
|
||||
* After sequence playback ends/stops while audio keeps running, keep header # idle until the
|
||||
* next beat bumps `beat_seq` (avoids the stuck final cumulative value vs sequence readout).
|
||||
*/
|
||||
let headerBeatStickyIdleAfterSeq = false;
|
||||
/** Suppresses duplicate `console.log` when the same `beat_seq` + server `beat_readout` repeats. */
|
||||
let lastBeatConsoleKey = "";
|
||||
/** @type {Set<ReturnType<typeof setTimeout>>} */
|
||||
const pendingBeatPhaseTimers = new Set();
|
||||
|
||||
const STORAGE_KEY = "led-controller-audio-restore";
|
||||
const PHASE_MS_KEY = "led-controller-audio-beat-phase-ms";
|
||||
const STORAGE_VERSION = 1;
|
||||
|
||||
function readRestorePrefs() {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY);
|
||||
if (!raw) return null;
|
||||
const o = JSON.parse(raw);
|
||||
if (!o || o.v !== STORAGE_VERSION || !o.restore) return null;
|
||||
return {
|
||||
override: typeof o.override === "string" ? o.override : "",
|
||||
select: typeof o.select === "string" ? o.select : "",
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function writeRestorePrefs(override, select) {
|
||||
try {
|
||||
localStorage.setItem(
|
||||
STORAGE_KEY,
|
||||
JSON.stringify({
|
||||
v: STORAGE_VERSION,
|
||||
restore: true,
|
||||
override: override || "",
|
||||
select: select || "",
|
||||
}),
|
||||
);
|
||||
} catch (e) {
|
||||
console.warn("audio restore prefs save failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
function clearRestorePrefs() {
|
||||
try {
|
||||
localStorage.removeItem(STORAGE_KEY);
|
||||
} catch (e) {
|
||||
console.warn("audio restore prefs clear failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
function el(id) {
|
||||
return document.getElementById(id);
|
||||
}
|
||||
|
||||
/** @param {Record<string, unknown>} status */
|
||||
function updateBeatReadoutDisplays(status) {
|
||||
const text = String((status && status.beat_readout) || "").trim();
|
||||
for (const id of ["audio-top-beat-readout", "audio-modal-beat-readout"]) {
|
||||
const n = el(id);
|
||||
if (n) n.textContent = text;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* On each new audio `beat_seq`, log server `beat_readout` once (deduped when poll repeats the
|
||||
* same `beat_seq` + line).
|
||||
* @param {Record<string, unknown>} status
|
||||
*/
|
||||
function logServerBeatConsoleOnPollEdge(status) {
|
||||
const beatSeq = Number((status && status.beat_seq) || 0);
|
||||
const line = String((status && status.beat_readout) || "").trim();
|
||||
const key = `${beatSeq}\t${line}`;
|
||||
if (key !== lastBeatConsoleKey) {
|
||||
lastBeatConsoleKey = key;
|
||||
if (!line) return;
|
||||
const seq = /** @type {Record<string, unknown>|undefined} */ (status && status.sequence);
|
||||
const seqBeats = !!seq && !!seq.active;
|
||||
let out = line;
|
||||
if (seqBeats) {
|
||||
const nLanes = Number(seq && seq.num_lanes);
|
||||
const lanesNote =
|
||||
Number.isFinite(nLanes) && nLanes > 1
|
||||
? `lane 1 of ${nLanes} (readout is for this lane only)`
|
||||
: "lane 1";
|
||||
out = `${line} — ${lanesNote}`;
|
||||
}
|
||||
console.log(out);
|
||||
}
|
||||
}
|
||||
|
||||
function updateBpmDisplay(bpm) {
|
||||
const node = el("audio-bpm-value");
|
||||
if (!node) return;
|
||||
node.textContent = Number.isFinite(bpm) ? bpm.toFixed(1) : "--";
|
||||
const topNode = el("audio-top-bpm-value");
|
||||
if (topNode) {
|
||||
topNode.textContent = Number.isFinite(bpm) ? bpm.toFixed(1) : "--";
|
||||
}
|
||||
}
|
||||
|
||||
/** Zone sequence playback (server); only when `active === true` is beat X/Y meaningful. */
|
||||
function sequencePlaybackActiveFromStatus(status) {
|
||||
const seq = /** @type {Record<string, unknown>|undefined} */ (
|
||||
status && status.sequence
|
||||
);
|
||||
return !!(seq && seq.active);
|
||||
}
|
||||
|
||||
/** Build sequence beat fractions for debug logging (browser console only). */
|
||||
function formatSequenceBeatFractionsForLog(status) {
|
||||
const seq = /** @type {Record<string, unknown>|undefined} */ (status && status.sequence);
|
||||
if (!seq || !seq.active) return null;
|
||||
|
||||
const laneBeatAt = Number(seq.lane0_beat_in_step);
|
||||
const laneBeatsPerStep = Number(seq.lane0_beats_per_step);
|
||||
if (
|
||||
!Number.isFinite(laneBeatAt) ||
|
||||
laneBeatAt <= 0 ||
|
||||
!Number.isFinite(laneBeatsPerStep) ||
|
||||
laneBeatsPerStep <= 0
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
const presetFraction = `${Math.floor(laneBeatAt)}/${Math.floor(laneBeatsPerStep)}`;
|
||||
|
||||
const sequenceBeatAt = Number(seq.sequence_beat_at);
|
||||
const sequenceBeatsPerPass = Number(seq.sequence_beats_per_pass);
|
||||
if (
|
||||
!Number.isFinite(sequenceBeatAt) ||
|
||||
sequenceBeatAt <= 0 ||
|
||||
!Number.isFinite(sequenceBeatsPerPass) ||
|
||||
sequenceBeatsPerPass <= 0
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
const sequenceFraction = `${Math.floor(sequenceBeatAt)}/${Math.floor(sequenceBeatsPerPass)}`;
|
||||
|
||||
return `${presetFraction} ${sequenceFraction}`;
|
||||
}
|
||||
|
||||
function updateHitTypeDisplay(hitType, confidence) {
|
||||
const node = el("audio-hit-type-value");
|
||||
if (!node) return;
|
||||
const label = String(hitType || "unknown").toLowerCase();
|
||||
const conf = Number.isFinite(confidence) ? ` (${confidence.toFixed(2)})` : "";
|
||||
node.textContent = `${label}${conf}`;
|
||||
}
|
||||
|
||||
function setTopBpmVisible(on) {
|
||||
const top = el("audio-top-indicator");
|
||||
if (!top) return;
|
||||
top.classList.toggle("audio-running", !!on);
|
||||
}
|
||||
|
||||
function flashBeat() {
|
||||
const node = el("audio-beat-flash");
|
||||
if (!node) return;
|
||||
node.classList.add("active");
|
||||
setTimeout(() => node.classList.remove("active"), 80);
|
||||
const top = el("audio-top-indicator");
|
||||
if (top && top.classList.contains("audio-running")) {
|
||||
top.classList.add("flash");
|
||||
setTimeout(() => top.classList.remove("flash"), 90);
|
||||
}
|
||||
}
|
||||
|
||||
function clearBeatPhaseTimers() {
|
||||
pendingBeatPhaseTimers.forEach((t) => clearTimeout(t));
|
||||
pendingBeatPhaseTimers.clear();
|
||||
}
|
||||
|
||||
function getBeatPhaseDelayMs() {
|
||||
const inp = el("audio-beat-phase-ms");
|
||||
if (inp && String(inp.value).trim() !== "") {
|
||||
const n = parseInt(String(inp.value).trim(), 10);
|
||||
if (Number.isFinite(n)) return Math.min(500, Math.max(0, n));
|
||||
}
|
||||
try {
|
||||
const v = parseInt(localStorage.getItem(PHASE_MS_KEY) || "0", 10);
|
||||
return Number.isFinite(v) ? Math.min(500, Math.max(0, v)) : 0;
|
||||
} catch {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function persistBeatPhaseMs() {
|
||||
try {
|
||||
localStorage.setItem(PHASE_MS_KEY, String(getBeatPhaseDelayMs()));
|
||||
} catch (e) {
|
||||
console.warn("beat phase ms save failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
function scheduleBeatPhaseFire(seq, delayMs) {
|
||||
let tid = null;
|
||||
const run = () => {
|
||||
if (tid != null) pendingBeatPhaseTimers.delete(tid);
|
||||
flashBeat();
|
||||
try {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("ledControllerAudioBeat", { detail: { beatSeq: seq } }),
|
||||
);
|
||||
} catch (e) {
|
||||
/* ignore */
|
||||
}
|
||||
};
|
||||
if (delayMs <= 0) {
|
||||
run();
|
||||
return;
|
||||
}
|
||||
tid = setTimeout(run, delayMs);
|
||||
pendingBeatPhaseTimers.add(tid);
|
||||
}
|
||||
|
||||
/** Stop detector and polling; does not clear “resume on load” prefs (used before restart). */
|
||||
async function stopAudioOnly() {
|
||||
setTopBpmVisible(false);
|
||||
clearBeatPhaseTimers();
|
||||
if (pollTimer) {
|
||||
clearInterval(pollTimer);
|
||||
pollTimer = null;
|
||||
}
|
||||
lastBeatSeq = 0;
|
||||
prevZoneSequencePlaybackActive = false;
|
||||
headerBeatStickyIdleAfterSeq = false;
|
||||
lastBeatConsoleKey = "";
|
||||
updateBeatReadoutDisplays({});
|
||||
try {
|
||||
await fetch("/api/audio/stop", { method: "POST" });
|
||||
} catch (e) {
|
||||
console.warn("audio stop failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
/** User-initiated stop: also forget auto-restart on next page load. */
|
||||
async function stopAudio() {
|
||||
await stopAudioOnly();
|
||||
clearRestorePrefs();
|
||||
}
|
||||
|
||||
async function pollStatus() {
|
||||
try {
|
||||
const res = await fetch("/api/audio/status", { cache: "no-store" });
|
||||
const data = await res.json();
|
||||
const status = data?.status || {};
|
||||
if (status.error && String(status.error).trim()) {
|
||||
const node = el("audio-hit-type-value");
|
||||
if (node) {
|
||||
node.textContent = String(status.error).trim().slice(0, 120);
|
||||
}
|
||||
updateBeatReadoutDisplays({});
|
||||
updateBpmDisplay(null);
|
||||
setTopBpmVisible(!!status.running);
|
||||
if (!status.running && pollTimer) {
|
||||
clearInterval(pollTimer);
|
||||
pollTimer = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
setTopBpmVisible(!!status.running);
|
||||
updateBpmDisplay(status.bpm);
|
||||
updateHitTypeDisplay(status.beat_type, Number(status.beat_type_confidence));
|
||||
/*
|
||||
* `status.beat_seq` is cumulative since Audio Start — used only for flash / sticky idle
|
||||
* after sequence ends. Preset and sequence loop counts come from `manual_beat_stride` /
|
||||
* `sequence` on each poll.
|
||||
*/
|
||||
const beatSeq = Number(status.beat_seq || 0);
|
||||
const zoneSeqActive = sequencePlaybackActiveFromStatus(status);
|
||||
const endedSeq = prevZoneSequencePlaybackActive && !zoneSeqActive;
|
||||
const startedSeq = !prevZoneSequencePlaybackActive && zoneSeqActive;
|
||||
prevZoneSequencePlaybackActive = zoneSeqActive;
|
||||
if (startedSeq) {
|
||||
headerBeatStickyIdleAfterSeq = false;
|
||||
lastLoggedSequenceBeatFractions = "";
|
||||
}
|
||||
if (endedSeq) {
|
||||
headerBeatStickyIdleAfterSeq = true;
|
||||
clearBeatPhaseTimers();
|
||||
lastBeatSeq = beatSeq;
|
||||
}
|
||||
if (!zoneSeqActive && headerBeatStickyIdleAfterSeq) {
|
||||
if (beatSeq > lastBeatSeq) {
|
||||
lastBeatSeq = beatSeq;
|
||||
logServerBeatConsoleOnPollEdge(status);
|
||||
scheduleBeatPhaseFire(beatSeq, getBeatPhaseDelayMs());
|
||||
headerBeatStickyIdleAfterSeq = false;
|
||||
}
|
||||
} else if (beatSeq > lastBeatSeq) {
|
||||
lastBeatSeq = beatSeq;
|
||||
logServerBeatConsoleOnPollEdge(status);
|
||||
scheduleBeatPhaseFire(beatSeq, getBeatPhaseDelayMs());
|
||||
}
|
||||
const beatFractions = formatSequenceBeatFractionsForLog(status);
|
||||
if (beatFractions) {
|
||||
if (beatFractions !== lastLoggedSequenceBeatFractions) {
|
||||
lastLoggedSequenceBeatFractions = beatFractions;
|
||||
}
|
||||
} else {
|
||||
lastLoggedSequenceBeatFractions = "";
|
||||
}
|
||||
updateBeatReadoutDisplays(status);
|
||||
} catch (e) {
|
||||
console.warn("audio status poll failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
async function startAudio() {
|
||||
await stopAudioOnly();
|
||||
const override = (el("audio-device-override")?.value || "").trim();
|
||||
const selected = el("audio-device-select")?.value || "";
|
||||
const rawDevice = override !== "" ? override : selected;
|
||||
const numeric = rawDevice !== "" && /^-?\d+$/.test(rawDevice) ? Number(rawDevice) : rawDevice;
|
||||
const body = { device: rawDevice === "" ? null : numeric };
|
||||
const res = await fetch("/api/audio/start", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
throw new Error(data.error || "Failed to start audio detector");
|
||||
}
|
||||
writeRestorePrefs(override, selected);
|
||||
updateBpmDisplay(null);
|
||||
updateHitTypeDisplay("unknown", NaN);
|
||||
pollTimer = setInterval(pollStatus, 250);
|
||||
await pollStatus();
|
||||
}
|
||||
|
||||
async function refreshDevices() {
|
||||
const select = el("audio-device-select");
|
||||
const debug = el("audio-devices-debug");
|
||||
if (!select) return;
|
||||
const current = select.value;
|
||||
const res = await fetch("/api/audio/devices");
|
||||
const data = await res.json();
|
||||
const inputs = Array.isArray(data?.devices) ? data.devices.slice() : [];
|
||||
if (debug) {
|
||||
debug.value = JSON.stringify(data?.diagnostics || data, null, 2);
|
||||
}
|
||||
inputs.sort((a, b) => {
|
||||
const am = String(a?.name || "").toLowerCase().includes("monitor");
|
||||
const bm = String(b?.name || "").toLowerCase().includes("monitor");
|
||||
if (am !== bm) return am ? -1 : 1;
|
||||
return Number(a?.id || 0) - Number(b?.id || 0);
|
||||
});
|
||||
select.innerHTML = '<option value="">System default input</option>';
|
||||
let defaultId = "";
|
||||
inputs.forEach((d, idx) => {
|
||||
const option = document.createElement("option");
|
||||
option.value = String(d.id);
|
||||
option.textContent = d.label || d.name || `Input ${idx + 1}`;
|
||||
if (d.is_default) {
|
||||
defaultId = String(d.id);
|
||||
}
|
||||
select.appendChild(option);
|
||||
});
|
||||
if (current) {
|
||||
select.value = current;
|
||||
} else if (defaultId) {
|
||||
select.value = defaultId;
|
||||
}
|
||||
}
|
||||
|
||||
function bind() {
|
||||
const modal = el("audio-modal");
|
||||
const openBtn = el("audio-btn");
|
||||
const closeBtn = el("audio-close-btn");
|
||||
const startBtn = el("audio-start-btn");
|
||||
const stopBtn = el("audio-stop-btn");
|
||||
const refreshBtn = el("audio-refresh-btn");
|
||||
if (!modal || !openBtn) return;
|
||||
|
||||
openBtn.addEventListener("click", async () => {
|
||||
modal.classList.add("active");
|
||||
try {
|
||||
await refreshDevices();
|
||||
} catch (e) {
|
||||
console.warn("audio device refresh failed", e);
|
||||
}
|
||||
});
|
||||
if (closeBtn) {
|
||||
closeBtn.addEventListener("click", () => {
|
||||
modal.classList.remove("active");
|
||||
});
|
||||
}
|
||||
if (startBtn) {
|
||||
startBtn.addEventListener("click", async () => {
|
||||
try {
|
||||
await startAudio();
|
||||
await refreshDevices();
|
||||
} catch (e) {
|
||||
console.error("audio start failed", e);
|
||||
alert("Failed to start audio input. Check mic permissions.");
|
||||
}
|
||||
});
|
||||
}
|
||||
if (stopBtn) {
|
||||
stopBtn.addEventListener("click", async () => {
|
||||
await stopAudio();
|
||||
});
|
||||
}
|
||||
if (refreshBtn) {
|
||||
refreshBtn.addEventListener("click", async () => {
|
||||
try {
|
||||
await refreshDevices();
|
||||
} catch (e) {
|
||||
console.error("refresh devices failed", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const phaseInp = el("audio-beat-phase-ms");
|
||||
if (phaseInp) {
|
||||
try {
|
||||
const stored = parseInt(localStorage.getItem(PHASE_MS_KEY) || "0", 10);
|
||||
if (Number.isFinite(stored)) {
|
||||
phaseInp.value = String(Math.min(500, Math.max(0, stored)));
|
||||
}
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
phaseInp.addEventListener("change", () => persistBeatPhaseMs());
|
||||
phaseInp.addEventListener("input", () => persistBeatPhaseMs());
|
||||
}
|
||||
}
|
||||
|
||||
async function resumePollingIfDetectorRunning() {
|
||||
try {
|
||||
const res = await fetch("/api/audio/status", { cache: "no-store" });
|
||||
const data = await res.json();
|
||||
const status = data?.status || {};
|
||||
if (status.running && !pollTimer) {
|
||||
pollTimer = setInterval(pollStatus, 250);
|
||||
lastBeatSeq = Number(status.beat_seq || 0);
|
||||
prevZoneSequencePlaybackActive = sequencePlaybackActiveFromStatus(status);
|
||||
await pollStatus();
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("audio resume poll check failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply browser-stored device fields only (GET /devices list); does not start detection.
|
||||
* Beat detector run/stop is server-owned (`db/audio_run.json` + explicit Start/Stop in UI).
|
||||
*/
|
||||
async function applySavedAudioDeviceFormOnly() {
|
||||
const prefs = readRestorePrefs();
|
||||
if (!prefs) return;
|
||||
const ov = el("audio-device-override");
|
||||
const sel = el("audio-device-select");
|
||||
if (ov) ov.value = prefs.override || "";
|
||||
try {
|
||||
await refreshDevices();
|
||||
} catch (e) {
|
||||
console.warn("audio device list refresh failed", e);
|
||||
}
|
||||
if (sel && prefs.select) sel.value = prefs.select;
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
bind();
|
||||
await resumePollingIfDetectorRunning();
|
||||
await applySavedAudioDeviceFormOnly();
|
||||
});
|
||||
})();
|
||||
25
src/static/dev-live-reload.js
Normal file
25
src/static/dev-live-reload.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/* Polls server build id; full reload when watchfiles restarts Python (new process = new id). */
|
||||
(function () {
|
||||
var prev = null;
|
||||
function tick() {
|
||||
fetch('/__dev/build-id', { cache: 'no-store', credentials: 'same-origin' })
|
||||
.then(function (r) {
|
||||
return r.ok ? r.text() : '';
|
||||
})
|
||||
.then(function (id) {
|
||||
id = (id || '').trim();
|
||||
if (!id) return;
|
||||
if (prev === null) {
|
||||
prev = id;
|
||||
return;
|
||||
}
|
||||
if (id !== prev) {
|
||||
prev = id;
|
||||
window.location.reload();
|
||||
}
|
||||
})
|
||||
.catch(function () {});
|
||||
}
|
||||
setInterval(tick, 750);
|
||||
tick();
|
||||
})();
|
||||
@@ -149,8 +149,10 @@ function applyTransportVisibility(transport) {
|
||||
const isWifi = transport === 'wifi';
|
||||
const esp = document.getElementById('edit-device-address-espnow');
|
||||
const wifiWrap = document.getElementById('edit-device-address-wifi-wrap');
|
||||
const drvWrap = document.getElementById('edit-device-wifi-driver-wrap');
|
||||
if (esp) esp.hidden = isWifi;
|
||||
if (wifiWrap) wifiWrap.hidden = !isWifi;
|
||||
if (drvWrap) drvWrap.hidden = !isWifi;
|
||||
}
|
||||
|
||||
function getAddressForPayload(transport) {
|
||||
@@ -166,6 +168,63 @@ function getAddressForPayload(transport) {
|
||||
return hex || null;
|
||||
}
|
||||
|
||||
function collectDeviceEditPayload() {
|
||||
const idInput = document.getElementById('edit-device-id');
|
||||
const nameInput = document.getElementById('edit-device-name');
|
||||
const typeSel = document.getElementById('edit-device-type');
|
||||
const transportSel = document.getElementById('edit-device-transport');
|
||||
const devId = idInput && idInput.value;
|
||||
const transport = (transportSel && transportSel.value) || 'espnow';
|
||||
const address = getAddressForPayload(transport);
|
||||
const obr = document.getElementById('edit-device-output-brightness');
|
||||
let output_brightness = 255;
|
||||
if (obr && obr.value !== '') {
|
||||
const n = parseInt(obr.value, 10);
|
||||
output_brightness = !Number.isNaN(n) ? Math.max(0, Math.min(255, n)) : 255;
|
||||
}
|
||||
const payload = {
|
||||
name: nameInput ? nameInput.value.trim() : '',
|
||||
type: (typeSel && typeSel.value) || 'led',
|
||||
transport,
|
||||
address,
|
||||
output_brightness,
|
||||
};
|
||||
if (transport === 'wifi') {
|
||||
const dn = document.getElementById('edit-device-wifi-driver-name');
|
||||
const nl = document.getElementById('edit-device-wifi-num-leds');
|
||||
const co = document.getElementById('edit-device-wifi-color-order');
|
||||
const ws = document.getElementById('edit-device-wifi-startup-mode');
|
||||
if (dn && dn.value.trim()) payload.wifi_driver_display_name = dn.value.trim();
|
||||
if (nl && nl.value !== '') {
|
||||
const n = parseInt(nl.value, 10);
|
||||
if (!Number.isNaN(n) && n >= 1) payload.wifi_driver_num_leds = n;
|
||||
}
|
||||
if (co && co.value) payload.wifi_color_order = co.value;
|
||||
if (ws && ws.value) payload.wifi_startup_mode = ws.value;
|
||||
}
|
||||
return { devId, payload };
|
||||
}
|
||||
|
||||
function refreshEditDeviceDebug() {
|
||||
const ta = document.getElementById('edit-device-debug');
|
||||
if (!ta) return;
|
||||
try {
|
||||
const { devId, payload } = collectDeviceEditPayload();
|
||||
const loaded = window.__editDeviceLoadedSnapshot;
|
||||
ta.value = JSON.stringify(
|
||||
{
|
||||
device_id: devId || null,
|
||||
loaded_from_server: loaded != null ? loaded : null,
|
||||
save_payload_preview: payload,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
);
|
||||
} catch (e) {
|
||||
ta.value = String(e);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadDevicesModal() {
|
||||
const container = document.getElementById('devices-list-modal');
|
||||
if (!container) return;
|
||||
@@ -307,6 +366,11 @@ function renderDevicesList(devices) {
|
||||
}
|
||||
|
||||
function openEditDeviceModal(devId, dev) {
|
||||
try {
|
||||
window.__editDeviceLoadedSnapshot = dev ? JSON.parse(JSON.stringify(dev)) : null;
|
||||
} catch (e) {
|
||||
window.__editDeviceLoadedSnapshot = dev || null;
|
||||
}
|
||||
const modal = document.getElementById('edit-device-modal');
|
||||
const idInput = document.getElementById('edit-device-id');
|
||||
const storageLabel = document.getElementById('edit-device-storage-id');
|
||||
@@ -325,20 +389,83 @@ function openEditDeviceModal(devId, dev) {
|
||||
applyTransportVisibility(tr);
|
||||
setAddressToBoxes(addressBoxes, tr === 'espnow' ? ((dev && dev.address) || '') : '');
|
||||
if (wifiInput) wifiInput.value = tr === 'wifi' ? ((dev && dev.address) || '') : '';
|
||||
const wName = document.getElementById('edit-device-wifi-driver-name');
|
||||
const wLeds = document.getElementById('edit-device-wifi-num-leds');
|
||||
const wCo = document.getElementById('edit-device-wifi-color-order');
|
||||
const wStart = document.getElementById('edit-device-wifi-startup-mode');
|
||||
if (wName) {
|
||||
const savedDisp =
|
||||
dev && Object.prototype.hasOwnProperty.call(dev, 'wifi_driver_display_name')
|
||||
? dev.wifi_driver_display_name
|
||||
: undefined;
|
||||
if (savedDisp != null && String(savedDisp).trim() !== '') {
|
||||
wName.value = String(savedDisp).trim();
|
||||
} else {
|
||||
wName.value = dev && dev.name ? String(dev.name) : '';
|
||||
}
|
||||
}
|
||||
if (wLeds) {
|
||||
wLeds.value =
|
||||
dev && dev.wifi_driver_num_leds != null && dev.wifi_driver_num_leds !== ''
|
||||
? String(dev.wifi_driver_num_leds)
|
||||
: '';
|
||||
}
|
||||
if (wCo) {
|
||||
const co = (dev && dev.wifi_color_order) || 'rgb';
|
||||
wCo.value = ['rgb', 'rbg', 'grb', 'gbr', 'brg', 'bgr'].includes(String(co).toLowerCase())
|
||||
? String(co).toLowerCase()
|
||||
: 'rgb';
|
||||
}
|
||||
if (wStart) {
|
||||
const sm = (dev && dev.wifi_startup_mode) || 'default';
|
||||
wStart.value = ['default', 'last', 'off'].includes(String(sm).toLowerCase())
|
||||
? String(sm).toLowerCase()
|
||||
: 'default';
|
||||
}
|
||||
const obr = document.getElementById('edit-device-output-brightness');
|
||||
const obv = document.getElementById('edit-device-output-brightness-value');
|
||||
if (obr) {
|
||||
let bv = 255;
|
||||
if (dev && dev.output_brightness != null && dev.output_brightness !== '') {
|
||||
const n = parseInt(String(dev.output_brightness), 10);
|
||||
if (!Number.isNaN(n)) bv = Math.max(0, Math.min(255, n));
|
||||
}
|
||||
obr.value = String(bv);
|
||||
if (obv) obv.textContent = String(bv);
|
||||
}
|
||||
refreshEditDeviceDebug();
|
||||
modal.classList.add('active');
|
||||
}
|
||||
|
||||
async function updateDevice(devId, name, type, transport, address) {
|
||||
async function updateDevice(devId, name, type, transport, address, wifiDriverFields, outputBrightness) {
|
||||
try {
|
||||
const payload = {
|
||||
name,
|
||||
type: type || 'led',
|
||||
transport: transport || 'espnow',
|
||||
address,
|
||||
};
|
||||
if (typeof outputBrightness === 'number') {
|
||||
payload.output_brightness = Math.max(0, Math.min(255, Math.round(outputBrightness)));
|
||||
}
|
||||
if (transport === 'wifi' && wifiDriverFields && typeof wifiDriverFields === 'object') {
|
||||
if (wifiDriverFields.wifi_driver_display_name != null) {
|
||||
payload.wifi_driver_display_name = wifiDriverFields.wifi_driver_display_name;
|
||||
}
|
||||
if (wifiDriverFields.wifi_driver_num_leds != null) {
|
||||
payload.wifi_driver_num_leds = wifiDriverFields.wifi_driver_num_leds;
|
||||
}
|
||||
if (wifiDriverFields.wifi_color_order != null) {
|
||||
payload.wifi_color_order = wifiDriverFields.wifi_color_order;
|
||||
}
|
||||
if (wifiDriverFields.wifi_startup_mode != null) {
|
||||
payload.wifi_startup_mode = wifiDriverFields.wifi_startup_mode;
|
||||
}
|
||||
}
|
||||
const res = await fetch(`/devices/${encodeURIComponent(devId)}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
name,
|
||||
type: type || 'led',
|
||||
transport: transport || 'espnow',
|
||||
address,
|
||||
}),
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (res.ok) {
|
||||
@@ -354,6 +481,41 @@ async function updateDevice(devId, name, type, transport, address) {
|
||||
}
|
||||
}
|
||||
|
||||
async function pushWifiDriverConfig(devId, fields) {
|
||||
const push = {};
|
||||
if (fields.name != null && String(fields.name).trim()) push.name = String(fields.name).trim();
|
||||
if (fields.num_leds != null && fields.num_leds !== '') {
|
||||
const n = parseInt(String(fields.num_leds), 10);
|
||||
if (!Number.isNaN(n) && n >= 1) push.num_leds = n;
|
||||
}
|
||||
if (fields.color_order != null && String(fields.color_order).trim()) {
|
||||
push.color_order = String(fields.color_order).trim().toLowerCase();
|
||||
}
|
||||
if (fields.startup_mode != null && String(fields.startup_mode).trim()) {
|
||||
const sm = String(fields.startup_mode).trim().toLowerCase();
|
||||
if (sm === 'default' || sm === 'last' || sm === 'off') push.startup_mode = sm;
|
||||
}
|
||||
if (Object.keys(push).length === 0) return { ok: true, skipped: true };
|
||||
try {
|
||||
const res = await fetch(`/devices/${encodeURIComponent(devId)}/driver-config`, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
||||
body: JSON.stringify(push),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
alert(data.error || 'Could not send settings to the driver (is it connected?)');
|
||||
return { ok: false };
|
||||
}
|
||||
return { ok: true };
|
||||
} catch (e) {
|
||||
console.error('pushWifiDriverConfig:', e);
|
||||
alert('Could not send settings to the driver');
|
||||
return { ok: false };
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
window.addEventListener('deviceTcpStatus', (ev) => {
|
||||
const { ip, connected } = ev.detail || {};
|
||||
@@ -380,10 +542,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
makeHexAddressBoxes(document.getElementById('edit-device-address-boxes'));
|
||||
|
||||
const devOutBr = document.getElementById('edit-device-output-brightness');
|
||||
const devOutBrVal = document.getElementById('edit-device-output-brightness-value');
|
||||
if (devOutBr && devOutBrVal) {
|
||||
devOutBr.addEventListener('input', () => {
|
||||
devOutBrVal.textContent = devOutBr.value;
|
||||
});
|
||||
}
|
||||
|
||||
const transportEdit = document.getElementById('edit-device-transport');
|
||||
if (transportEdit) {
|
||||
transportEdit.addEventListener('change', () => {
|
||||
applyTransportVisibility(transportEdit.value);
|
||||
refreshEditDeviceDebug();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -420,24 +591,67 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
|
||||
if (editForm) {
|
||||
editForm.addEventListener('input', () => refreshEditDeviceDebug());
|
||||
editForm.addEventListener('change', () => refreshEditDeviceDebug());
|
||||
editForm.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const idInput = document.getElementById('edit-device-id');
|
||||
const nameInput = document.getElementById('edit-device-name');
|
||||
const typeSel = document.getElementById('edit-device-type');
|
||||
const transportSel = document.getElementById('edit-device-transport');
|
||||
const devId = idInput && idInput.value;
|
||||
const { devId, payload } = collectDeviceEditPayload();
|
||||
if (!devId) return;
|
||||
const transport = (transportSel && transportSel.value) || 'espnow';
|
||||
const address = getAddressForPayload(transport);
|
||||
const transport = payload.transport || 'espnow';
|
||||
let wifiDriverFields = null;
|
||||
if (transport === 'wifi') {
|
||||
wifiDriverFields = {};
|
||||
if (payload.wifi_driver_display_name != null) {
|
||||
wifiDriverFields.wifi_driver_display_name = payload.wifi_driver_display_name;
|
||||
}
|
||||
if (payload.wifi_driver_num_leds != null) {
|
||||
wifiDriverFields.wifi_driver_num_leds = payload.wifi_driver_num_leds;
|
||||
}
|
||||
if (payload.wifi_color_order != null) {
|
||||
wifiDriverFields.wifi_color_order = payload.wifi_color_order;
|
||||
}
|
||||
if (payload.wifi_startup_mode != null) {
|
||||
wifiDriverFields.wifi_startup_mode = payload.wifi_startup_mode;
|
||||
}
|
||||
}
|
||||
const ok = await updateDevice(
|
||||
devId,
|
||||
nameInput ? nameInput.value.trim() : '',
|
||||
(typeSel && typeSel.value) || 'led',
|
||||
payload.name,
|
||||
payload.type,
|
||||
transport,
|
||||
address
|
||||
payload.address,
|
||||
wifiDriverFields,
|
||||
payload.output_brightness,
|
||||
);
|
||||
if (ok) editDeviceModal.classList.remove('active');
|
||||
if (!ok) return;
|
||||
try {
|
||||
const brRes = await fetch(`/devices/${encodeURIComponent(devId)}/brightness`, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({}),
|
||||
});
|
||||
if (!brRes.ok && brRes.status !== 503) {
|
||||
const brData = await brRes.json().catch(() => ({}));
|
||||
console.warn('brightness push:', brData.error || brRes.status);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('brightness push failed', e);
|
||||
}
|
||||
if (transport === 'wifi' && wifiDriverFields) {
|
||||
const dn = document.getElementById('edit-device-wifi-driver-name');
|
||||
const nl = document.getElementById('edit-device-wifi-num-leds');
|
||||
const co = document.getElementById('edit-device-wifi-color-order');
|
||||
const ws = document.getElementById('edit-device-wifi-startup-mode');
|
||||
const pushRes = await pushWifiDriverConfig(devId, {
|
||||
name: dn ? dn.value : '',
|
||||
num_leds: nl ? nl.value : '',
|
||||
color_order: co ? co.value : '',
|
||||
startup_mode: ws ? ws.value : '',
|
||||
});
|
||||
if (!pushRes.ok) return;
|
||||
}
|
||||
editDeviceModal.classList.remove('active');
|
||||
});
|
||||
}
|
||||
if (editCloseBtn) {
|
||||
|
||||
571
src/static/groups.js
Normal file
571
src/static/groups.js
Normal file
@@ -0,0 +1,571 @@
|
||||
// Device groups: members (MAC ids) + Wi‑Fi driver defaults; persisted via /groups.
|
||||
// Without ``profile_id``, a group is shared across all profiles; with ``profile_id`` it is listed only for that profile.
|
||||
|
||||
async function getCurrentProfileIdForGroups() {
|
||||
try {
|
||||
const res = await fetch('/profiles/current', {
|
||||
headers: { Accept: 'application/json' },
|
||||
credentials: 'same-origin',
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
const data = await res.json();
|
||||
const id = data && (data.id || (data.profile && data.profile.id));
|
||||
return id != null ? String(id) : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchGroupsMap() {
|
||||
try {
|
||||
const response = await fetch('/groups', {
|
||||
headers: { Accept: 'application/json' },
|
||||
credentials: 'same-origin',
|
||||
});
|
||||
if (!response.ok) return {};
|
||||
const data = await response.json();
|
||||
return data && typeof data === 'object' ? data : {};
|
||||
} catch (e) {
|
||||
console.error('fetchGroupsMap:', e);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchDevicesMapForGroups() {
|
||||
try {
|
||||
const response = await fetch('/devices', { headers: { Accept: 'application/json' } });
|
||||
if (!response.ok) return {};
|
||||
const data = await response.json();
|
||||
return data && typeof data === 'object' ? data : {};
|
||||
} catch (e) {
|
||||
console.error('fetchDevicesMapForGroups:', e);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function renderGroupDevicesEditor(containerEl, macRows, devicesMap) {
|
||||
if (!containerEl) return;
|
||||
containerEl.innerHTML = '';
|
||||
const entries = Object.entries(devicesMap || {}).sort(([a], [b]) => a.localeCompare(b));
|
||||
|
||||
macRows.forEach((row, idx) => {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'zone-device-row profiles-row';
|
||||
const label = document.createElement('span');
|
||||
label.className = 'zone-device-row-label';
|
||||
const strong = document.createElement('strong');
|
||||
strong.textContent = row.label || row.mac || '—';
|
||||
label.appendChild(strong);
|
||||
label.appendChild(document.createTextNode(' '));
|
||||
const sub = document.createElement('span');
|
||||
sub.className = 'muted-text';
|
||||
sub.textContent = row.mac || '';
|
||||
label.appendChild(sub);
|
||||
|
||||
const rm = document.createElement('button');
|
||||
rm.type = 'button';
|
||||
rm.className = 'btn btn-danger btn-small';
|
||||
rm.textContent = 'Remove';
|
||||
rm.addEventListener('click', () => {
|
||||
macRows.splice(idx, 1);
|
||||
renderGroupDevicesEditor(containerEl, macRows, devicesMap);
|
||||
});
|
||||
div.appendChild(label);
|
||||
div.appendChild(rm);
|
||||
containerEl.appendChild(div);
|
||||
});
|
||||
|
||||
const macsInRows = new Set(macRows.map((r) => r.mac).filter(Boolean));
|
||||
const addWrap = document.createElement('div');
|
||||
addWrap.className = 'zone-devices-add profiles-actions';
|
||||
const sel = document.createElement('select');
|
||||
sel.className = 'zone-device-add-select';
|
||||
sel.appendChild(new Option('Add device…', ''));
|
||||
entries.forEach(([mac, d]) => {
|
||||
if (macsInRows.has(mac)) return;
|
||||
const labelName = d && d.name ? String(d.name).trim() : '';
|
||||
const optLabel = labelName ? `${labelName} — ${mac}` : mac;
|
||||
sel.appendChild(new Option(optLabel, mac));
|
||||
});
|
||||
const addBtn = document.createElement('button');
|
||||
addBtn.type = 'button';
|
||||
addBtn.className = 'btn btn-primary btn-small';
|
||||
addBtn.textContent = 'Add';
|
||||
addBtn.addEventListener('click', () => {
|
||||
const mac = sel.value;
|
||||
if (!mac || !devicesMap[mac]) return;
|
||||
const n = String((devicesMap[mac].name || '').trim() || mac);
|
||||
macRows.push({ mac, label: n });
|
||||
sel.value = '';
|
||||
renderGroupDevicesEditor(containerEl, macRows, devicesMap);
|
||||
});
|
||||
addWrap.appendChild(sel);
|
||||
addWrap.appendChild(addBtn);
|
||||
containerEl.appendChild(addWrap);
|
||||
refreshEditGroupDebug();
|
||||
}
|
||||
|
||||
function collectGroupEditPayload() {
|
||||
const idInput = document.getElementById('edit-group-id');
|
||||
const nameInput = document.getElementById('edit-group-name');
|
||||
const gid = idInput && idInput.value;
|
||||
const rows = window.__editGroupDeviceRows || [];
|
||||
const devices = rows.map((r) => r.mac).filter(Boolean);
|
||||
const payload = {
|
||||
name: nameInput ? nameInput.value.trim() : '',
|
||||
devices,
|
||||
};
|
||||
const dn = document.getElementById('edit-group-wifi-driver-name');
|
||||
const nl = document.getElementById('edit-group-wifi-num-leds');
|
||||
const co = document.getElementById('edit-group-wifi-color-order');
|
||||
const ws = document.getElementById('edit-group-wifi-startup-mode');
|
||||
if (dn && dn.value.trim()) payload.wifi_driver_display_name = dn.value.trim();
|
||||
else payload.wifi_driver_display_name = null;
|
||||
if (nl && nl.value !== '') {
|
||||
const n = parseInt(nl.value, 10);
|
||||
if (!Number.isNaN(n) && n >= 1) payload.wifi_driver_num_leds = n;
|
||||
else payload.wifi_driver_num_leds = null;
|
||||
} else payload.wifi_driver_num_leds = null;
|
||||
if (co && co.value) payload.wifi_color_order = co.value;
|
||||
if (ws && ws.value) payload.wifi_startup_mode = ws.value;
|
||||
const gob = document.getElementById('edit-group-output-brightness');
|
||||
if (gob && gob.value !== '') {
|
||||
const nb = parseInt(gob.value, 10);
|
||||
if (!Number.isNaN(nb)) payload.output_brightness = Math.max(0, Math.min(255, nb));
|
||||
}
|
||||
return { gid, payload };
|
||||
}
|
||||
|
||||
function refreshEditGroupDebug() {
|
||||
const ta = document.getElementById('edit-group-debug');
|
||||
if (!ta) return;
|
||||
try {
|
||||
const { gid, payload } = collectGroupEditPayload();
|
||||
const loaded = window.__editGroupLoadedSnapshot;
|
||||
ta.value = JSON.stringify(
|
||||
{
|
||||
group_id: gid || null,
|
||||
loaded_from_server: loaded != null ? loaded : null,
|
||||
save_payload_preview: payload,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
);
|
||||
} catch (e) {
|
||||
ta.value = String(e);
|
||||
}
|
||||
}
|
||||
|
||||
function syncGroupShareCheckboxFromDoc(g) {
|
||||
const cb = document.getElementById('edit-group-share-all-profiles');
|
||||
if (!cb) return;
|
||||
const raw = g && (g.profile_id != null ? g.profile_id : g.profileId);
|
||||
const scoped = raw != null && String(raw).trim() !== '';
|
||||
cb.checked = !scoped;
|
||||
}
|
||||
|
||||
function loadWifiFieldsFromGroup(g) {
|
||||
const wName = document.getElementById('edit-group-wifi-driver-name');
|
||||
const wLeds = document.getElementById('edit-group-wifi-num-leds');
|
||||
const wCo = document.getElementById('edit-group-wifi-color-order');
|
||||
const wStart = document.getElementById('edit-group-wifi-startup-mode');
|
||||
if (wName) {
|
||||
const v = g && Object.prototype.hasOwnProperty.call(g, 'wifi_driver_display_name')
|
||||
? g.wifi_driver_display_name
|
||||
: null;
|
||||
wName.value = v != null && String(v).trim() !== '' ? String(v).trim() : '';
|
||||
}
|
||||
if (wLeds) {
|
||||
const v = g && g.wifi_driver_num_leds;
|
||||
wLeds.value =
|
||||
v != null && v !== '' && String(v).trim() !== ''
|
||||
? String(v)
|
||||
: '';
|
||||
}
|
||||
if (wCo) {
|
||||
const co = (g && g.wifi_color_order) || 'rgb';
|
||||
wCo.value = ['rgb', 'rbg', 'grb', 'gbr', 'brg', 'bgr'].includes(String(co).toLowerCase())
|
||||
? String(co).toLowerCase()
|
||||
: 'rgb';
|
||||
}
|
||||
if (wStart) {
|
||||
const sm = (g && g.wifi_startup_mode) || 'default';
|
||||
wStart.value = ['default', 'last', 'off'].includes(String(sm).toLowerCase())
|
||||
? String(sm).toLowerCase()
|
||||
: 'default';
|
||||
}
|
||||
const gob = document.getElementById('edit-group-output-brightness');
|
||||
const gobv = document.getElementById('edit-group-output-brightness-value');
|
||||
if (gob) {
|
||||
let bv = 255;
|
||||
if (g && g.output_brightness != null && g.output_brightness !== '') {
|
||||
const n = parseInt(String(g.output_brightness), 10);
|
||||
if (!Number.isNaN(n)) bv = Math.max(0, Math.min(255, n));
|
||||
}
|
||||
gob.value = String(bv);
|
||||
if (gobv) gobv.textContent = String(bv);
|
||||
}
|
||||
}
|
||||
|
||||
async function openEditGroupModal(groupId, groupDoc) {
|
||||
const modal = document.getElementById('edit-group-modal');
|
||||
const idInput = document.getElementById('edit-group-id');
|
||||
const nameInput = document.getElementById('edit-group-name');
|
||||
const editor = document.getElementById('edit-group-devices-editor');
|
||||
|
||||
let g = groupDoc;
|
||||
if (!g || typeof g !== 'object') {
|
||||
try {
|
||||
const response = await fetch(`/groups/${encodeURIComponent(groupId)}`, {
|
||||
credentials: 'same-origin',
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
if (response.ok) g = await response.json();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
g = g || {};
|
||||
try {
|
||||
window.__editGroupLoadedSnapshot = JSON.parse(JSON.stringify(g));
|
||||
} catch (e) {
|
||||
window.__editGroupLoadedSnapshot = g;
|
||||
}
|
||||
|
||||
if (idInput) idInput.value = groupId;
|
||||
if (nameInput) nameInput.value = g.name || '';
|
||||
|
||||
const dm = await fetchDevicesMapForGroups();
|
||||
const macs = Array.isArray(g.devices) ? g.devices : [];
|
||||
window.__editGroupDeviceRows = macs.map((m) => {
|
||||
const mac = String(m).trim().toLowerCase().replace(/:/g, '').replace(/-/g, '');
|
||||
const d = dm[mac];
|
||||
return {
|
||||
mac,
|
||||
label: d && d.name ? String(d.name).trim() : mac,
|
||||
};
|
||||
});
|
||||
renderGroupDevicesEditor(editor, window.__editGroupDeviceRows, dm);
|
||||
loadWifiFieldsFromGroup(g);
|
||||
syncGroupShareCheckboxFromDoc(g);
|
||||
refreshEditGroupDebug();
|
||||
if (modal) modal.classList.add('active');
|
||||
}
|
||||
|
||||
async function loadGroupsModal() {
|
||||
const container = document.getElementById('groups-list-modal');
|
||||
if (!container) return;
|
||||
container.innerHTML = '<span class="muted-text">Loading...</span>';
|
||||
try {
|
||||
const data = await fetchGroupsMap();
|
||||
renderGroupsList(data || {});
|
||||
} catch (e) {
|
||||
console.error('loadGroupsModal:', e);
|
||||
container.innerHTML = '<span class="muted-text">Failed to load groups.</span>';
|
||||
}
|
||||
}
|
||||
|
||||
function renderGroupsList(groups) {
|
||||
const container = document.getElementById('groups-list-modal');
|
||||
if (!container) return;
|
||||
container.innerHTML = '';
|
||||
const ids = Object.keys(groups).filter((k) => groups[k] && typeof groups[k] === 'object');
|
||||
if (ids.length === 0) {
|
||||
const p = document.createElement('p');
|
||||
p.className = 'muted-text';
|
||||
p.textContent = 'No groups yet. Create one to assign devices and Wi‑Fi defaults.';
|
||||
container.appendChild(p);
|
||||
return;
|
||||
}
|
||||
ids.sort((a, b) => parseInt(a, 10) - parseInt(b, 10));
|
||||
ids.forEach((gid) => {
|
||||
const g = groups[gid];
|
||||
const row = document.createElement('div');
|
||||
row.className = 'profiles-row';
|
||||
row.style.display = 'flex';
|
||||
row.style.alignItems = 'center';
|
||||
row.style.gap = '0.5rem';
|
||||
row.style.flexWrap = 'wrap';
|
||||
|
||||
const label = document.createElement('span');
|
||||
const devs = Array.isArray(g.devices) ? g.devices : [];
|
||||
label.textContent = `${g.name || gid} (${devs.length} device${devs.length === 1 ? '' : 's'})`;
|
||||
|
||||
const meta = document.createElement('div');
|
||||
meta.className = 'muted-text';
|
||||
meta.style.fontSize = '0.8em';
|
||||
const rawPid = g.profile_id != null ? g.profile_id : g.profileId;
|
||||
const scoped = rawPid != null && String(rawPid).trim() !== '';
|
||||
meta.textContent = scoped ? `This profile only (${rawPid})` : 'Shared across profiles';
|
||||
const editBtn = document.createElement('button');
|
||||
editBtn.className = 'btn btn-secondary btn-small';
|
||||
editBtn.textContent = 'Edit';
|
||||
editBtn.addEventListener('click', () => openEditGroupModal(gid, g));
|
||||
|
||||
const brightBtn = document.createElement('button');
|
||||
brightBtn.className = 'btn btn-secondary btn-small';
|
||||
brightBtn.type = 'button';
|
||||
brightBtn.textContent = 'Apply brightness';
|
||||
brightBtn.title = 'Push group output brightness to Wi‑Fi drivers in this group';
|
||||
brightBtn.addEventListener('click', async () => {
|
||||
try {
|
||||
const res = await fetch(`/groups/${encodeURIComponent(gid)}/brightness`, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({}),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
alert(data.error || 'Apply brightness failed');
|
||||
return;
|
||||
}
|
||||
const n = typeof data.sent === 'number' ? data.sent : 0;
|
||||
alert(
|
||||
n
|
||||
? `Sent brightness to ${n} driver(s).`
|
||||
: 'No Wi‑Fi drivers received brightness (check connections).',
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
alert('Apply brightness failed');
|
||||
}
|
||||
});
|
||||
|
||||
const applyBtn = document.createElement('button');
|
||||
applyBtn.className = 'btn btn-primary btn-small';
|
||||
applyBtn.type = 'button';
|
||||
applyBtn.textContent = 'Apply defaults to drivers';
|
||||
applyBtn.title = 'Push Wi‑Fi defaults to each connected driver in this group';
|
||||
applyBtn.addEventListener('click', async () => {
|
||||
try {
|
||||
const res = await fetch(`/groups/${encodeURIComponent(gid)}/driver-config`, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({}),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
alert(data.error || 'Apply failed');
|
||||
return;
|
||||
}
|
||||
const n = typeof data.sent === 'number' ? data.sent : 0;
|
||||
alert(
|
||||
n
|
||||
? `Sent defaults to ${n} driver(s).`
|
||||
: 'No Wi‑Fi drivers received the config (check defaults and connections).',
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
alert('Apply failed');
|
||||
}
|
||||
});
|
||||
|
||||
const identifyBtn = document.createElement('button');
|
||||
identifyBtn.className = 'btn btn-secondary btn-small';
|
||||
identifyBtn.type = 'button';
|
||||
identifyBtn.textContent = 'Identify';
|
||||
identifyBtn.title =
|
||||
'Identify all devices in this group at once (red blink at 10 Hz)';
|
||||
identifyBtn.addEventListener('click', async () => {
|
||||
await identifyGroupById(gid);
|
||||
});
|
||||
|
||||
const delBtn = document.createElement('button');
|
||||
delBtn.className = 'btn btn-danger btn-small';
|
||||
delBtn.textContent = 'Delete';
|
||||
delBtn.addEventListener('click', async () => {
|
||||
if (!confirm(`Delete group "${g.name || gid}"? Zones referencing it may need updating.`)) return;
|
||||
try {
|
||||
const res = await fetch(`/groups/${encodeURIComponent(gid)}`, {
|
||||
method: 'DELETE',
|
||||
credentials: 'same-origin',
|
||||
});
|
||||
if (res.ok) await loadGroupsModal();
|
||||
else {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
alert(data.error || 'Delete failed');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
alert('Delete failed');
|
||||
}
|
||||
});
|
||||
|
||||
const left = document.createElement('div');
|
||||
left.style.flex = '1';
|
||||
left.style.minWidth = '0';
|
||||
left.appendChild(label);
|
||||
left.appendChild(meta);
|
||||
row.appendChild(left);
|
||||
row.appendChild(editBtn);
|
||||
row.appendChild(brightBtn);
|
||||
row.appendChild(applyBtn);
|
||||
row.appendChild(identifyBtn);
|
||||
row.appendChild(delBtn);
|
||||
container.appendChild(row);
|
||||
});
|
||||
}
|
||||
|
||||
async function identifyGroupById(gid) {
|
||||
if (!gid) return;
|
||||
try {
|
||||
const res = await fetch(`/groups/${encodeURIComponent(gid)}/identify`, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
alert(data.error || 'Identify failed');
|
||||
return;
|
||||
}
|
||||
const n = typeof data.sent === 'number' ? data.sent : 0;
|
||||
const errs = Array.isArray(data.errors) ? data.errors : [];
|
||||
const failed = errs.filter((e) => e && e.error).length;
|
||||
let msg = n ? `Identify sent to ${n} device(s).` : 'No devices received identify.';
|
||||
if (failed) {
|
||||
msg += ` ${failed} failed — see console for details.`;
|
||||
console.warn('Group identify errors', errs);
|
||||
}
|
||||
alert(msg);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert('Identify failed');
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const groupsBtn = document.getElementById('groups-btn');
|
||||
const groupsModal = document.getElementById('groups-modal');
|
||||
const groupsCloseBtn = document.getElementById('groups-close-btn');
|
||||
const newNameInput = document.getElementById('new-group-name');
|
||||
const createBtn = document.getElementById('create-group-btn');
|
||||
const editForm = document.getElementById('edit-group-form');
|
||||
const editCloseBtn = document.getElementById('edit-group-close-btn');
|
||||
const editModal = document.getElementById('edit-group-modal');
|
||||
|
||||
if (groupsBtn && groupsModal) {
|
||||
groupsBtn.addEventListener('click', () => {
|
||||
groupsModal.classList.add('active');
|
||||
loadGroupsModal();
|
||||
});
|
||||
}
|
||||
if (groupsCloseBtn && groupsModal) {
|
||||
groupsCloseBtn.addEventListener('click', () => groupsModal.classList.remove('active'));
|
||||
}
|
||||
|
||||
const grpOutBr = document.getElementById('edit-group-output-brightness');
|
||||
const grpOutBrVal = document.getElementById('edit-group-output-brightness-value');
|
||||
if (grpOutBr && grpOutBrVal) {
|
||||
grpOutBr.addEventListener('input', () => {
|
||||
grpOutBrVal.textContent = grpOutBr.value;
|
||||
});
|
||||
}
|
||||
|
||||
const editIdentifyBtn = document.getElementById('edit-group-identify-btn');
|
||||
if (editIdentifyBtn) {
|
||||
editIdentifyBtn.addEventListener('click', async () => {
|
||||
const idInput = document.getElementById('edit-group-id');
|
||||
const gid = idInput && idInput.value;
|
||||
if (!gid) return;
|
||||
await identifyGroupById(gid);
|
||||
});
|
||||
}
|
||||
|
||||
const createHandler = async () => {
|
||||
const name = newNameInput && newNameInput.value.trim();
|
||||
if (!name) return;
|
||||
const profileOnly = document.getElementById('new-group-profile-only');
|
||||
try {
|
||||
const res = await fetch('/groups', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
||||
body: JSON.stringify({
|
||||
name,
|
||||
profile_scoped: !!(profileOnly && profileOnly.checked),
|
||||
}),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
alert(data.error || 'Create failed');
|
||||
return;
|
||||
}
|
||||
if (newNameInput) newNameInput.value = '';
|
||||
if (profileOnly) profileOnly.checked = false;
|
||||
await loadGroupsModal();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert('Create failed');
|
||||
}
|
||||
};
|
||||
if (createBtn) createBtn.addEventListener('click', createHandler);
|
||||
if (newNameInput) {
|
||||
newNameInput.addEventListener('keypress', (ev) => {
|
||||
if (ev.key === 'Enter') createHandler();
|
||||
});
|
||||
}
|
||||
|
||||
if (editForm) {
|
||||
editForm.addEventListener('input', () => refreshEditGroupDebug());
|
||||
editForm.addEventListener('change', () => refreshEditGroupDebug());
|
||||
editForm.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const { gid, payload } = collectGroupEditPayload();
|
||||
if (!gid) return;
|
||||
|
||||
const shareCb = document.getElementById('edit-group-share-all-profiles');
|
||||
if (shareCb && shareCb.checked) {
|
||||
payload.profile_id = null;
|
||||
} else {
|
||||
const pid = await getCurrentProfileIdForGroups();
|
||||
payload.profile_id = pid || null;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(`/groups/${encodeURIComponent(gid)}`, {
|
||||
method: 'PUT',
|
||||
credentials: 'same-origin',
|
||||
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
alert(data.error || 'Save failed');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await fetch(`/groups/${encodeURIComponent(gid)}/brightness`, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({}),
|
||||
});
|
||||
} catch (_) {
|
||||
/* ignore push errors after save */
|
||||
}
|
||||
if (editModal) editModal.classList.remove('active');
|
||||
await loadGroupsModal();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
alert('Save failed');
|
||||
}
|
||||
});
|
||||
}
|
||||
if (editCloseBtn && editModal) {
|
||||
editCloseBtn.addEventListener('click', () => editModal.classList.remove('active'));
|
||||
}
|
||||
|
||||
window.openDeviceGroupsModal = async () => {
|
||||
const gm = document.getElementById('groups-modal');
|
||||
if (!gm) return;
|
||||
gm.classList.add('active');
|
||||
try {
|
||||
await loadGroupsModal();
|
||||
} catch (e) {
|
||||
console.error('openDeviceGroupsModal', e);
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -33,6 +33,33 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
return Number.isFinite(t) ? t : def;
|
||||
};
|
||||
|
||||
const coercePresetAuto = (preset) => {
|
||||
if (!preset || typeof preset !== 'object') {
|
||||
return true;
|
||||
}
|
||||
const v =
|
||||
preset.auto !== undefined && preset.auto !== null ? preset.auto : preset.a;
|
||||
if (typeof v === 'boolean') {
|
||||
return v;
|
||||
}
|
||||
if (v === 0 || v === '0') {
|
||||
return false;
|
||||
}
|
||||
if (v === 1 || v === '1') {
|
||||
return true;
|
||||
}
|
||||
if (typeof v === 'string') {
|
||||
const l = v.trim().toLowerCase();
|
||||
if (['false', '0', 'no', 'off'].includes(l)) {
|
||||
return false;
|
||||
}
|
||||
if (['true', '1', 'yes', 'on'].includes(l)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
const getCurrentProfileId = async () => {
|
||||
try {
|
||||
const response = await fetch('/profiles/current', { headers: { Accept: 'application/json' } });
|
||||
@@ -531,6 +558,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const colors = Array.isArray(preset.colors) && preset.colors.length
|
||||
? preset.colors
|
||||
: ['#FFFFFF'];
|
||||
const presetAuto = coercePresetAuto(preset);
|
||||
wirePresets[presetId] = {
|
||||
pattern: preset.pattern || 'off',
|
||||
colors,
|
||||
@@ -538,7 +566,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
brightness: typeof preset.brightness === 'number'
|
||||
? preset.brightness
|
||||
: (typeof preset.br === 'number' ? preset.br : 127),
|
||||
auto: typeof preset.auto === 'boolean' ? preset.auto : true,
|
||||
auto: presetAuto,
|
||||
a: presetAuto,
|
||||
n1: coercePresetInt(preset.n1),
|
||||
n2: coercePresetInt(preset.n2),
|
||||
n3: coercePresetInt(preset.n3),
|
||||
|
||||
@@ -29,6 +29,9 @@ const filterPresetsForCurrentProfile = async (presetsObj) => {
|
||||
}),
|
||||
);
|
||||
};
|
||||
try {
|
||||
window.filterPresetsForCurrentProfile = filterPresetsForCurrentProfile;
|
||||
} catch (e) {}
|
||||
|
||||
const getCurrentProfileData = async () => {
|
||||
try {
|
||||
@@ -154,7 +157,44 @@ function tabDeviceNamesFromSection(section) {
|
||||
: [];
|
||||
}
|
||||
|
||||
async function postDriverSequence(sequence, targetMacs, delayS) {
|
||||
/** Device names for ``presetId`` on the current zone tab (zone ``group_ids`` for presets, else tab devices). */
|
||||
async function deviceNamesForPresetOnCurrentZone(presetId) {
|
||||
const section = document.querySelector('.presets-section[data-zone-id]');
|
||||
const fallback = tabDeviceNamesFromSection(section);
|
||||
if (!section || !presetId) return fallback;
|
||||
const zm = window.zonesManager;
|
||||
if (!zm || typeof zm.resolveDeviceNamesForZonePreset !== 'function') return fallback;
|
||||
const zoneId = section.dataset.zoneId;
|
||||
try {
|
||||
const res = await fetch(`/zones/${zoneId}`, { headers: { Accept: 'application/json' } });
|
||||
if (!res.ok) return fallback;
|
||||
const zd = await res.json();
|
||||
const names = await zm.resolveDeviceNamesForZonePreset(zd, String(presetId));
|
||||
return names.length ? names : fallback;
|
||||
} catch (_) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
function formatPresetTargetGroupsLine(zoneDoc, groupsMap) {
|
||||
const zm = window.zonesManager;
|
||||
const gids =
|
||||
zm && typeof zm.effectiveGroupIdsForZonePreset === 'function'
|
||||
? zm.effectiveGroupIdsForZonePreset(zoneDoc || {})
|
||||
: Array.isArray(zoneDoc && zoneDoc.group_ids)
|
||||
? zoneDoc.group_ids.map((x) => String(x).trim()).filter((x) => x.length > 0)
|
||||
: [];
|
||||
const parts = (gids || [])
|
||||
.map((id) => {
|
||||
const g = groupsMap && groupsMap[id];
|
||||
const gn = g && g.name ? String(g.name).trim() : '';
|
||||
return gn;
|
||||
})
|
||||
.filter(Boolean);
|
||||
return parts.length ? parts.join(', ') : '';
|
||||
}
|
||||
|
||||
async function postDriverSequence(sequence, targetMacs, delayS, pushOptions) {
|
||||
const body = {
|
||||
sequence,
|
||||
targets: Array.isArray(targetMacs) && targetMacs.length ? [...new Set(targetMacs)] : undefined,
|
||||
@@ -190,10 +230,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const presetNewColorInput = document.getElementById('preset-new-color');
|
||||
const presetBrightnessInput = document.getElementById('preset-brightness-input');
|
||||
const presetDelayInput = document.getElementById('preset-delay-input');
|
||||
const presetDelayField = presetDelayInput ? presetDelayInput.closest('.preset-editor-field') : null;
|
||||
const presetBackgroundInput = document.getElementById('preset-background-input');
|
||||
const presetBackgroundButton = document.getElementById('preset-background-btn');
|
||||
const presetManualModeInput = document.getElementById('preset-manual-mode-input');
|
||||
const presetManualModeHint = document.getElementById('preset-manual-mode-hint');
|
||||
const presetManualModeLabel = document.getElementById('preset-manual-mode-label');
|
||||
const presetManualBeatNWrap = document.getElementById('preset-manual-beat-n-wrap');
|
||||
const presetManualBeatNInput = document.getElementById('preset-manual-beat-n-input');
|
||||
const presetDefaultButton = document.getElementById('preset-default-btn');
|
||||
const presetRemoveFromTabButton = document.getElementById('preset-remove-from-zone-btn');
|
||||
const presetSaveButton = document.getElementById('preset-save-btn');
|
||||
const presetAddFromPaletteButton = document.getElementById('preset-add-from-palette-btn');
|
||||
const presetBackgroundFromPaletteButton = document.getElementById('preset-background-from-palette-btn');
|
||||
|
||||
if (!presetsButton || !presetsModal || !presetsList || !presetSaveButton) {
|
||||
return;
|
||||
@@ -205,6 +254,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
let cachedPatterns = {};
|
||||
let currentPresetColors = []; // Track colors for the current preset
|
||||
let currentPresetPaletteRefs = []; // Palette index refs per color (null for direct colors)
|
||||
let currentBackgroundPaletteRef = null;
|
||||
let bgPaletteResolveGen = 0;
|
||||
|
||||
// Function to get max colors for current pattern
|
||||
const getMaxColors = () => {
|
||||
@@ -219,6 +270,104 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
return Infinity; // No limit if not specified
|
||||
};
|
||||
|
||||
const resolvePatternConfig = (patternName) => {
|
||||
const rawPatternName = String(patternName || '').trim();
|
||||
const normalizedPatternName = rawPatternName.endsWith('.py')
|
||||
? rawPatternName.slice(0, -3)
|
||||
: rawPatternName;
|
||||
let patternConfig =
|
||||
(cachedPatterns && cachedPatterns[rawPatternName]) ||
|
||||
(cachedPatterns && cachedPatterns[normalizedPatternName]) ||
|
||||
null;
|
||||
if (!patternConfig && cachedPatterns && typeof cachedPatterns === 'object') {
|
||||
const lower = normalizedPatternName.toLowerCase();
|
||||
const matchedKey = Object.keys(cachedPatterns).find(
|
||||
(k) => String(k).toLowerCase() === lower,
|
||||
);
|
||||
if (matchedKey) {
|
||||
patternConfig = cachedPatterns[matchedKey];
|
||||
}
|
||||
}
|
||||
if (patternConfig && typeof patternConfig === 'object' && patternConfig.data && typeof patternConfig.data === 'object') {
|
||||
patternConfig = patternConfig.data;
|
||||
}
|
||||
if (
|
||||
patternConfig &&
|
||||
typeof patternConfig === 'object' &&
|
||||
patternConfig.parameter_mappings &&
|
||||
typeof patternConfig.parameter_mappings === 'object'
|
||||
) {
|
||||
patternConfig = patternConfig.parameter_mappings;
|
||||
}
|
||||
return patternConfig && typeof patternConfig === 'object' ? patternConfig : null;
|
||||
};
|
||||
|
||||
/** From db/pattern.json; missing key means pattern allows manual / beat (backward compatible). */
|
||||
const patternSupportsManual = (patternName) => {
|
||||
const cfg = resolvePatternConfig(patternName);
|
||||
if (!cfg) {
|
||||
return true;
|
||||
}
|
||||
return cfg.supports_manual !== false;
|
||||
};
|
||||
|
||||
const updateManualBeatNVisibility = () => {
|
||||
if (!presetManualBeatNWrap) {
|
||||
return;
|
||||
}
|
||||
const manualOn = presetManualModeInput && presetManualModeInput.checked;
|
||||
const patternName = presetPatternInput ? presetPatternInput.value.trim() : '';
|
||||
const ok = !patternName || patternSupportsManual(patternName);
|
||||
presetManualBeatNWrap.style.display = manualOn && ok ? '' : 'none';
|
||||
};
|
||||
|
||||
const updatePresetBackgroundButton = () => {
|
||||
if (!presetBackgroundButton || !presetBackgroundInput) return;
|
||||
const color = coercePresetBackground({ background: presetBackgroundInput.value });
|
||||
presetBackgroundInput.value = color;
|
||||
presetBackgroundButton.textContent = color;
|
||||
presetBackgroundButton.style.backgroundColor = color;
|
||||
presetBackgroundButton.style.color = '#fff';
|
||||
presetBackgroundButton.style.borderColor = 'rgba(255, 255, 255, 0.6)';
|
||||
presetBackgroundButton.title =
|
||||
currentBackgroundPaletteRef != null
|
||||
? `Background from profile palette (index ${currentBackgroundPaletteRef}); click to pick a custom colour`
|
||||
: 'Choose background colour';
|
||||
};
|
||||
|
||||
const updateDelayVisibilityForManualMode = () => {
|
||||
if (!presetDelayField) return;
|
||||
const manualOn = presetManualModeInput && presetManualModeInput.checked;
|
||||
presetDelayField.style.display = manualOn ? 'none' : '';
|
||||
};
|
||||
|
||||
const updateManualModeAvailability = () => {
|
||||
if (!presetManualModeInput) {
|
||||
return;
|
||||
}
|
||||
const patternName = presetPatternInput ? presetPatternInput.value.trim() : '';
|
||||
const ok = !patternName || patternSupportsManual(patternName);
|
||||
presetManualModeInput.disabled = !ok;
|
||||
if (presetManualModeLabel) {
|
||||
presetManualModeLabel.style.opacity = ok ? '' : '0.55';
|
||||
}
|
||||
if (presetManualModeHint) {
|
||||
if (!patternName || ok) {
|
||||
presetManualModeHint.style.display = 'none';
|
||||
presetManualModeHint.textContent = '';
|
||||
} else {
|
||||
presetManualModeHint.style.display = '';
|
||||
presetManualModeHint.textContent =
|
||||
'This pattern is a poor fit for manual mode or audio beat triggers; use auto mode for best results.';
|
||||
}
|
||||
}
|
||||
if (!ok) {
|
||||
presetManualModeInput.checked = false;
|
||||
}
|
||||
updateManualBeatNVisibility();
|
||||
updateDelayVisibilityForManualMode();
|
||||
};
|
||||
|
||||
// Function to show/hide color section based on max_colors
|
||||
const updateColorSectionVisibility = () => {
|
||||
const maxColors = getMaxColors();
|
||||
@@ -296,7 +445,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
|
||||
const swatchContainer = document.createElement('div');
|
||||
swatchContainer.style.cssText = 'display: flex; flex-wrap: wrap; gap: 0.5rem;';
|
||||
swatchContainer.style.cssText = 'display: flex; flex-wrap: nowrap; gap: 0.5rem; align-items: flex-start; overflow-x: auto;';
|
||||
swatchContainer.classList.add('color-swatches-container');
|
||||
|
||||
currentPresetColors.forEach((color, index) => {
|
||||
@@ -468,7 +617,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
presetColorsContainer.appendChild(swatchContainer);
|
||||
};
|
||||
|
||||
|
||||
// Function to get drag after element for colors (horizontal layout)
|
||||
const getDragAfterElementForColors = (container, x) => {
|
||||
const draggableElements = [...container.querySelectorAll('.draggable-color-swatch:not(.dragging-color)')];
|
||||
@@ -492,12 +641,46 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
presetNameInput.value = preset.name || '';
|
||||
const patternName = preset.pattern || '';
|
||||
presetPatternInput.value = patternName;
|
||||
const colors = Array.isArray(preset.colors) ? preset.colors : [];
|
||||
const paletteRefs = Array.isArray(preset.palette_refs) ? preset.palette_refs : [];
|
||||
const colors = Array.isArray(preset.colors) ? preset.colors.slice() : [];
|
||||
const paletteRefs = Array.isArray(preset.palette_refs) ? preset.palette_refs.slice() : [];
|
||||
renderPresetColors(colors, paletteRefs);
|
||||
presetBrightnessInput.value = preset.brightness || 0;
|
||||
presetDelayInput.value = preset.delay || 0;
|
||||
|
||||
if (presetBackgroundInput) {
|
||||
const rawBgRef = preset.background_palette_ref ?? preset.backgroundPaletteRef;
|
||||
let bgRef = null;
|
||||
if (rawBgRef != null && rawBgRef !== '') {
|
||||
const n = typeof rawBgRef === 'number' ? rawBgRef : parseInt(String(rawBgRef), 10);
|
||||
if (Number.isInteger(n) && n >= 0) {
|
||||
bgRef = n;
|
||||
}
|
||||
}
|
||||
currentBackgroundPaletteRef = bgRef;
|
||||
presetBackgroundInput.value = coercePresetBackground(preset);
|
||||
updatePresetBackgroundButton();
|
||||
const gen = ++bgPaletteResolveGen;
|
||||
void getCurrentProfilePaletteColors().then((pal) => {
|
||||
if (gen !== bgPaletteResolveGen || !presetBackgroundInput) {
|
||||
return;
|
||||
}
|
||||
presetBackgroundInput.value = resolvePresetBackgroundHex(preset, pal);
|
||||
updatePresetBackgroundButton();
|
||||
});
|
||||
} else {
|
||||
updatePresetBackgroundButton();
|
||||
}
|
||||
if (presetManualModeInput) {
|
||||
const autoVal = typeof preset.auto === 'boolean' ? preset.auto : true;
|
||||
presetManualModeInput.checked = !autoVal;
|
||||
}
|
||||
if (presetManualBeatNInput) {
|
||||
const raw = preset.manual_beat_n;
|
||||
let n = typeof raw === 'number' ? raw : parseInt(String(raw != null ? raw : '1'), 10);
|
||||
if (!Number.isFinite(n)) n = 1;
|
||||
n = Math.max(1, Math.min(64, n));
|
||||
presetManualBeatNInput.value = String(n);
|
||||
}
|
||||
|
||||
// Update color section visibility based on pattern
|
||||
updateColorSectionVisibility();
|
||||
|
||||
@@ -552,10 +735,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
// After values: show only mapped n params with labels from pattern.json; clear hidden inputs
|
||||
updatePresetNLabels(patternName);
|
||||
updateManualModeAvailability();
|
||||
updatePresetEditorTabActionsVisibility();
|
||||
};
|
||||
|
||||
const clearForm = () => {
|
||||
bgPaletteResolveGen += 1;
|
||||
currentEditId = null;
|
||||
currentEditTabId = null;
|
||||
currentPresetColors = [];
|
||||
@@ -574,7 +759,18 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
n6: 0,
|
||||
n7: 0,
|
||||
n8: 0,
|
||||
background: '#000000',
|
||||
auto: true,
|
||||
manual_beat_n: 1,
|
||||
});
|
||||
if (presetManualModeInput) {
|
||||
presetManualModeInput.checked = false;
|
||||
}
|
||||
if (presetManualBeatNInput) {
|
||||
presetManualBeatNInput.value = '1';
|
||||
}
|
||||
updatePresetBackgroundButton();
|
||||
updateManualModeAvailability();
|
||||
// Re-enable name and pattern when clearing (for new preset)
|
||||
if (presetNameInput) {
|
||||
presetNameInput.disabled = false;
|
||||
@@ -652,6 +848,15 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
// Use canonical field names expected by the device / API
|
||||
brightness: presetBrightnessInput ? parseInt(presetBrightnessInput.value, 10) || 0 : 0,
|
||||
delay: presetDelayInput ? parseInt(presetDelayInput.value, 10) || 0 : 0,
|
||||
background: presetBackgroundInput ? presetBackgroundInput.value : '#000000',
|
||||
background_palette_ref: currentBackgroundPaletteRef != null ? currentBackgroundPaletteRef : null,
|
||||
auto: presetManualModeInput ? !presetManualModeInput.checked : true,
|
||||
manual_beat_n: (() => {
|
||||
if (!presetManualBeatNInput) return 1;
|
||||
let n = parseInt(presetManualBeatNInput.value, 10);
|
||||
if (!Number.isFinite(n)) n = 1;
|
||||
return Math.max(1, Math.min(64, n));
|
||||
})(),
|
||||
};
|
||||
|
||||
// Always store numeric parameters as n1..n8.
|
||||
@@ -812,6 +1017,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if (nGrid) {
|
||||
nGrid.style.display = visibleNKeys.size > 0 ? '' : 'none';
|
||||
}
|
||||
updateManualModeAvailability();
|
||||
};
|
||||
|
||||
const renderPresets = (presets) => {
|
||||
@@ -1028,7 +1234,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
// Create modal
|
||||
const modal = document.createElement('div');
|
||||
modal.className = 'modal active';
|
||||
modal.className = 'modal active modal-child-overlay';
|
||||
modal.id = 'add-preset-to-zone-modal';
|
||||
modal.innerHTML = `
|
||||
<div class="modal-content">
|
||||
@@ -1121,7 +1327,15 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
throw new Error('Failed to load zone');
|
||||
}
|
||||
const tabData = await tabResponse.json();
|
||||
|
||||
const kind =
|
||||
typeof window.normalizeZoneContentKind === 'function'
|
||||
? window.normalizeZoneContentKind(tabData)
|
||||
: null;
|
||||
if (kind === 'sequences') {
|
||||
alert('This zone is for sequences only. Add a sequence from the zone Edit menu instead.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Normalize to flat array to check and update usage
|
||||
let flat = [];
|
||||
if (Array.isArray(tabData.presets_flat)) {
|
||||
@@ -1143,7 +1357,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const newGrid = arrayToGrid(flat, 3);
|
||||
tabData.presets = newGrid;
|
||||
tabData.presets_flat = flat;
|
||||
|
||||
|
||||
// Update zone
|
||||
const updateResponse = await fetch(`/zones/${zoneId}`, {
|
||||
method: 'PUT',
|
||||
@@ -1185,6 +1399,22 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
updateColorSectionVisibility();
|
||||
// Re-render colors to show updated max colors limit
|
||||
renderPresetColors(currentPresetColors, currentPresetPaletteRefs);
|
||||
updateManualModeAvailability();
|
||||
});
|
||||
}
|
||||
if (presetManualModeInput) {
|
||||
presetManualModeInput.addEventListener('change', () => {
|
||||
updateManualBeatNVisibility();
|
||||
updateDelayVisibilityForManualMode();
|
||||
});
|
||||
}
|
||||
if (presetBackgroundButton && presetBackgroundInput) {
|
||||
presetBackgroundButton.addEventListener('click', () => {
|
||||
presetBackgroundInput.click();
|
||||
});
|
||||
presetBackgroundInput.addEventListener('input', () => {
|
||||
currentBackgroundPaletteRef = null;
|
||||
updatePresetBackgroundButton();
|
||||
});
|
||||
}
|
||||
// Color picker auto-add handler
|
||||
@@ -1222,7 +1452,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
|
||||
const modal = document.createElement('div');
|
||||
modal.className = 'modal active';
|
||||
modal.className = 'modal active modal-child-overlay';
|
||||
modal.innerHTML = `
|
||||
<div class="modal-content">
|
||||
<h2>Pick Palette Color</h2>
|
||||
@@ -1263,10 +1493,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const ref = parseInt(row.dataset.paletteIndex, 10);
|
||||
if (!color || !Number.isInteger(ref)) return;
|
||||
|
||||
if (currentPresetColors.includes(color) && currentPresetPaletteRefs.includes(ref)) {
|
||||
alert('That palette color is already linked.');
|
||||
return;
|
||||
}
|
||||
const maxColors = getMaxColors();
|
||||
if (currentPresetColors.length >= maxColors) {
|
||||
alert(`This pattern allows a maximum of ${maxColors} color${maxColors !== 1 ? 's' : ''}.`);
|
||||
@@ -1280,7 +1506,72 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Failed to add from palette:', err);
|
||||
alert('Failed to load palette colors.');
|
||||
alert('Failed to load palette colours.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (presetBackgroundFromPaletteButton) {
|
||||
presetBackgroundFromPaletteButton.addEventListener('click', async () => {
|
||||
try {
|
||||
const paletteColors = await getCurrentProfilePaletteColors();
|
||||
if (!Array.isArray(paletteColors) || paletteColors.length === 0) {
|
||||
alert('No profile palette colours available.');
|
||||
return;
|
||||
}
|
||||
|
||||
const modal = document.createElement('div');
|
||||
modal.className = 'modal active modal-child-overlay';
|
||||
modal.innerHTML = `
|
||||
<div class="modal-content">
|
||||
<h2>Pick background colour</h2>
|
||||
<div id="pick-bg-palette-list" class="profiles-list" style="max-height: 300px; overflow-y: auto;"></div>
|
||||
<div class="modal-actions">
|
||||
<button class="btn btn-secondary" id="pick-bg-palette-close-btn">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
document.body.appendChild(modal);
|
||||
|
||||
const list = modal.querySelector('#pick-bg-palette-list');
|
||||
paletteColors.forEach((color, idx) => {
|
||||
const row = document.createElement('div');
|
||||
row.className = 'profiles-row';
|
||||
row.style.display = 'flex';
|
||||
row.style.alignItems = 'center';
|
||||
row.style.gap = '0.75rem';
|
||||
row.dataset.paletteIndex = String(idx);
|
||||
row.dataset.paletteColor = color;
|
||||
row.innerHTML = `
|
||||
<div style="width:28px;height:28px;border-radius:4px;border:1px solid #555;background:${color};"></div>
|
||||
<span style="flex:1">${color}</span>
|
||||
<button class="btn btn-primary btn-small" type="button">Use</button>
|
||||
`;
|
||||
list.appendChild(row);
|
||||
});
|
||||
|
||||
const close = () => modal.remove();
|
||||
modal.querySelector('#pick-bg-palette-close-btn').addEventListener('click', close);
|
||||
|
||||
list.addEventListener('click', (e) => {
|
||||
const btn = e.target.closest('button');
|
||||
if (!btn) return;
|
||||
const row = e.target.closest('[data-palette-index]');
|
||||
if (!row) return;
|
||||
const color = row.dataset.paletteColor;
|
||||
const ref = parseInt(row.dataset.paletteIndex, 10);
|
||||
if (!color || !Number.isInteger(ref)) return;
|
||||
|
||||
currentBackgroundPaletteRef = ref;
|
||||
if (presetBackgroundInput) {
|
||||
presetBackgroundInput.value = color;
|
||||
}
|
||||
updatePresetBackgroundButton();
|
||||
close();
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Failed to pick background from palette:', err);
|
||||
alert('Failed to load palette colours.');
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1293,12 +1584,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
alert('Preset name is required to send.');
|
||||
return;
|
||||
}
|
||||
// Send current editor values and then select on all devices in the current zone (if any)
|
||||
const section = document.querySelector('.presets-section[data-zone-id]');
|
||||
const deviceNames = tabDeviceNamesFromSection(section);
|
||||
// Work out the preset ID: for existing presets use currentEditId, otherwise fall back to name
|
||||
// Send current editor values to zone devices (if any); never persist on device.
|
||||
const presetId = currentEditId || payload.name;
|
||||
// Try sends preset first, then select; never persist on device.
|
||||
const deviceNames = await deviceNamesForPresetOnCurrentZone(presetId);
|
||||
// Auto: load + immediate select. Manual: load only; first advance on the next audio beat.
|
||||
await sendPresetViaEspNow(presetId, payload, deviceNames, false, false, '2');
|
||||
});
|
||||
}
|
||||
@@ -1310,9 +1599,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
alert('Preset name is required.');
|
||||
return;
|
||||
}
|
||||
const section = document.querySelector('.presets-section[data-zone-id]');
|
||||
const deviceNames = tabDeviceNamesFromSection(section);
|
||||
const presetId = currentEditId || payload.name;
|
||||
const deviceNames = await deviceNamesForPresetOnCurrentZone(presetId);
|
||||
await sendPresetViaEspNow(presetId, payload, deviceNames, true, true, '1');
|
||||
await updateTabDefaultPreset(presetId);
|
||||
await sendDefaultPreset('1', deviceNames);
|
||||
@@ -1347,9 +1635,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
throw new Error('Failed to save preset');
|
||||
}
|
||||
|
||||
// Same device targeting as Try: zone tab supplies names and selection without persistence.
|
||||
const section = document.querySelector('.presets-section[data-zone-id]');
|
||||
const deviceNames = tabDeviceNamesFromSection(section);
|
||||
// Same device targeting as Try: per-preset zone groups when in a zone tab.
|
||||
const presetIdForSend = currentEditId || payload.name;
|
||||
const deviceNames = await deviceNamesForPresetOnCurrentZone(presetIdForSend);
|
||||
|
||||
// Use saved preset from server response for sending
|
||||
const saved = await response.json().catch(() => null);
|
||||
@@ -1417,6 +1705,85 @@ const coercePresetInt = (v, def = 0) => {
|
||||
return Number.isFinite(t) ? t : def;
|
||||
};
|
||||
|
||||
/** Device field ``a`` / API ``auto``; missing → auto-run (matches server build_preset_dict). */
|
||||
const coercePresetAuto = (preset) => {
|
||||
if (!preset || typeof preset !== 'object') {
|
||||
return true;
|
||||
}
|
||||
const v =
|
||||
preset.auto !== undefined && preset.auto !== null ? preset.auto : preset.a;
|
||||
if (typeof v === 'boolean') {
|
||||
return v;
|
||||
}
|
||||
if (v === 0 || v === '0') {
|
||||
return false;
|
||||
}
|
||||
if (v === 1 || v === '1') {
|
||||
return true;
|
||||
}
|
||||
if (typeof v === 'string') {
|
||||
const l = v.trim().toLowerCase();
|
||||
if (['false', '0', 'no', 'off'].includes(l)) {
|
||||
return false;
|
||||
}
|
||||
if (['true', '1', 'yes', 'on'].includes(l)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
/** Preset background colour; accepts #RRGGBB or [r,g,b]. */
|
||||
const coercePresetBackground = (preset) => {
|
||||
if (!preset || typeof preset !== 'object') {
|
||||
return '#000000';
|
||||
}
|
||||
const raw = preset.background !== undefined && preset.background !== null ? preset.background : preset.bg;
|
||||
if (typeof raw === 'string') {
|
||||
const s = raw.trim();
|
||||
if (/^#[0-9a-fA-F]{6}$/.test(s)) {
|
||||
return s.toUpperCase();
|
||||
}
|
||||
}
|
||||
if (Array.isArray(raw) && raw.length === 3) {
|
||||
const r = coercePresetInt(raw[0], 0);
|
||||
const g = coercePresetInt(raw[1], 0);
|
||||
const b = coercePresetInt(raw[2], 0);
|
||||
const clamp = (n) => Math.max(0, Math.min(255, n));
|
||||
return `#${clamp(r).toString(16).padStart(2, '0')}${clamp(g).toString(16).padStart(2, '0')}${clamp(b).toString(16).padStart(2, '0')}`.toUpperCase();
|
||||
}
|
||||
return '#000000';
|
||||
};
|
||||
|
||||
/** Resolved background hex; uses ``background_palette_ref`` when set and palette is available. */
|
||||
const resolvePresetBackgroundHex = (preset, paletteColors) => {
|
||||
if (!preset || typeof preset !== 'object') {
|
||||
return coercePresetBackground(preset);
|
||||
}
|
||||
const rawRef =
|
||||
preset.background_palette_ref !== undefined && preset.background_palette_ref !== null
|
||||
? preset.background_palette_ref
|
||||
: preset.backgroundPaletteRef;
|
||||
const ref = typeof rawRef === 'number' ? rawRef : parseInt(String(rawRef != null ? rawRef : ''), 10);
|
||||
const pal = Array.isArray(paletteColors) ? paletteColors : [];
|
||||
if (Number.isInteger(ref) && ref >= 0 && ref < pal.length && pal[ref]) {
|
||||
const c = String(pal[ref]).trim();
|
||||
if (/^#[0-9a-fA-F]{6}$/i.test(c)) {
|
||||
return c.toUpperCase();
|
||||
}
|
||||
}
|
||||
return coercePresetBackground(preset);
|
||||
};
|
||||
|
||||
/** Audio beat stride for manual presets (led-controller only; firmware ignores this key). */
|
||||
const coerceManualBeatN = (preset) => {
|
||||
if (!preset || typeof preset !== 'object') return 1;
|
||||
const raw = preset.manual_beat_n;
|
||||
let n = typeof raw === 'number' ? raw : parseInt(String(raw != null ? raw : '1'), 10);
|
||||
if (!Number.isFinite(n)) n = 1;
|
||||
return Math.max(1, Math.min(64, n));
|
||||
};
|
||||
|
||||
// Build driver messages for a single preset; deliver via /presets/push (ESP-NOW + TCP).
|
||||
// Send order:
|
||||
// 1) preset payload (optionally with save)
|
||||
@@ -1429,6 +1796,7 @@ const sendPresetViaEspNow = async (
|
||||
saveToDevice = true,
|
||||
setDefault = false,
|
||||
devicePresetId = null,
|
||||
pushOptions = null,
|
||||
) => {
|
||||
try {
|
||||
const baseColors = Array.isArray(preset.colors) && preset.colors.length
|
||||
@@ -1438,23 +1806,28 @@ const sendPresetViaEspNow = async (
|
||||
const colors = resolveColorsWithPaletteRefs(baseColors, preset.palette_refs, paletteColors);
|
||||
|
||||
const wirePresetId = devicePresetId != null ? String(devicePresetId) : String(presetId);
|
||||
const presetAuto = coercePresetAuto(preset);
|
||||
const presetBackground = resolvePresetBackgroundHex(preset, paletteColors);
|
||||
const presetMessage = {
|
||||
v: '1',
|
||||
presets: {
|
||||
[wirePresetId]: {
|
||||
pattern: preset.pattern || 'off',
|
||||
colors,
|
||||
bg: presetBackground,
|
||||
delay: typeof preset.delay === 'number' ? preset.delay : 100,
|
||||
brightness: typeof preset.brightness === 'number'
|
||||
? preset.brightness
|
||||
: (typeof preset.br === 'number' ? preset.br : 127),
|
||||
auto: typeof preset.auto === 'boolean' ? preset.auto : true,
|
||||
auto: presetAuto,
|
||||
a: presetAuto,
|
||||
n1: coercePresetInt(preset.n1),
|
||||
n2: coercePresetInt(preset.n2),
|
||||
n3: coercePresetInt(preset.n3),
|
||||
n4: coercePresetInt(preset.n4),
|
||||
n5: coercePresetInt(preset.n5),
|
||||
n6: coercePresetInt(preset.n6),
|
||||
manual_beat_n: coerceManualBeatN(preset),
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1474,7 +1847,8 @@ const sendPresetViaEspNow = async (
|
||||
: [];
|
||||
|
||||
const sequence = [presetMessage];
|
||||
if (names.length > 0) {
|
||||
// Auto: apply preset immediately via select. Manual: load definition only — first step is on the next audio beat.
|
||||
if (names.length > 0 && presetAuto) {
|
||||
const select = {};
|
||||
names.forEach((name) => {
|
||||
if (name) {
|
||||
@@ -1486,7 +1860,7 @@ const sendPresetViaEspNow = async (
|
||||
}
|
||||
}
|
||||
|
||||
await postDriverSequence(sequence, targetMacs, 0.05);
|
||||
await postDriverSequence(sequence, targetMacs, 0.05, pushOptions);
|
||||
} catch (error) {
|
||||
console.error('Failed to send preset to devices:', error);
|
||||
alert('Failed to send preset to devices.');
|
||||
@@ -1520,6 +1894,29 @@ const sendDefaultPreset = async (presetId, deviceNames) => {
|
||||
}
|
||||
};
|
||||
|
||||
const sendPresetSelectViaEspNow = async (presetId, deviceNames) => {
|
||||
if (!presetId) {
|
||||
return;
|
||||
}
|
||||
const nameTargets = Array.isArray(deviceNames)
|
||||
? deviceNames.map((n) => (n || '').trim()).filter((n) => n.length > 0)
|
||||
: [];
|
||||
if (!nameTargets.length) {
|
||||
return;
|
||||
}
|
||||
const select = {};
|
||||
nameTargets.forEach((name) => {
|
||||
select[name] = [String(presetId)];
|
||||
});
|
||||
const macTargets =
|
||||
nameTargets.length > 0 &&
|
||||
typeof window.tabsManager !== 'undefined' &&
|
||||
typeof window.tabsManager.resolveTabDeviceMacs === 'function'
|
||||
? await window.tabsManager.resolveTabDeviceMacs(nameTargets)
|
||||
: [];
|
||||
await postDriverSequence([{ v: '1', select }], macTargets);
|
||||
};
|
||||
|
||||
// Expose for other scripts (zones.js) so they can reuse the shared WebSocket.
|
||||
try {
|
||||
window.sendPresetViaEspNow = sendPresetViaEspNow;
|
||||
@@ -1532,8 +1929,52 @@ try {
|
||||
// window may not exist in some environments; ignore.
|
||||
}
|
||||
|
||||
// Store selected preset(s) per zone (multi-select; merge send order = click order, last wins on device).
|
||||
const zoneSelectedPresetIds = {};
|
||||
const zonePresetSelectionOrder = {};
|
||||
|
||||
function ensureZonePresetSelection(zoneId) {
|
||||
const z = String(zoneId);
|
||||
if (!zoneSelectedPresetIds[z]) zoneSelectedPresetIds[z] = new Set();
|
||||
if (!zonePresetSelectionOrder[z]) zonePresetSelectionOrder[z] = [];
|
||||
}
|
||||
|
||||
function pruneZonePresetSelection(zoneId, validIdSet) {
|
||||
const z = String(zoneId);
|
||||
ensureZonePresetSelection(z);
|
||||
const set = zoneSelectedPresetIds[z];
|
||||
for (const id of [...set]) {
|
||||
if (!validIdSet.has(String(id))) set.delete(id);
|
||||
}
|
||||
zonePresetSelectionOrder[z] = (zonePresetSelectionOrder[z] || []).filter((id) => set.has(String(id)));
|
||||
}
|
||||
|
||||
function getOrderedZonePresetSelection(zoneId) {
|
||||
const z = String(zoneId);
|
||||
ensureZonePresetSelection(z);
|
||||
const set = zoneSelectedPresetIds[z];
|
||||
return (zonePresetSelectionOrder[z] || []).filter((id) => set.has(String(id)));
|
||||
}
|
||||
|
||||
async function sendMergedZonePresetSelection(zoneId, tabData, allPresets) {
|
||||
const ids = getOrderedZonePresetSelection(zoneId);
|
||||
if (!ids.length) return;
|
||||
for (let i = 0; i < ids.length; i += 1) {
|
||||
const pid = ids[i];
|
||||
const preset = allPresets[pid];
|
||||
if (!preset) continue;
|
||||
const names =
|
||||
window.zonesManager && typeof window.zonesManager.resolveDeviceNamesForZonePreset === 'function'
|
||||
? await window.zonesManager.resolveDeviceNamesForZonePreset(tabData, pid)
|
||||
: [];
|
||||
await sendPresetViaEspNow(pid, preset, names, false, false, '2');
|
||||
}
|
||||
}
|
||||
|
||||
// Store selected preset per zone
|
||||
const selectedPresets = {};
|
||||
// Store selected preset payload per zone for beat-trigger reliability.
|
||||
const selectedPresetPayloads = {};
|
||||
// Run vs Edit for zone preset strip (in-memory only — each full page load starts in run mode)
|
||||
let presetUiMode = 'run';
|
||||
|
||||
@@ -1674,20 +2115,42 @@ const insertDraggingOntoTarget = (presetsList, dragging, dropTarget) => {
|
||||
};
|
||||
|
||||
// Function to render presets for a specific zone in 2D grid
|
||||
const renderTabPresets = async (zoneId) => {
|
||||
/**
|
||||
* @param {string} zoneId
|
||||
* @param {{ stopSequencePlayback?: boolean }} [options] - pass `{ stopSequencePlayback: true }` only when
|
||||
* the UI action should stop server zone sequence playback (default: do not POST /sequences/stop).
|
||||
*/
|
||||
const renderTabPresets = async (zoneId, options = {}) => {
|
||||
const presetsList = document.getElementById('presets-list-zone');
|
||||
if (!presetsList) return;
|
||||
|
||||
|
||||
const stopSeq = options.stopSequencePlayback === true;
|
||||
if (stopSeq && typeof window.stopZoneSequencePlayback === 'function') {
|
||||
// Pass false: an earlier render's stop() can finish after this pass rebuilds the DOM and
|
||||
// would otherwise clear .active from new sequence tiles (breaks edit/run selection).
|
||||
await window.stopZoneSequencePlayback(false);
|
||||
}
|
||||
|
||||
try {
|
||||
// Get zone data to see which presets are associated
|
||||
const tabResponse = await fetch(`/zones/${zoneId}`, {
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
const [tabResponse, groupsStripRes, presetsResponse] = await Promise.all([
|
||||
fetch(`/zones/${zoneId}`, {
|
||||
headers: { Accept: 'application/json' },
|
||||
}),
|
||||
fetch('/groups', { headers: { Accept: 'application/json' } }),
|
||||
fetch('/presets', {
|
||||
headers: { Accept: 'application/json' },
|
||||
}),
|
||||
]);
|
||||
if (!tabResponse.ok) {
|
||||
throw new Error('Failed to load zone');
|
||||
}
|
||||
const tabData = await tabResponse.json();
|
||||
|
||||
const groupsMapStrip = groupsStripRes.ok ? await groupsStripRes.json() : {};
|
||||
const ck =
|
||||
typeof window.normalizeZoneContentKind === 'function'
|
||||
? window.normalizeZoneContentKind(tabData)
|
||||
: null;
|
||||
|
||||
// Get presets - support both 2D grid and flat array (for backward compatibility)
|
||||
let presetGrid = tabData.presets;
|
||||
if (!presetGrid || !Array.isArray(presetGrid)) {
|
||||
@@ -1698,11 +2161,10 @@ const renderTabPresets = async (zoneId) => {
|
||||
// It's a flat array, convert to grid
|
||||
presetGrid = arrayToGrid(presetGrid, 3);
|
||||
}
|
||||
if (ck === 'sequences') {
|
||||
presetGrid = [];
|
||||
}
|
||||
|
||||
// Get all presets
|
||||
const presetsResponse = await fetch('/presets', {
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
if (!presetsResponse.ok) {
|
||||
throw new Error('Failed to load presets');
|
||||
}
|
||||
@@ -1775,41 +2237,64 @@ const renderTabPresets = async (zoneId) => {
|
||||
});
|
||||
}
|
||||
|
||||
// Get the currently selected preset for this zone
|
||||
const selectedPresetId = selectedPresets[zoneId];
|
||||
|
||||
// Render presets in grid layout
|
||||
// Flatten the grid and render all presets (grid CSS will handle layout)
|
||||
const flatPresets = presetGrid.flat().filter(id => id);
|
||||
|
||||
const validIdSet = new Set(flatPresets.map((id) => String(id)));
|
||||
pruneZonePresetSelection(zoneId, validIdSet);
|
||||
|
||||
const hasSeq =
|
||||
Array.isArray(tabData.sequence_ids) &&
|
||||
tabData.sequence_ids.some((x) => x != null && String(x).trim());
|
||||
|
||||
if (flatPresets.length === 0) {
|
||||
// Show empty message if this zone has no presets
|
||||
const empty = document.createElement('p');
|
||||
empty.className = 'muted-text';
|
||||
empty.style.gridColumn = '1 / -1'; // Span all columns
|
||||
empty.textContent = 'No presets added to this zone. Open the zone\'s Edit menu and click "Add Preset" to add one.';
|
||||
presetsList.appendChild(empty);
|
||||
if (ck === 'sequences') {
|
||||
if (!hasSeq) {
|
||||
empty.textContent =
|
||||
"No sequences on this zone yet. Open the zone's Edit menu to add one.";
|
||||
presetsList.appendChild(empty);
|
||||
}
|
||||
} else {
|
||||
empty.textContent =
|
||||
'No presets added to this zone. Open the zone\'s Edit menu and click "Add Preset" to add one.';
|
||||
presetsList.appendChild(empty);
|
||||
}
|
||||
} else {
|
||||
flatPresets.forEach((presetId) => {
|
||||
const preset = allPresets[presetId];
|
||||
if (preset) {
|
||||
const isSelected = presetId === selectedPresetId;
|
||||
ensureZonePresetSelection(zoneId);
|
||||
const isSelected = zoneSelectedPresetIds[String(zoneId)].has(String(presetId));
|
||||
const displayPreset = {
|
||||
...preset,
|
||||
colors: resolveColorsWithPaletteRefs(preset.colors, preset.palette_refs, paletteColors),
|
||||
background: resolvePresetBackgroundHex(preset, paletteColors),
|
||||
};
|
||||
const wrapper = createPresetButton(presetId, displayPreset, zoneId, isSelected);
|
||||
const wrapper = createPresetButton(
|
||||
presetId,
|
||||
displayPreset,
|
||||
zoneId,
|
||||
isSelected,
|
||||
tabData,
|
||||
groupsMapStrip,
|
||||
allPresets,
|
||||
);
|
||||
presetsList.appendChild(wrapper);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof window.appendZoneSequenceTiles === 'function' && ck !== 'presets') {
|
||||
await window.appendZoneSequenceTiles(zoneId, tabData, allPresets, paletteColors, presetsList);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to render zone presets:', error);
|
||||
presetsList.innerHTML = '<p class="muted-text">Failed to load presets.</p>';
|
||||
}
|
||||
};
|
||||
|
||||
const createPresetButton = (presetId, preset, zoneId, isSelected = false) => {
|
||||
const createPresetButton = (presetId, preset, zoneId, isSelected, tabData, groupsMap, allPresets) => {
|
||||
const uiMode = getPresetUiMode();
|
||||
|
||||
const row = document.createElement('div');
|
||||
@@ -1846,19 +2331,92 @@ const createPresetButton = (presetId, preset, zoneId, isSelected = false) => {
|
||||
presetNameLabel.className = 'pattern-button-label';
|
||||
button.appendChild(presetNameLabel);
|
||||
|
||||
const groupsText = formatPresetTargetGroupsLine(tabData || {}, groupsMap || {});
|
||||
if (groupsText) {
|
||||
const groupsSpan = document.createElement('span');
|
||||
groupsSpan.className = 'preset-tile-groups';
|
||||
groupsSpan.textContent = groupsText;
|
||||
button.appendChild(groupsSpan);
|
||||
}
|
||||
|
||||
const bgSwatch = document.createElement('span');
|
||||
const bgColor = coercePresetBackground(preset);
|
||||
bgSwatch.title = `Background: ${bgColor}`;
|
||||
bgSwatch.style.cssText = `
|
||||
position: absolute;
|
||||
left: 4px;
|
||||
bottom: 4px;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 2px;
|
||||
background: ${bgColor};
|
||||
border: 1px solid rgba(255, 255, 255, 0.7);
|
||||
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
|
||||
pointer-events: none;
|
||||
z-index: 2;
|
||||
`;
|
||||
button.appendChild(bgSwatch);
|
||||
|
||||
const isManualPreset = preset && !coercePresetAuto(preset);
|
||||
if (isManualPreset) {
|
||||
const manualBadge = document.createElement('span');
|
||||
manualBadge.textContent = '1';
|
||||
manualBadge.title = 'Manual preset';
|
||||
manualBadge.style.cssText = `
|
||||
position: absolute;
|
||||
right: 4px;
|
||||
bottom: 4px;
|
||||
min-width: 16px;
|
||||
height: 16px;
|
||||
border-radius: 8px;
|
||||
background: rgba(0, 0, 0, 0.72);
|
||||
color: #fff;
|
||||
border: 1px solid rgba(255, 255, 255, 0.5);
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
line-height: 14px;
|
||||
text-align: center;
|
||||
pointer-events: none;
|
||||
z-index: 2;
|
||||
`;
|
||||
button.appendChild(manualBadge);
|
||||
}
|
||||
|
||||
button.addEventListener('click', () => {
|
||||
if (isDraggingPreset) return;
|
||||
console.info('Preset button pressed', { zoneId, presetId, name: (preset && preset.name) || presetId });
|
||||
const presetsListEl = document.getElementById('presets-list-zone');
|
||||
if (presetsListEl) {
|
||||
presetsListEl.querySelectorAll('.pattern-button').forEach((btn) => btn.classList.remove('active'));
|
||||
ensureZonePresetSelection(zoneId);
|
||||
const z = String(zoneId);
|
||||
const set = zoneSelectedPresetIds[z];
|
||||
const order = zonePresetSelectionOrder[z];
|
||||
const idStr = String(presetId);
|
||||
if (set.has(idStr)) {
|
||||
set.delete(idStr);
|
||||
zonePresetSelectionOrder[z] = order.filter((x) => String(x) !== idStr);
|
||||
} else {
|
||||
set.add(idStr);
|
||||
order.push(idStr);
|
||||
}
|
||||
button.classList.add('active');
|
||||
selectedPresets[zoneId] = presetId;
|
||||
const section = row.closest('.presets-section');
|
||||
const deviceNames = tabDeviceNamesFromSection(section);
|
||||
sendPresetViaEspNow(presetId, preset, deviceNames, false, false, '2').catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
if (presetsListEl) {
|
||||
presetsListEl.querySelectorAll('.preset-tile-row:not(.sequence-tile-row)').forEach((rw) => {
|
||||
const pid = rw.dataset.presetId;
|
||||
const btnEl = rw.querySelector('.preset-tile-main');
|
||||
if (!btnEl || !pid) return;
|
||||
if (set.has(String(pid))) btnEl.classList.add('active');
|
||||
else btnEl.classList.remove('active');
|
||||
});
|
||||
}
|
||||
const orderList = getOrderedZonePresetSelection(zoneId);
|
||||
if (orderList.length) {
|
||||
const lastPid = orderList[orderList.length - 1];
|
||||
selectedPresets[zoneId] = lastPid;
|
||||
selectedPresetPayloads[zoneId] = (allPresets && allPresets[lastPid]) || preset;
|
||||
} else {
|
||||
delete selectedPresets[zoneId];
|
||||
delete selectedPresetPayloads[zoneId];
|
||||
}
|
||||
void sendMergedZonePresetSelection(zoneId, tabData, allPresets);
|
||||
});
|
||||
|
||||
if (canDrag) {
|
||||
@@ -1882,7 +2440,9 @@ const createPresetButton = (presetId, preset, zoneId, isSelected = false) => {
|
||||
});
|
||||
}
|
||||
|
||||
row.appendChild(button);
|
||||
const top = document.createElement('div');
|
||||
top.className = 'preset-tile-row-top';
|
||||
top.appendChild(button);
|
||||
|
||||
if (uiMode === 'edit') {
|
||||
const actions = document.createElement('div');
|
||||
@@ -1901,9 +2461,11 @@ const createPresetButton = (presetId, preset, zoneId, isSelected = false) => {
|
||||
});
|
||||
|
||||
actions.appendChild(editBtn);
|
||||
row.appendChild(actions);
|
||||
top.appendChild(actions);
|
||||
}
|
||||
|
||||
row.appendChild(top);
|
||||
|
||||
return row;
|
||||
};
|
||||
|
||||
@@ -2006,6 +2568,10 @@ const removePresetFromTab = async (zoneId, presetId) => {
|
||||
try {
|
||||
window.removePresetFromTab = removePresetFromTab;
|
||||
} catch (e) {}
|
||||
try {
|
||||
window.renderTabPresets = renderTabPresets;
|
||||
window.getPresetUiMode = getPresetUiMode;
|
||||
} catch (e) {}
|
||||
|
||||
// Listen for HTMX swaps to render presets
|
||||
document.body.addEventListener('htmx:afterSwap', (event) => {
|
||||
@@ -2036,10 +2602,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
const mainMenu = document.getElementById('main-menu-dropdown');
|
||||
if (mainMenu) mainMenu.classList.remove('open');
|
||||
const leftPanel = document.querySelector('.presets-section[data-zone-id]');
|
||||
if (leftPanel) {
|
||||
renderTabPresets(leftPanel.dataset.zoneId);
|
||||
}
|
||||
// Preset strip re-renders from `zones.js` after `loadZones()` (no driver/playback side effects).
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
1176
src/static/sequences.js
Normal file
1176
src/static/sequences.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -94,10 +94,11 @@ header {
|
||||
background-color: #1a1a1a;
|
||||
padding: 0.75rem 1rem;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
justify-content: flex-start;
|
||||
border-bottom: 2px solid #4a4a4a;
|
||||
gap: 0.75rem;
|
||||
gap: 0.65rem;
|
||||
}
|
||||
|
||||
header h1 {
|
||||
@@ -105,6 +106,18 @@ header h1 {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Second header row: BPM, brightness, desktop buttons / mobile menu */
|
||||
.header-end {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
margin-left: 0;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
@@ -115,6 +128,7 @@ header h1 {
|
||||
.header-menu-mobile {
|
||||
display: none;
|
||||
position: relative;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.main-menu-dropdown {
|
||||
@@ -183,6 +197,86 @@ header h1 {
|
||||
width: 8.5rem;
|
||||
}
|
||||
|
||||
.audio-top-indicator {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 0.15rem;
|
||||
padding: 0.25rem 0.55rem;
|
||||
border: 1px solid #4a4a4a;
|
||||
border-radius: 6px;
|
||||
background-color: #1a1a1a;
|
||||
min-width: 9rem;
|
||||
}
|
||||
|
||||
.audio-top-indicator-main {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
|
||||
.audio-top-indicator-extra {
|
||||
font-size: 0.62rem;
|
||||
color: #9e9e9e;
|
||||
line-height: 1.25;
|
||||
text-align: right;
|
||||
max-width: 16rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.audio-top-indicator.audio-running {
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
.audio-top-indicator-label {
|
||||
font-size: 0.72rem;
|
||||
color: #bdbdbd;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.audio-top-indicator-value {
|
||||
font-size: 1rem;
|
||||
font-weight: 700;
|
||||
color: #ffd54f;
|
||||
min-width: 2.4rem;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.audio-top-beat-readout {
|
||||
font-size: 0.62rem;
|
||||
color: #b0bec5;
|
||||
line-height: 1.25;
|
||||
max-width: 12rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.audio-top-indicator-subvalue {
|
||||
font-size: 0.75rem;
|
||||
color: #9e9e9e;
|
||||
min-width: 2.2rem;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.audio-top-indicator.flash {
|
||||
background-color: #ff5252;
|
||||
border-color: #ff8a80;
|
||||
}
|
||||
|
||||
.audio-top-indicator.flash .audio-top-indicator-value,
|
||||
.audio-top-indicator.flash .audio-top-indicator-label,
|
||||
.audio-top-indicator.flash .audio-top-indicator-subvalue,
|
||||
.audio-top-indicator.flash .audio-top-indicator-extra,
|
||||
.audio-top-indicator.flash .audio-top-beat-readout {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* Header/menu actions that should only appear in Edit mode */
|
||||
body.preset-ui-run .edit-mode-only {
|
||||
display: none !important;
|
||||
@@ -239,8 +333,9 @@ body.preset-ui-run .edit-mode-only {
|
||||
|
||||
.zones-container {
|
||||
background-color: transparent;
|
||||
padding: 0.5rem 0;
|
||||
flex: 1;
|
||||
padding: 0.35rem 0 0;
|
||||
flex: 0 0 auto;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
align-self: stretch;
|
||||
display: flex;
|
||||
@@ -550,15 +645,16 @@ body.preset-ui-run .edit-mode-only {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* Zone preset selecting area: 3 columns, vertical scroll only */
|
||||
/* Zone preset selecting area: 8 columns on desktop, vertical scroll only */
|
||||
#presets-list-zone {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
grid-auto-rows: 5rem;
|
||||
grid-template-columns: repeat(8, minmax(0, 1fr));
|
||||
/* min-content height prevents taller tiles (edit actions, wrapping) from overlapping the next row and stealing clicks */
|
||||
grid-auto-rows: minmax(5rem, auto);
|
||||
column-gap: 0.3rem;
|
||||
row-gap: 0.3rem;
|
||||
align-content: start;
|
||||
@@ -710,6 +806,66 @@ body.preset-ui-run .edit-mode-only {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.audio-bpm-readout {
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.05em;
|
||||
color: #ffd54f;
|
||||
text-align: center;
|
||||
padding: 0.4rem;
|
||||
background-color: #1a1a1a;
|
||||
border: 1px solid #4a4a4a;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.audio-bpm-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.audio-bpm-row .audio-bpm-readout {
|
||||
flex: 0 0 auto;
|
||||
min-width: 5rem;
|
||||
}
|
||||
|
||||
.audio-modal-beat-readout {
|
||||
flex: 1;
|
||||
min-width: 10rem;
|
||||
font-size: 0.85rem;
|
||||
line-height: 1.35;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.audio-hit-type-readout {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.04em;
|
||||
color: #81d4fa;
|
||||
text-transform: lowercase;
|
||||
text-align: center;
|
||||
padding: 0.35rem;
|
||||
background-color: #1a1a1a;
|
||||
border: 1px solid #4a4a4a;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.audio-beat-flash {
|
||||
width: 100%;
|
||||
height: 56px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid #4a4a4a;
|
||||
background: #202020;
|
||||
box-shadow: inset 0 0 0 0 rgba(255, 82, 82, 0.5);
|
||||
transition: background-color 80ms linear, box-shadow 120ms linear;
|
||||
}
|
||||
|
||||
.audio-beat-flash.active {
|
||||
background: #ff5252;
|
||||
box-shadow: inset 0 0 24px 6px rgba(255, 255, 255, 0.35);
|
||||
}
|
||||
|
||||
.patterns-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -749,17 +905,43 @@ body.preset-ui-run .edit-mode-only {
|
||||
flex-direction: row;
|
||||
align-items: stretch;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
min-height: 5rem;
|
||||
}
|
||||
|
||||
.preset-tile-row--run .preset-tile-actions {
|
||||
display: none;
|
||||
.preset-tile-row-top {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: stretch;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 5rem;
|
||||
}
|
||||
|
||||
.preset-tile-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
height: 5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 0.12rem;
|
||||
}
|
||||
|
||||
.preset-tile-main .preset-tile-groups {
|
||||
font-size: 0.68rem;
|
||||
font-weight: 500;
|
||||
line-height: 1.15;
|
||||
opacity: 0.88;
|
||||
text-align: center;
|
||||
max-width: 100%;
|
||||
padding: 0 0.35rem;
|
||||
box-sizing: border-box;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.preset-tile-row--run .preset-tile-actions {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Edit only beside the preset tile in edit mode. */
|
||||
@@ -928,6 +1110,46 @@ body.preset-ui-run .edit-mode-only {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
/* Stack sequence modals below groups / preset editor so in-modal actions stay visible */
|
||||
#sequence-editor-modal.active,
|
||||
#sequences-modal.active {
|
||||
z-index: 1040;
|
||||
}
|
||||
#groups-modal.active,
|
||||
#edit-group-modal.active,
|
||||
#presets-modal.active {
|
||||
z-index: 1050;
|
||||
}
|
||||
#preset-editor-modal.active {
|
||||
z-index: 1060;
|
||||
}
|
||||
|
||||
/* Child / overlay modals: must paint above preset editor (1060) and list modals (1050). */
|
||||
#color-palette-modal.active,
|
||||
#pattern-editor-modal.active,
|
||||
#edit-device-modal.active,
|
||||
#edit-zone-modal.active {
|
||||
z-index: 1070;
|
||||
}
|
||||
|
||||
/* Patterns library (often used next to presets); below preset editor, above sequences. */
|
||||
#patterns-modal.active {
|
||||
z-index: 1055;
|
||||
}
|
||||
|
||||
/* Header / global dialogs */
|
||||
#help-modal.active,
|
||||
#audio-modal.active,
|
||||
#settings-modal.active,
|
||||
#led-tool-modal.active {
|
||||
z-index: 1080;
|
||||
}
|
||||
|
||||
/* JS-appended overlays (e.g. preset “From Palette”, add-preset-to-zone) — must sit above #preset-editor-modal */
|
||||
.modal.modal-child-overlay.active {
|
||||
z-index: 1080;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background-color: #2e2e2e;
|
||||
padding: 2rem;
|
||||
@@ -992,20 +1214,38 @@ body.preset-ui-run .edit-mode-only {
|
||||
/* Mobile-friendly layout */
|
||||
@media (max-width: 1000px) {
|
||||
header {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
} header h1 {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
header h1 {
|
||||
font-size: 1.1rem;
|
||||
} /* On mobile, hide header buttons; all actions (including Tabs) are in the Menu dropdown */
|
||||
}
|
||||
|
||||
/* On mobile, hide header buttons; all actions (including Tabs) are in the Menu dropdown */
|
||||
.header-actions {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.header-menu-mobile {
|
||||
display: block;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
margin-top: 0;
|
||||
margin-left: auto;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.header-end {
|
||||
gap: 0.35rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.header-end .audio-top-indicator {
|
||||
min-width: 5rem;
|
||||
padding: 0.2rem 0.45rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.btn {
|
||||
@@ -1014,8 +1254,9 @@ body.preset-ui-run .edit-mode-only {
|
||||
}
|
||||
|
||||
.zones-container {
|
||||
padding: 0.5rem 0;
|
||||
padding: 0.35rem 0 0;
|
||||
border-bottom: none;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.zone-content {
|
||||
@@ -1261,8 +1502,8 @@ body.preset-ui-run .edit-mode-only {
|
||||
.color-swatches-container {
|
||||
min-height: 80px;
|
||||
}
|
||||
/* Presets list: 3 columns and vertical scroll (defined above); mobile same */
|
||||
@media (max-width: 1000px) {
|
||||
/* Presets list: 3 columns on phone-sized screens */
|
||||
@media (max-width: 600px) {
|
||||
#presets-list-zone {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 7rem);
|
||||
@@ -1379,6 +1620,14 @@ body.preset-ui-run .edit-mode-only {
|
||||
}
|
||||
}
|
||||
|
||||
.sequence-step-drag-handle:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
.sequence-step-row.dragging {
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
/* Settings modal */
|
||||
#settings-modal .modal-content {
|
||||
max-width: 900px;
|
||||
|
||||
@@ -1,8 +1,48 @@
|
||||
// Zone management JavaScript
|
||||
let currentZoneId = null;
|
||||
let brightnessSendTimeout = null;
|
||||
/**
|
||||
* When true, the next `loadZoneContent` skips `sendZoneBrightness` (run/edit toggle: same zone, UI only).
|
||||
*/
|
||||
let suppressZoneContentDriverSideEffects = false;
|
||||
/** First successful `loadZoneContent` after open: skip hardware brightness push (read-only hydration). */
|
||||
let isFirstZoneContentHydration = true;
|
||||
|
||||
function sendZoneBrightness(value) {
|
||||
function clamp255(n) {
|
||||
const v = parseInt(n, 10);
|
||||
if (Number.isNaN(v)) return null;
|
||||
return Math.max(0, Math.min(255, v));
|
||||
}
|
||||
|
||||
function applyBrightnessSliders(val) {
|
||||
const v = clamp255(val);
|
||||
if (v === null) return;
|
||||
const headerSlider = document.getElementById("header-brightness-slider");
|
||||
const menuSlider = document.getElementById("menu-brightness-slider");
|
||||
if (headerSlider) headerSlider.value = String(v);
|
||||
if (menuSlider) menuSlider.value = String(v);
|
||||
}
|
||||
|
||||
async function saveZoneBrightnessToServer(zoneId, val) {
|
||||
if (!zoneId) return;
|
||||
try {
|
||||
const res = await fetch(`/zones/${zoneId}`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
||||
credentials: "same-origin",
|
||||
body: JSON.stringify({ brightness: val }),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(() => ({}));
|
||||
console.warn("zone brightness save failed:", err.error || res.status);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("zone brightness save failed:", e);
|
||||
}
|
||||
}
|
||||
|
||||
function sendZoneBrightness(zoneId, value) {
|
||||
if (!zoneId) return;
|
||||
const val = Math.max(0, Math.min(255, parseInt(value, 10) || 0));
|
||||
const headerSlider = document.getElementById('header-brightness-slider');
|
||||
const menuSlider = document.getElementById('menu-brightness-slider');
|
||||
@@ -18,6 +58,7 @@ function sendZoneBrightness(value) {
|
||||
brightnessSendTimeout = setTimeout(() => {
|
||||
(async () => {
|
||||
try {
|
||||
await saveZoneBrightnessToServer(zoneId, val);
|
||||
const section = document.querySelector('.presets-section[data-zone-id]');
|
||||
const names = typeof window.parseTabDeviceNames === 'function'
|
||||
? window.parseTabDeviceNames(section)
|
||||
@@ -29,6 +70,47 @@ function sendZoneBrightness(value) {
|
||||
? await window.tabsManager.resolveTabDeviceMacs(names)
|
||||
: [];
|
||||
if (typeof window.postDriverSequence === 'function') {
|
||||
if (targetMacs.length > 0) {
|
||||
let resolved = {};
|
||||
try {
|
||||
const rr = await fetch('/devices/resolve-brightness', {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
macs: targetMacs,
|
||||
zone_brightness: val,
|
||||
}),
|
||||
});
|
||||
if (rr.ok) {
|
||||
const pack = await rr.json().catch(() => ({}));
|
||||
if (pack && pack.values && typeof pack.values === 'object') {
|
||||
resolved = pack.values;
|
||||
}
|
||||
}
|
||||
} catch (re) {
|
||||
console.warn('resolve-brightness failed:', re);
|
||||
}
|
||||
for (const mac of targetMacs) {
|
||||
const k = String(mac).toLowerCase();
|
||||
const b =
|
||||
resolved[k] != null && resolved[k] !== ''
|
||||
? parseInt(resolved[k], 10)
|
||||
: val;
|
||||
const bv = Number.isNaN(b)
|
||||
? val
|
||||
: Math.max(0, Math.min(255, b));
|
||||
await window.postDriverSequence(
|
||||
[{ v: '1', b: bv, save: true }],
|
||||
[mac],
|
||||
0,
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
await window.postDriverSequence([{ v: '1', b: val, save: true }], targetMacs, 0);
|
||||
return;
|
||||
}
|
||||
@@ -72,8 +154,225 @@ async function fetchDevicesMap() {
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchGroupsMap() {
|
||||
try {
|
||||
const response = await fetch("/groups", {
|
||||
headers: { Accept: "application/json" },
|
||||
credentials: "same-origin",
|
||||
});
|
||||
if (!response.ok) return {};
|
||||
const data = await response.json();
|
||||
return data && typeof data === "object" ? data : {};
|
||||
} catch (e) {
|
||||
console.error("fetchGroupsMap:", e);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve registry names + MACs for a zone document (``group_ids`` expands groups;
|
||||
* otherwise ``names`` only).
|
||||
*/
|
||||
async function computeZoneTargets(zone) {
|
||||
const dm = await fetchDevicesMap();
|
||||
const gids = Array.isArray(zone && zone.group_ids)
|
||||
? zone.group_ids.map((x) => String(x).trim()).filter((x) => x.length > 0)
|
||||
: [];
|
||||
if (gids.length > 0) {
|
||||
const gm = await fetchGroupsMap();
|
||||
const seen = new Set();
|
||||
const names = [];
|
||||
const macs = [];
|
||||
for (const gid of gids) {
|
||||
const g = gm[gid];
|
||||
if (!g || !Array.isArray(g.devices)) continue;
|
||||
for (const raw of g.devices) {
|
||||
const m = String(raw || "")
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/:/g, "")
|
||||
.replace(/-/g, "");
|
||||
if (m.length !== 12) continue;
|
||||
if (seen.has(m)) continue;
|
||||
seen.add(m);
|
||||
const d = dm[m];
|
||||
const n = d && String((d.name || "").trim()) ? String(d.name).trim() : m;
|
||||
names.push(n);
|
||||
macs.push(m);
|
||||
}
|
||||
}
|
||||
return { names, macs };
|
||||
}
|
||||
const zoneNames = Array.isArray(zone && zone.names) ? zone.names : [];
|
||||
const rows = namesToRows(zoneNames, dm);
|
||||
return {
|
||||
names: rowsToNames(rows),
|
||||
macs: [...new Set(rows.map((r) => r.mac).filter(Boolean))],
|
||||
};
|
||||
}
|
||||
|
||||
/** Tab device list for sequences: zone ``group_ids`` first, else legacy ``names`` only. */
|
||||
async function computeZoneNamesTargets(zone) {
|
||||
const gids = Array.isArray(zone && zone.group_ids)
|
||||
? zone.group_ids.map((x) => String(x).trim()).filter((x) => x.length > 0)
|
||||
: [];
|
||||
if (gids.length > 0) {
|
||||
const t = await resolveTargetsFromGroupIds(gids);
|
||||
return {
|
||||
names: Array.isArray(t.names) ? t.names : [],
|
||||
macs: Array.isArray(t.macs) ? [...new Set(t.macs.filter(Boolean))] : [],
|
||||
};
|
||||
}
|
||||
const dm = await fetchDevicesMap();
|
||||
const zoneNames = Array.isArray(zone && zone.names) ? zone.names : [];
|
||||
const rows = namesToRows(zoneNames, dm);
|
||||
return {
|
||||
names: rowsToNames(rows),
|
||||
macs: [...new Set(rows.map((r) => r.mac).filter(Boolean))],
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeDeviceMac(raw) {
|
||||
return String(raw || "")
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/:/g, "")
|
||||
.replace(/-/g, "");
|
||||
}
|
||||
|
||||
/** Flat preset ids on a zone document (grid or flat). */
|
||||
function tabPresetIdsInZoneDoc(zoneDoc) {
|
||||
let ids = [];
|
||||
if (Array.isArray(zoneDoc && zoneDoc.presets_flat)) {
|
||||
ids = zoneDoc.presets_flat.slice();
|
||||
} else if (Array.isArray(zoneDoc && zoneDoc.presets)) {
|
||||
if (zoneDoc.presets.length && typeof zoneDoc.presets[0] === "string") {
|
||||
ids = zoneDoc.presets.slice();
|
||||
} else if (zoneDoc.presets.length && Array.isArray(zoneDoc.presets[0])) {
|
||||
ids = zoneDoc.presets.flat();
|
||||
}
|
||||
}
|
||||
return (ids || []).filter(Boolean);
|
||||
}
|
||||
|
||||
/** Group ids used for standalone presets on this zone: zone ``group_ids`` only. */
|
||||
function effectiveGroupIdsForZonePreset(zoneDoc) {
|
||||
return Array.isArray(zoneDoc && zoneDoc.group_ids)
|
||||
? zoneDoc.group_ids.map((x) => String(x).trim()).filter((x) => x.length > 0)
|
||||
: [];
|
||||
}
|
||||
|
||||
/** Resolve device names + MACs from a list of group ids (same rules as zone group expansion). */
|
||||
async function resolveTargetsFromGroupIds(groupIds) {
|
||||
const dm = await fetchDevicesMap();
|
||||
const gids = Array.isArray(groupIds)
|
||||
? groupIds.map((x) => String(x).trim()).filter((x) => x.length > 0)
|
||||
: [];
|
||||
if (!gids.length) {
|
||||
return { names: [], macs: [] };
|
||||
}
|
||||
const gm = await fetchGroupsMap();
|
||||
const seen = new Set();
|
||||
const names = [];
|
||||
const macs = [];
|
||||
for (const gid of gids) {
|
||||
const g = gm[gid];
|
||||
if (!g || !Array.isArray(g.devices)) continue;
|
||||
for (const raw of g.devices) {
|
||||
const m = normalizeDeviceMac(raw);
|
||||
if (m.length !== 12) continue;
|
||||
if (seen.has(m)) continue;
|
||||
seen.add(m);
|
||||
const d = dm[m];
|
||||
const n = d && String((d.name || "").trim()) ? String(d.name).trim() : m;
|
||||
names.push(n);
|
||||
macs.push(m);
|
||||
}
|
||||
}
|
||||
return { names, macs };
|
||||
}
|
||||
|
||||
/** Device names for standalone presets: zone ``group_ids``, or all devices on the tab (``names``). */
|
||||
async function resolveDeviceNamesForZonePreset(zoneDoc, presetId) {
|
||||
void presetId;
|
||||
const gids = effectiveGroupIdsForZonePreset(zoneDoc);
|
||||
if (gids.length) {
|
||||
const t = await resolveTargetsFromGroupIds(gids);
|
||||
if (t.names.length) return t.names;
|
||||
}
|
||||
const zt = await computeZoneTargets(zoneDoc);
|
||||
return Array.isArray(zt.names) ? zt.names.slice() : [];
|
||||
}
|
||||
|
||||
/** Union of devices targeted by standalone presets on the zone (same as zone preset targeting). */
|
||||
async function computeZonePresetUnionTargets(zoneDoc) {
|
||||
return await computeZoneTargets(zoneDoc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Device names for one sequence step. Empty stepGroupIds => all zone tab devices (``names`` only).
|
||||
* Otherwise: lane groups intersected with that tab device list (not zone ``group_ids``).
|
||||
*/
|
||||
async function resolveSequenceStepDeviceNames(zone, stepGroupIds) {
|
||||
const zoneT = await computeZoneNamesTargets(zone);
|
||||
const names = Array.isArray(zoneT.names) ? zoneT.names : [];
|
||||
const macs = Array.isArray(zoneT.macs) ? zoneT.macs : [];
|
||||
const gids = Array.isArray(stepGroupIds)
|
||||
? stepGroupIds.map((x) => String(x).trim()).filter((x) => x.length > 0)
|
||||
: [];
|
||||
if (!gids.length) {
|
||||
return names.slice();
|
||||
}
|
||||
const zoneMacSet = new Set(
|
||||
macs.map((m) => normalizeDeviceMac(m)).filter((m) => m.length === 12),
|
||||
);
|
||||
const zoneNameByMac = new Map();
|
||||
for (let i = 0; i < macs.length; i++) {
|
||||
const m = normalizeDeviceMac(macs[i]);
|
||||
if (m.length === 12 && !zoneNameByMac.has(m)) {
|
||||
zoneNameByMac.set(m, names[i] || m);
|
||||
}
|
||||
}
|
||||
const gm = await fetchGroupsMap();
|
||||
const stepMacs = new Set();
|
||||
for (const gid of gids) {
|
||||
const g = gm[gid];
|
||||
if (!g || !Array.isArray(g.devices)) continue;
|
||||
for (const raw of g.devices) {
|
||||
const m = normalizeDeviceMac(raw);
|
||||
if (m.length !== 12 || !zoneMacSet.has(m)) continue;
|
||||
stepMacs.add(m);
|
||||
}
|
||||
}
|
||||
const out = [];
|
||||
for (const m of stepMacs) {
|
||||
const n = zoneNameByMac.get(m);
|
||||
if (n) out.push(n);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
async function resolveZoneDeviceMacsFromZoneData(zone) {
|
||||
const t = await computeZoneTargets(zone);
|
||||
return t.macs;
|
||||
}
|
||||
|
||||
/** Registry MACs for zone device names (order matches zone names; skips unknown names). */
|
||||
async function resolveZoneDeviceMacs(zoneNames) {
|
||||
const section = document.querySelector(".presets-section[data-zone-id]");
|
||||
if (section) {
|
||||
const enc = section.getAttribute("data-zone-target-macs-json");
|
||||
if (enc) {
|
||||
try {
|
||||
const macs = JSON.parse(decodeURIComponent(enc));
|
||||
if (Array.isArray(macs) && macs.length) {
|
||||
return [...new Set(macs.map((m) => String(m).toLowerCase()))];
|
||||
}
|
||||
} catch (e) {
|
||||
/* fall through */
|
||||
}
|
||||
}
|
||||
}
|
||||
const dm = await fetchDevicesMap();
|
||||
const rows = namesToRows(Array.isArray(zoneNames) ? zoneNames : [], dm);
|
||||
const macs = rows.map((r) => r.mac).filter(Boolean);
|
||||
@@ -101,10 +400,10 @@ function rowsToNames(rows) {
|
||||
return (rows || []).map((r) => String(r.name || "").trim()).filter((n) => n.length > 0);
|
||||
}
|
||||
|
||||
function renderZoneDevicesEditor(containerEl, rows, devicesMap) {
|
||||
function renderZoneGroupsEditor(containerEl, rows, groupsMap) {
|
||||
if (!containerEl) return;
|
||||
containerEl.innerHTML = "";
|
||||
const entries = Object.entries(devicesMap || {}).sort(([a], [b]) => a.localeCompare(b));
|
||||
const entries = Object.entries(groupsMap || {}).sort(([a], [b]) => a.localeCompare(b));
|
||||
|
||||
rows.forEach((row, idx) => {
|
||||
const div = document.createElement("div");
|
||||
@@ -112,12 +411,12 @@ function renderZoneDevicesEditor(containerEl, rows, devicesMap) {
|
||||
const label = document.createElement("span");
|
||||
label.className = "zone-device-row-label";
|
||||
const strong = document.createElement("strong");
|
||||
strong.textContent = row.name || "—";
|
||||
strong.textContent = row.name || row.id || "—";
|
||||
label.appendChild(strong);
|
||||
label.appendChild(document.createTextNode(" "));
|
||||
const sub = document.createElement("span");
|
||||
sub.className = "muted-text";
|
||||
sub.textContent = row.mac ? row.mac : "(not in registry)";
|
||||
sub.textContent = `group ${row.id}`;
|
||||
label.appendChild(sub);
|
||||
|
||||
const rm = document.createElement("button");
|
||||
@@ -126,53 +425,42 @@ function renderZoneDevicesEditor(containerEl, rows, devicesMap) {
|
||||
rm.textContent = "Remove";
|
||||
rm.addEventListener("click", () => {
|
||||
rows.splice(idx, 1);
|
||||
renderZoneDevicesEditor(containerEl, rows, devicesMap);
|
||||
renderZoneGroupsEditor(containerEl, rows, groupsMap);
|
||||
});
|
||||
div.appendChild(label);
|
||||
div.appendChild(rm);
|
||||
containerEl.appendChild(div);
|
||||
});
|
||||
|
||||
const macsInRows = new Set(rows.map((r) => r.mac).filter(Boolean));
|
||||
const idsInRows = new Set(rows.map((r) => String(r.id)));
|
||||
const addWrap = document.createElement("div");
|
||||
addWrap.className = "zone-devices-add profiles-actions";
|
||||
const sel = document.createElement("select");
|
||||
sel.className = "zone-device-add-select";
|
||||
sel.appendChild(new Option("Add device…", ""));
|
||||
entries.forEach(([mac, d]) => {
|
||||
if (macsInRows.has(mac)) return;
|
||||
const labelName = d && d.name ? String(d.name).trim() : "";
|
||||
const optLabel = labelName ? `${labelName} — ${mac}` : mac;
|
||||
sel.appendChild(new Option(optLabel, mac));
|
||||
sel.appendChild(new Option("Add group…", ""));
|
||||
entries.forEach(([gid, g]) => {
|
||||
if (idsInRows.has(gid)) return;
|
||||
const gn = g && g.name ? String(g.name).trim() : "";
|
||||
const optLabel = gn ? `${gn} (${gid})` : `Group ${gid}`;
|
||||
sel.appendChild(new Option(optLabel, gid));
|
||||
});
|
||||
const addBtn = document.createElement("button");
|
||||
addBtn.type = "button";
|
||||
addBtn.className = "btn btn-primary btn-small";
|
||||
addBtn.textContent = "Add";
|
||||
addBtn.addEventListener("click", () => {
|
||||
const mac = sel.value;
|
||||
if (!mac || !devicesMap[mac]) return;
|
||||
const n = String((devicesMap[mac].name || "").trim() || mac);
|
||||
rows.push({ mac, name: n });
|
||||
const gid = sel.value;
|
||||
if (!gid || !groupsMap[gid]) return;
|
||||
const gn = groupsMap[gid].name ? String(groupsMap[gid].name).trim() : gid;
|
||||
rows.push({ id: gid, name: gn });
|
||||
sel.value = "";
|
||||
renderZoneDevicesEditor(containerEl, rows, devicesMap);
|
||||
renderZoneGroupsEditor(containerEl, rows, groupsMap);
|
||||
});
|
||||
addWrap.appendChild(sel);
|
||||
addWrap.appendChild(addBtn);
|
||||
containerEl.appendChild(addWrap);
|
||||
}
|
||||
|
||||
/** Default device name list when creating a zone (refined in Edit zone). */
|
||||
async function defaultDeviceNamesForNewTab() {
|
||||
const dm = await fetchDevicesMap();
|
||||
const macs = Object.keys(dm);
|
||||
if (macs.length > 0) {
|
||||
const m0 = macs[0];
|
||||
return [String((dm[m0].name || "").trim() || m0)];
|
||||
}
|
||||
return ["1"];
|
||||
}
|
||||
|
||||
/** Read zone device names from the presets section (JSON attr preferred; legacy comma list fallback). */
|
||||
function parseTabDeviceNames(section) {
|
||||
if (!section) return [];
|
||||
@@ -202,6 +490,32 @@ function escapeHtmlAttr(s) {
|
||||
.replace(/</g, "<");
|
||||
}
|
||||
|
||||
/** @returns {null | 'presets' | 'sequences'} */
|
||||
function normalizeZoneContentKind(zoneDoc) {
|
||||
const k = zoneDoc && zoneDoc.content_kind;
|
||||
if (k === 'presets' || k === 'sequences') return k;
|
||||
return null;
|
||||
}
|
||||
|
||||
function applyZoneContentKindEditModal(kind) {
|
||||
const presetsBlock = document.getElementById('edit-zone-block-presets');
|
||||
const groupsBlock = document.getElementById('edit-zone-block-groups');
|
||||
const seqBlock = document.getElementById('edit-zone-block-sequences');
|
||||
const vis = (el, show) => {
|
||||
if (el) el.style.display = show ? '' : 'none';
|
||||
};
|
||||
vis(groupsBlock, true);
|
||||
if (!kind) {
|
||||
vis(presetsBlock, true);
|
||||
vis(seqBlock, true);
|
||||
return;
|
||||
}
|
||||
vis(presetsBlock, kind === 'presets');
|
||||
vis(seqBlock, kind === 'sequences');
|
||||
}
|
||||
|
||||
window.normalizeZoneContentKind = normalizeZoneContentKind;
|
||||
|
||||
// Load tabs list
|
||||
async function loadZones() {
|
||||
try {
|
||||
@@ -259,13 +573,16 @@ function renderZonesList(tabs, tabOrder, currentZoneId) {
|
||||
const zone = tabs[zoneId];
|
||||
if (zone) {
|
||||
const activeClass = zoneId === currentZoneId ? 'active' : '';
|
||||
const tabName = zone.name || `Zone ${zoneId}`;
|
||||
let disp = zone.name || `Zone ${zoneId}`;
|
||||
const kind = normalizeZoneContentKind(zone);
|
||||
if (kind === 'presets') disp += ' · presets';
|
||||
else if (kind === 'sequences') disp += ' · sequences';
|
||||
html += `
|
||||
<button class="zone-button ${activeClass}"
|
||||
data-zone-id="${zoneId}"
|
||||
title="${editMode ? 'Click to select, right-click to edit' : 'Click to select'}"
|
||||
onclick="selectZone('${zoneId}')">
|
||||
${tabName}
|
||||
${escapeHtmlAttr(disp)}
|
||||
</button>
|
||||
`;
|
||||
}
|
||||
@@ -305,9 +622,13 @@ function renderZonesListModal(tabs, tabOrder, currentZoneId) {
|
||||
row.dataset.zoneId = String(zoneId);
|
||||
|
||||
const label = document.createElement("span");
|
||||
label.textContent = (zone && zone.name) || zoneId;
|
||||
let disp = (zone && zone.name) || zoneId;
|
||||
const kind = normalizeZoneContentKind(zone);
|
||||
if (kind === 'presets') disp += ' · presets';
|
||||
else if (kind === 'sequences') disp += ' · sequences';
|
||||
label.textContent = disp;
|
||||
if (String(zoneId) === String(currentZoneId)) {
|
||||
label.textContent = `✓ ${label.textContent}`;
|
||||
label.textContent = `✓ ${disp}`;
|
||||
label.style.fontWeight = "bold";
|
||||
label.style.color = "#FFD700";
|
||||
}
|
||||
@@ -504,12 +825,16 @@ async function loadZoneContent(zoneId) {
|
||||
|
||||
// Render zone content (presets section)
|
||||
const tabName = zone.name || `Zone ${zoneId}`;
|
||||
const names = Array.isArray(zone.names) ? zone.names : [];
|
||||
const namesJsonAttr = encodeURIComponent(JSON.stringify(names));
|
||||
const legacyOk = names.length > 0 && !names.some((n) => /[",]/.test(String(n)));
|
||||
const legacyAttr = legacyOk ? ` data-device-names="${escapeHtmlAttr(names.join(","))}"` : "";
|
||||
const targets = await computeZoneTargets(zone);
|
||||
const namesJsonAttr = encodeURIComponent(JSON.stringify(targets.names));
|
||||
const macsJsonAttr = encodeURIComponent(JSON.stringify(targets.macs));
|
||||
const legacyOk =
|
||||
targets.names.length > 0 && !targets.names.some((n) => /[",]/.test(String(n)));
|
||||
const legacyAttr = legacyOk
|
||||
? ` data-device-names="${escapeHtmlAttr(targets.names.join(","))}"`
|
||||
: "";
|
||||
container.innerHTML = `
|
||||
<div class="presets-section" data-zone-id="${zoneId}" data-device-names-json="${namesJsonAttr}"${legacyAttr}>
|
||||
<div class="presets-section" data-zone-id="${zoneId}" data-device-names-json="${namesJsonAttr}" data-zone-target-macs-json="${macsJsonAttr}"${legacyAttr}>
|
||||
<div id="presets-list-zone" class="presets-list">
|
||||
<!-- Presets will be loaded here by presets.js -->
|
||||
</div>
|
||||
@@ -517,10 +842,21 @@ async function loadZoneContent(zoneId) {
|
||||
`;
|
||||
|
||||
// Keep header and menu brightness controls in sync.
|
||||
const brightnessSlider = document.getElementById('header-brightness-slider');
|
||||
const menuBrightnessSlider = document.getElementById('menu-brightness-slider');
|
||||
if (menuBrightnessSlider && brightnessSlider) {
|
||||
menuBrightnessSlider.value = brightnessSlider.value;
|
||||
const zoneBrightness =
|
||||
typeof zone.brightness === 'number'
|
||||
? zone.brightness
|
||||
: parseInt(String(zone.brightness ?? ''), 10);
|
||||
const normalizedBrightness = Number.isFinite(zoneBrightness)
|
||||
? Math.max(0, Math.min(255, Math.round(zoneBrightness)))
|
||||
: 255;
|
||||
applyBrightnessSliders(normalizedBrightness);
|
||||
const initialHydration = isFirstZoneContentHydration;
|
||||
if (isFirstZoneContentHydration) {
|
||||
isFirstZoneContentHydration = false;
|
||||
}
|
||||
if (!suppressZoneContentDriverSideEffects && !initialHydration) {
|
||||
// Apply this zone's saved brightness when switching zones (not initial page load or UI-only strip refresh).
|
||||
sendZoneBrightness(zoneId, normalizedBrightness);
|
||||
}
|
||||
|
||||
// Trigger presets loading if the function exists
|
||||
@@ -599,8 +935,7 @@ async function sendProfilePresets() {
|
||||
continue;
|
||||
}
|
||||
zonesWithPresets += 1;
|
||||
const zoneNames = Array.isArray(tabData.names) ? tabData.names : [];
|
||||
const targets = await resolveZoneDeviceMacs(zoneNames);
|
||||
const targets = await resolveZoneDeviceMacsFromZoneData(tabData);
|
||||
const payload = { preset_ids: presetIds };
|
||||
if (tabData.default_preset) {
|
||||
payload.default = tabData.default_preset;
|
||||
@@ -643,17 +978,7 @@ async function sendProfilePresets() {
|
||||
}
|
||||
|
||||
function tabPresetIdsInOrder(tabData) {
|
||||
let ids = [];
|
||||
if (Array.isArray(tabData.presets_flat)) {
|
||||
ids = tabData.presets_flat.slice();
|
||||
} else if (Array.isArray(tabData.presets)) {
|
||||
if (tabData.presets.length && typeof tabData.presets[0] === "string") {
|
||||
ids = tabData.presets.slice();
|
||||
} else if (tabData.presets.length && Array.isArray(tabData.presets[0])) {
|
||||
ids = tabData.presets.flat();
|
||||
}
|
||||
}
|
||||
return (ids || []).filter(Boolean);
|
||||
return tabPresetIdsInZoneDoc(tabData);
|
||||
}
|
||||
|
||||
// Presets already on the zone (remove) and presets available to add (select).
|
||||
@@ -674,6 +999,13 @@ async function refreshEditTabPresetsUi(zoneId) {
|
||||
return;
|
||||
}
|
||||
const tabData = await tabRes.json();
|
||||
const kind = normalizeZoneContentKind(tabData);
|
||||
if (kind === 'sequences') {
|
||||
currentEl.innerHTML =
|
||||
'<span class="muted-text">This zone is for sequences only. Presets are hidden.</span>';
|
||||
addEl.innerHTML = '<span class="muted-text">—</span>';
|
||||
return;
|
||||
}
|
||||
const inTabIds = tabPresetIdsInOrder(tabData);
|
||||
const inTabSet = new Set(inTabIds.map((id) => String(id)));
|
||||
|
||||
@@ -697,8 +1029,12 @@ async function refreshEditTabPresetsUi(zoneId) {
|
||||
for (const presetId of inTabIds) {
|
||||
const preset = allPresets[presetId] || {};
|
||||
const name = preset.name || presetId;
|
||||
const row = makeRow();
|
||||
const block = document.createElement("div");
|
||||
block.style.cssText =
|
||||
"border:1px solid rgba(255,255,255,0.12);border-radius:6px;padding:0.5rem 0.65rem;margin-bottom:0.65rem;";
|
||||
const top = makeRow();
|
||||
const label = document.createElement("span");
|
||||
label.style.fontWeight = "600";
|
||||
label.textContent = name;
|
||||
const removeBtn = document.createElement("button");
|
||||
removeBtn.type = "button";
|
||||
@@ -710,9 +1046,11 @@ async function refreshEditTabPresetsUi(zoneId) {
|
||||
await window.removePresetFromTab(zoneId, presetId);
|
||||
await refreshEditTabPresetsUi(zoneId);
|
||||
});
|
||||
row.appendChild(label);
|
||||
row.appendChild(removeBtn);
|
||||
currentEl.appendChild(row);
|
||||
top.appendChild(label);
|
||||
top.appendChild(removeBtn);
|
||||
block.appendChild(top);
|
||||
|
||||
currentEl.appendChild(block);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -773,7 +1111,6 @@ async function openEditZoneModal(zoneId, zone) {
|
||||
const modal = document.getElementById("edit-zone-modal");
|
||||
const idInput = document.getElementById("edit-zone-id");
|
||||
const nameInput = document.getElementById("edit-zone-name");
|
||||
const editor = document.getElementById("edit-zone-devices-editor");
|
||||
|
||||
let tabData = zone;
|
||||
if (!tabData || typeof tabData !== "object" || tabData.error) {
|
||||
@@ -791,31 +1128,30 @@ async function openEditZoneModal(zoneId, zone) {
|
||||
if (idInput) idInput.value = zoneId;
|
||||
if (nameInput) nameInput.value = tabData.name || "";
|
||||
|
||||
const devicesMap = await fetchDevicesMap();
|
||||
const zoneNames =
|
||||
Array.isArray(tabData.names) && tabData.names.length > 0 ? tabData.names : ["1"];
|
||||
window.__editTabDeviceRows = namesToRows(zoneNames, devicesMap);
|
||||
renderZoneDevicesEditor(editor, window.__editTabDeviceRows, devicesMap);
|
||||
const groupsEditor = document.getElementById("edit-zone-groups-editor");
|
||||
const groupsMap = await fetchGroupsMap();
|
||||
const rawGids = Array.isArray(tabData.group_ids) ? tabData.group_ids : [];
|
||||
window.__editTabGroupRows = rawGids.map((gid) => {
|
||||
const id = String(gid);
|
||||
const g = groupsMap[id];
|
||||
return { id, name: g && g.name ? String(g.name).trim() : id };
|
||||
});
|
||||
renderZoneGroupsEditor(groupsEditor, window.__editTabGroupRows, groupsMap);
|
||||
|
||||
if (modal) modal.classList.add("active");
|
||||
applyZoneContentKindEditModal(normalizeZoneContentKind(tabData));
|
||||
await refreshEditTabPresetsUi(zoneId);
|
||||
if (typeof window.refreshEditTabSequencesUi === "function") {
|
||||
await window.refreshEditTabSequencesUi(zoneId);
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeTabNamesArg(namesOrString) {
|
||||
if (Array.isArray(namesOrString)) {
|
||||
return namesOrString.map((n) => String(n).trim()).filter((n) => n.length > 0);
|
||||
}
|
||||
if (typeof namesOrString === "string" && namesOrString.trim()) {
|
||||
return namesOrString.split(",").map((id) => id.trim()).filter((id) => id.length > 0);
|
||||
}
|
||||
return ["1"];
|
||||
}
|
||||
|
||||
// Update an existing zone
|
||||
async function updateZone(zoneId, name, namesOrString) {
|
||||
// Update an existing zone (name, group list; devices come from groups only).
|
||||
async function updateZone(zoneId, name, groupRows) {
|
||||
try {
|
||||
let names = normalizeTabNamesArg(namesOrString);
|
||||
if (!names.length) names = ["1"];
|
||||
const gids = Array.isArray(groupRows)
|
||||
? groupRows.map((r) => String(r.id || "").trim()).filter((x) => x.length > 0)
|
||||
: [];
|
||||
const response = await fetch(`/zones/${zoneId}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
@@ -823,7 +1159,9 @@ async function updateZone(zoneId, name, namesOrString) {
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: name,
|
||||
names: names
|
||||
names: [],
|
||||
group_ids: gids,
|
||||
preset_group_ids: {},
|
||||
})
|
||||
});
|
||||
|
||||
@@ -846,11 +1184,11 @@ async function updateZone(zoneId, name, namesOrString) {
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new zone
|
||||
async function createZone(name, namesOrString) {
|
||||
// Create a new zone (add devices in Edit zone). ``contentKind`` is ``'presets'`` | ``'sequences'``.
|
||||
async function createZone(name, contentKind) {
|
||||
try {
|
||||
let names = normalizeTabNamesArg(namesOrString);
|
||||
if (!names.length) names = ["1"];
|
||||
const ck =
|
||||
contentKind === 'sequences' || contentKind === 'presets' ? contentKind : 'presets';
|
||||
const response = await fetch('/zones', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -858,7 +1196,9 @@ async function createZone(name, namesOrString) {
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: name,
|
||||
names: names
|
||||
names: [],
|
||||
group_ids: [],
|
||||
content_kind: ck,
|
||||
})
|
||||
});
|
||||
|
||||
@@ -939,8 +1279,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const name = newTabNameInput.value.trim();
|
||||
|
||||
if (name) {
|
||||
const deviceNames = await defaultDeviceNamesForNewTab();
|
||||
await createZone(name, deviceNames);
|
||||
const kindRadio = document.querySelector(
|
||||
'input[name="new-zone-content-kind"]:checked',
|
||||
);
|
||||
const contentKind =
|
||||
kindRadio && kindRadio.value === 'sequences' ? 'sequences' : 'presets';
|
||||
await createZone(name, contentKind);
|
||||
if (newTabNameInput) newTabNameInput.value = "";
|
||||
}
|
||||
};
|
||||
@@ -967,15 +1311,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
const zoneId = idInput ? idInput.value : null;
|
||||
const name = nameInput ? nameInput.value.trim() : "";
|
||||
const rows = window.__editTabDeviceRows || [];
|
||||
const deviceNames = rowsToNames(rows);
|
||||
const groupRows = window.__editTabGroupRows || [];
|
||||
|
||||
if (zoneId && name) {
|
||||
if (deviceNames.length === 0) {
|
||||
alert("Add at least one device.");
|
||||
return;
|
||||
}
|
||||
await updateZone(zoneId, name, deviceNames);
|
||||
await updateZone(zoneId, name, groupRows);
|
||||
editZoneForm.reset();
|
||||
}
|
||||
});
|
||||
@@ -990,26 +1329,33 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
|
||||
const menuBrightnessSlider = document.getElementById('menu-brightness-slider');
|
||||
if (menuBrightnessSlider) {
|
||||
menuBrightnessSlider.addEventListener('input', (e) => {
|
||||
sendZoneBrightness(e.target.value);
|
||||
});
|
||||
}
|
||||
const headerBrightnessSlider = document.getElementById('header-brightness-slider');
|
||||
if (headerBrightnessSlider) {
|
||||
headerBrightnessSlider.addEventListener('input', (e) => {
|
||||
sendZoneBrightness(e.target.value);
|
||||
});
|
||||
// Initial sync so both controls start aligned.
|
||||
sendZoneBrightness(headerBrightnessSlider.value);
|
||||
}
|
||||
(async () => {
|
||||
if (menuBrightnessSlider) {
|
||||
menuBrightnessSlider.addEventListener('input', (e) => {
|
||||
if (!currentZoneId) return;
|
||||
sendZoneBrightness(currentZoneId, e.target.value);
|
||||
});
|
||||
}
|
||||
if (headerBrightnessSlider) {
|
||||
headerBrightnessSlider.addEventListener('input', (e) => {
|
||||
if (!currentZoneId) return;
|
||||
sendZoneBrightness(currentZoneId, e.target.value);
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
// When run/edit mode toggles, refresh tabs UI so edit actions show/hide immediately.
|
||||
document.querySelectorAll('.ui-mode-toggle').forEach((btn) => {
|
||||
btn.addEventListener('click', async () => {
|
||||
await loadZones();
|
||||
if (zonesModal && zonesModal.classList.contains("active")) {
|
||||
await loadZonesModal();
|
||||
suppressZoneContentDriverSideEffects = true;
|
||||
try {
|
||||
await loadZones();
|
||||
if (zonesModal && zonesModal.classList.contains("active")) {
|
||||
await loadZonesModal();
|
||||
}
|
||||
} finally {
|
||||
suppressZoneContentDriverSideEffects = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1024,8 +1370,17 @@ window.zonesManager = {
|
||||
updateZone,
|
||||
openEditZoneModal,
|
||||
resolveZoneDeviceMacs,
|
||||
resolveZoneDeviceMacsFromZoneData,
|
||||
resolveTabDeviceMacs: resolveZoneDeviceMacs,
|
||||
getCurrentZoneId: () => currentZoneId,
|
||||
computeZoneTargets,
|
||||
computeZoneNamesTargets,
|
||||
computeZonePresetUnionTargets,
|
||||
effectiveGroupIdsForZonePreset,
|
||||
resolveDeviceNamesForZonePreset,
|
||||
resolveSequenceStepDeviceNames,
|
||||
fetchGroupsMap,
|
||||
renderZoneGroupsEditor,
|
||||
};
|
||||
window.tabsManager = window.zonesManager;
|
||||
window.tabsManager.getCurrentTabId = () => currentZoneId;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user