|
| 1 | +# Development |
| 2 | + |
| 3 | +This document covers the internal architecture of the ExpressLRS configuration tool and the CRSF simulator used for testing inside the EdgeTX simulator without real hardware. |
| 4 | + |
| 5 | +## Make targets |
| 6 | + |
| 7 | +Run `make help` to list all targets. The Makefile groups them into three categories: |
| 8 | + |
| 9 | +### Setup |
| 10 | + |
| 11 | +| Target | Purpose | |
| 12 | +|--------|---------| |
| 13 | +| `install-tools` | Install both `stylua` and `lua-language-server` | |
| 14 | +| `install-stylua` | Install [stylua](https://github.com/JohnnyMorganz/StyLua) via `cargo` (requires Rust toolchain). Built with the `lua53` feature for EdgeTX compatibility. | |
| 15 | +| `install-luals` | Download [lua-language-server](https://github.com/LuaLS/lua-language-server) `3.17.1` to `bin/lua-language-server/` | |
| 16 | + |
| 17 | +### Quality checks |
| 18 | + |
| 19 | +| Target | Purpose | |
| 20 | +|--------|---------| |
| 21 | +| `format` | Format all Lua sources in `src/` with `stylua` (config: `.stylua.toml`) | |
| 22 | +| `format-check` | Verify formatting without modifying files. Used in CI. | |
| 23 | +| `typecheck` | Run `lua-language-server --check .` against the project (config: `.luarc.json`) | |
| 24 | +| `check` | Convenience target: runs `format-check` then `typecheck` | |
| 25 | + |
| 26 | +### Deployment |
| 27 | + |
| 28 | +| Target | Purpose | |
| 29 | +|--------|---------| |
| 30 | +| `sync` | Copy sources to the EdgeTX simulator SD card at `../edgetx-sdcard` via `edgetx-cli dev sync`. Includes dev-only libraries like the CRSF simulator. | |
| 31 | +| `push` | Install the package to a connected EdgeTX radio via `edgetx-cli pkg install . --eject`. Excludes dev-only libraries. | |
| 32 | + |
| 33 | +## Architecture |
| 34 | + |
| 35 | +| Module | Purpose | |
| 36 | +|--------|---------| |
| 37 | +| `main.lua` | Entry point and run-loop orchestrator | |
| 38 | +| `protocol.lua` | CRSF frame parsing, device discovery, parameter read/write | |
| 39 | +| `navigation.lua` | Folder and device navigation stack | |
| 40 | +| `shim.lua` | Polyfills for BW radios missing standard Lua functions | |
| 41 | +| `ui/lvgl.lua` | Color LCD interface (LVGL dialogs, command pages, warnings) | |
| 42 | +| `ui/lcd.lua` | BW LCD interface (text cursor, popups) | |
| 43 | + |
| 44 | +## CRSF Simulator |
| 45 | + |
| 46 | +The `src/SCRIPTS/CRSFSimulator/` library provides a CRSF protocol simulator for development and testing without real hardware. It is declared as a dev-only library in `edgetx.yml` (`dev: true`), so it is included by `edgetx-cli dev sync` but skipped by `edgetx-cli pkg install`. |
| 47 | + |
| 48 | +**File:** `src/SCRIPTS/CRSFSimulator/csrfsimulator.lua` |
| 49 | + |
| 50 | +The simulator provides a packet-level mock of `crossfireTelemetryPop` and `crossfireTelemetryPush`, allowing the ELRS tool to exercise the full communication flow (device discovery, parameter loading, value writes, ELRS status) inside the EdgeTX simulator. Multiple scenarios are available to simulate different states such as normal operation, disconnected links, model mismatch, and more. |
| 51 | + |
| 52 | +### How it works |
| 53 | + |
| 54 | +When the tool detects it is running in the EdgeTX simulator (version string ends with `-simu`), `main.lua` automatically loads the simulator module from `/SCRIPTS/CRSFSimulator/csrfsimulator.lua` and patches the protocol's `pop`, `push`, and `hasCrsfModule` functions with the mock implementations. |
| 55 | + |
| 56 | +Run `make sync` (which runs `edgetx-cli dev sync`) to copy the sources -- including the dev-only `CRSFSimulator` library -- onto the simulator SD card. `edgetx-cli pkg install` omits the library automatically, so the simulator is never shipped to real hardware. |
| 57 | + |
| 58 | +### Scenarios |
| 59 | + |
| 60 | +The simulator supports multiple test scenarios, configurable via the `config.scenario` variable at the top of the file: |
| 61 | + |
| 62 | +| Scenario | Description | |
| 63 | +|----------|-------------| |
| 64 | +| `normal` | TX + RX connected. Happy path with full telemetry and all parameters. | |
| 65 | +| `no_telemetry` | TX present but no RX telemetry. Shows "No telemetry" state. | |
| 66 | +| `reconnect` | Starts disconnected, transitions to connected after ~5 seconds. | |
| 67 | +| `model_mismatch` | TX + RX connected with Model ID mismatch flag. Triggers warning dialog. | |
| 68 | +| `armed` | TX + RX connected with "is Armed" warning flag. | |
| 69 | +| `slow_loading` | Parameter reads delayed by ~2 seconds each. Tests loading UI states. | |
| 70 | +| `no_module` | No CRSF module found. Triggers "No Module Found" error dialog. | |
0 commit comments