From ea4530a5e4b25f30ca6e5e0cb09614cb53cebd3f Mon Sep 17 00:00:00 2001 From: osiu97 Date: Mon, 6 Jul 2026 19:26:50 +0200 Subject: [PATCH] Working BLE on S3 --- .gitignore | 27 ++++ gemini.md | 23 +-- index.html | 16 +- platformio.ini | 3 + src/main.cpp | 405 ++++++++++++++++++++++++------------------------- test_ble.py | 55 +++++++ web/js/ble.js | 37 +++-- 7 files changed, 327 insertions(+), 239 deletions(-) create mode 100644 .gitignore create mode 100644 test_ble.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1200c86 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# PlatformIO +.pio/ +.pioenvs/ +.piolibdeps/ +lib/readme.txt + +# Python Virtual Environments +venv/ +env/ +.venv/ +__pycache__/ +*.pyc + +# IDEs and Editors +.vscode/ +.idea/ +*.swp +*.swo + +# OS Generated Files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db diff --git a/gemini.md b/gemini.md index 24cb260..d6988c7 100644 --- a/gemini.md +++ b/gemini.md @@ -75,9 +75,9 @@ STEP_ANGLE = 360/2048 ≈ 0.17578125 °/step ### UUIDs (must be identical in firmware AND `web/js/ble.js`) ``` -Service: a0b1c2d3-e4f5-6789-abcd-ef0123456700 -Command: a0b1c2d3-e4f5-6789-abcd-ef0123456701 (WRITE | WRITE_NR) -Status: a0b1c2d3-e4f5-6789-abcd-ef0123456702 (NOTIFY) +Service: 18f3b235-9831-4c75-8ec0-210469b820a0 +Command: cd083b06-4447-4cf3-a7c3-322ecf802ce4 (WRITE) +Status: 82e38c5b-d3ab-41d1-861c-b84dc6bb1e03 (NOTIFY) Name: WijiBoard ``` @@ -127,19 +127,8 @@ esp32s3-wiji/ ### Module loading (index.html) -All ES modules are loaded with a **cache-buster** to prevent stale code on refresh: - -```javascript -const V = Date.now(); -const { default: Router } = await import(`./web/js/router.js?v=${V}`); -const { default: BLE } = await import(`./web/js/ble.js?v=${V}`); -const { default: UI } = await import(`./web/js/ui.js?v=${V}`); -const { default: HomeSection } = await import(`./web/js/sections/home.js?v=${V}`); -const { default: StepperSection } = await import(`./web/js/sections/stepper-test.js?v=${V}`); -``` - -> The `?v=${V}` suffix on ES module imports is mandatory. Without it, browsers aggressively -> cache modules and you will see stale code running despite file changes. +All ES modules are loaded with static imports in `index.html`. +**CRITICAL**: Do NOT use dynamic cache-busting imports (e.g. `import('./ble.js?v=123')`) for the BLE module. Doing so causes the browser to instantiate multiple copies of the `BLE` singleton, breaking the event emitter (UI will not update when BLE connects). --- @@ -414,6 +403,8 @@ To add a new section: | **M1 at +d2, M2 at -d2** | This is the PositionControl.cpp convention. Reversing it causes visual arm crossing. Verified by tracing `xmd = x - d2` (offset from +d2 pivot) and `xpd = x + d2` (offset from -d2 pivot). | | **`forward()` picks upward EE** | Two circle-circle intersections exist; the mechanism always operates in the "above" configuration. The lower solution is physically blocked by the board. | | **`armsCrossed()` guard** | Prevents IK moves that would drive an elbow into the mechanism housing from the wrong side. Tunable via `LIMITS.ELBOW_BOX_X_INNER` and `ELBOW_BOX_Y_MAX`. | +| **Linux/BlueZ stability** | `pAdv->setMaxPreferred(0x0C)` is mandatory in firmware. Without it, Linux/ChromeOS will drop the connection immediately after the handshake. | +| **No dynamic BLE imports**| `index.html` must import `ble.js` via static `import`. Dynamic cache-busters create multiple instances of the BLE singleton, isolating UI event listeners! | | **`fivebarIKGame.js` is reference only** | The original site's game uses a different angle convention (absolute degrees, different home, with `ikElbowSigns` tracking). We use the C++ IK formula instead because it directly produces step deltas from home. `fivebarIKGame.js` is kept in the repo for reference and understanding, not imported. | | **Hash-based routing** | Keeps the SPA working from `file://` and simple static servers without needing a history API setup | diff --git a/index.html b/index.html index cf90dda..23cbc51 100644 --- a/index.html +++ b/index.html @@ -121,12 +121,11 @@