velxio/test/backend/unit
davidmonterocrespo24 adad446518 fix(esp32): LEDC signal IDs are 71-86 per ESP32 TRM, not 72-87
User report: on the solar-tracker project (5218f9e3) only one servo
moved and the log showed `ch=0 duty=X% gpio=12` (wrong — servoPan was
attached to GPIO 13) and `ch=1 ... gpio=-1` (servoTilt's channel
never resolved).

Root cause traced through the GPIO Matrix dump: the firmware does
exactly what the Arduino-ESP32 Servo library says — `ledcAttachPin(
13, 0)` writes signal 71 (LEDC_HS_SIG_OUT0) into `gpio_out_sel[13]`,
and `ledcAttachPin(12, 1)` writes signal 72 (LEDC_HS_SIG_OUT1) into
`gpio_out_sel[12]`. Per the ESP32 Technical Reference Manual section
4.11, Table 4-3:

    71 .. 78  →  LEDC HS channels 0..7
    79 .. 86  →  LEDC LS channels 0..7

The legacy worker code at esp32_worker.py:426 used the off-by-one
range `72 <= signal <= 87` with `ledc_ch = signal - 72`. The mistake
masked itself for single-servo projects because the 0x5000 duty
callback's channel index was internally consistent with the bogus
math, so the duty STILL reached the correctly-routed pin (just
labelled wrong). The new SignalRouter unit tests caught the
discrepancy the moment two servos drove distinct channels: signal
71 (HS_CH0, gpio 13) was REJECTED by the off-by-one filter and
signal 72 (HS_CH1, gpio 12) was misclassified as channel 0.

When I ported the legacy range into `esp32_signals.SIG_LEDC_HS_CH0_OUT_IDX`
the bug came along for the ride. Fix both modules:

* `backend/app/services/esp32_signals.py`: HS 71-78, LS 79-86.
* `frontend/src/simulation/esp32-signals.ts`: mirror.
* tests updated; 20 backend + 23 frontend pass.

After deploy the user's two servos will resolve to their declared
pins:

    ch=0  duty=X%  gpio=13   (servoPan, was wrongly emitting gpio=12)
    ch=1  duty=X%  gpio=12   (servoTilt, was wrongly emitting gpio=-1)

This is also why the multi-servo blink "patch" in commit 77bf897
appeared to help: with both pins ALIASED to the same channel via
the off-by-one, the broadcast fallback was the only thing producing
ANY movement on the second servo at all.
2026-05-17 05:42:52 +02:00
..
__init__.py Add unit tests for I2C slave devices, MCP tools, and WiFi/BLE status parser 2026-04-10 23:39:51 -03:00
test_arduino_cli_attinycore.py fix(ci): two stale-path bugs from the recent refactors 2026-05-05 11:22:02 -03:00
test_boot_images.py fix(pi3): show kernel boot + autologin SD + sidecar cache invalidation 2026-05-16 06:23:22 +02:00
test_compile_dedup.py perf(compile): dedup, concurrency limits, and persistent build dir for ESP-IDF 2026-05-09 08:33:11 +02:00
test_dht22_worker.py test(dht22): skip the microsecond-timing analysis under CI=true 2026-05-17 03:56:43 +02:00
test_esp32_wifi_args.py chore(tests): silence three noisy warnings in deploy-gate output 2026-05-16 22:39:43 +02:00
test_esp32_wifi_webserver.py Add unit tests for I2C slave devices, MCP tools, and WiFi/BLE status parser 2026-04-10 23:39:51 -03:00
test_esp32c3_wifi_args.py Add unit tests for I2C slave devices, MCP tools, and WiFi/BLE status parser 2026-04-10 23:39:51 -03:00
test_espidf_compiler.py feat: Enhance ESPIDFCompiler library resolution logic; add support for dynamic library detection and patching in CMakeLists.txt 2026-04-11 15:25:40 -03:00
test_espidf_real_paths.py feat: Skip real paths test in CI; mark subproject commits as dirty 2026-04-11 15:49:32 -03:00
test_i2c_slaves.py test: update BMP280 chip ID assertions and clarify tagName uniqueness in metadata drift test 2026-04-21 17:31:51 -03:00
test_mcp_tools.py Add unit tests for I2C slave devices, MCP tools, and WiFi/BLE status parser 2026-04-10 23:39:51 -03:00
test_signal_router.py fix(esp32): LEDC signal IDs are 71-86 per ESP32 TRM, not 72-87 2026-05-17 05:42:52 +02:00
test_wifi_status_parser.py Add unit tests for I2C slave devices, MCP tools, and WiFi/BLE status parser 2026-04-10 23:39:51 -03:00