Compare commits
16 Commits
974082cb3e
..
v0.1.5
| Author | SHA1 | Date | |
|---|---|---|---|
| e68fad73b6 | |||
| 766019a01e | |||
| 842f270398 | |||
| 29711fa25e | |||
| 51fd4a868a | |||
| eb9cbd985f | |||
| 0a76cd8c0e | |||
| bb0895674a | |||
| f5b7f43e7c | |||
| 1ec93dc413 | |||
| effa949429 | |||
| da4c96903b | |||
| 6bdf4d43a9 | |||
| 61e190b1b9 | |||
| 7a7398243b | |||
| e9fc24778a |
@@ -0,0 +1,171 @@
|
|||||||
|
name: Firmware
|
||||||
|
|
||||||
|
# Controller A firmware, built by PlatformIO on every push. Two outputs:
|
||||||
|
#
|
||||||
|
# - push to main -> rolling PRE-release `main-latest` (firmware.bin + .elf),
|
||||||
|
# unsigned, no manifest. For bench testing / USB flashing.
|
||||||
|
# The device never installs it: it only reads
|
||||||
|
# /releases/latest, which skips pre-releases, and it
|
||||||
|
# needs a signed manifest.txt anyway.
|
||||||
|
# - push tag v* -> the OTA release: firmware.bin + firmware.elf +
|
||||||
|
# manifest.txt (size, sha256, ECDSA P-256 signature over
|
||||||
|
# "patrol-a|<tag>|<sha256>"). This is what `ota install`
|
||||||
|
# on the controller pulls.
|
||||||
|
#
|
||||||
|
# Signing key: repo secret BMW_NISSAN_FIRMWARE_SIGNING_KEY (PEM, EC P-256). Its public
|
||||||
|
# half is compiled into the firmware (include/config/ota_config.h) and kept in
|
||||||
|
# tools/ota/firmware_signing_pub.pem, which this job uses to self-check the
|
||||||
|
# signature before publishing. See wiki/pages/ota-updates.md.
|
||||||
|
#
|
||||||
|
# Releases go through the Gitea API with plain curl (actions/upload-artifact
|
||||||
|
# is unreliable on this runner - same pattern as parking_solution).
|
||||||
|
#
|
||||||
|
# A main push skips itself (step "Skip?") when (a) the commit already carries a
|
||||||
|
# v* tag - the tag build covers it; release with ONE push so the tag exists
|
||||||
|
# when this runs: git push --follow-tags origin main - or (b) it only
|
||||||
|
# changes docs (wiki/**, *.md). Done in-job rather than with paths-ignore so a
|
||||||
|
# tag build can never be skipped by a path filter. Tag builds always run.
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
tags: ['v*']
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Skip?
|
||||||
|
env:
|
||||||
|
BEFORE: ${{ github.event.before }}
|
||||||
|
run: |
|
||||||
|
SKIP=false
|
||||||
|
if [ "${GITHUB_REF#refs/tags/}" = "${GITHUB_REF}" ] && [ "${GITHUB_EVENT_NAME}" = "push" ]; then
|
||||||
|
# (a) already tagged v* ? (annotated tags list their commit as <tag>^{})
|
||||||
|
if git ls-remote --tags origin 'v*' | grep -q "^${GITHUB_SHA}"; then
|
||||||
|
echo "commit ${GITHUB_SHA:0:7} is tagged - the tag build covers it"; SKIP=true
|
||||||
|
# (b) docs only? Needs the previous head; a new branch / force push just builds.
|
||||||
|
elif [ -n "$BEFORE" ] && [ "$BEFORE" != "0000000000000000000000000000000000000000" ] &&
|
||||||
|
git fetch -q --depth=1 origin "$BEFORE" 2>/dev/null; then
|
||||||
|
CHANGED=$(git diff --name-only "$BEFORE" "$GITHUB_SHA")
|
||||||
|
echo "changed files:"; echo "$CHANGED"
|
||||||
|
if [ -n "$CHANGED" ] && ! echo "$CHANGED" | grep -qvE '^wiki/|\.md$'; then
|
||||||
|
echo "docs-only change - no firmware build"; SKIP=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "SKIP=${SKIP}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
|
- name: Version
|
||||||
|
if: env.SKIP != 'true'
|
||||||
|
run: |
|
||||||
|
if [ "${GITHUB_REF#refs/tags/}" != "${GITHUB_REF}" ]; then
|
||||||
|
VERSION="${GITHUB_REF_NAME}"
|
||||||
|
else
|
||||||
|
VERSION="main-${GITHUB_SHA:0:7}"
|
||||||
|
fi
|
||||||
|
case "$VERSION" in *[!A-Za-z0-9._-]*) echo "::error::bad version '$VERSION'"; exit 1;; esac
|
||||||
|
[ ${#VERSION} -lt 32 ] || { echo "::error::version too long"; exit 1; }
|
||||||
|
echo "VERSION=${VERSION}" >> "$GITHUB_ENV"
|
||||||
|
echo "version: ${VERSION}"
|
||||||
|
|
||||||
|
- name: Cache PlatformIO
|
||||||
|
if: env.SKIP != 'true'
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.platformio/packages
|
||||||
|
~/.platformio/platforms
|
||||||
|
.pio/libdeps
|
||||||
|
key: pio-${{ hashFiles('platformio.ini') }}
|
||||||
|
|
||||||
|
- name: Install PlatformIO
|
||||||
|
if: env.SKIP != 'true'
|
||||||
|
run: |
|
||||||
|
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||||
|
export PATH="$HOME/.local/bin:$PATH"
|
||||||
|
uv tool install platformio
|
||||||
|
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
if: env.SKIP != 'true'
|
||||||
|
run: |
|
||||||
|
export PLATFORMIO_BUILD_FLAGS="-DFW_VERSION=\\\"${VERSION}\\\""
|
||||||
|
pio run
|
||||||
|
mkdir -p dist
|
||||||
|
cp .pio/build/waveshare_esp32_s3_lcd_5b/firmware.bin dist/
|
||||||
|
cp .pio/build/waveshare_esp32_s3_lcd_5b/firmware.elf dist/
|
||||||
|
grep -q "${VERSION}" dist/firmware.bin || { echo "::error::FW_VERSION not baked into the image"; exit 1; }
|
||||||
|
ls -la dist/
|
||||||
|
|
||||||
|
- name: Sign + manifest (tags only)
|
||||||
|
if: env.SKIP != 'true' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
env:
|
||||||
|
BMW_NISSAN_FIRMWARE_SIGNING_KEY: ${{ secrets.BMW_NISSAN_FIRMWARE_SIGNING_KEY }}
|
||||||
|
run: |
|
||||||
|
set -e
|
||||||
|
[ -n "$BMW_NISSAN_FIRMWARE_SIGNING_KEY" ] || { echo "::error::secret BMW_NISSAN_FIRMWARE_SIGNING_KEY is not set"; exit 1; }
|
||||||
|
SHA=$(sha256sum dist/firmware.bin | cut -d' ' -f1)
|
||||||
|
SIZE=$(stat -c%s dist/firmware.bin)
|
||||||
|
printf '%s' "patrol-a|${VERSION}|${SHA}" > stmt.txt
|
||||||
|
umask 077
|
||||||
|
printf '%s\n' "$BMW_NISSAN_FIRMWARE_SIGNING_KEY" > key.pem
|
||||||
|
openssl dgst -sha256 -sign key.pem -out sig.der stmt.txt
|
||||||
|
rm -f key.pem
|
||||||
|
# Self-check against the public key the firmware carries.
|
||||||
|
openssl dgst -sha256 -verify tools/ota/firmware_signing_pub.pem -signature sig.der stmt.txt
|
||||||
|
SIG=$(od -An -v -tx1 sig.der | tr -d ' \n')
|
||||||
|
printf 'target=patrol-a\nversion=%s\nsize=%s\nsha256=%s\nsig=%s\n' \
|
||||||
|
"$VERSION" "$SIZE" "$SHA" "$SIG" > dist/manifest.txt
|
||||||
|
cat dist/manifest.txt
|
||||||
|
|
||||||
|
- name: Publish release
|
||||||
|
if: env.SKIP != 'true'
|
||||||
|
env:
|
||||||
|
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
API: ${{ github.api_url }}
|
||||||
|
REPO: ${{ github.repository }}
|
||||||
|
run: |
|
||||||
|
set -e
|
||||||
|
auth="Authorization: token ${TOKEN}"
|
||||||
|
if [ "${GITHUB_REF#refs/tags/}" != "${GITHUB_REF}" ]; then
|
||||||
|
TAG="${GITHUB_REF_NAME}"
|
||||||
|
PRE=false
|
||||||
|
NAME="Controller A ${TAG}"
|
||||||
|
BODY="Signed OTA release. Install on the controller with \`ota install\` (parked, Wi-Fi joined)."
|
||||||
|
else
|
||||||
|
TAG="main-latest"
|
||||||
|
PRE=true
|
||||||
|
NAME="Controller A main build"
|
||||||
|
BODY="Unsigned build of main @ ${GITHUB_SHA}. Rolling - overwritten each push. Not installable over OTA; flash over USB for bench tests."
|
||||||
|
# Rolling: drop the previous release and its tag, recreate at this commit.
|
||||||
|
OLD=$(curl -sS -H "$auth" "${API}/repos/${REPO}/releases/tags/${TAG}" \
|
||||||
|
| grep -o '"id":[0-9]*' | head -1 | cut -d: -f2 || true)
|
||||||
|
if [ -n "$OLD" ]; then
|
||||||
|
curl -sS -X DELETE -H "$auth" "${API}/repos/${REPO}/releases/${OLD}" || true
|
||||||
|
curl -sS -X DELETE -H "$auth" "${API}/repos/${REPO}/git/refs/tags/${TAG}" || true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
REL=$(curl -sS -X POST -H "$auth" -H "Content-Type: application/json" \
|
||||||
|
-d "{\"tag_name\":\"${TAG}\",\"target_commitish\":\"${GITHUB_SHA}\",\"name\":\"${NAME}\",\"body\":\"${BODY}\",\"draft\":false,\"prerelease\":${PRE}}" \
|
||||||
|
"${API}/repos/${REPO}/releases" || true)
|
||||||
|
REL_ID=$(printf '%s' "$REL" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2 || true)
|
||||||
|
if [ -z "$REL_ID" ]; then
|
||||||
|
REL_ID=$(curl -sS -H "$auth" "${API}/repos/${REPO}/releases/tags/${TAG}" \
|
||||||
|
| grep -o '"id":[0-9]*' | head -1 | cut -d: -f2 || true)
|
||||||
|
fi
|
||||||
|
[ -n "$REL_ID" ] || { echo "::error::could not create release: $REL"; exit 1; }
|
||||||
|
echo "release id: ${REL_ID}"
|
||||||
|
for f in dist/*; do
|
||||||
|
name=$(basename "$f")
|
||||||
|
echo "uploading ${name}"
|
||||||
|
code=$(curl -sS -o /tmp/up.json -w '%{http_code}' -X POST -H "$auth" \
|
||||||
|
-H "Content-Type: application/octet-stream" --data-binary @"${f}" \
|
||||||
|
"${API}/repos/${REPO}/releases/${REL_ID}/assets?name=${name}")
|
||||||
|
[ "$code" = "201" ] || { echo "::error::upload ${name} failed (HTTP ${code}): $(cat /tmp/up.json)"; exit 1; }
|
||||||
|
done
|
||||||
|
echo "published ${TAG}"
|
||||||
@@ -8,7 +8,7 @@ Automotive display controller for **Waveshare ESP32-S3-Touch-LCD-5B** (1024x600
|
|||||||
|
|
||||||
**Hardware**: ESP32-S3 dual-core @ 240MHz, 16MB Flash, 8MB OPI PSRAM, 5-inch capacitive touch LCD
|
**Hardware**: ESP32-S3 dual-core @ 240MHz, 16MB Flash, 8MB OPI PSRAM, 5-inch capacitive touch LCD
|
||||||
|
|
||||||
**Key Features**: WiFi scanning, UART data transmission @ 5Hz, debug metrics (FPS/CPU), NVS settings persistence, LVGL 8.4.0 UI (SquareLine Studio exports)
|
**Key Features**: CAN decode, link to B (UART + ESP-NOW @ 5 Hz), remembered Wi-Fi + on-screen OTA updates, gauge tuning, NVS settings persistence, LVGL 8.4.0 UI (hand-coded screens)
|
||||||
|
|
||||||
## Build & Development Commands
|
## Build & Development Commands
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ Use PlatformIO extension toolbar:
|
|||||||
The application uses **dual-core architecture** to maximize performance:
|
The application uses **dual-core architecture** to maximize performance:
|
||||||
|
|
||||||
- **Core 1** (Arduino core): LVGL rendering task (Priority 2)
|
- **Core 1** (Arduino core): LVGL rendering task (Priority 2)
|
||||||
- UI rendering at ~50 FPS @ 1024x600 resolution
|
- UI rendering @ 1024x600 (real render FPS never measured - the Debug "FPS" counts loop() passes)
|
||||||
- Touch input handling
|
- Touch input handling
|
||||||
- CPU load ~80% under normal operation
|
- CPU load ~80% under normal operation
|
||||||
|
|
||||||
@@ -74,14 +74,17 @@ The project follows a clean, organized structure with logical separation of conc
|
|||||||
src/
|
src/
|
||||||
main.cpp # Main application logic only
|
main.cpp # Main application logic only
|
||||||
modules/
|
modules/
|
||||||
wifi_manager.cpp # WiFi scanning and connection
|
wifi_manager.cpp # Wi-Fi: one remembered network, scans on request (no LVGL code)
|
||||||
|
settings_screen.cpp # Hand-coded Settings screen: Wi-Fi / Updates / System (swipe left from Driveline)
|
||||||
|
ui_kit.cpp # Shared look for hand-coded screens: header, buttons, switches, confirm dialog
|
||||||
uart_manager.cpp # Link transmitter: v2 DATA/CONFIG frames on UART1 + ESP-NOW
|
uart_manager.cpp # Link transmitter: v2 DATA/CONFIG frames on UART1 + ESP-NOW
|
||||||
tunables.cpp # Gauge calibration + alert thresholds (NVS, 'cfg' serial console)
|
tunables.cpp # Gauge calibration + alert thresholds (NVS, 'cfg' serial console)
|
||||||
espnow_link.cpp # ESP-NOW broadcast leg of the link
|
espnow_link.cpp # ESP-NOW broadcast leg of the link
|
||||||
tuning_screen.cpp # Hand-coded LVGL Gauge Tuning screen (swipe right from Driveline)
|
tuning_screen.cpp # Hand-coded Gauge Tuning screen, 4 tabs (swipe right from Driveline)
|
||||||
diag_probe.cpp # On-demand OBD-II requests ('diag' console) - the ONLY CAN transmitter
|
diag_probe.cpp # On-demand OBD-II requests ('diag' console) - the ONLY CAN transmitter
|
||||||
|
ota_update.cpp # Manual firmware updates from Gitea releases ('ota' console)
|
||||||
settings_manager.cpp # NVS persistent storage
|
settings_manager.cpp # NVS persistent storage
|
||||||
ui_state_manager.cpp # UI synchronization logic
|
ui_state_manager.cpp # Debug flag (performance overlay, sent to B)
|
||||||
display_init.cpp # Display initialization; boots into DrivelineScreen
|
display_init.cpp # Display initialization; boots into DrivelineScreen
|
||||||
driveline_screen.cpp # Hand-coded LVGL boot screen (gear, temps, rpm, status)
|
driveline_screen.cpp # Hand-coded LVGL boot screen (gear, temps, rpm, status)
|
||||||
drivers/
|
drivers/
|
||||||
@@ -102,10 +105,7 @@ include/
|
|||||||
|
|
||||||
**src/main.cpp** (~1530 lines)
|
**src/main.cpp** (~1530 lines)
|
||||||
- Main application logic, event handlers, FreeRTOS task implementations
|
- Main application logic, event handlers, FreeRTOS task implementations
|
||||||
- WiFi state machine: `wifiTask()` on Core 0 with async scanning
|
- Console command routing (`cfg`, `diag`, `ota`, `wifi`, `mem`), setup order, `loop()` ticks for the three screens
|
||||||
- UART state machine: `uartTask()` on Core 0 with periodic transmission
|
|
||||||
- Settings synchronization: `applySavedStatesToUI()` syncs toggle states when Settings screen loads
|
|
||||||
- Thread-safe UI updates via `lvgl_port_lock()`/`unlock()`
|
|
||||||
|
|
||||||
**include/protocol/automotive_data.h**
|
**include/protocol/automotive_data.h**
|
||||||
- **Shared with Controller B, must stay byte-identical in both repos.** Protocol v2 (2026-09-21).
|
- **Shared with Controller B, must stay byte-identical in both repos.** Protocol v2 (2026-09-21).
|
||||||
@@ -133,11 +133,8 @@ include/
|
|||||||
- LVGL 8.4.0 configuration file
|
- LVGL 8.4.0 configuration file
|
||||||
- Memory settings, theme configuration, widget enables
|
- Memory settings, theme configuration, widget enables
|
||||||
|
|
||||||
**include/ui/** directory (SquareLine Studio exports)
|
**include/ui/** directory (SquareLine Studio exports) - now only `ui_init()` (theme + an empty placeholder screen) and helpers
|
||||||
- `ui_Settings_Screen.c/h`: WiFi, UART, CAN Bus, Debug toggle switches and containers. Its right-swipe calls `app_show_driveline()` (C entry point in `driveline_screen.cpp`)
|
- **No SquareLine screens remain**: Home was removed 2026-09-21, Settings on 2026-09-27 (replaced by `settings_screen.cpp`). Every screen is hand-coded in `src/modules`. If SquareLine ever re-exports a screen, delete it from the SquareLine project - do not wire it back in
|
||||||
- The SquareLine **Home screen was removed on 2026-09-21** (its meters module too). `ui_init()` loads an empty placeholder; `display_init.cpp` then shows the Driveline screen. If SquareLine re-exports a Home screen, delete it from the SquareLine project — do not wire it back in
|
|
||||||
- External UI references: `uic_Toggle_Wifi_Switch`, `uic_Toggle_UART_Switch`, `uic_Toggle_CAN_Bus_Switch`, `uic_Toggle_Debug_Switch`, `uic_Wifi_Container`, `uic_Settings_Loading_Container`, `uic_Device_State_Container`
|
|
||||||
- Event handlers: `onWifiToggle()`, `onUARTToggle()`, `onCANBusToggle()`, `onDebugToggle()`
|
|
||||||
- **Important**: SquareLine Studio exports to `include/ui/` directory to avoid overwriting custom code in `src/`
|
- **Important**: SquareLine Studio exports to `include/ui/` directory to avoid overwriting custom code in `src/`
|
||||||
|
|
||||||
### NVS Persistent Storage
|
### NVS Persistent Storage
|
||||||
@@ -146,29 +143,17 @@ Settings persist across power cycles via ESP32 NVS (Non-Volatile Storage):
|
|||||||
- Namespace: "settings"
|
- Namespace: "settings"
|
||||||
- Keys: `wifi_en`, `uart_en`, `can_en`, `debug_en` (boolean values)
|
- Keys: `wifi_en`, `uart_en`, `can_en`, `debug_en` (boolean values)
|
||||||
- Functions: `saveWiFiState()`, `loadWiFiState()`, `saveUARTState()`, `loadUARTState()`, `saveCANState()`, `loadCANState()`, `saveDebugState()`, `loadDebugState()`
|
- Functions: `saveWiFiState()`, `loadWiFiState()`, `saveUARTState()`, `loadUARTState()`, `saveCANState()`, `loadCANState()`, `saveDebugState()`, `loadDebugState()`
|
||||||
|
- Namespace "wifi": `ssid`, `pass` - the one remembered network (`WiFiManager`); the password is never printed
|
||||||
|
|
||||||
### WiFi Architecture
|
### WiFi Architecture
|
||||||
|
|
||||||
**State Machine**: `WIFI_STATE_OFF` → `WIFI_STATE_SCANNING` → `WIFI_STATE_SCAN_COMPLETE` → `WIFI_STATE_CONNECTED`
|
`WiFiManager` (`wifi_manager.cpp`) owns **no LVGL objects**: the Settings screen polls `getStatus()` / `getNetworks()` and calls `setEnabled()`, `requestScan()`, `connect()`, `connectSaved()`, `forget()`. All radio work runs in `wifiTask()` (Core 0) from a command queue.
|
||||||
|
|
||||||
**Task Communication**:
|
- **One remembered network** (NVS namespace `wifi`), saved after a successful join, joined automatically ~3 s after boot when Wi-Fi is on (verified 2026-09-27)
|
||||||
- Main thread → WiFi task: Via `g_wifi_event_queue` (FreeRTOS queue)
|
- **Scans only on request** (Wi-Fi page opened while not connected, or the Scan button) - background scans every 10 s caused display glitches and hop the radio ESP-NOW uses
|
||||||
- Event types: `WIFI_UI_EVENT_TOGGLE_ON/OFF`, `WIFI_UI_EVENT_SCAN_START`, `WIFI_UI_EVENT_CONNECT`, `WIFI_UI_EVENT_DISCONNECT`
|
- **No endless reconnect**: `setAutoReconnect(false)`; one attempt at boot, one retry after a drop, then idle back on `ESPNOW_CHANNEL`
|
||||||
- Shared data protection: `g_wifi_mutex` (FreeRTOS semaphore) guards `g_scanned_networks[]` array
|
- Failure reasons come from the STA_DISCONNECTED event (wrong password, not in range, ...) and show on the screen
|
||||||
|
- Console: `wifi status | join <ssid> [pass] | forget | scan | on | off`
|
||||||
**Dynamic SSID Buttons**:
|
|
||||||
- WiFi scan results create dynamically-generated LVGL buttons (`lv_btn_create()` in `updateSSIDList()`)
|
|
||||||
- Button array: `g_ssid_buttons[WIFI_SCAN_MAX_NETWORKS]` (max 20 networks)
|
|
||||||
- Each button stores network index in user data: `lv_obj_set_user_data(btn, (void*)(intptr_t)i)`
|
|
||||||
- Click handler: `onSSIDButtonClick()` → shows password entry UI (keyboard + text area) for secured networks, or connects directly for open networks
|
|
||||||
|
|
||||||
**Connection Flow**:
|
|
||||||
1. User clicks SSID button → `onSSIDButtonClick()`
|
|
||||||
2. If secured: Show `uic_Wifi_Passkey_TB` (password text area) + `uic_Keyboard`
|
|
||||||
3. User enters password → `onKeyboardEvent()` (LV_EVENT_READY)
|
|
||||||
4. Allocate `wifi_credentials_t`, send `WIFI_UI_EVENT_CONNECT` to WiFi task
|
|
||||||
5. WiFi task: `WiFi.begin(ssid, password)` with 10-second timeout
|
|
||||||
6. Result: `showConnectionResult()` updates UI with success/failure
|
|
||||||
|
|
||||||
### UART Architecture
|
### UART Architecture
|
||||||
|
|
||||||
@@ -222,32 +207,29 @@ Settings persist across power cycles via ESP32 NVS (Non-Volatile Storage):
|
|||||||
|
|
||||||
### Tunables (gauge calibration, alert thresholds)
|
### Tunables (gauge calibration, alert thresholds)
|
||||||
|
|
||||||
`src/modules/tunables.cpp` owns `link_config_t`: tach pulses/rev + trim + clamps, coolant PWM frequency + duty law + min temp, per-output enables, a bench override (force rpm / duty), and the alert thresholds. Stored as an NVS blob (namespace `tunables`). Edited over the USB serial console: `cfg show`, `cfg set <name> <value>`, `cfg override rpm <n> | duty <n> | both <rpm> <duty> | off`, `cfg reset`. Every change bumps `cfg_version`, which makes the UART task push a CONFIG frame. Overrides are pushed but never saved. The **Gauge Tuning screen** (`src/modules/tuning_screen.cpp`, hand-coded like the driveline screen so SquareLine exports cannot clobber it; Home → swipe right → Driveline → swipe right → Tuning) edits the same values with −/+ buttons, enable switches, and an override panel with RPM and duty sliders. Overrides are never written to NVS (`save()` strips them).
|
`src/modules/tunables.cpp` owns `link_config_t`: tach pulses/rev + trim + clamps, coolant PWM frequency + duty law + min temp, per-output enables, a bench override (force rpm / duty), and the alert thresholds. Stored as an NVS blob (namespace `tunables`), written 3 s after the last change or on leaving the Tuning screen (`Tunables::flush()`, `isDirty()` drives the screen's save indicator) - every flash write flickers the RGB panel, so no write per tap. Edited over the USB serial console: `cfg show`, `cfg set <name> <value>`, `cfg override rpm <n> | duty <n> | both <rpm> <duty> | off`, `cfg reset`. Every change bumps `cfg_version`, which makes the UART task push a CONFIG frame. Overrides are pushed but never saved. The **Gauge Tuning screen** (`src/modules/tuning_screen.cpp`, see Screens) edits the same values with −/+ buttons, enable switches, and a Simulation tab with RPM and duty sliders. Overrides are never written to NVS (`save()` strips them).
|
||||||
|
|
||||||
### Diagnostic probe (`diag` console)
|
### Diagnostic probe (`diag` console)
|
||||||
|
|
||||||
`src/modules/diag_probe.cpp` is the only code allowed to call `CANDriver::transmit()`. It sends single OBD-II requests on `0x7DF` and reassembles ISO-TP replies from `0x7E8..0x7EF`: `diag pids` (supported-PID bitmap scan), `diag pid <hex>`, `diag vin`, `diag ecu`, `diag status`. One request in flight, single-shot frames, refused for 3 s after any foreign tester frame (`0x7DF`, `0x7E0-7`, `0x6F1`), services 01/09 only. Transmitted frames are echoed as `CANTX,` lines in the same format as `CANRAW,`. Console lines that `cfg` does not recognise are passed to it via `Tunables::setExtraCommandHandler()`. Background and test procedure: `wiki/pages/obd-diagnostic-polling.md`.
|
`src/modules/diag_probe.cpp` is the only code allowed to call `CANDriver::transmit()`. It sends single diagnostic requests and reassembles the ISO-TP replies, on two routes: generic OBD-II on `0x7DF` (replies `0x7E8..0x7EF`) and BMW-addressed KWP2000 on `0x6F1` with target byte (replies `0x600`+addr, extended addressing). Commands: `diag pids` (supported-PID bitmap scan), `diag pid <hex>`, `diag dtc` (mode 03), `diag vin`, `diag ecu`, `diag ident [addr]` (KWP `1A 80`), `diag bmw <addr> <hex...>` (raw, whitelisted), `diag raw on|off` (CANRAW mute for scans), `diag status`. One request in flight, single-shot frames, refused for 3 s after any foreign tester frame (`0x7DF`, `0x7E0-7`, `0x6F1`); read-only services only — generic 01/03/09, BMW `1A`/`18`/`21`/`22` (whitelist enforced in `sendBmwRequest()`), never session control or writes. Transmitted frames are echoed as `CANTX,` lines in the same format as `CANRAW,`. Console lines that `cfg` does not recognise are passed to it via `Tunables::setExtraCommandHandler()`. Background and test procedure: `wiki/pages/obd-diagnostic-polling.md`.
|
||||||
|
|
||||||
|
### OTA updates (`ota` console)
|
||||||
|
|
||||||
|
`src/modules/ota_update.cpp` pulls signed firmware from this repo's Gitea releases (`include/config/ota_config.h`: server, repo, Let's Encrypt roots, signing public key). Manual only: Settings → Updates (Check, then Install behind a confirm dialog; verified end-to-end from the screen 2026-09-27) or the console `ota status | check | install [force] | rollback`. `Ota::getStatus()` gives the screen a phase + latest tag + failure reason. Install is refused unless parked (engine off, shaft still, lever not in a drive gear; silent bus = parked), checked before download and again before the slot switch. The manifest's ECDSA P-256 signature over `patrol-a|version|sha256` is checked before download; the streamed image must match that sha256. `verifyRollbackLater()` is overridden so a new image stays pending until `Ota::tick()` confirms it after 30 s - a reset before that rolls back. CI: `.gitea/workflows/firmware.yml` (push `main` -> rolling unsigned pre-release `main-latest`; tag `v*` -> signed release, needs repo secret `BMW_NISSAN_FIRMWARE_SIGNING_KEY`). Release with one push so only the tag build runs: `git tag -a vX.Y.Z -m "..." && git push --follow-tags origin main` (a main push skips itself when its commit is tagged, or when it only touches `wiki/**` / `*.md`). Never put secrets in firmware source - the repo and its release binaries are public. Jobs run inside the loop task (8 KB stack) with mbedtls routed to PSRAM - internal RAM is too tight for a TLS task (15.9 KB free, largest block 7.6 KB with Wi-Fi up). Wi-Fi is joined on the Settings screen (remembered) or with `wifi join`. Details: `wiki/pages/ota-updates.md`.
|
||||||
|
|
||||||
### ESP-NOW link
|
### ESP-NOW link
|
||||||
|
|
||||||
`src/modules/espnow_link.cpp` broadcasts every frame on Wi-Fi channel `ESPNOW_CHANNEL` (1). The radio stays in STA mode permanently — `WiFiManager`'s "off" only stops scanning/association (it no longer calls `WiFi.mode(WIFI_OFF)`). If Wi-Fi joins an AP the channel follows the AP; B hops to find it.
|
`src/modules/espnow_link.cpp` broadcasts every frame on Wi-Fi channel `ESPNOW_CHANNEL` (1). The radio stays in STA mode permanently — `WiFiManager`'s "off" only stops scanning/association. Never call `WiFi.disconnect(true)` or `WiFi.mode(WIFI_OFF)`: powering the radio off de-initialises ESP-NOW (`send()` re-inits it as a safety net). If Wi-Fi joins an AP the channel follows the AP; B hops to find it.
|
||||||
|
|
||||||
### UI State Synchronization
|
### Screens
|
||||||
|
|
||||||
**Problem**: SquareLine Studio screens get destroyed/recreated when swiping between screens, losing runtime state.
|
All hand-coded in `src/modules`, built once and kept (never deleted - SquareLine's delete-on-leave caused dangling pointers and the 2026-09-27 freezes). Shared look in `ui_kit.cpp` (20/24 px text, >= 56 px touch targets, no shadows/animations, `UiKit::confirm()` modal dialog). Each screen has a `tick()` called from `loop()` that refreshes values under the LVGL lock, only while it is shown, and only re-sets label text that changed.
|
||||||
|
|
||||||
**Solution**: `applySavedStatesToUI()` function (called continuously in `loop()`)
|
- **Driveline** (boot) - swipe left: Settings, swipe right: Gauge Tuning
|
||||||
- Detects when Settings screen loads by checking if `uic_Toggle_Wifi_Switch != NULL`
|
- **Settings** (`settings_screen.cpp`) - sidebar: **Wi-Fi** (switch, status card, networks nearby, full-screen password page), **Updates** (installed vs latest, Check, Install behind a confirm dialog -> `Ota::requestCheck/requestInstall`), **System** (CAN / link to B / performance overlay switches, live ESP-NOW, CAN, memory, uptime). Swipe right or the Driveline button goes back
|
||||||
- Tracks screen instance via `g_last_synced_screen` pointer to prevent redundant syncing
|
- **Gauge Tuning** (`tuning_screen.cpp`) - tabs Tachometer / Coolant gauge / Alerts / Simulation; -/+ rows with hints (hold to repeat, speeds up), per-tab Reset with confirm, "Saving... / All changes saved" footer, SIMULATION ON chip while an override is active. Swipe left or the Driveline button goes back
|
||||||
- Syncs toggle switches with actual service states: `g_wifi_state`, `g_uart_state`, `g_debug_enabled`
|
- Screen switches are instant (`LV_SCR_LOAD_ANIM_NONE`): full-screen fades are software-blended every frame and stutter at 1024x600. The firmware version is a label on `lv_layer_top()` (bottom-right, every screen, `DisplayInit`)
|
||||||
- Shows loading spinner during sync for smooth UX
|
- The System page's "Performance overlay" switch shows LVGL's own perf monitor (real render FPS / CPU) and sets the debug flag sent to B
|
||||||
|
|
||||||
**Screens**: Driveline (boot, hand-coded) ← swipe left → Settings (SquareLine); Driveline → swipe right → Gauge Tuning (hand-coded).
|
|
||||||
|
|
||||||
**Debug Mode**:
|
|
||||||
- Toggle in Settings screen shows/hides `uic_Device_State_Container`
|
|
||||||
- Updates FPS (`uic_FPS_Values_LBL`) and CPU usage (`uic_CPU_Values_LBL`) every second
|
|
||||||
- Frame counting: `g_frame_count` incremented in `updateDebugMetrics()` called from `loop()`
|
|
||||||
|
|
||||||
## Configuration Files
|
## Configuration Files
|
||||||
|
|
||||||
@@ -255,7 +237,7 @@ Settings persist across power cycles via ESP32 NVS (Non-Volatile Storage):
|
|||||||
- Custom Arduino core: `pioarduino/platform-espressif32` (Arduino 3.3.3 / ESP-IDF 5.5.1) for RGB LCD support
|
- Custom Arduino core: `pioarduino/platform-espressif32` (Arduino 3.3.3 / ESP-IDF 5.5.1) for RGB LCD support
|
||||||
- Board: Custom `esp32-s3-wroom-1-n16r8` (defined in `boards/esp32-s3-wroom-1-n16r8.json`)
|
- Board: Custom `esp32-s3-wroom-1-n16r8` (defined in `boards/esp32-s3-wroom-1-n16r8.json`)
|
||||||
- PSRAM: OPI mode (`qio_opi` memory type) - REQUIRED for 8MB OPI PSRAM and 1024x600 display
|
- PSRAM: OPI mode (`qio_opi` memory type) - REQUIRED for 8MB OPI PSRAM and 1024x600 display
|
||||||
- Partition: `partition_table.csv` (12.5MB app / 3.375MB SPIFFS) - optimized for 16MB flash
|
- Partition: `partition_table.csv` (dual OTA: 2 x 7.9MB app slots, no SPIFFS) - see OTA updates below
|
||||||
- Debug level: `CORE_DEBUG_LEVEL=1` (1=Error, 5=Verbose)
|
- Debug level: `CORE_DEBUG_LEVEL=1` (1=Error, 5=Verbose)
|
||||||
- Libraries: ESP32_Display_Panel v1.0.4, LVGL 8.4.0 (from GitHub)
|
- Libraries: ESP32_Display_Panel v1.0.4, LVGL 8.4.0 (from GitHub)
|
||||||
|
|
||||||
@@ -267,48 +249,23 @@ Settings persist across power cycles via ESP32 NVS (Non-Volatile Storage):
|
|||||||
- Critical settings: `memory_type: qio_opi`, `psram_type: opi`
|
- Critical settings: `memory_type: qio_opi`, `psram_type: opi`
|
||||||
|
|
||||||
**partition_table.csv** (Partition Table)
|
**partition_table.csv** (Partition Table)
|
||||||
- NVS: 20KB @ 0x9000 (settings storage)
|
- NVS: 20KB @ 0x9000 (settings storage) - never move it, or saved settings/tunables are lost
|
||||||
- OTA Data: 8KB @ 0xe000 (for future OTA support)
|
- OTA Data: 8KB @ 0xe000 (which slot boots)
|
||||||
- App: 12.5MB @ 0x10000 (large partition for UI assets)
|
- app0 / app1: 7.9MB each @ 0x10000 / 0x800000 (OTA slots; firmware ~1.65MB)
|
||||||
- SPIFFS: 3.375MB @ 0xC90000 (file system)
|
|
||||||
- Coredump: 64KB @ 0xFF0000 (crash debugging)
|
- Coredump: 64KB @ 0xFF0000 (crash debugging)
|
||||||
|
- Changing this table needs one USB flash; OTA can't repartition
|
||||||
|
|
||||||
**include/lv_conf.h**
|
**include/lv_conf.h**
|
||||||
- LVGL 8.4.0 configuration
|
- LVGL 8.4.0 configuration
|
||||||
- Memory: Uses PSRAM for large objects
|
- Memory: LVGL's widget pool (`LV_MEM_SIZE`) is 512 KB in PSRAM via `LV_MEM_POOL_ALLOC` (was 48 KB internal and ran out). `mem` on the console prints internal heap, PSRAM and pool use/fragmentation
|
||||||
|
- Asserts: `LV_ASSERT_HANDLER` is `abort()` (backtrace + core dump + reboot), never `while(1)`, which froze the UI while holding the LVGL lock
|
||||||
- Theme: Material theme enabled
|
- Theme: Material theme enabled
|
||||||
|
|
||||||
## Common Patterns
|
## Common Patterns
|
||||||
|
|
||||||
### Adding a New Toggle Switch
|
### Adding a New Setting
|
||||||
|
|
||||||
1. Add NVS keys in main.cpp:
|
See "Adding a setting" under Important Notes: a row + `UiKit::toggle()` on the Settings screen, a `SettingsManager` save/load pair, and a sync line in the page's `refresh*()`.
|
||||||
```cpp
|
|
||||||
#define NVS_KEY_FEATURE_ENABLED "feature_en"
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Add save/load functions:
|
|
||||||
```cpp
|
|
||||||
void saveFeatureState(bool enabled) {
|
|
||||||
preferences.begin(NVS_NAMESPACE, false);
|
|
||||||
preferences.putBool(NVS_KEY_FEATURE_ENABLED, enabled);
|
|
||||||
preferences.end();
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Add global state variable: `static bool g_feature_enabled = false;`
|
|
||||||
|
|
||||||
4. Create event handler (called from SquareLine UI):
|
|
||||||
```cpp
|
|
||||||
void onFeatureToggle(lv_event_t *e) {
|
|
||||||
lv_obj_t *target = lv_event_get_target(e);
|
|
||||||
bool state = lv_obj_has_state(target, LV_STATE_CHECKED);
|
|
||||||
saveFeatureState(state);
|
|
||||||
// Update state, send to task if needed
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
5. Add sync logic in `applySavedStatesToUI()` to restore state when Settings screen loads
|
|
||||||
|
|
||||||
### Thread-Safe UI Update from Background Task
|
### Thread-Safe UI Update from Background Task
|
||||||
|
|
||||||
@@ -350,7 +307,8 @@ xTaskCreatePinnedToCore(
|
|||||||
|
|
||||||
- **CAN Bus**: GPIO 15 (TX), GPIO 16 (RX) - 500 Kbps, TWAI_MODE_NORMAL, onboard TJA1051 on the terminal block
|
- **CAN Bus**: GPIO 15 (TX), GPIO 16 (RX) - 500 Kbps, TWAI_MODE_NORMAL, onboard TJA1051 on the terminal block
|
||||||
- **UART1**: GPIO 44 (TX), GPIO 43 (RX, unused) - reaches the terminal block only as the RS485 A/B pair (SP3485), 115200 baud. Bench: `485_A` straight into B's IO1 + GND works (verified 2026-09-21)
|
- **UART1**: GPIO 44 (TX), GPIO 43 (RX, unused) - reaches the terminal block only as the RS485 A/B pair (SP3485), 115200 baud. Bench: `485_A` straight into B's IO1 + GND works (verified 2026-09-21)
|
||||||
- **USB Serial**: UART0 (default Serial) - 115200 baud for debug output
|
- **USB Serial**: native USB-CDC (`Serial`, 303A:1001). Opening the port with default DTR/RTS resets the board - attach with `pio device monitor -p COM10 --dtr 0 --rts 0 --echo`
|
||||||
|
- **Uploading from a script/pipe on Windows**: set `PYTHONIOENCODING=utf-8` (and `PYTHONUTF8=1`). Otherwise esptool crashes printing its progress bar to a cp1252 pipe *mid-write* and leaves the board frozen until a power cycle (happened 2026-09-27; the bootloader then fell back to the other OTA slot)
|
||||||
|
|
||||||
### Display Panel
|
### Display Panel
|
||||||
|
|
||||||
@@ -383,7 +341,7 @@ xTaskCreatePinnedToCore(
|
|||||||
|
|
||||||
- **Screen drift/artifacts**: RGB LCD timing issue - already optimized in `platformio.ini` with high-performance platform packages
|
- **Screen drift/artifacts**: RGB LCD timing issue - already optimized in `platformio.ini` with high-performance platform packages
|
||||||
- **White flash on boot**: Backlight control sequence in setup() minimizes this (lines 1383-1414)
|
- **White flash on boot**: Backlight control sequence in setup() minimizes this (lines 1383-1414)
|
||||||
- **UI toggles don't match state**: Check `applySavedStatesToUI()` is called in `loop()` - this syncs UI with running services
|
- **UI switches don't match state**: `SettingsScreen::tick()` must run in `loop()` - it re-reads the live state every 250 ms
|
||||||
- **WiFi/UART task not responding**: Check FreeRTOS queue creation succeeded (NULL check in setup())
|
- **WiFi/UART task not responding**: Check FreeRTOS queue creation succeeded (NULL check in setup())
|
||||||
- **LVGL crash from background task**: Ensure `lvgl_port_lock()` / `unlock()` wraps ALL LVGL API calls
|
- **LVGL crash from background task**: Ensure `lvgl_port_lock()` / `unlock()` wraps ALL LVGL API calls
|
||||||
- **Screen flickering**: This was resolved by fixing the proper board configuration and partition table. The key fixes were:
|
- **Screen flickering**: This was resolved by fixing the proper board configuration and partition table. The key fixes were:
|
||||||
@@ -396,7 +354,7 @@ xTaskCreatePinnedToCore(
|
|||||||
|
|
||||||
## Performance Metrics
|
## Performance Metrics
|
||||||
|
|
||||||
- **FPS**: ~50 FPS @ 1024x600 resolution
|
- **FPS**: not measured yet (the Debug-panel counter counts loop() passes, not frames) - see wiki open-questions #13
|
||||||
- **CPU Load**: ~80% on Core 1 (LVGL rendering)
|
- **CPU Load**: ~80% on Core 1 (LVGL rendering)
|
||||||
- **WiFi Scan**: 1-3 seconds for 10-20 networks
|
- **WiFi Scan**: 1-3 seconds for 10-20 networks
|
||||||
- **UART Overhead**: +1-2% CPU @ 5Hz transmission rate
|
- **UART Overhead**: +1-2% CPU @ 5Hz transmission rate
|
||||||
@@ -405,6 +363,6 @@ xTaskCreatePinnedToCore(
|
|||||||
## Important Notes
|
## Important Notes
|
||||||
|
|
||||||
- **SquareLine Studio Export**: ALWAYS export UI files to `ui/` directory, NEVER to `src/` (prevents overwriting main.cpp)
|
- **SquareLine Studio Export**: ALWAYS export UI files to `ui/` directory, NEVER to `src/` (prevents overwriting main.cpp)
|
||||||
- **Event Handler Registration**: Event handlers for SquareLine UI elements are registered in `ui_Settings_Screen.c` auto-generated code. When adding new toggles, add event callback registration via `lv_obj_add_event_cb()` and declare handler in `ui_events.h`
|
- **Adding a setting**: add a row to the right page in `settings_screen.cpp` (`makeSettingRow()` + `UiKit::toggle()`), persist it via `SettingsManager`, and sync it in that page's `refresh*()` function
|
||||||
- **CAN Bus Integration**: BMW CAN IDs are defined in `automotive_data.h` (all 11-bit standard frames, verified live on the swap bus). The CAN driver runs in `TWAI_MODE_NORMAL` (it ACKs frames; not LISTEN_ONLY). Evidence and confidence labels live in `wiki/pages/can-id-candidates.md`. Never add a second caller of `CANDriver::transmit()` without a design discussion — transmitting on the vehicle bus is a safety decision
|
- **CAN Bus Integration**: BMW CAN IDs are defined in `automotive_data.h` (all 11-bit standard frames, verified live on the swap bus). The CAN driver runs in `TWAI_MODE_NORMAL` (it ACKs frames; not LISTEN_ONLY). Evidence and confidence labels live in `wiki/pages/can-id-candidates.md`. Never add a second caller of `CANDriver::transmit()` without a design discussion — transmitting on the vehicle bus is a safety decision
|
||||||
- **Security**: Password field (`uic_Wifi_Passkey_TB`) is cleared after connection attempt for security (line 1015, 1029)
|
- **Security**: the Wi-Fi password field is cleared when the password page closes; the saved password lives only in NVS and is never logged (the pre-2026-09-27 code printed it on every join)
|
||||||
|
|||||||
@@ -49,14 +49,19 @@
|
|||||||
#define LV_MEM_CUSTOM 0
|
#define LV_MEM_CUSTOM 0
|
||||||
#if LV_MEM_CUSTOM == 0
|
#if LV_MEM_CUSTOM == 0
|
||||||
/*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/
|
/*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/
|
||||||
#define LV_MEM_SIZE (48U * 1024U) /*[bytes]*/
|
/* 512 KB pool in PSRAM (2026-09-27). The old 48 KB pool lived in internal
|
||||||
|
* RAM and ran out: Settings + its Wi-Fi list is ~15 KB, and screen churn +
|
||||||
|
* fragmentation reached 87% used / 4.5 KB biggest block, then a label draw
|
||||||
|
* failed lv_mem_buf_get() -> assert. Moving it out also frees 48 KB of the
|
||||||
|
* scarce internal RAM. `mem` on the console prints the pool state. */
|
||||||
|
#define LV_MEM_SIZE (512U * 1024U) /*[bytes]*/
|
||||||
|
|
||||||
/*Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too.*/
|
/*Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too.*/
|
||||||
#define LV_MEM_ADR 0 /*0: unused*/
|
#define LV_MEM_ADR 0 /*0: unused*/
|
||||||
/*Instead of an address give a memory allocator that will be called to get a memory pool for LVGL. E.g. my_malloc*/
|
/*Instead of an address give a memory allocator that will be called to get a memory pool for LVGL. E.g. my_malloc*/
|
||||||
#if LV_MEM_ADR == 0
|
#if LV_MEM_ADR == 0
|
||||||
#undef LV_MEM_POOL_INCLUDE
|
#define LV_MEM_POOL_INCLUDE <esp_heap_caps.h>
|
||||||
#undef LV_MEM_POOL_ALLOC
|
#define LV_MEM_POOL_ALLOC(size) heap_caps_malloc((size), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else /*LV_MEM_CUSTOM*/
|
#else /*LV_MEM_CUSTOM*/
|
||||||
@@ -271,8 +276,12 @@
|
|||||||
#define LV_USE_ASSERT_OBJ 0 /*Check the object's type and existence (e.g. not deleted). (Slow)*/
|
#define LV_USE_ASSERT_OBJ 0 /*Check the object's type and existence (e.g. not deleted). (Slow)*/
|
||||||
|
|
||||||
/*Add a custom handler when assert happens e.g. to restart the MCU*/
|
/*Add a custom handler when assert happens e.g. to restart the MCU*/
|
||||||
#define LV_ASSERT_HANDLER_INCLUDE <stdint.h>
|
#define LV_ASSERT_HANDLER_INCLUDE <stdlib.h>
|
||||||
#define LV_ASSERT_HANDLER while(1); /*Halt by default*/
|
/* Was `while(1);`: a failed assert spun forever inside the calling task while it
|
||||||
|
* held the LVGL lock - the UI froze, loop() blocked on the lock, and only the
|
||||||
|
* link task kept running (2026-09-27). abort() panics instead: backtrace on the
|
||||||
|
* console, core dump to flash (ELF), reboot. A reboot beats a frozen screen. */
|
||||||
|
#define LV_ASSERT_HANDLER abort();
|
||||||
|
|
||||||
/*-------------
|
/*-------------
|
||||||
* Others
|
* Others
|
||||||
@@ -367,9 +376,9 @@
|
|||||||
#define LV_FONT_MONTSERRAT_14 1
|
#define LV_FONT_MONTSERRAT_14 1
|
||||||
#define LV_FONT_MONTSERRAT_16 0
|
#define LV_FONT_MONTSERRAT_16 0
|
||||||
#define LV_FONT_MONTSERRAT_18 0
|
#define LV_FONT_MONTSERRAT_18 0
|
||||||
#define LV_FONT_MONTSERRAT_20 0
|
#define LV_FONT_MONTSERRAT_20 1
|
||||||
#define LV_FONT_MONTSERRAT_22 0
|
#define LV_FONT_MONTSERRAT_22 0
|
||||||
#define LV_FONT_MONTSERRAT_24 0
|
#define LV_FONT_MONTSERRAT_24 1
|
||||||
#define LV_FONT_MONTSERRAT_26 0
|
#define LV_FONT_MONTSERRAT_26 0
|
||||||
#define LV_FONT_MONTSERRAT_28 0
|
#define LV_FONT_MONTSERRAT_28 0
|
||||||
#define LV_FONT_MONTSERRAT_30 1
|
#define LV_FONT_MONTSERRAT_30 1
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
/**
|
||||||
|
* ota_config.h - where Controller A looks for firmware updates, and what it trusts.
|
||||||
|
*
|
||||||
|
* Updates are pulled over HTTPS from this repo's Gitea releases (public repo,
|
||||||
|
* no token). CI (.gitea/workflows/firmware.yml) attaches firmware.bin +
|
||||||
|
* manifest.txt to every v* tag; manifest carries size, sha256 and an ECDSA
|
||||||
|
* P-256 signature. See wiki/pages/ota-updates.md.
|
||||||
|
*
|
||||||
|
* Nothing in here is secret: the CA roots and the signing PUBLIC key are meant
|
||||||
|
* to be public. The signing private key lives only in the Gitea repo secret
|
||||||
|
* BMW_NISSAN_FIRMWARE_SIGNING_KEY (plus the owner's offline backup).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OTA_CONFIG_H
|
||||||
|
#define OTA_CONFIG_H
|
||||||
|
|
||||||
|
// Version string baked in by CI (-DFW_VERSION="v1.2.3"); local builds say "dev".
|
||||||
|
#ifndef FW_VERSION
|
||||||
|
#define FW_VERSION "dev"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Identity inside the signed statement, so a Controller B image can never be
|
||||||
|
// accepted by A (and vice versa) even though both are signed by the same key.
|
||||||
|
#define OTA_TARGET "patrol-a"
|
||||||
|
|
||||||
|
#define OTA_SERVER "https://git.infra.msai.al"
|
||||||
|
#define OTA_REPO "art/ESP32-S3-Touch-LCD-5B"
|
||||||
|
// Latest non-draft, non-prerelease release (the rolling `main` build is a
|
||||||
|
// prerelease, so it is never offered to the car).
|
||||||
|
#define OTA_LATEST_API_URL OTA_SERVER "/api/v1/repos/" OTA_REPO "/releases/latest"
|
||||||
|
// + "<tag>/<asset>"
|
||||||
|
#define OTA_DOWNLOAD_BASE OTA_SERVER "/" OTA_REPO "/releases/download/"
|
||||||
|
|
||||||
|
// TLS trust: Let's Encrypt roots. The server's chain (2026-09-26) is
|
||||||
|
// leaf -> YR2 -> Root YR (cross-signed by ISRG Root X1); both roots verify it
|
||||||
|
// on their own, so either survives LE dropping the cross-sign. Valid to
|
||||||
|
// 2035 (X1) / 2045 (YR). Leaf certs rotate every ~90 days - never pin them.
|
||||||
|
static const char OTA_CA_PEM[] =
|
||||||
|
// ISRG Root X1
|
||||||
|
"-----BEGIN CERTIFICATE-----\n"
|
||||||
|
"MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw\n"
|
||||||
|
"TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh\n"
|
||||||
|
"cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4\n"
|
||||||
|
"WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu\n"
|
||||||
|
"ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY\n"
|
||||||
|
"MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc\n"
|
||||||
|
"h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+\n"
|
||||||
|
"0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U\n"
|
||||||
|
"A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW\n"
|
||||||
|
"T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH\n"
|
||||||
|
"B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC\n"
|
||||||
|
"B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv\n"
|
||||||
|
"KBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWn\n"
|
||||||
|
"OlFuhjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTn\n"
|
||||||
|
"jh8BCNAw1FtxNrQHusEwMFxIt4I7mKZ9YIqioymCzLq9gwQbooMDQaHWBfEbwrbw\n"
|
||||||
|
"qHyGO0aoSCqI3Haadr8faqU9GY/rOPNk3sgrDQoo//fb4hVC1CLQJ13hef4Y53CI\n"
|
||||||
|
"rU7m2Ys6xt0nUW7/vGT1M0NPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNV\n"
|
||||||
|
"HRMBAf8EBTADAQH/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY9umbbjANBgkq\n"
|
||||||
|
"hkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL\n"
|
||||||
|
"ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ\n"
|
||||||
|
"3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK\n"
|
||||||
|
"NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5\n"
|
||||||
|
"ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur\n"
|
||||||
|
"TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC\n"
|
||||||
|
"jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc\n"
|
||||||
|
"oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq\n"
|
||||||
|
"4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA\n"
|
||||||
|
"mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d\n"
|
||||||
|
"emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=\n"
|
||||||
|
"-----END CERTIFICATE-----\n"
|
||||||
|
// ISRG Root YR
|
||||||
|
"-----BEGIN CERTIFICATE-----\n"
|
||||||
|
"MIIFKTCCAxGgAwIBAgIRAOxGNJNgz0sP+KmC2Tqpyj0wDQYJKoZIhvcNAQELBQAw\n"
|
||||||
|
"LjELMAkGA1UEBhMCVVMxDTALBgNVBAoTBElTUkcxEDAOBgNVBAMTB1Jvb3QgWVIw\n"
|
||||||
|
"HhcNMjUwOTAzMDAwMDAwWhcNNDUwOTAyMjM1OTU5WjAuMQswCQYDVQQGEwJVUzEN\n"
|
||||||
|
"MAsGA1UEChMESVNSRzEQMA4GA1UEAxMHUm9vdCBZUjCCAiIwDQYJKoZIhvcNAQEB\n"
|
||||||
|
"BQADggIPADCCAgoCggIBANvGJnN78CTJdWL3+eGfsLN5TrNBJs+VH9hRXqRbwxu9\n"
|
||||||
|
"sGNiB0BD1fcOxbSUQCJIM1xE13Db+5Cw1w0s0EBYsvuIP/6joF0w8cuImbgR1OGg\n"
|
||||||
|
"YbSQ4OpzI+DG8SGuTlcE873OCS+kh3srlo6vl43M5OJg4Aeo1sfHp6kTJDoIiFBN\n"
|
||||||
|
"JAY+OKfX/FUvYKuhjT+no49lmqmupSBI5PkBQiqrEGtWU5uxU/cQWHGu8jSjFBzn\n"
|
||||||
|
"ZqvbNPLMXMLFxCb3WTfrJBXXjqvWG+v4bjzxjjeAtOlU7qarRDvNOyAuQYLln904\n"
|
||||||
|
"M+faKx8hnLCpJ15ZqaEgcNlY+9MMWcC5yvL2A2j3l9+2buggZX+dOE91zYmIdawT\n"
|
||||||
|
"vSZuVvlbRrAlLxIB6pwMBjneXCjYQ8+3BCCjssbSNpZU3hTcBDdhfAlEDlYr6pEa\n"
|
||||||
|
"tnMdmDT5BqnKC92bd0EhM1fbLHioLccLCuievT8ZkPhZrq7Mii7gNXAcUEAR8+lz\n"
|
||||||
|
"Yal+9zTg7C5DALyVOeG/CqfRAMn1KSHCR0NSA6P8tn/mGRlnCct5rtVCLnVySVpU\n"
|
||||||
|
"6H1qGg3DgTOuskf8eahTMiYbI5ezPJmO5ertalskQ1utp74+eDy92PI4ftHKTbq9\n"
|
||||||
|
"IWhH4YZKh3WnJEIt+oQvlYZbY8tpEroKrFB6PFGzrJIDRyts4HqvuH52RFj2zv/B\n"
|
||||||
|
"AgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1Ud\n"
|
||||||
|
"DgQWBBTe51tg0CJtQCh9Pw0B/qS1UrRRlDANBgkqhkiG9w0BAQsFAAOCAgEAWHnf\n"
|
||||||
|
"713Bdkq7t5yN2dNIgQakUb94X9WuyhMEHHkgx4oDpSUlnG0w4g94MoqaEUE31ZjR\n"
|
||||||
|
"LU7L5LD1g9ujFHTQu8AD215AHMVQFbm6j8hQxdXHAzDajFNQnOlDJrLjzIx176oy\n"
|
||||||
|
"AjvUtejZx2NNmdb5fd0WGVGsCdoAJ3N8ozo7ajE8t6vfxStZb4BQ9WYJGHUDrv2N\n"
|
||||||
|
"i5tJF6CNiPnlzs3BUfECRbE4JSk+jvy8+VoGiFE8qsH/j78x2fjgQhAQFV7P7Zxy\n"
|
||||||
|
"dBTZ1wEkNpZNW2qnaK1SKBLa+xf6E06YRIq5uaI+HWH8SY1y5VbRgzq40EKg3yxP\n"
|
||||||
|
"06fz+uYAUIFJoLNfhwRCc3Q6pQVuMX3yAjHAes4gk4moGcLQ5p7HAh39yeylZc1J\n"
|
||||||
|
"41sx/jKwLIkPE6Rr1Nf4pxdsxf9SA4yOEiAkDgq04DVxn8hgYFdUtBCuiuVC2heA\n"
|
||||||
|
"EiqVEa+8QZjuw8Gj0EbHXcRd1nInvGqRS1o9Is7YBdQN57X1AYveGBNNqjICSb7c\n"
|
||||||
|
"awuw1EawTDrs13VUlJVEsbQ0/O/1aaV73mCdOQ8azqL2KTv1Ewu1xbquE2S+kdQU\n"
|
||||||
|
"To9TUwat3wUA6cwXh1EfpS/3fJ0aGah5hdpRyoCLDlsSn8tkrjMfFFX0viC+GxHc\n"
|
||||||
|
"sI1ANRYvqSFC2X1VRZfDg+wD6E21BccmifG4yWc=\n"
|
||||||
|
"-----END CERTIFICATE-----\n";
|
||||||
|
|
||||||
|
// Firmware signing public key (ECDSA P-256). The device verifies
|
||||||
|
// sig over SHA-256("<target>|<version>|<sha256-of-image-hex>").
|
||||||
|
static const char OTA_SIGNING_PUBKEY_PEM[] =
|
||||||
|
"-----BEGIN PUBLIC KEY-----\n"
|
||||||
|
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE496tys+NeIrdDLNaGHLzr6L4oGmF\n"
|
||||||
|
"Y9brIfDTgn8IOWBm8J4nmLUef7zU4ydPM5BKXqUrTshJEpLd74GJIIOtkg==\n"
|
||||||
|
"-----END PUBLIC KEY-----\n";
|
||||||
|
|
||||||
|
#endif // OTA_CONFIG_H
|
||||||
@@ -178,10 +178,9 @@ namespace CANDriver {
|
|||||||
void setVerboseDecode(bool enabled);
|
void setVerboseDecode(bool enabled);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UI event handler for CAN toggle switch
|
* Settings-screen switch: start/stop the CAN task and remember the choice in NVS.
|
||||||
* @param e LVGL event
|
|
||||||
*/
|
*/
|
||||||
void onCANToggle(lv_event_t *e);
|
void setEnabled(bool enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // _CAN_DRIVER_H
|
#endif // _CAN_DRIVER_H
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
SET(SOURCES screens/ui_Settings_Screen.c
|
SET(SOURCES ui_theme_manager.c
|
||||||
ui_theme_manager.c
|
|
||||||
ui_themes.c
|
ui_themes.c
|
||||||
ui.c
|
ui.c
|
||||||
components/ui_comp_hook.c
|
components/ui_comp_hook.c
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
screens/ui_Settings_Screen.c
|
|
||||||
ui_theme_manager.c
|
ui_theme_manager.c
|
||||||
ui_themes.c
|
ui_themes.c
|
||||||
ui.c
|
ui.c
|
||||||
|
|||||||
@@ -1,552 +0,0 @@
|
|||||||
// This file was generated by SquareLine Studio
|
|
||||||
// SquareLine Studio version: SquareLine Studio 1.5.4
|
|
||||||
// LVGL version: 8.3.6
|
|
||||||
// Project name: ESP32-S3-Touch-LCD-5B
|
|
||||||
|
|
||||||
#include "../ui.h"
|
|
||||||
|
|
||||||
// Hand-coded Driveline screen (src/modules/driveline_screen.cpp) - replaces Home
|
|
||||||
void app_show_driveline(void);
|
|
||||||
|
|
||||||
lv_obj_t * uic_Settings_Loading_Spinner;
|
|
||||||
lv_obj_t * uic_Settings_Loading_Container;
|
|
||||||
lv_obj_t * uic_CPU_Values_LBL;
|
|
||||||
lv_obj_t * uic_FPS_Values_LBL;
|
|
||||||
lv_obj_t * uic_Device_State_Values_LBL;
|
|
||||||
lv_obj_t * uic_CPU_Static_LBL;
|
|
||||||
lv_obj_t * uic_FPS_Static_LBL;
|
|
||||||
lv_obj_t * uic_Static_LBLS_Container;
|
|
||||||
lv_obj_t * uic_Device_State_Container;
|
|
||||||
lv_obj_t * uic_Keyboard;
|
|
||||||
lv_obj_t * uic_Wifi_Passkey_TB;
|
|
||||||
lv_obj_t * uic_Select_SSID_BTN;
|
|
||||||
lv_obj_t * uic_Wifi_Container;
|
|
||||||
lv_obj_t * uic_Enable_Debug_LBL;
|
|
||||||
lv_obj_t * uic_Toggle_Debug_Switch;
|
|
||||||
lv_obj_t * uic_Debug_CTRL_Panel;
|
|
||||||
lv_obj_t * uic_Enable_BLE_LBL;
|
|
||||||
lv_obj_t * uic_Toggle_BLE_Switch;
|
|
||||||
lv_obj_t * uic_BLE_CTRL_Panel;
|
|
||||||
lv_obj_t * uic_Enable_Wifi_LBL;
|
|
||||||
lv_obj_t * uic_Toggle_Wifi_Switch;
|
|
||||||
lv_obj_t * uic_Wifi_CTRL_Panel;
|
|
||||||
lv_obj_t * uic_Enable_UART_LBL;
|
|
||||||
lv_obj_t * uic_Toggle_UART_Switch;
|
|
||||||
lv_obj_t * uic_UART_CTRL_Panel;
|
|
||||||
lv_obj_t * uic_Enable_CAN_Bus_LBL;
|
|
||||||
lv_obj_t * uic_Toggle_CAN_Bus_Switch;
|
|
||||||
lv_obj_t * uic_CAN_Bus_CTRL_Panel;
|
|
||||||
lv_obj_t * uic_Settings_CTRL_Container;
|
|
||||||
lv_obj_t * uic_Main_Container;
|
|
||||||
lv_obj_t * uic_Settings_Screen_LBL;
|
|
||||||
lv_obj_t * uic_Settings_Screen;
|
|
||||||
lv_obj_t * ui_Settings_Screen = NULL;
|
|
||||||
lv_obj_t * ui_Settings_Screen_LBL = NULL;
|
|
||||||
lv_obj_t * ui_Main_Container = NULL;
|
|
||||||
lv_obj_t * ui_Settings_CTRL_Container = NULL;
|
|
||||||
lv_obj_t * ui_CAN_Bus_CTRL_Panel = NULL;
|
|
||||||
lv_obj_t * ui_Toggle_CAN_Bus_Switch = NULL;
|
|
||||||
lv_obj_t * ui_Enable_CAN_Bus_LBL = NULL;
|
|
||||||
lv_obj_t * ui_UART_CTRL_Panel = NULL;
|
|
||||||
lv_obj_t * ui_Toggle_UART_Switch = NULL;
|
|
||||||
lv_obj_t * ui_Enable_UART_LBL = NULL;
|
|
||||||
lv_obj_t * ui_Wifi_CTRL_Panel = NULL;
|
|
||||||
lv_obj_t * ui_Toggle_Wifi_Switch = NULL;
|
|
||||||
lv_obj_t * ui_Enable_Wifi_LBL = NULL;
|
|
||||||
lv_obj_t * ui_BLE_CTRL_Panel = NULL;
|
|
||||||
lv_obj_t * ui_Toggle_BLE_Switch = NULL;
|
|
||||||
lv_obj_t * ui_Enable_BLE_LBL = NULL;
|
|
||||||
lv_obj_t * ui_Debug_CTRL_Panel = NULL;
|
|
||||||
lv_obj_t * ui_Toggle_Debug_Switch = NULL;
|
|
||||||
lv_obj_t * ui_Enable_Debug_LBL = NULL;
|
|
||||||
lv_obj_t * ui_Wifi_Container = NULL;
|
|
||||||
lv_obj_t * ui_Select_SSID_BTN = NULL;
|
|
||||||
lv_obj_t * ui_Wifi_Passkey_TB = NULL;
|
|
||||||
lv_obj_t * ui_Keyboard = NULL;
|
|
||||||
lv_obj_t * ui_Device_State_Container = NULL;
|
|
||||||
lv_obj_t * ui_Static_LBLS_Container = NULL;
|
|
||||||
lv_obj_t * ui_FPS_Static_LBL = NULL;
|
|
||||||
lv_obj_t * ui_CPU_Static_LBL = NULL;
|
|
||||||
lv_obj_t * ui_Device_State_Values_LBL = NULL;
|
|
||||||
lv_obj_t * ui_FPS_Values_LBL = NULL;
|
|
||||||
lv_obj_t * ui_CPU_Values_LBL = NULL;
|
|
||||||
lv_obj_t * ui_Settings_Loading_Container = NULL;
|
|
||||||
lv_obj_t * ui_Settings_Loading_Spinner = NULL;
|
|
||||||
// event funtions
|
|
||||||
void ui_event_Settings_Screen(lv_event_t * e)
|
|
||||||
{
|
|
||||||
lv_event_code_t event_code = lv_event_get_code(e);
|
|
||||||
|
|
||||||
if(event_code == LV_EVENT_GESTURE && lv_indev_get_gesture_dir(lv_indev_get_act()) == LV_DIR_RIGHT) {
|
|
||||||
lv_indev_wait_release(lv_indev_get_act());
|
|
||||||
app_show_driveline(); // Home screen removed; back goes to the Driveline screen
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ui_event_Toggle_UART_Switch(lv_event_t * e)
|
|
||||||
{
|
|
||||||
lv_event_code_t event_code = lv_event_get_code(e);
|
|
||||||
|
|
||||||
if(event_code == LV_EVENT_RELEASED) {
|
|
||||||
onUARTToggle(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ui_event_Toggle_Wifi_Switch(lv_event_t * e)
|
|
||||||
{
|
|
||||||
lv_event_code_t event_code = lv_event_get_code(e);
|
|
||||||
|
|
||||||
if(event_code == LV_EVENT_RELEASED) {
|
|
||||||
onWifiToggle(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ui_event_Toggle_CAN_Bus_Switch(lv_event_t * e)
|
|
||||||
{
|
|
||||||
lv_event_code_t event_code = lv_event_get_code(e);
|
|
||||||
|
|
||||||
if(event_code == LV_EVENT_RELEASED) {
|
|
||||||
onCANBusToggle(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ui_event_Toggle_Debug_Switch(lv_event_t * e)
|
|
||||||
{
|
|
||||||
lv_event_code_t event_code = lv_event_get_code(e);
|
|
||||||
|
|
||||||
if(event_code == LV_EVENT_RELEASED) {
|
|
||||||
onDebugToggle(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ui_event_Select_SSID_BTN(lv_event_t * e)
|
|
||||||
{
|
|
||||||
lv_event_code_t event_code = lv_event_get_code(e);
|
|
||||||
|
|
||||||
if(event_code == LV_EVENT_CLICKED) {
|
|
||||||
onSelectSSID(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// build funtions
|
|
||||||
|
|
||||||
void ui_Settings_Screen_screen_init(void)
|
|
||||||
{
|
|
||||||
ui_Settings_Screen = lv_obj_create(NULL);
|
|
||||||
lv_obj_clear_flag(ui_Settings_Screen, LV_OBJ_FLAG_SCROLLABLE); /// Flags
|
|
||||||
lv_obj_add_event_cb(ui_Settings_Screen, scr_unloaded_delete_cb, LV_EVENT_SCREEN_UNLOADED,
|
|
||||||
ui_Settings_Screen_screen_destroy);
|
|
||||||
|
|
||||||
ui_Settings_Screen_LBL = lv_label_create(ui_Settings_Screen);
|
|
||||||
lv_obj_set_width(ui_Settings_Screen_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_height(ui_Settings_Screen_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_x(ui_Settings_Screen_LBL, -405);
|
|
||||||
lv_obj_set_y(ui_Settings_Screen_LBL, -268);
|
|
||||||
lv_obj_set_align(ui_Settings_Screen_LBL, LV_ALIGN_CENTER);
|
|
||||||
lv_label_set_text(ui_Settings_Screen_LBL, "Settings");
|
|
||||||
lv_obj_set_style_text_font(ui_Settings_Screen_LBL, &lv_font_montserrat_48, LV_PART_MAIN | LV_STATE_DEFAULT);
|
|
||||||
|
|
||||||
ui_Main_Container = lv_obj_create(ui_Settings_Screen);
|
|
||||||
lv_obj_remove_style_all(ui_Main_Container);
|
|
||||||
lv_obj_set_width(ui_Main_Container, 1024);
|
|
||||||
lv_obj_set_height(ui_Main_Container, 530);
|
|
||||||
lv_obj_set_x(ui_Main_Container, 0);
|
|
||||||
lv_obj_set_y(ui_Main_Container, 34);
|
|
||||||
lv_obj_set_align(ui_Main_Container, LV_ALIGN_CENTER);
|
|
||||||
lv_obj_set_flex_flow(ui_Main_Container, LV_FLEX_FLOW_ROW_WRAP);
|
|
||||||
lv_obj_set_flex_align(ui_Main_Container, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER);
|
|
||||||
lv_obj_clear_flag(ui_Main_Container, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE); /// Flags
|
|
||||||
|
|
||||||
ui_Settings_CTRL_Container = lv_obj_create(ui_Main_Container);
|
|
||||||
lv_obj_remove_style_all(ui_Settings_CTRL_Container);
|
|
||||||
lv_obj_set_width(ui_Settings_CTRL_Container, 410);
|
|
||||||
lv_obj_set_height(ui_Settings_CTRL_Container, 530);
|
|
||||||
lv_obj_set_x(ui_Settings_CTRL_Container, -130);
|
|
||||||
lv_obj_set_y(ui_Settings_CTRL_Container, 8);
|
|
||||||
lv_obj_set_align(ui_Settings_CTRL_Container, LV_ALIGN_CENTER);
|
|
||||||
lv_obj_set_flex_flow(ui_Settings_CTRL_Container, LV_FLEX_FLOW_COLUMN);
|
|
||||||
lv_obj_set_flex_align(ui_Settings_CTRL_Container, LV_FLEX_ALIGN_SPACE_AROUND, LV_FLEX_ALIGN_CENTER,
|
|
||||||
LV_FLEX_ALIGN_SPACE_EVENLY);
|
|
||||||
lv_obj_clear_flag(ui_Settings_CTRL_Container, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE); /// Flags
|
|
||||||
|
|
||||||
ui_CAN_Bus_CTRL_Panel = lv_obj_create(ui_Settings_CTRL_Container);
|
|
||||||
lv_obj_set_width(ui_CAN_Bus_CTRL_Panel, 400);
|
|
||||||
lv_obj_set_height(ui_CAN_Bus_CTRL_Panel, 100);
|
|
||||||
lv_obj_set_x(ui_CAN_Bus_CTRL_Panel, 0);
|
|
||||||
lv_obj_set_y(ui_CAN_Bus_CTRL_Panel, 1);
|
|
||||||
lv_obj_set_align(ui_CAN_Bus_CTRL_Panel, LV_ALIGN_CENTER);
|
|
||||||
lv_obj_set_flex_flow(ui_CAN_Bus_CTRL_Panel, LV_FLEX_FLOW_ROW);
|
|
||||||
lv_obj_set_flex_align(ui_CAN_Bus_CTRL_Panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
||||||
lv_obj_clear_flag(ui_CAN_Bus_CTRL_Panel, LV_OBJ_FLAG_SCROLLABLE); /// Flags
|
|
||||||
lv_obj_set_style_bg_color(ui_CAN_Bus_CTRL_Panel, lv_color_hex(0x7F7A9C), LV_PART_MAIN | LV_STATE_DEFAULT);
|
|
||||||
lv_obj_set_style_bg_opa(ui_CAN_Bus_CTRL_Panel, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
|
|
||||||
|
|
||||||
ui_Toggle_CAN_Bus_Switch = lv_switch_create(ui_CAN_Bus_CTRL_Panel);
|
|
||||||
lv_obj_set_width(ui_Toggle_CAN_Bus_Switch, 110);
|
|
||||||
lv_obj_set_height(ui_Toggle_CAN_Bus_Switch, 60);
|
|
||||||
lv_obj_set_x(ui_Toggle_CAN_Bus_Switch, -181);
|
|
||||||
lv_obj_set_y(ui_Toggle_CAN_Bus_Switch, -3);
|
|
||||||
lv_obj_set_align(ui_Toggle_CAN_Bus_Switch, LV_ALIGN_CENTER);
|
|
||||||
|
|
||||||
ui_Enable_CAN_Bus_LBL = lv_label_create(ui_CAN_Bus_CTRL_Panel);
|
|
||||||
lv_obj_set_width(ui_Enable_CAN_Bus_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_height(ui_Enable_CAN_Bus_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_x(ui_Enable_CAN_Bus_LBL, -117);
|
|
||||||
lv_obj_set_y(ui_Enable_CAN_Bus_LBL, -2);
|
|
||||||
lv_obj_set_align(ui_Enable_CAN_Bus_LBL, LV_ALIGN_CENTER);
|
|
||||||
lv_label_set_text(ui_Enable_CAN_Bus_LBL, "Enable CANBus");
|
|
||||||
lv_obj_set_style_text_font(ui_Enable_CAN_Bus_LBL, &lv_font_montserrat_30, LV_PART_MAIN | LV_STATE_DEFAULT);
|
|
||||||
|
|
||||||
ui_UART_CTRL_Panel = lv_obj_create(ui_Settings_CTRL_Container);
|
|
||||||
lv_obj_set_width(ui_UART_CTRL_Panel, 400);
|
|
||||||
lv_obj_set_height(ui_UART_CTRL_Panel, 100);
|
|
||||||
lv_obj_set_x(ui_UART_CTRL_Panel, 0);
|
|
||||||
lv_obj_set_y(ui_UART_CTRL_Panel, 1);
|
|
||||||
lv_obj_set_align(ui_UART_CTRL_Panel, LV_ALIGN_CENTER);
|
|
||||||
lv_obj_set_flex_flow(ui_UART_CTRL_Panel, LV_FLEX_FLOW_ROW);
|
|
||||||
lv_obj_set_flex_align(ui_UART_CTRL_Panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
||||||
lv_obj_clear_flag(ui_UART_CTRL_Panel, LV_OBJ_FLAG_SCROLLABLE); /// Flags
|
|
||||||
ui_object_set_themeable_style_property(ui_UART_CTRL_Panel, LV_PART_MAIN | LV_STATE_DEFAULT, LV_STYLE_BG_COLOR,
|
|
||||||
_ui_theme_color_panel_backgroung);
|
|
||||||
ui_object_set_themeable_style_property(ui_UART_CTRL_Panel, LV_PART_MAIN | LV_STATE_DEFAULT, LV_STYLE_BG_OPA,
|
|
||||||
_ui_theme_alpha_panel_backgroung);
|
|
||||||
|
|
||||||
ui_Toggle_UART_Switch = lv_switch_create(ui_UART_CTRL_Panel);
|
|
||||||
lv_obj_set_width(ui_Toggle_UART_Switch, 110);
|
|
||||||
lv_obj_set_height(ui_Toggle_UART_Switch, 60);
|
|
||||||
lv_obj_set_x(ui_Toggle_UART_Switch, -181);
|
|
||||||
lv_obj_set_y(ui_Toggle_UART_Switch, -3);
|
|
||||||
lv_obj_set_align(ui_Toggle_UART_Switch, LV_ALIGN_CENTER);
|
|
||||||
|
|
||||||
ui_Enable_UART_LBL = lv_label_create(ui_UART_CTRL_Panel);
|
|
||||||
lv_obj_set_width(ui_Enable_UART_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_height(ui_Enable_UART_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_x(ui_Enable_UART_LBL, -117);
|
|
||||||
lv_obj_set_y(ui_Enable_UART_LBL, -2);
|
|
||||||
lv_obj_set_align(ui_Enable_UART_LBL, LV_ALIGN_CENTER);
|
|
||||||
lv_label_set_text(ui_Enable_UART_LBL, "Enable UART");
|
|
||||||
lv_obj_set_style_text_font(ui_Enable_UART_LBL, &lv_font_montserrat_30, LV_PART_MAIN | LV_STATE_DEFAULT);
|
|
||||||
|
|
||||||
ui_Wifi_CTRL_Panel = lv_obj_create(ui_Settings_CTRL_Container);
|
|
||||||
lv_obj_set_width(ui_Wifi_CTRL_Panel, 405);
|
|
||||||
lv_obj_set_height(ui_Wifi_CTRL_Panel, 100);
|
|
||||||
lv_obj_set_x(ui_Wifi_CTRL_Panel, 0);
|
|
||||||
lv_obj_set_y(ui_Wifi_CTRL_Panel, 1);
|
|
||||||
lv_obj_set_align(ui_Wifi_CTRL_Panel, LV_ALIGN_CENTER);
|
|
||||||
lv_obj_set_flex_flow(ui_Wifi_CTRL_Panel, LV_FLEX_FLOW_ROW);
|
|
||||||
lv_obj_set_flex_align(ui_Wifi_CTRL_Panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
||||||
lv_obj_clear_flag(ui_Wifi_CTRL_Panel, LV_OBJ_FLAG_SCROLLABLE); /// Flags
|
|
||||||
ui_object_set_themeable_style_property(ui_Wifi_CTRL_Panel, LV_PART_MAIN | LV_STATE_DEFAULT, LV_STYLE_BG_COLOR,
|
|
||||||
_ui_theme_color_panel_backgroung);
|
|
||||||
ui_object_set_themeable_style_property(ui_Wifi_CTRL_Panel, LV_PART_MAIN | LV_STATE_DEFAULT, LV_STYLE_BG_OPA,
|
|
||||||
_ui_theme_alpha_panel_backgroung);
|
|
||||||
|
|
||||||
ui_Toggle_Wifi_Switch = lv_switch_create(ui_Wifi_CTRL_Panel);
|
|
||||||
lv_obj_set_width(ui_Toggle_Wifi_Switch, 110);
|
|
||||||
lv_obj_set_height(ui_Toggle_Wifi_Switch, 60);
|
|
||||||
lv_obj_set_x(ui_Toggle_Wifi_Switch, -181);
|
|
||||||
lv_obj_set_y(ui_Toggle_Wifi_Switch, -3);
|
|
||||||
lv_obj_set_align(ui_Toggle_Wifi_Switch, LV_ALIGN_CENTER);
|
|
||||||
lv_obj_add_state(ui_Toggle_Wifi_Switch, LV_STATE_DISABLED); /// States
|
|
||||||
|
|
||||||
ui_Enable_Wifi_LBL = lv_label_create(ui_Wifi_CTRL_Panel);
|
|
||||||
lv_obj_set_width(ui_Enable_Wifi_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_height(ui_Enable_Wifi_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_x(ui_Enable_Wifi_LBL, -117);
|
|
||||||
lv_obj_set_y(ui_Enable_Wifi_LBL, -2);
|
|
||||||
lv_obj_set_align(ui_Enable_Wifi_LBL, LV_ALIGN_CENTER);
|
|
||||||
lv_label_set_text(ui_Enable_Wifi_LBL, "Enable Wifi");
|
|
||||||
lv_obj_set_style_text_font(ui_Enable_Wifi_LBL, &lv_font_montserrat_30, LV_PART_MAIN | LV_STATE_DEFAULT);
|
|
||||||
|
|
||||||
ui_BLE_CTRL_Panel = lv_obj_create(ui_Settings_CTRL_Container);
|
|
||||||
lv_obj_set_width(ui_BLE_CTRL_Panel, 400);
|
|
||||||
lv_obj_set_height(ui_BLE_CTRL_Panel, 100);
|
|
||||||
lv_obj_set_x(ui_BLE_CTRL_Panel, 0);
|
|
||||||
lv_obj_set_y(ui_BLE_CTRL_Panel, 1);
|
|
||||||
lv_obj_set_align(ui_BLE_CTRL_Panel, LV_ALIGN_CENTER);
|
|
||||||
lv_obj_set_flex_flow(ui_BLE_CTRL_Panel, LV_FLEX_FLOW_ROW);
|
|
||||||
lv_obj_set_flex_align(ui_BLE_CTRL_Panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
||||||
lv_obj_clear_flag(ui_BLE_CTRL_Panel, LV_OBJ_FLAG_SCROLLABLE); /// Flags
|
|
||||||
ui_object_set_themeable_style_property(ui_BLE_CTRL_Panel, LV_PART_MAIN | LV_STATE_DEFAULT, LV_STYLE_BG_COLOR,
|
|
||||||
_ui_theme_color_panel_backgroung);
|
|
||||||
ui_object_set_themeable_style_property(ui_BLE_CTRL_Panel, LV_PART_MAIN | LV_STATE_DEFAULT, LV_STYLE_BG_OPA,
|
|
||||||
_ui_theme_alpha_panel_backgroung);
|
|
||||||
|
|
||||||
ui_Toggle_BLE_Switch = lv_switch_create(ui_BLE_CTRL_Panel);
|
|
||||||
lv_obj_set_width(ui_Toggle_BLE_Switch, 110);
|
|
||||||
lv_obj_set_height(ui_Toggle_BLE_Switch, 60);
|
|
||||||
lv_obj_set_x(ui_Toggle_BLE_Switch, -181);
|
|
||||||
lv_obj_set_y(ui_Toggle_BLE_Switch, -3);
|
|
||||||
lv_obj_set_align(ui_Toggle_BLE_Switch, LV_ALIGN_CENTER);
|
|
||||||
lv_obj_add_state(ui_Toggle_BLE_Switch, LV_STATE_DISABLED); /// States
|
|
||||||
|
|
||||||
ui_Enable_BLE_LBL = lv_label_create(ui_BLE_CTRL_Panel);
|
|
||||||
lv_obj_set_width(ui_Enable_BLE_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_height(ui_Enable_BLE_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_x(ui_Enable_BLE_LBL, -117);
|
|
||||||
lv_obj_set_y(ui_Enable_BLE_LBL, -2);
|
|
||||||
lv_obj_set_align(ui_Enable_BLE_LBL, LV_ALIGN_CENTER);
|
|
||||||
lv_label_set_text(ui_Enable_BLE_LBL, "Enable BLE");
|
|
||||||
lv_obj_set_style_text_font(ui_Enable_BLE_LBL, &lv_font_montserrat_30, LV_PART_MAIN | LV_STATE_DEFAULT);
|
|
||||||
|
|
||||||
ui_Debug_CTRL_Panel = lv_obj_create(ui_Settings_CTRL_Container);
|
|
||||||
lv_obj_set_width(ui_Debug_CTRL_Panel, 400);
|
|
||||||
lv_obj_set_height(ui_Debug_CTRL_Panel, 100);
|
|
||||||
lv_obj_set_x(ui_Debug_CTRL_Panel, 0);
|
|
||||||
lv_obj_set_y(ui_Debug_CTRL_Panel, 1);
|
|
||||||
lv_obj_set_align(ui_Debug_CTRL_Panel, LV_ALIGN_CENTER);
|
|
||||||
lv_obj_set_flex_flow(ui_Debug_CTRL_Panel, LV_FLEX_FLOW_ROW);
|
|
||||||
lv_obj_set_flex_align(ui_Debug_CTRL_Panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
||||||
lv_obj_clear_flag(ui_Debug_CTRL_Panel, LV_OBJ_FLAG_SCROLLABLE); /// Flags
|
|
||||||
ui_object_set_themeable_style_property(ui_Debug_CTRL_Panel, LV_PART_MAIN | LV_STATE_DEFAULT, LV_STYLE_BG_COLOR,
|
|
||||||
_ui_theme_color_panel_backgroung);
|
|
||||||
ui_object_set_themeable_style_property(ui_Debug_CTRL_Panel, LV_PART_MAIN | LV_STATE_DEFAULT, LV_STYLE_BG_OPA,
|
|
||||||
_ui_theme_alpha_panel_backgroung);
|
|
||||||
|
|
||||||
ui_Toggle_Debug_Switch = lv_switch_create(ui_Debug_CTRL_Panel);
|
|
||||||
lv_obj_set_width(ui_Toggle_Debug_Switch, 110);
|
|
||||||
lv_obj_set_height(ui_Toggle_Debug_Switch, 60);
|
|
||||||
lv_obj_set_x(ui_Toggle_Debug_Switch, -181);
|
|
||||||
lv_obj_set_y(ui_Toggle_Debug_Switch, -3);
|
|
||||||
lv_obj_set_align(ui_Toggle_Debug_Switch, LV_ALIGN_CENTER);
|
|
||||||
|
|
||||||
ui_Enable_Debug_LBL = lv_label_create(ui_Debug_CTRL_Panel);
|
|
||||||
lv_obj_set_width(ui_Enable_Debug_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_height(ui_Enable_Debug_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_x(ui_Enable_Debug_LBL, -117);
|
|
||||||
lv_obj_set_y(ui_Enable_Debug_LBL, -2);
|
|
||||||
lv_obj_set_align(ui_Enable_Debug_LBL, LV_ALIGN_CENTER);
|
|
||||||
lv_label_set_text(ui_Enable_Debug_LBL, "Enable Debug");
|
|
||||||
lv_obj_set_style_text_font(ui_Enable_Debug_LBL, &lv_font_montserrat_30, LV_PART_MAIN | LV_STATE_DEFAULT);
|
|
||||||
|
|
||||||
ui_Wifi_Container = lv_obj_create(ui_Main_Container);
|
|
||||||
lv_obj_remove_style_all(ui_Wifi_Container);
|
|
||||||
lv_obj_set_width(ui_Wifi_Container, 610);
|
|
||||||
lv_obj_set_height(ui_Wifi_Container, 530);
|
|
||||||
lv_obj_set_x(ui_Wifi_Container, -100);
|
|
||||||
lv_obj_set_y(ui_Wifi_Container, 8);
|
|
||||||
lv_obj_set_align(ui_Wifi_Container, LV_ALIGN_CENTER);
|
|
||||||
lv_obj_set_flex_flow(ui_Wifi_Container, LV_FLEX_FLOW_COLUMN);
|
|
||||||
lv_obj_set_flex_align(ui_Wifi_Container, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START);
|
|
||||||
lv_obj_clear_flag(ui_Wifi_Container, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE); /// Flags
|
|
||||||
|
|
||||||
ui_Select_SSID_BTN = lv_btn_create(ui_Wifi_Container);
|
|
||||||
lv_obj_set_width(ui_Select_SSID_BTN, 668);
|
|
||||||
lv_obj_set_height(ui_Select_SSID_BTN, 50);
|
|
||||||
lv_obj_set_x(ui_Select_SSID_BTN, 7);
|
|
||||||
lv_obj_set_y(ui_Select_SSID_BTN, -4);
|
|
||||||
lv_obj_set_align(ui_Select_SSID_BTN, LV_ALIGN_CENTER);
|
|
||||||
lv_obj_add_flag(ui_Select_SSID_BTN, LV_OBJ_FLAG_HIDDEN); /// Flags
|
|
||||||
lv_obj_set_style_bg_color(ui_Select_SSID_BTN, lv_color_hex(0x7F7A9C), LV_PART_MAIN | LV_STATE_DEFAULT);
|
|
||||||
lv_obj_set_style_bg_opa(ui_Select_SSID_BTN, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
|
|
||||||
|
|
||||||
ui_Wifi_Passkey_TB = lv_textarea_create(ui_Wifi_Container);
|
|
||||||
lv_obj_set_width(ui_Wifi_Passkey_TB, 200);
|
|
||||||
lv_obj_set_height(ui_Wifi_Passkey_TB, LV_SIZE_CONTENT); /// 70
|
|
||||||
lv_obj_set_x(ui_Wifi_Passkey_TB, 129);
|
|
||||||
lv_obj_set_y(ui_Wifi_Passkey_TB, -173);
|
|
||||||
lv_obj_set_align(ui_Wifi_Passkey_TB, LV_ALIGN_CENTER);
|
|
||||||
lv_textarea_set_placeholder_text(ui_Wifi_Passkey_TB, "Placeholder...");
|
|
||||||
lv_textarea_set_one_line(ui_Wifi_Passkey_TB, true);
|
|
||||||
lv_obj_add_flag(ui_Wifi_Passkey_TB, LV_OBJ_FLAG_HIDDEN); /// Flags
|
|
||||||
|
|
||||||
ui_Keyboard = lv_keyboard_create(ui_Settings_Screen);
|
|
||||||
lv_obj_set_width(ui_Keyboard, 1012);
|
|
||||||
lv_obj_set_height(ui_Keyboard, 268);
|
|
||||||
lv_obj_set_x(ui_Keyboard, 3);
|
|
||||||
lv_obj_set_y(ui_Keyboard, 161);
|
|
||||||
lv_obj_set_align(ui_Keyboard, LV_ALIGN_CENTER);
|
|
||||||
lv_obj_add_flag(ui_Keyboard, LV_OBJ_FLAG_HIDDEN); /// Flags
|
|
||||||
|
|
||||||
ui_Device_State_Container = lv_obj_create(ui_Settings_Screen);
|
|
||||||
lv_obj_remove_style_all(ui_Device_State_Container);
|
|
||||||
lv_obj_set_width(ui_Device_State_Container, 75);
|
|
||||||
lv_obj_set_height(ui_Device_State_Container, 30);
|
|
||||||
lv_obj_set_x(ui_Device_State_Container, 470);
|
|
||||||
lv_obj_set_y(ui_Device_State_Container, -282);
|
|
||||||
lv_obj_set_align(ui_Device_State_Container, LV_ALIGN_CENTER);
|
|
||||||
lv_obj_set_flex_flow(ui_Device_State_Container, LV_FLEX_FLOW_ROW);
|
|
||||||
lv_obj_set_flex_align(ui_Device_State_Container, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START);
|
|
||||||
lv_obj_add_flag(ui_Device_State_Container, LV_OBJ_FLAG_HIDDEN); /// Flags
|
|
||||||
lv_obj_clear_flag(ui_Device_State_Container, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE); /// Flags
|
|
||||||
|
|
||||||
ui_Static_LBLS_Container = lv_obj_create(ui_Device_State_Container);
|
|
||||||
lv_obj_remove_style_all(ui_Static_LBLS_Container);
|
|
||||||
lv_obj_set_width(ui_Static_LBLS_Container, 35);
|
|
||||||
lv_obj_set_height(ui_Static_LBLS_Container, 30);
|
|
||||||
lv_obj_set_align(ui_Static_LBLS_Container, LV_ALIGN_CENTER);
|
|
||||||
lv_obj_set_flex_flow(ui_Static_LBLS_Container, LV_FLEX_FLOW_COLUMN);
|
|
||||||
lv_obj_set_flex_align(ui_Static_LBLS_Container, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_END, LV_FLEX_ALIGN_START);
|
|
||||||
lv_obj_clear_flag(ui_Static_LBLS_Container, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE); /// Flags
|
|
||||||
|
|
||||||
ui_FPS_Static_LBL = lv_label_create(ui_Static_LBLS_Container);
|
|
||||||
lv_obj_set_width(ui_FPS_Static_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_height(ui_FPS_Static_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_x(ui_FPS_Static_LBL, -176);
|
|
||||||
lv_obj_set_y(ui_FPS_Static_LBL, 34);
|
|
||||||
lv_obj_set_align(ui_FPS_Static_LBL, LV_ALIGN_CENTER);
|
|
||||||
lv_label_set_text(ui_FPS_Static_LBL, "FPS:");
|
|
||||||
|
|
||||||
ui_CPU_Static_LBL = lv_label_create(ui_Static_LBLS_Container);
|
|
||||||
lv_obj_set_width(ui_CPU_Static_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_height(ui_CPU_Static_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_x(ui_CPU_Static_LBL, -1);
|
|
||||||
lv_obj_set_y(ui_CPU_Static_LBL, -1);
|
|
||||||
lv_obj_set_align(ui_CPU_Static_LBL, LV_ALIGN_CENTER);
|
|
||||||
lv_label_set_text(ui_CPU_Static_LBL, "CPU:");
|
|
||||||
|
|
||||||
ui_Device_State_Values_LBL = lv_obj_create(ui_Device_State_Container);
|
|
||||||
lv_obj_remove_style_all(ui_Device_State_Values_LBL);
|
|
||||||
lv_obj_set_width(ui_Device_State_Values_LBL, 35);
|
|
||||||
lv_obj_set_height(ui_Device_State_Values_LBL, 30);
|
|
||||||
lv_obj_set_align(ui_Device_State_Values_LBL, LV_ALIGN_CENTER);
|
|
||||||
lv_obj_set_flex_flow(ui_Device_State_Values_LBL, LV_FLEX_FLOW_COLUMN);
|
|
||||||
lv_obj_set_flex_align(ui_Device_State_Values_LBL, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START);
|
|
||||||
lv_obj_clear_flag(ui_Device_State_Values_LBL, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE); /// Flags
|
|
||||||
|
|
||||||
ui_FPS_Values_LBL = lv_label_create(ui_Device_State_Values_LBL);
|
|
||||||
lv_obj_set_width(ui_FPS_Values_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_height(ui_FPS_Values_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_x(ui_FPS_Values_LBL, -176);
|
|
||||||
lv_obj_set_y(ui_FPS_Values_LBL, 34);
|
|
||||||
lv_obj_set_align(ui_FPS_Values_LBL, LV_ALIGN_CENTER);
|
|
||||||
lv_label_set_text(ui_FPS_Values_LBL, "0");
|
|
||||||
|
|
||||||
ui_CPU_Values_LBL = lv_label_create(ui_Device_State_Values_LBL);
|
|
||||||
lv_obj_set_width(ui_CPU_Values_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_height(ui_CPU_Values_LBL, LV_SIZE_CONTENT); /// 1
|
|
||||||
lv_obj_set_x(ui_CPU_Values_LBL, -1);
|
|
||||||
lv_obj_set_y(ui_CPU_Values_LBL, -1);
|
|
||||||
lv_obj_set_align(ui_CPU_Values_LBL, LV_ALIGN_CENTER);
|
|
||||||
lv_label_set_text(ui_CPU_Values_LBL, "0%");
|
|
||||||
|
|
||||||
ui_Settings_Loading_Container = lv_obj_create(ui_Settings_Screen);
|
|
||||||
lv_obj_remove_style_all(ui_Settings_Loading_Container);
|
|
||||||
lv_obj_set_width(ui_Settings_Loading_Container, 1024);
|
|
||||||
lv_obj_set_height(ui_Settings_Loading_Container, 600);
|
|
||||||
lv_obj_set_align(ui_Settings_Loading_Container, LV_ALIGN_CENTER);
|
|
||||||
lv_obj_set_flex_flow(ui_Settings_Loading_Container, LV_FLEX_FLOW_ROW);
|
|
||||||
lv_obj_set_flex_align(ui_Settings_Loading_Container, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
||||||
lv_obj_clear_flag(ui_Settings_Loading_Container, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE); /// Flags
|
|
||||||
|
|
||||||
ui_Settings_Loading_Spinner = lv_spinner_create(ui_Settings_Loading_Container, 1000, 90);
|
|
||||||
lv_obj_set_width(ui_Settings_Loading_Spinner, 80);
|
|
||||||
lv_obj_set_height(ui_Settings_Loading_Spinner, 80);
|
|
||||||
lv_obj_set_x(ui_Settings_Loading_Spinner, -22);
|
|
||||||
lv_obj_set_y(ui_Settings_Loading_Spinner, -22);
|
|
||||||
lv_obj_set_align(ui_Settings_Loading_Spinner, LV_ALIGN_CENTER);
|
|
||||||
lv_obj_add_flag(ui_Settings_Loading_Spinner, LV_OBJ_FLAG_HIDDEN); /// Flags
|
|
||||||
lv_obj_clear_flag(ui_Settings_Loading_Spinner, LV_OBJ_FLAG_CLICKABLE); /// Flags
|
|
||||||
|
|
||||||
lv_obj_add_event_cb(ui_Toggle_UART_Switch, ui_event_Toggle_UART_Switch, LV_EVENT_ALL, NULL);
|
|
||||||
lv_obj_add_event_cb(ui_Toggle_Wifi_Switch, ui_event_Toggle_Wifi_Switch, LV_EVENT_ALL, NULL);
|
|
||||||
lv_obj_add_event_cb(ui_Toggle_CAN_Bus_Switch, ui_event_Toggle_CAN_Bus_Switch, LV_EVENT_ALL, NULL);
|
|
||||||
lv_obj_add_event_cb(ui_Toggle_Debug_Switch, ui_event_Toggle_Debug_Switch, LV_EVENT_ALL, NULL);
|
|
||||||
lv_obj_add_event_cb(ui_Select_SSID_BTN, ui_event_Select_SSID_BTN, LV_EVENT_ALL, NULL);
|
|
||||||
lv_obj_add_event_cb(ui_Settings_Screen, ui_event_Settings_Screen, LV_EVENT_ALL, NULL);
|
|
||||||
uic_Settings_Screen = ui_Settings_Screen;
|
|
||||||
uic_Settings_Screen_LBL = ui_Settings_Screen_LBL;
|
|
||||||
uic_Main_Container = ui_Main_Container;
|
|
||||||
uic_Settings_CTRL_Container = ui_Settings_CTRL_Container;
|
|
||||||
uic_CAN_Bus_CTRL_Panel = ui_CAN_Bus_CTRL_Panel;
|
|
||||||
uic_Toggle_CAN_Bus_Switch = ui_Toggle_CAN_Bus_Switch;
|
|
||||||
uic_Enable_CAN_Bus_LBL = ui_Enable_CAN_Bus_LBL;
|
|
||||||
uic_UART_CTRL_Panel = ui_UART_CTRL_Panel;
|
|
||||||
uic_Toggle_UART_Switch = ui_Toggle_UART_Switch;
|
|
||||||
uic_Enable_UART_LBL = ui_Enable_UART_LBL;
|
|
||||||
uic_Wifi_CTRL_Panel = ui_Wifi_CTRL_Panel;
|
|
||||||
uic_Toggle_Wifi_Switch = ui_Toggle_Wifi_Switch;
|
|
||||||
uic_Enable_Wifi_LBL = ui_Enable_Wifi_LBL;
|
|
||||||
uic_BLE_CTRL_Panel = ui_BLE_CTRL_Panel;
|
|
||||||
uic_Toggle_BLE_Switch = ui_Toggle_BLE_Switch;
|
|
||||||
uic_Enable_BLE_LBL = ui_Enable_BLE_LBL;
|
|
||||||
uic_Debug_CTRL_Panel = ui_Debug_CTRL_Panel;
|
|
||||||
uic_Toggle_Debug_Switch = ui_Toggle_Debug_Switch;
|
|
||||||
uic_Enable_Debug_LBL = ui_Enable_Debug_LBL;
|
|
||||||
uic_Wifi_Container = ui_Wifi_Container;
|
|
||||||
uic_Select_SSID_BTN = ui_Select_SSID_BTN;
|
|
||||||
uic_Wifi_Passkey_TB = ui_Wifi_Passkey_TB;
|
|
||||||
uic_Keyboard = ui_Keyboard;
|
|
||||||
uic_Device_State_Container = ui_Device_State_Container;
|
|
||||||
uic_Static_LBLS_Container = ui_Static_LBLS_Container;
|
|
||||||
uic_FPS_Static_LBL = ui_FPS_Static_LBL;
|
|
||||||
uic_CPU_Static_LBL = ui_CPU_Static_LBL;
|
|
||||||
uic_Device_State_Values_LBL = ui_Device_State_Values_LBL;
|
|
||||||
uic_FPS_Values_LBL = ui_FPS_Values_LBL;
|
|
||||||
uic_CPU_Values_LBL = ui_CPU_Values_LBL;
|
|
||||||
uic_Settings_Loading_Container = ui_Settings_Loading_Container;
|
|
||||||
uic_Settings_Loading_Spinner = ui_Settings_Loading_Spinner;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ui_Settings_Screen_screen_destroy(void)
|
|
||||||
{
|
|
||||||
if(ui_Settings_Screen) lv_obj_del(ui_Settings_Screen);
|
|
||||||
|
|
||||||
// NULL screen variables
|
|
||||||
uic_Settings_Screen = NULL;
|
|
||||||
ui_Settings_Screen = NULL;
|
|
||||||
uic_Settings_Screen_LBL = NULL;
|
|
||||||
ui_Settings_Screen_LBL = NULL;
|
|
||||||
uic_Main_Container = NULL;
|
|
||||||
ui_Main_Container = NULL;
|
|
||||||
uic_Settings_CTRL_Container = NULL;
|
|
||||||
ui_Settings_CTRL_Container = NULL;
|
|
||||||
uic_CAN_Bus_CTRL_Panel = NULL;
|
|
||||||
ui_CAN_Bus_CTRL_Panel = NULL;
|
|
||||||
uic_Toggle_CAN_Bus_Switch = NULL;
|
|
||||||
ui_Toggle_CAN_Bus_Switch = NULL;
|
|
||||||
uic_Enable_CAN_Bus_LBL = NULL;
|
|
||||||
ui_Enable_CAN_Bus_LBL = NULL;
|
|
||||||
uic_UART_CTRL_Panel = NULL;
|
|
||||||
ui_UART_CTRL_Panel = NULL;
|
|
||||||
uic_Toggle_UART_Switch = NULL;
|
|
||||||
ui_Toggle_UART_Switch = NULL;
|
|
||||||
uic_Enable_UART_LBL = NULL;
|
|
||||||
ui_Enable_UART_LBL = NULL;
|
|
||||||
uic_Wifi_CTRL_Panel = NULL;
|
|
||||||
ui_Wifi_CTRL_Panel = NULL;
|
|
||||||
uic_Toggle_Wifi_Switch = NULL;
|
|
||||||
ui_Toggle_Wifi_Switch = NULL;
|
|
||||||
uic_Enable_Wifi_LBL = NULL;
|
|
||||||
ui_Enable_Wifi_LBL = NULL;
|
|
||||||
uic_BLE_CTRL_Panel = NULL;
|
|
||||||
ui_BLE_CTRL_Panel = NULL;
|
|
||||||
uic_Toggle_BLE_Switch = NULL;
|
|
||||||
ui_Toggle_BLE_Switch = NULL;
|
|
||||||
uic_Enable_BLE_LBL = NULL;
|
|
||||||
ui_Enable_BLE_LBL = NULL;
|
|
||||||
uic_Debug_CTRL_Panel = NULL;
|
|
||||||
ui_Debug_CTRL_Panel = NULL;
|
|
||||||
uic_Toggle_Debug_Switch = NULL;
|
|
||||||
ui_Toggle_Debug_Switch = NULL;
|
|
||||||
uic_Enable_Debug_LBL = NULL;
|
|
||||||
ui_Enable_Debug_LBL = NULL;
|
|
||||||
uic_Wifi_Container = NULL;
|
|
||||||
ui_Wifi_Container = NULL;
|
|
||||||
uic_Select_SSID_BTN = NULL;
|
|
||||||
ui_Select_SSID_BTN = NULL;
|
|
||||||
uic_Wifi_Passkey_TB = NULL;
|
|
||||||
ui_Wifi_Passkey_TB = NULL;
|
|
||||||
uic_Keyboard = NULL;
|
|
||||||
ui_Keyboard = NULL;
|
|
||||||
uic_Device_State_Container = NULL;
|
|
||||||
ui_Device_State_Container = NULL;
|
|
||||||
uic_Static_LBLS_Container = NULL;
|
|
||||||
ui_Static_LBLS_Container = NULL;
|
|
||||||
uic_FPS_Static_LBL = NULL;
|
|
||||||
ui_FPS_Static_LBL = NULL;
|
|
||||||
uic_CPU_Static_LBL = NULL;
|
|
||||||
ui_CPU_Static_LBL = NULL;
|
|
||||||
uic_Device_State_Values_LBL = NULL;
|
|
||||||
ui_Device_State_Values_LBL = NULL;
|
|
||||||
uic_FPS_Values_LBL = NULL;
|
|
||||||
ui_FPS_Values_LBL = NULL;
|
|
||||||
uic_CPU_Values_LBL = NULL;
|
|
||||||
ui_CPU_Values_LBL = NULL;
|
|
||||||
uic_Settings_Loading_Container = NULL;
|
|
||||||
ui_Settings_Loading_Container = NULL;
|
|
||||||
uic_Settings_Loading_Spinner = NULL;
|
|
||||||
ui_Settings_Loading_Spinner = NULL;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
// This file was generated by SquareLine Studio
|
|
||||||
// SquareLine Studio version: SquareLine Studio 1.5.4
|
|
||||||
// LVGL version: 8.3.6
|
|
||||||
// Project name: ESP32-S3-Touch-LCD-5B
|
|
||||||
|
|
||||||
#ifndef UI_SETTINGS_SCREEN_H
|
|
||||||
#define UI_SETTINGS_SCREEN_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// SCREEN: ui_Settings_Screen
|
|
||||||
extern void ui_Settings_Screen_screen_init(void);
|
|
||||||
extern void ui_Settings_Screen_screen_destroy(void);
|
|
||||||
extern void ui_event_Settings_Screen(lv_event_t * e);
|
|
||||||
extern lv_obj_t * ui_Settings_Screen;
|
|
||||||
extern lv_obj_t * ui_Settings_Screen_LBL;
|
|
||||||
extern lv_obj_t * ui_Main_Container;
|
|
||||||
extern lv_obj_t * ui_Settings_CTRL_Container;
|
|
||||||
extern lv_obj_t * ui_CAN_Bus_CTRL_Panel;
|
|
||||||
extern lv_obj_t * ui_Toggle_CAN_Bus_Switch;
|
|
||||||
extern lv_obj_t * ui_Enable_CAN_Bus_LBL;
|
|
||||||
extern lv_obj_t * ui_UART_CTRL_Panel;
|
|
||||||
extern void ui_event_Toggle_UART_Switch(lv_event_t * e);
|
|
||||||
extern lv_obj_t * ui_Toggle_UART_Switch;
|
|
||||||
extern lv_obj_t * ui_Enable_UART_LBL;
|
|
||||||
extern lv_obj_t * ui_Wifi_CTRL_Panel;
|
|
||||||
extern void ui_event_Toggle_Wifi_Switch(lv_event_t * e);
|
|
||||||
extern lv_obj_t * ui_Toggle_Wifi_Switch;
|
|
||||||
extern lv_obj_t * ui_Enable_Wifi_LBL;
|
|
||||||
extern lv_obj_t * ui_BLE_CTRL_Panel;
|
|
||||||
extern lv_obj_t * ui_Toggle_BLE_Switch;
|
|
||||||
extern lv_obj_t * ui_Enable_BLE_LBL;
|
|
||||||
extern lv_obj_t * ui_Debug_CTRL_Panel;
|
|
||||||
extern void ui_event_Toggle_Debug_Switch(lv_event_t * e);
|
|
||||||
extern lv_obj_t * ui_Toggle_Debug_Switch;
|
|
||||||
extern lv_obj_t * ui_Enable_Debug_LBL;
|
|
||||||
extern lv_obj_t * ui_Wifi_Container;
|
|
||||||
extern void ui_event_Select_SSID_BTN(lv_event_t * e);
|
|
||||||
extern lv_obj_t * ui_Select_SSID_BTN;
|
|
||||||
extern lv_obj_t * ui_Wifi_Passkey_TB;
|
|
||||||
extern lv_obj_t * ui_Keyboard;
|
|
||||||
extern lv_obj_t * ui_Device_State_Container;
|
|
||||||
extern lv_obj_t * ui_Static_LBLS_Container;
|
|
||||||
extern lv_obj_t * ui_FPS_Static_LBL;
|
|
||||||
extern lv_obj_t * ui_CPU_Static_LBL;
|
|
||||||
extern lv_obj_t * ui_Device_State_Values_LBL;
|
|
||||||
extern lv_obj_t * ui_FPS_Values_LBL;
|
|
||||||
extern lv_obj_t * ui_CPU_Values_LBL;
|
|
||||||
extern lv_obj_t * ui_Settings_Loading_Container;
|
|
||||||
extern lv_obj_t * ui_Settings_Loading_Spinner;
|
|
||||||
// CUSTOM VARIABLES
|
|
||||||
extern lv_obj_t * uic_Settings_Screen;
|
|
||||||
extern lv_obj_t * uic_Settings_Screen_LBL;
|
|
||||||
extern lv_obj_t * uic_Main_Container;
|
|
||||||
extern lv_obj_t * uic_Settings_CTRL_Container;
|
|
||||||
extern lv_obj_t * uic_CAN_Bus_CTRL_Panel;
|
|
||||||
extern lv_obj_t * uic_Toggle_CAN_Bus_Switch;
|
|
||||||
extern lv_obj_t * uic_Enable_CAN_Bus_LBL;
|
|
||||||
extern lv_obj_t * uic_UART_CTRL_Panel;
|
|
||||||
extern lv_obj_t * uic_Toggle_UART_Switch;
|
|
||||||
extern lv_obj_t * uic_Enable_UART_LBL;
|
|
||||||
extern lv_obj_t * uic_Wifi_CTRL_Panel;
|
|
||||||
extern lv_obj_t * uic_Toggle_Wifi_Switch;
|
|
||||||
extern lv_obj_t * uic_Enable_Wifi_LBL;
|
|
||||||
extern lv_obj_t * uic_BLE_CTRL_Panel;
|
|
||||||
extern lv_obj_t * uic_Toggle_BLE_Switch;
|
|
||||||
extern lv_obj_t * uic_Enable_BLE_LBL;
|
|
||||||
extern lv_obj_t * uic_Debug_CTRL_Panel;
|
|
||||||
extern lv_obj_t * uic_Toggle_Debug_Switch;
|
|
||||||
extern lv_obj_t * uic_Enable_Debug_LBL;
|
|
||||||
extern lv_obj_t * uic_Wifi_Container;
|
|
||||||
extern lv_obj_t * uic_Select_SSID_BTN;
|
|
||||||
extern lv_obj_t * uic_Wifi_Passkey_TB;
|
|
||||||
extern lv_obj_t * uic_Keyboard;
|
|
||||||
extern lv_obj_t * uic_Device_State_Container;
|
|
||||||
extern lv_obj_t * uic_Static_LBLS_Container;
|
|
||||||
extern lv_obj_t * uic_FPS_Static_LBL;
|
|
||||||
extern lv_obj_t * uic_CPU_Static_LBL;
|
|
||||||
extern lv_obj_t * uic_Device_State_Values_LBL;
|
|
||||||
extern lv_obj_t * uic_FPS_Values_LBL;
|
|
||||||
extern lv_obj_t * uic_CPU_Values_LBL;
|
|
||||||
extern lv_obj_t * uic_Settings_Loading_Container;
|
|
||||||
extern lv_obj_t * uic_Settings_Loading_Spinner;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
} /*extern "C"*/
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
+2
-4
@@ -33,14 +33,12 @@ void ui_init(void)
|
|||||||
lv_theme_t * theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED),
|
lv_theme_t * theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED),
|
||||||
true, LV_FONT_DEFAULT);
|
true, LV_FONT_DEFAULT);
|
||||||
lv_disp_set_theme(dispp, theme);
|
lv_disp_set_theme(dispp, theme);
|
||||||
// Home screen removed (2026-09-21): the firmware boots into the hand-coded
|
// Home (2026-09-21) and Settings (2026-09-27) screens removed: every screen
|
||||||
// Driveline screen (DrivelineScreen::show() in display_init.cpp). Settings is
|
// is hand-coded in src/modules; display_init.cpp shows the Driveline screen.
|
||||||
// created lazily by _ui_screen_change() when swiped to.
|
|
||||||
ui____initial_actions0 = lv_obj_create(NULL);
|
ui____initial_actions0 = lv_obj_create(NULL);
|
||||||
lv_disp_load_scr(ui____initial_actions0);
|
lv_disp_load_scr(ui____initial_actions0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_destroy(void)
|
void ui_destroy(void)
|
||||||
{
|
{
|
||||||
ui_Settings_Screen_screen_destroy();
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -28,7 +28,8 @@ extern "C" {
|
|||||||
#include "ui_themes.h"
|
#include "ui_themes.h"
|
||||||
|
|
||||||
///////////////////// SCREENS ////////////////////
|
///////////////////// SCREENS ////////////////////
|
||||||
#include "screens/ui_Settings_Screen.h"
|
// None: every screen is hand-coded in src/modules (Driveline, Settings, Gauge
|
||||||
|
// Tuning). The SquareLine Settings screen was removed on 2026-09-27.
|
||||||
|
|
||||||
///////////////////// VARIABLES ////////////////////
|
///////////////////// VARIABLES ////////////////////
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,6 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void onUARTToggle(lv_event_t * e);
|
|
||||||
void onWifiToggle(lv_event_t * e);
|
|
||||||
void onCANBusToggle(lv_event_t * e);
|
|
||||||
void onDebugToggle(lv_event_t * e);
|
|
||||||
void onSelectSSID(lv_event_t * e);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /*extern "C"*/
|
} /*extern "C"*/
|
||||||
|
|||||||
+9
-3
@@ -1,7 +1,13 @@
|
|||||||
# ESP32-S3-WROOM-1-N16R8 Partition Table (16MB Flash)
|
# ESP32-S3-WROOM-1-N16R8 Partition Table (16MB Flash) - dual-slot OTA
|
||||||
# Name, Type, SubType, Offset, Size, Flags
|
# Name, Type, SubType, Offset, Size, Flags
|
||||||
|
#
|
||||||
|
# nvs + otadata keep their original offsets so saved settings/tunables survive
|
||||||
|
# the change. Two equal app slots for OTA (src/modules/ota_update.cpp): the
|
||||||
|
# running image writes the new one into the idle slot and flips otadata.
|
||||||
|
# SPIFFS was dropped (nothing used it) to give each slot ~7.9 MB; firmware is
|
||||||
|
# ~1.5 MB. Changing this table needs one USB flash; OTA works after that.
|
||||||
nvs, data, nvs, 0x9000, 0x5000,
|
nvs, data, nvs, 0x9000, 0x5000,
|
||||||
otadata, data, ota, 0xe000, 0x2000,
|
otadata, data, ota, 0xe000, 0x2000,
|
||||||
app0, app, ota_0, 0x10000, 0xC80000,
|
app0, app, ota_0, 0x10000, 0x7F0000,
|
||||||
spiffs, data, spiffs, 0xC90000, 0x360000,
|
app1, app, ota_1, 0x800000, 0x7F0000,
|
||||||
coredump, data, coredump,0xFF0000, 0x10000,
|
coredump, data, coredump,0xFF0000, 0x10000,
|
||||||
|
|||||||
|
@@ -718,14 +718,7 @@ void setVerboseDecode(bool enabled) {
|
|||||||
ESP_LOGI("CANDrv", "Verbose decode logging %s", enabled ? "ENABLED" : "disabled");
|
ESP_LOGI("CANDrv", "Verbose decode logging %s", enabled ? "ENABLED" : "disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
void onCANToggle(lv_event_t *e) {
|
void setEnabled(bool state) {
|
||||||
lv_obj_t *target = lv_event_get_target(e);
|
|
||||||
if (target == NULL) {
|
|
||||||
ESP_LOGE("CANDrv", "ERROR: CAN toggle target is NULL!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool state = lv_obj_has_state(target, LV_STATE_CHECKED);
|
|
||||||
ESP_LOGI("CANDrv", "===== CAN Toggle Event =====");
|
ESP_LOGI("CANDrv", "===== CAN Toggle Event =====");
|
||||||
ESP_LOGI("CANDrv", "CAN Toggle State: %s", state ? "ON" : "OFF");
|
ESP_LOGI("CANDrv", "CAN Toggle State: %s", state ? "ON" : "OFF");
|
||||||
|
|
||||||
|
|||||||
+39
-95
@@ -1,5 +1,6 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <lvgl.h>
|
#include <lvgl.h>
|
||||||
|
#include <esp_heap_caps.h>
|
||||||
#include "display/lvgl_v8_port.h" // LVGL port layer (for lvgl_port_lock/unlock)
|
#include "display/lvgl_v8_port.h" // LVGL port layer (for lvgl_port_lock/unlock)
|
||||||
#include "modules/display_init.h" // Display initialization module
|
#include "modules/display_init.h" // Display initialization module
|
||||||
#include "modules/wifi_manager.h" // WiFi manager module
|
#include "modules/wifi_manager.h" // WiFi manager module
|
||||||
@@ -9,109 +10,56 @@
|
|||||||
#include "modules/ui_state_manager.h" // UI state manager module
|
#include "modules/ui_state_manager.h" // UI state manager module
|
||||||
#include "modules/driveline_screen.h" // Hand-coded driveline screen (boot screen)
|
#include "modules/driveline_screen.h" // Hand-coded driveline screen (boot screen)
|
||||||
#include "modules/tuning_screen.h" // Hand-coded gauge tuning screen (swipe right from Driveline)
|
#include "modules/tuning_screen.h" // Hand-coded gauge tuning screen (swipe right from Driveline)
|
||||||
|
#include "modules/settings_screen.h" // Hand-coded settings screen (swipe left from Driveline)
|
||||||
#include "modules/serial_lock.h" // Global serial write mutex
|
#include "modules/serial_lock.h" // Global serial write mutex
|
||||||
#include "modules/tunables.h" // Gauge calibration + alert thresholds (NVS, serial console)
|
#include "modules/tunables.h" // Gauge calibration + alert thresholds (NVS, serial console)
|
||||||
#include "modules/espnow_link.h" // ESP-NOW transmit leg of the link to Controller B
|
#include "modules/espnow_link.h" // ESP-NOW transmit leg of the link to Controller B
|
||||||
#include "modules/diag_probe.h" // On-demand OBD-II requests (`diag` console) - the only CAN transmitter
|
#include "modules/diag_probe.h" // On-demand OBD-II requests (`diag` console) - the only CAN transmitter
|
||||||
|
#include "modules/ota_update.h" // Manual firmware updates from Gitea releases (`ota` console)
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// MINIMAL LVGL + UI SETTINGS + WIFI + UART
|
// MINIMAL LVGL + UI SETTINGS + WIFI + UART
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// This is a minimal setup with:
|
// This is a minimal setup with:
|
||||||
// - LVGL display and touch initialization
|
// - LVGL display and touch initialization
|
||||||
// - Hand-coded Driveline (boot) + Gauge Tuning screens, SquareLine Settings screen
|
// - Hand-coded Driveline (boot), Settings and Gauge Tuning screens
|
||||||
// - WiFi module with async scanning (managed by WiFiManager)
|
// - WiFi: one remembered network, scans on request (WiFiManager)
|
||||||
// - UART data transmission at 5Hz (managed by UARTManager)
|
// - UART data transmission at 5Hz (managed by UARTManager)
|
||||||
// - UI state synchronization (managed by UIStateManager)
|
|
||||||
// - Persistent settings storage (managed by SettingsManager)
|
// - Persistent settings storage (managed by SettingsManager)
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
// External UI element references (from ui_Settings_Screen.c)
|
// `mem`: internal heap, PSRAM, and LVGL's own pool (LV_MEM_SIZE, where every
|
||||||
extern "C" {
|
// widget lives). Takes the LVGL lock with a timeout so a hung UI is reported
|
||||||
extern lv_obj_t *uic_Main_Container;
|
// rather than hanging the console too.
|
||||||
extern lv_obj_t *uic_Toggle_Wifi_Switch;
|
static bool memCommand(const char* line) {
|
||||||
extern lv_obj_t *uic_Toggle_UART_Switch;
|
if (strcmp(line, "mem") != 0) return false;
|
||||||
extern lv_obj_t *uic_Toggle_CAN_Bus_Switch;
|
SerialLock::lock();
|
||||||
}
|
Serial.printf("[mem] internal free %u (largest block %u), PSRAM free %u\n",
|
||||||
|
(unsigned)heap_caps_get_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT),
|
||||||
|
(unsigned)heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT),
|
||||||
// ============================================================================
|
(unsigned)heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
|
||||||
// EVENT HANDLERS (C linkage for SquareLine Studio UI callbacks)
|
SerialLock::unlock();
|
||||||
// ============================================================================
|
if (!lvgl_port_lock(500)) {
|
||||||
|
Serial.println("[mem] LVGL lock busy > 500 ms - UI task stuck?");
|
||||||
extern "C" {
|
return true;
|
||||||
|
|
||||||
// WiFi-related event handlers (delegated to WiFiManager)
|
|
||||||
void onSelectSSID(lv_event_t *e) {
|
|
||||||
WiFiManager::onSelectSSID(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// WiFi toggle event handler - delegates to WiFiManager module
|
|
||||||
void onWifiToggle(lv_event_t *e)
|
|
||||||
{
|
|
||||||
// Get the actual widget from the event (safer than global variable)
|
|
||||||
lv_obj_t *target = lv_event_get_target(e);
|
|
||||||
|
|
||||||
// Verify the widget is valid
|
|
||||||
if (target == NULL) {
|
|
||||||
Serial.println("ERROR: WiFi toggle target is NULL!");
|
|
||||||
Serial.flush();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
lv_mem_monitor_t m;
|
||||||
// Check the toggle state
|
lv_mem_monitor(&m);
|
||||||
bool state = lv_obj_has_state(target, LV_STATE_CHECKED);
|
lvgl_port_unlock();
|
||||||
|
SerialLock::lock();
|
||||||
Serial.printf("WiFi Toggle RELEASED - State: %s\n", state ? "ON" : "OFF");
|
Serial.printf("[mem] LVGL pool: used %u of %u B (%u%%), frag %u%%, biggest free %u\n",
|
||||||
Serial.flush();
|
(unsigned)(m.total_size - m.free_size), (unsigned)m.total_size,
|
||||||
|
(unsigned)m.used_pct, (unsigned)m.frag_pct, (unsigned)m.free_biggest_size);
|
||||||
// Save state to NVS for persistence across power cycles
|
SerialLock::unlock();
|
||||||
SettingsManager::saveWiFiState(state);
|
return true;
|
||||||
|
|
||||||
// Delegate to WiFiManager module
|
|
||||||
WiFiManager::onWifiToggle(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UART toggle event handler - delegates to UARTManager module
|
// Console lines `cfg` doesn't recognise: diagnostic probe, OTA, Wi-Fi, mem.
|
||||||
void onUARTToggle(lv_event_t *e)
|
static bool consoleExtraCommand(const char* line) {
|
||||||
{
|
return DiagProbe::handleCommand(line) || Ota::handleCommand(line) ||
|
||||||
// Get the actual widget from the event (safer than global variable)
|
WiFiManager::handleCommand(line) || memCommand(line);
|
||||||
lv_obj_t *target = lv_event_get_target(e);
|
|
||||||
|
|
||||||
// Verify the widget is valid
|
|
||||||
if (target == NULL) {
|
|
||||||
Serial.println("ERROR: UART toggle target is NULL!");
|
|
||||||
Serial.flush();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check the toggle state
|
|
||||||
bool state = lv_obj_has_state(target, LV_STATE_CHECKED);
|
|
||||||
|
|
||||||
Serial.printf("UART Toggle RELEASED - State: %s\n", state ? "ON" : "OFF");
|
|
||||||
Serial.flush();
|
|
||||||
|
|
||||||
// Save state to NVS for persistence across power cycles
|
|
||||||
SettingsManager::saveUARTState(state);
|
|
||||||
|
|
||||||
// Delegate to UARTManager module
|
|
||||||
UARTManager::onUARTToggle(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CAN Bus toggle event handler - delegates to CANDriver module
|
|
||||||
void onCANBusToggle(lv_event_t *e)
|
|
||||||
{
|
|
||||||
CANDriver::onCANToggle(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debug toggle event handler - delegates to UIStateManager module
|
|
||||||
void onDebugToggle(lv_event_t *e)
|
|
||||||
{
|
|
||||||
UIStateManager::onDebugToggle(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // extern "C"
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// SETUP - Initialize hardware and UI
|
// SETUP - Initialize hardware and UI
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -131,6 +79,7 @@ void setup()
|
|||||||
// Use ESP_LOG instead of Serial.println to match library output
|
// Use ESP_LOG instead of Serial.println to match library output
|
||||||
ESP_LOGI("MAIN", "=== ESP32-S3-LCD-5B Minimal Setup ===");
|
ESP_LOGI("MAIN", "=== ESP32-S3-LCD-5B Minimal Setup ===");
|
||||||
ESP_LOGI("MAIN", "Firmware compiled: %s %s", __DATE__, __TIME__);
|
ESP_LOGI("MAIN", "Firmware compiled: %s %s", __DATE__, __TIME__);
|
||||||
|
Ota::init(); // version + slot; flags an unconfirmed freshly-installed image
|
||||||
|
|
||||||
// Initialize display hardware and UI
|
// Initialize display hardware and UI
|
||||||
ESP_LOGI("MAIN", "Initializing display and UI...");
|
ESP_LOGI("MAIN", "Initializing display and UI...");
|
||||||
@@ -144,7 +93,7 @@ void setup()
|
|||||||
// Tunables (gauge calibration, alert thresholds) - before CAN/UART start
|
// Tunables (gauge calibration, alert thresholds) - before CAN/UART start
|
||||||
Tunables::init();
|
Tunables::init();
|
||||||
DiagProbe::init();
|
DiagProbe::init();
|
||||||
Tunables::setExtraCommandHandler(DiagProbe::handleCommand);
|
Tunables::setExtraCommandHandler(consoleExtraCommand);
|
||||||
|
|
||||||
// Load saved switch states from NVS
|
// Load saved switch states from NVS
|
||||||
ESP_LOGI("MAIN", "Loading saved switch states from NVS...");
|
ESP_LOGI("MAIN", "Loading saved switch states from NVS...");
|
||||||
@@ -186,8 +135,7 @@ void setup()
|
|||||||
ESP_LOGI("MAIN", "- Link: UART1 TX GPIO44 (RS485 A/B) + ESP-NOW broadcast, protocol v%u", PACKET_VERSION);
|
ESP_LOGI("MAIN", "- Link: UART1 TX GPIO44 (RS485 A/B) + ESP-NOW broadcast, protocol v%u", PACKET_VERSION);
|
||||||
ESP_LOGI("MAIN", "- Console: type 'cfg help' to tune the Patrol gauge outputs");
|
ESP_LOGI("MAIN", "- Console: type 'cfg help' to tune the Patrol gauge outputs");
|
||||||
ESP_LOGI("MAIN", "- Screens: Driveline (boot) <- left: Settings | right: Gauge tuning ->");
|
ESP_LOGI("MAIN", "- Screens: Driveline (boot) <- left: Settings | right: Gauge tuning ->");
|
||||||
ESP_LOGI("MAIN", "- Settings screen has WiFi and UART toggles");
|
ESP_LOGI("MAIN", "- Settings: Wi-Fi (remembered network), Updates, System");
|
||||||
ESP_LOGI("MAIN", "- WiFi scan updates every 10 seconds when enabled");
|
|
||||||
ESP_LOGI("MAIN", "- UART transmits at 5Hz (200ms) when enabled");
|
ESP_LOGI("MAIN", "- UART transmits at 5Hz (200ms) when enabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,19 +151,15 @@ void loop()
|
|||||||
last_print = millis();
|
last_print = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
// LVGL task runs automatically in separate task
|
// LVGL renders in its own task; the screen ticks below only refresh values.
|
||||||
// Keep loop() minimal and empty to avoid interfering with LVGL rendering
|
// Serial console: gauge tunables (cfg ...), diagnostic probe (diag ...), updates (ota ...)
|
||||||
|
|
||||||
// Continuously sync UI switches with actual service states
|
|
||||||
// (Settings screen gets destroyed/recreated when swiping)
|
|
||||||
UIStateManager::applySavedStatesToUI();
|
|
||||||
|
|
||||||
// Serial console: gauge tunables (cfg ...) and the diagnostic probe (diag ...)
|
|
||||||
Tunables::pollSerial();
|
Tunables::pollSerial();
|
||||||
DiagProbe::tick();
|
DiagProbe::tick();
|
||||||
|
Ota::tick(); // confirms a freshly installed image after healthy uptime
|
||||||
|
|
||||||
DrivelineScreen::tick();
|
DrivelineScreen::tick();
|
||||||
TuningScreen::tick();
|
TuningScreen::tick();
|
||||||
|
SettingsScreen::tick();
|
||||||
|
|
||||||
delay(100); // Check frequently to catch screen changes quickly
|
delay(100); // Check frequently to catch screen changes quickly
|
||||||
}
|
}
|
||||||
|
|||||||
+202
-34
@@ -25,13 +25,15 @@ static const uint32_t OBD_RESP_LAST = 0x7EF; // physical request = response
|
|||||||
static const uint32_t OBD_REQ_FIRST = 0x7E0;
|
static const uint32_t OBD_REQ_FIRST = 0x7E0;
|
||||||
static const uint32_t OBD_REQ_LAST = 0x7E7;
|
static const uint32_t OBD_REQ_LAST = 0x7E7;
|
||||||
static const uint32_t BMW_TESTER_ID = 0x6F1; // BMW KWP/UDS tester (Launch, INPA)
|
static const uint32_t BMW_TESTER_ID = 0x6F1; // BMW KWP/UDS tester (Launch, INPA)
|
||||||
|
static const uint32_t BMW_RX_BASE = 0x600; // an ECU replies on 0x600 + its address
|
||||||
|
static const uint8_t BMW_ADDR_DDE = 0x12; // engine ECU address (reply on 0x612)
|
||||||
|
|
||||||
static const uint32_t REPLY_TIMEOUT_MS = 500; // P2 is 50 ms; be generous
|
static const uint32_t REPLY_TIMEOUT_MS = 500; // P2 is 50 ms; be generous
|
||||||
static const uint32_t LINGER_MS = 150; // after the first reply, wait for other ECUs
|
static const uint32_t LINGER_MS = 150; // after the first reply, wait for other ECUs
|
||||||
static const uint32_t PENDING_EXTRA_MS = 2000; // NRC 0x78 "response pending"
|
static const uint32_t PENDING_EXTRA_MS = 2000; // NRC 0x78 "response pending"
|
||||||
static const uint32_t TESTER_GUARD_MS = 3000; // refuse to send this soon after a foreign tester
|
static const uint32_t TESTER_GUARD_MS = 3000; // refuse to send this soon after a foreign tester
|
||||||
static const uint8_t PAD_BYTE = 0x00;
|
static const uint8_t PAD_BYTE = 0x00;
|
||||||
static const size_t MAX_PAYLOAD = 64;
|
static const size_t MAX_PAYLOAD = 384; // KWP ident replies can be long
|
||||||
static const int MAX_RESPONDERS = 4;
|
static const int MAX_RESPONDERS = 4;
|
||||||
static const int SCAN_BLOCKS = 8; // 0x00, 0x20, ... 0xE0
|
static const int SCAN_BLOCKS = 8; // 0x00, 0x20, ... 0xE0
|
||||||
|
|
||||||
@@ -50,7 +52,10 @@ struct responder_t {
|
|||||||
static SemaphoreHandle_t g_mutex = NULL;
|
static SemaphoreHandle_t g_mutex = NULL;
|
||||||
|
|
||||||
static state_t g_state = ST_IDLE;
|
static state_t g_state = ST_IDLE;
|
||||||
static uint8_t g_req_mode = 0, g_req_pid = 0;
|
static uint8_t g_req_mode = 0;
|
||||||
|
static int g_req_pid = 0; // -1 = request had no PID/sub byte (e.g. mode 03)
|
||||||
|
static bool g_bmw = false; // current request is BMW-addressed on 0x6F1
|
||||||
|
static uint8_t g_bmw_target = 0; // its target ECU address (reply on 0x600+addr)
|
||||||
static uint32_t g_deadline_ms = 0;
|
static uint32_t g_deadline_ms = 0;
|
||||||
static uint8_t g_replies_this_req = 0;
|
static uint8_t g_replies_this_req = 0;
|
||||||
|
|
||||||
@@ -190,8 +195,8 @@ static responder_t* findResponder(uint32_t id, bool create) {
|
|||||||
// Transmit
|
// Transmit
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
/** Build and send one single-frame request. Caller holds no lock. */
|
/** Common preconditions for any transmit; prints the refusal reason. */
|
||||||
static bool sendRequest(uint8_t mode, uint8_t pid) {
|
static bool clearToSend() {
|
||||||
if (!CANDriver::isActive()) {
|
if (!CANDriver::isActive()) {
|
||||||
print("[diag] refused: CAN is not running");
|
print("[diag] refused: CAN is not running");
|
||||||
return false;
|
return false;
|
||||||
@@ -212,23 +217,41 @@ static bool sendRequest(uint8_t mode, uint8_t pid) {
|
|||||||
(unsigned long)tester_id, (unsigned long)since_tester);
|
(unsigned long)tester_id, (unsigned long)since_tester);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t f[8];
|
/** Arm the waiting state. Caller sends the frame right after. */
|
||||||
memset(f, PAD_BYTE, sizeof(f));
|
static void armRequest(uint8_t mode, int pid, bool bmw, uint8_t target) {
|
||||||
f[0] = 0x02; // ISO-TP single frame, 2 bytes
|
|
||||||
f[1] = mode;
|
|
||||||
f[2] = pid;
|
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
g_state = ST_WAITING;
|
g_state = ST_WAITING;
|
||||||
|
g_bmw = bmw;
|
||||||
|
g_bmw_target = target;
|
||||||
g_req_mode = mode;
|
g_req_mode = mode;
|
||||||
g_req_pid = pid;
|
g_req_pid = pid;
|
||||||
g_deadline_ms = now + REPLY_TIMEOUT_MS;
|
g_deadline_ms = millis() + REPLY_TIMEOUT_MS;
|
||||||
g_replies_this_req = 0;
|
g_replies_this_req = 0;
|
||||||
g_rx_active = false;
|
g_rx_active = false;
|
||||||
g_requests++;
|
g_requests++;
|
||||||
g_tx_fail_at_send = CANDriver::getStats().tx_failures;
|
g_tx_fail_at_send = CANDriver::getStats().tx_failures;
|
||||||
unlock();
|
unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Build and send one single-frame OBD request on 0x7DF. pid < 0 = mode only. */
|
||||||
|
static bool sendRequest(uint8_t mode, int pid) {
|
||||||
|
if (!clearToSend()) return false;
|
||||||
|
|
||||||
|
uint8_t f[8];
|
||||||
|
memset(f, PAD_BYTE, sizeof(f));
|
||||||
|
if (pid < 0) {
|
||||||
|
f[0] = 0x01; // ISO-TP single frame, 1 byte (e.g. mode 03)
|
||||||
|
f[1] = mode;
|
||||||
|
} else {
|
||||||
|
f[0] = 0x02; // ISO-TP single frame, 2 bytes
|
||||||
|
f[1] = mode;
|
||||||
|
f[2] = (uint8_t)pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
armRequest(mode, pid, false, 0);
|
||||||
|
|
||||||
if (!CANDriver::transmit(OBD_FUNCTIONAL_ID, f, sizeof(f))) {
|
if (!CANDriver::transmit(OBD_FUNCTIONAL_ID, f, sizeof(f))) {
|
||||||
lock();
|
lock();
|
||||||
@@ -237,7 +260,52 @@ static bool sendRequest(uint8_t mode, uint8_t pid) {
|
|||||||
print("[diag] transmit failed (TWAI queue)");
|
print("[diag] transmit failed (TWAI queue)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
print("[diag] -> 0x7DF %02X %02X", mode, pid);
|
if (pid < 0) print("[diag] -> 0x7DF %02X", mode);
|
||||||
|
else print("[diag] -> 0x7DF %02X %02X", mode, pid);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One single-frame BMW-addressed request on 0x6F1 (ISO 15765 extended
|
||||||
|
* addressing: byte 0 = target ECU address, then normal ISO-TP). Read-only
|
||||||
|
* services only - enforced here, not just at the console.
|
||||||
|
*/
|
||||||
|
static bool sendBmwRequest(uint8_t target, const uint8_t* req, size_t n) {
|
||||||
|
static const uint8_t OK_SERVICES[] = {0x1A, 0x18, 0x21, 0x22};
|
||||||
|
if (n < 1 || n > 6) {
|
||||||
|
print("[diag] BMW request must be 1..6 bytes (single frame)");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool allowed = false;
|
||||||
|
for (size_t i = 0; i < sizeof(OK_SERVICES); i++) {
|
||||||
|
if (req[0] == OK_SERVICES[i]) allowed = true;
|
||||||
|
}
|
||||||
|
if (!allowed) {
|
||||||
|
print("[diag] service 0x%02X refused - read-only services only (1A ident, 18 DTCs, 21/22 read data)",
|
||||||
|
req[0]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!clearToSend()) return false;
|
||||||
|
|
||||||
|
uint8_t f[8];
|
||||||
|
memset(f, PAD_BYTE, sizeof(f));
|
||||||
|
f[0] = target;
|
||||||
|
f[1] = (uint8_t)n;
|
||||||
|
memcpy(f + 2, req, n);
|
||||||
|
|
||||||
|
armRequest(req[0], (n >= 2) ? (int)req[1] : -1, true, target);
|
||||||
|
|
||||||
|
if (!CANDriver::transmit(BMW_TESTER_ID, f, sizeof(f))) {
|
||||||
|
lock();
|
||||||
|
g_state = ST_IDLE;
|
||||||
|
unlock();
|
||||||
|
print("[diag] transmit failed (TWAI queue)");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
char hex[3 * 6 + 1];
|
||||||
|
hexdump(hex, sizeof(hex), req, n);
|
||||||
|
print("[diag] -> 0x6F1 [%02X] %s (reply expected on 0x%03lX)", target, hex,
|
||||||
|
(unsigned long)(BMW_RX_BASE + target));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,9 +313,17 @@ static bool sendRequest(uint8_t mode, uint8_t pid) {
|
|||||||
static void sendFlowControl(uint32_t responder_id) {
|
static void sendFlowControl(uint32_t responder_id) {
|
||||||
uint8_t f[8];
|
uint8_t f[8];
|
||||||
memset(f, PAD_BYTE, sizeof(f));
|
memset(f, PAD_BYTE, sizeof(f));
|
||||||
f[0] = 0x30; // FC, ContinueToSend
|
if (g_bmw) {
|
||||||
f[1] = 0x00; // block size: all
|
f[0] = g_bmw_target; // extended addressing: target first, then the FC
|
||||||
f[2] = 0x00; // STmin: 0 ms
|
f[1] = 0x30; // FC, ContinueToSend
|
||||||
|
f[2] = 0x00; // block size: all
|
||||||
|
f[3] = 0x00; // STmin: 0 ms
|
||||||
|
CANDriver::transmit(BMW_TESTER_ID, f, sizeof(f));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
f[0] = 0x30;
|
||||||
|
f[1] = 0x00;
|
||||||
|
f[2] = 0x00;
|
||||||
CANDriver::transmit(responder_id - 8, f, sizeof(f));
|
CANDriver::transmit(responder_id - 8, f, sizeof(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,8 +335,8 @@ static void finishScanBlockIfPrimary(uint32_t id, const uint8_t* p, size_t n);
|
|||||||
|
|
||||||
/** A complete ISO-TP payload from `id`. Caller holds g_mutex. */
|
/** A complete ISO-TP payload from `id`. Caller holds g_mutex. */
|
||||||
static void handleReply(uint32_t id, const uint8_t* p, size_t n) {
|
static void handleReply(uint32_t id, const uint8_t* p, size_t n) {
|
||||||
char hex[3 * 24 + 1];
|
char hex[3 * 48 + 1];
|
||||||
hexdump(hex, sizeof(hex), p, n > 24 ? 24 : n);
|
hexdump(hex, sizeof(hex), p, n > 48 ? 48 : n);
|
||||||
g_replies++;
|
g_replies++;
|
||||||
|
|
||||||
if (n >= 3 && p[0] == 0x7F) {
|
if (n >= 3 && p[0] == 0x7F) {
|
||||||
@@ -284,10 +360,40 @@ static void handleReply(uint32_t id, const uint8_t* p, size_t n) {
|
|||||||
|
|
||||||
g_replies_this_req++;
|
g_replies_this_req++;
|
||||||
if (g_deadline_ms > millis() + LINGER_MS) g_deadline_ms = millis() + LINGER_MS;
|
if (g_deadline_ms > millis() + LINGER_MS) g_deadline_ms = millis() + LINGER_MS;
|
||||||
print("[diag] <- 0x%03lX %s%s", (unsigned long)id, hex, n > 24 ? " ..." : "");
|
print("[diag] <- 0x%03lX %s%s", (unsigned long)id, hex, n > 48 ? " ..." : "");
|
||||||
|
|
||||||
if (n < 2 || p[0] != (uint8_t)(g_req_mode + 0x40) || p[1] != g_req_pid) {
|
if (n < 1 || p[0] != (uint8_t)(g_req_mode + 0x40) ||
|
||||||
print("[diag] (unexpected payload for request %02X %02X)", g_req_mode, g_req_pid);
|
(!g_bmw && g_req_pid >= 0 && (n < 2 || p[1] != (uint8_t)g_req_pid))) {
|
||||||
|
print("[diag] (unexpected payload for request %02X)", g_req_mode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_bmw) {
|
||||||
|
// KWP ident replies are long and the header line clips at 48 bytes:
|
||||||
|
// dump the whole payload, 16 bytes per line, hex + ascii.
|
||||||
|
for (size_t i = 1; i < n; i += 16) {
|
||||||
|
size_t k = (n - i < 16) ? (n - i) : 16;
|
||||||
|
char hx[3 * 16 + 1];
|
||||||
|
hexdump(hx, sizeof(hx), p + i, k);
|
||||||
|
char as[17];
|
||||||
|
for (size_t j = 0; j < k; j++) {
|
||||||
|
as[j] = (p[i + j] >= 0x20 && p[i + j] < 0x7F) ? (char)p[i + j] : '.';
|
||||||
|
}
|
||||||
|
as[k] = 0;
|
||||||
|
print("[diag] +%03u %-48s |%s|", (unsigned)(i - 1), hx, as);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_req_mode == 0x03) {
|
||||||
|
// 43 <count> <2 bytes per DTC>
|
||||||
|
uint8_t cnt = (n >= 2) ? p[1] : 0;
|
||||||
|
print("[diag] %u stored DTC(s):", cnt);
|
||||||
|
for (size_t i = 2; i + 1 < n; i += 2) {
|
||||||
|
uint8_t a = p[i], b = p[i + 1];
|
||||||
|
if (a == 0 && b == 0) continue;
|
||||||
|
print("[diag] %c%u%X%02X", "PCBU"[a >> 6], (a >> 4) & 3, a & 0x0F, b);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,27 +446,40 @@ void onFrame(const twai_message_t& m) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id < OBD_RESP_FIRST || id > OBD_RESP_LAST) return;
|
|
||||||
if (m.data_length_code == 0) return;
|
if (m.data_length_code == 0) return;
|
||||||
|
bool maybe_obd = (id >= OBD_RESP_FIRST && id <= OBD_RESP_LAST);
|
||||||
|
bool maybe_bmw = (id >= BMW_RX_BASE && id < BMW_RX_BASE + 0x100);
|
||||||
|
if (!maybe_obd && !maybe_bmw) return;
|
||||||
|
|
||||||
lock();
|
lock();
|
||||||
if (g_state != ST_WAITING) { unlock(); return; }
|
if (g_state != ST_WAITING) { unlock(); return; }
|
||||||
|
|
||||||
uint8_t pci = m.data[0] >> 4;
|
|
||||||
const uint8_t* d = m.data;
|
const uint8_t* d = m.data;
|
||||||
uint8_t dlc = m.data_length_code;
|
uint8_t dlc = m.data_length_code;
|
||||||
|
uint8_t off = 0; // index of the ISO-TP PCI byte
|
||||||
|
|
||||||
|
if (g_bmw) {
|
||||||
|
// extended addressing: reply on 0x600+target, byte 0 = tester addr 0xF1
|
||||||
|
if (id != BMW_RX_BASE + g_bmw_target || dlc < 2 || d[0] != 0xF1) { unlock(); return; }
|
||||||
|
off = 1;
|
||||||
|
} else if (!maybe_obd) {
|
||||||
|
unlock();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t pci = d[off] >> 4;
|
||||||
|
|
||||||
if (pci == 0x0) {
|
if (pci == 0x0) {
|
||||||
// single frame
|
// single frame
|
||||||
size_t len = d[0] & 0x0F;
|
size_t len = d[off] & 0x0F;
|
||||||
if (len > 0 && len + 1 <= dlc) handleReply(id, d + 1, len);
|
if (len > 0 && off + 1 + len <= dlc) handleReply(id, d + off + 1, len);
|
||||||
} else if (pci == 0x1) {
|
} else if (pci == 0x1) {
|
||||||
// first frame: 1L LL data[6]
|
// first frame: 1L LL data[...]
|
||||||
if (!g_rx_active && dlc >= 2) {
|
if (!g_rx_active && dlc >= (uint8_t)(off + 2)) {
|
||||||
g_rx_expected = ((size_t)(d[0] & 0x0F) << 8) | d[1];
|
g_rx_expected = ((size_t)(d[off] & 0x0F) << 8) | d[off + 1];
|
||||||
if (g_rx_expected > MAX_PAYLOAD) g_rx_expected = MAX_PAYLOAD;
|
if (g_rx_expected > MAX_PAYLOAD) g_rx_expected = MAX_PAYLOAD;
|
||||||
g_rx_len = 0;
|
g_rx_len = 0;
|
||||||
for (uint8_t i = 2; i < dlc && g_rx_len < g_rx_expected; i++) g_rx_buf[g_rx_len++] = d[i];
|
for (uint8_t i = off + 2; i < dlc && g_rx_len < g_rx_expected; i++) g_rx_buf[g_rx_len++] = d[i];
|
||||||
g_rx_id = id;
|
g_rx_id = id;
|
||||||
g_rx_seq = 1;
|
g_rx_seq = 1;
|
||||||
g_rx_active = true;
|
g_rx_active = true;
|
||||||
@@ -370,9 +489,9 @@ void onFrame(const twai_message_t& m) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (pci == 0x2) {
|
} else if (pci == 0x2) {
|
||||||
// consecutive frame: 2N data[7]
|
// consecutive frame: 2N data[...]
|
||||||
if (g_rx_active && id == g_rx_id && (d[0] & 0x0F) == (g_rx_seq & 0x0F)) {
|
if (g_rx_active && id == g_rx_id && (d[off] & 0x0F) == (g_rx_seq & 0x0F)) {
|
||||||
for (uint8_t i = 1; i < dlc && g_rx_len < g_rx_expected; i++) g_rx_buf[g_rx_len++] = d[i];
|
for (uint8_t i = off + 1; i < dlc && g_rx_len < g_rx_expected; i++) g_rx_buf[g_rx_len++] = d[i];
|
||||||
g_rx_seq++;
|
g_rx_seq++;
|
||||||
g_deadline_ms = millis() + REPLY_TIMEOUT_MS;
|
g_deadline_ms = millis() + REPLY_TIMEOUT_MS;
|
||||||
if (g_rx_len >= g_rx_expected) {
|
if (g_rx_len >= g_rx_expected) {
|
||||||
@@ -455,9 +574,14 @@ void tick() {
|
|||||||
unlock();
|
unlock();
|
||||||
|
|
||||||
if (!got_reply) {
|
if (!got_reply) {
|
||||||
|
if (g_req_pid < 0) {
|
||||||
|
print("[diag] no reply within %lu ms (request %02X)%s", (unsigned long)REPLY_TIMEOUT_MS,
|
||||||
|
g_req_mode, unacked ? " - frame was not ACKed by any node" : " - frame was ACKed, ECU stayed silent");
|
||||||
|
} else {
|
||||||
print("[diag] no reply within %lu ms (request %02X %02X)%s", (unsigned long)REPLY_TIMEOUT_MS,
|
print("[diag] no reply within %lu ms (request %02X %02X)%s", (unsigned long)REPLY_TIMEOUT_MS,
|
||||||
g_req_mode, g_req_pid, unacked ? " - frame was not ACKed by any node" : " - frame was ACKed, ECU stayed silent");
|
g_req_mode, g_req_pid, unacked ? " - frame was not ACKed by any node" : " - frame was ACKed, ECU stayed silent");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (scan) {
|
if (scan) {
|
||||||
if (send_next) {
|
if (send_next) {
|
||||||
sendRequest(0x01, (uint8_t)(g_scan_block * 0x20));
|
sendRequest(0x01, (uint8_t)(g_scan_block * 0x20));
|
||||||
@@ -474,10 +598,14 @@ void tick() {
|
|||||||
static void help() {
|
static void help() {
|
||||||
print("diag pids scan mode-01 supported-PID bitmaps (the Route A probe)");
|
print("diag pids scan mode-01 supported-PID bitmaps (the Route A probe)");
|
||||||
print("diag pid <hex> one mode-01 request, e.g. `diag pid 0C` (rpm), `diag pid 70` (boost)");
|
print("diag pid <hex> one mode-01 request, e.g. `diag pid 0C` (rpm), `diag pid 70` (boost)");
|
||||||
|
print("diag dtc mode 03 - read stored generic DTCs");
|
||||||
print("diag vin mode 09 PID 02 - VIN");
|
print("diag vin mode 09 PID 02 - VIN");
|
||||||
print("diag ecu mode 09 PID 0A - ECU name");
|
print("diag ecu mode 09 PID 0A - ECU name");
|
||||||
|
print("diag ident [addr] BMW KWP `1A 80` ECU identification (default addr 12 = DDE, reply 0x612)");
|
||||||
|
print("diag bmw <addr> <hex...> raw BMW request on 0x6F1, read-only services only (1A/18/21/22)");
|
||||||
|
print("diag raw on|off CANRAW frame logging (off = clean console during scans)");
|
||||||
print("diag status counters, responders, tester guard");
|
print("diag status counters, responders, tester guard");
|
||||||
print("Sends on 0x7DF only, one request at a time; refused while a scan tool is polling.");
|
print("Sends on 0x7DF / 0x6F1 only, one request at a time; refused while a scan tool is polling.");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void status() {
|
static void status() {
|
||||||
@@ -507,9 +635,9 @@ bool handleCommand(const char* line) {
|
|||||||
strncpy(buf, line, sizeof(buf) - 1);
|
strncpy(buf, line, sizeof(buf) - 1);
|
||||||
buf[sizeof(buf) - 1] = 0;
|
buf[sizeof(buf) - 1] = 0;
|
||||||
|
|
||||||
char* argv[4] = {0};
|
char* argv[10] = {0};
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
for (char* tok = strtok(buf, " \t"); tok && argc < 4; tok = strtok(NULL, " \t")) {
|
for (char* tok = strtok(buf, " \t"); tok && argc < 10; tok = strtok(NULL, " \t")) {
|
||||||
argv[argc++] = tok;
|
argv[argc++] = tok;
|
||||||
}
|
}
|
||||||
if (argc == 0 || strcmp(argv[0], "diag") != 0) return false;
|
if (argc == 0 || strcmp(argv[0], "diag") != 0) return false;
|
||||||
@@ -544,6 +672,46 @@ bool handleCommand(const char* line) {
|
|||||||
|
|
||||||
if (!strcmp(argv[1], "vin")) { sendRequest(0x09, 0x02); return true; }
|
if (!strcmp(argv[1], "vin")) { sendRequest(0x09, 0x02); return true; }
|
||||||
if (!strcmp(argv[1], "ecu")) { sendRequest(0x09, 0x0A); return true; }
|
if (!strcmp(argv[1], "ecu")) { sendRequest(0x09, 0x0A); return true; }
|
||||||
|
if (!strcmp(argv[1], "dtc")) { sendRequest(0x03, -1); return true; }
|
||||||
|
|
||||||
|
if (!strcmp(argv[1], "raw") && argc == 3) {
|
||||||
|
bool on = !strcmp(argv[2], "on");
|
||||||
|
CANDriver::setRawLogging(on);
|
||||||
|
print("[diag] CANRAW logging %s", on ? "on" : "off");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(argv[1], "ident")) {
|
||||||
|
uint8_t target = BMW_ADDR_DDE;
|
||||||
|
if (argc >= 3) target = (uint8_t)strtol(argv[2], NULL, 16);
|
||||||
|
uint8_t req[2] = {0x1A, 0x80};
|
||||||
|
sendBmwRequest(target, req, sizeof(req));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(argv[1], "bmw") && argc >= 4) {
|
||||||
|
uint8_t target = (uint8_t)strtol(argv[2], NULL, 16);
|
||||||
|
char hexs[13] = {0}; // up to 6 bytes = 12 hex chars
|
||||||
|
size_t hl = 0;
|
||||||
|
for (int i = 3; i < argc; i++) {
|
||||||
|
for (const char* c = argv[i]; *c; c++) {
|
||||||
|
if (hl >= sizeof(hexs) - 1) { print("[diag] too many bytes (max 6)"); return true; }
|
||||||
|
hexs[hl++] = *c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hl == 0 || (hl % 2) != 0) {
|
||||||
|
print("[diag] give whole hex bytes, e.g. `diag bmw 12 1A 80`");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
uint8_t req[6];
|
||||||
|
size_t n = 0;
|
||||||
|
for (size_t i = 0; i < hl; i += 2) {
|
||||||
|
char b[3] = {hexs[i], hexs[i + 1], 0};
|
||||||
|
req[n++] = (uint8_t)strtol(b, NULL, 16);
|
||||||
|
}
|
||||||
|
sendBmwRequest(target, req, n);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
help();
|
help();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -15,11 +15,19 @@
|
|||||||
* Console (USB serial, same line reader as `cfg`):
|
* Console (USB serial, same line reader as `cfg`):
|
||||||
* diag pids scan the mode-01 supported-PID bitmaps (00, 20, 40, ...)
|
* diag pids scan the mode-01 supported-PID bitmaps (00, 20, 40, ...)
|
||||||
* diag pid <hex> one mode-01 request, e.g. `diag pid 0C` (rpm)
|
* diag pid <hex> one mode-01 request, e.g. `diag pid 0C` (rpm)
|
||||||
|
* diag dtc mode 03 — stored generic DTCs
|
||||||
* diag vin mode 09 PID 02 — VIN (identifies the donor)
|
* diag vin mode 09 PID 02 — VIN (identifies the donor)
|
||||||
* diag ecu mode 09 PID 0A — ECU name string
|
* diag ecu mode 09 PID 0A — ECU name string
|
||||||
|
* diag ident [addr] BMW KWP `1A 80` ECU identification on 0x6F1 (default 12 = DDE)
|
||||||
|
* diag bmw <addr> <hex...> raw BMW-addressed request; read-only services only
|
||||||
* diag status counters, responders seen, tester-guard timer
|
* diag status counters, responders seen, tester-guard timer
|
||||||
* diag help
|
* diag help
|
||||||
*
|
*
|
||||||
|
* BMW requests use ISO 15765 extended addressing: TX on 0x6F1 with byte 0 =
|
||||||
|
* target ECU address, reply on 0x600+address with byte 0 = 0xF1. Allowed
|
||||||
|
* services are whitelisted in sendBmwRequest(): 1A (ident), 18 (DTCs),
|
||||||
|
* 21/22 (read data) — never session control, resets, or writes.
|
||||||
|
*
|
||||||
* Every frame we send is echoed on the console as
|
* Every frame we send is echoed on the console as
|
||||||
* CANTX,<ts_ms>,<id_hex>,0,<dlc>,<data_hex>
|
* CANTX,<ts_ms>,<id_hex>,0,<dlc>,<data_hex>
|
||||||
* — the same shape as CANRAW — so a capture holds both halves of every exchange.
|
* — the same shape as CANRAW — so a capture holds both halves of every exchange.
|
||||||
|
|||||||
@@ -6,9 +6,32 @@
|
|||||||
#include "display/lvgl_v8_port.h"
|
#include "display/lvgl_v8_port.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
#include "driveline_screen.h"
|
#include "driveline_screen.h"
|
||||||
|
#include "config/ota_config.h" // FW_VERSION
|
||||||
|
|
||||||
namespace DisplayInit {
|
namespace DisplayInit {
|
||||||
|
|
||||||
|
static Backlight* g_backlight = nullptr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Firmware version, bottom-right on every screen. Lives on lv_layer_top(), which
|
||||||
|
* sits above all screens and survives screen switches. Labels aren't
|
||||||
|
* clickable, so it never steals touches or swipes from the screen below.
|
||||||
|
* Call with the LVGL lock held.
|
||||||
|
*/
|
||||||
|
static void createVersionLabel() {
|
||||||
|
lv_obj_t* lbl = lv_label_create(lv_layer_top());
|
||||||
|
lv_label_set_text(lbl, "A " FW_VERSION);
|
||||||
|
lv_obj_set_style_text_font(lbl, &lv_font_montserrat_14, 0);
|
||||||
|
lv_obj_set_style_text_color(lbl, lv_color_hex(0x808080), 0);
|
||||||
|
lv_obj_align(lbl, LV_ALIGN_BOTTOM_RIGHT, -8, -4);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBacklight(bool on) {
|
||||||
|
if (g_backlight == nullptr) return;
|
||||||
|
if (on) g_backlight->on();
|
||||||
|
else g_backlight->off();
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// PUBLIC API IMPLEMENTATION
|
// PUBLIC API IMPLEMENTATION
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -71,11 +94,11 @@ DisplayObjects init() {
|
|||||||
Serial.println("[DisplayInit] Step 12: Loading SquareLine Studio UI...");
|
Serial.println("[DisplayInit] Step 12: Loading SquareLine Studio UI...");
|
||||||
lvgl_port_lock(-1);
|
lvgl_port_lock(-1);
|
||||||
ui_init(); // Initialize the SquareLine Studio generated UI
|
ui_init(); // Initialize the SquareLine Studio generated UI
|
||||||
// Note: onSelectSSID event handler is registered in ui_Settings_Screen.c
|
|
||||||
// Boot screen: the hand-coded Driveline screen. ui_init() only loads an
|
// Boot screen: the hand-coded Driveline screen. ui_init() only loads an
|
||||||
// empty placeholder now (the SquareLine Home screen was removed 2026-09-21);
|
// empty placeholder now (the SquareLine Home screen was removed 2026-09-21);
|
||||||
// swap while the backlight is still off so there's no flash.
|
// swap while the backlight is still off so there's no flash.
|
||||||
DrivelineScreen::show();
|
DrivelineScreen::show();
|
||||||
|
createVersionLabel();
|
||||||
lvgl_port_unlock();
|
lvgl_port_unlock();
|
||||||
Serial.println("[DisplayInit] Step 13: SquareLine UI loaded successfully!");
|
Serial.println("[DisplayInit] Step 13: SquareLine UI loaded successfully!");
|
||||||
|
|
||||||
@@ -91,6 +114,7 @@ DisplayObjects init() {
|
|||||||
Serial.println("[DisplayInit] Display initialization complete!");
|
Serial.println("[DisplayInit] Display initialization complete!");
|
||||||
|
|
||||||
// Return board and backlight objects for later use
|
// Return board and backlight objects for later use
|
||||||
|
g_backlight = backlight;
|
||||||
return {board, backlight};
|
return {board, backlight};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,4 +43,7 @@ struct DisplayObjects {
|
|||||||
*/
|
*/
|
||||||
DisplayObjects init();
|
DisplayObjects init();
|
||||||
|
|
||||||
|
/** Backlight on/off after init() (e.g. dark during OTA flash writes, which flicker the panel). */
|
||||||
|
void setBacklight(bool on);
|
||||||
|
|
||||||
} // namespace DisplayInit
|
} // namespace DisplayInit
|
||||||
|
|||||||
@@ -7,12 +7,9 @@
|
|||||||
#include "display/lvgl_v8_port.h"
|
#include "display/lvgl_v8_port.h"
|
||||||
#include "drivers/can_driver.h"
|
#include "drivers/can_driver.h"
|
||||||
#include "tuning_screen.h"
|
#include "tuning_screen.h"
|
||||||
|
#include "settings_screen.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "ui.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace DrivelineScreen {
|
namespace DrivelineScreen {
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -137,16 +134,15 @@ static lv_obj_t* makeStat(lv_obj_t* parent, const char* title,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gesture handler on OUR screen: swipe LEFT opens Settings (SquareLine),
|
* @brief Gesture handler: swipe LEFT opens Settings, swipe RIGHT the Gauge
|
||||||
* swipe RIGHT continues to the Gauge Tuning screen.
|
* Tuning screen (both hand-coded, instant switches).
|
||||||
*/
|
*/
|
||||||
static void onScreenGesture(lv_event_t* e) {
|
static void onScreenGesture(lv_event_t* e) {
|
||||||
if (lv_event_get_code(e) != LV_EVENT_GESTURE) return;
|
if (lv_event_get_code(e) != LV_EVENT_GESTURE) return;
|
||||||
lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
|
lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
|
||||||
if (dir == LV_DIR_LEFT) {
|
if (dir == LV_DIR_LEFT) {
|
||||||
lv_indev_wait_release(lv_indev_get_act());
|
lv_indev_wait_release(lv_indev_get_act());
|
||||||
_ui_screen_change(&ui_Settings_Screen, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0,
|
SettingsScreen::show();
|
||||||
&ui_Settings_Screen_screen_init);
|
|
||||||
} else if (dir == LV_DIR_RIGHT) {
|
} else if (dir == LV_DIR_RIGHT) {
|
||||||
lv_indev_wait_release(lv_indev_get_act());
|
lv_indev_wait_release(lv_indev_get_act());
|
||||||
TuningScreen::show();
|
TuningScreen::show();
|
||||||
@@ -257,7 +253,7 @@ static void build() {
|
|||||||
|
|
||||||
void show() {
|
void show() {
|
||||||
build();
|
build();
|
||||||
lv_scr_load_anim(g_screen, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0, false);
|
lv_scr_load_anim(g_screen, LV_SCR_LOAD_ANIM_NONE, 0, 0, false); // instant: fades stutter at 1024x600
|
||||||
}
|
}
|
||||||
|
|
||||||
void tick() {
|
void tick() {
|
||||||
@@ -390,9 +386,3 @@ void tick() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace DrivelineScreen
|
} // namespace DrivelineScreen
|
||||||
|
|
||||||
// C entry point used by the SquareLine-generated Settings screen's back gesture.
|
|
||||||
// Runs inside an LVGL event handler, so the LVGL lock is already held.
|
|
||||||
extern "C" void app_show_driveline(void) {
|
|
||||||
DrivelineScreen::show();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -62,14 +62,30 @@ bool init() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Anything that restarts the Wi-Fi driver drops ESP-NOW with it. Re-init at
|
||||||
|
// most once a second instead of failing every frame from then on.
|
||||||
|
static void reinitIfDue() {
|
||||||
|
static uint32_t last = 0;
|
||||||
|
if (millis() - last < 1000) return;
|
||||||
|
last = millis();
|
||||||
|
g_ready = false;
|
||||||
|
ESP_LOGW("EspNow", "ESP-NOW not initialised - re-initialising");
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
bool send(const uint8_t* frame, size_t len) {
|
bool send(const uint8_t* frame, size_t len) {
|
||||||
if (!g_ready || len == 0 || len > ESP_NOW_MAX_DATA_LEN) return false;
|
if (len == 0 || len > ESP_NOW_MAX_DATA_LEN) return false;
|
||||||
|
if (!g_ready) {
|
||||||
|
reinitIfDue();
|
||||||
|
if (!g_ready) return false;
|
||||||
|
}
|
||||||
esp_err_t err = esp_now_send(BROADCAST_MAC, frame, len);
|
esp_err_t err = esp_now_send(BROADCAST_MAC, frame, len);
|
||||||
if (err == ESP_OK) {
|
if (err == ESP_OK) {
|
||||||
g_sent++;
|
g_sent++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
g_fail++;
|
g_fail++;
|
||||||
|
if (err == ESP_ERR_ESPNOW_NOT_INIT) reinitIfDue();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,667 @@
|
|||||||
|
/**
|
||||||
|
* ota_update.cpp - see ota_update.h for the command set and safety rules.
|
||||||
|
*
|
||||||
|
* Flow of `ota install`:
|
||||||
|
* 1. gate: Wi-Fi joined, vehicle parked
|
||||||
|
* 2. GET /api/v1/repos/<repo>/releases/latest -> tag_name
|
||||||
|
* 3. GET /<repo>/releases/download/<tag>/manifest.txt
|
||||||
|
* 4. verify ECDSA P-256 signature over "target|version|sha256" (before download)
|
||||||
|
* 5. GET /<repo>/releases/download/<tag>/firmware.bin -> idle OTA slot,
|
||||||
|
* hashing as it streams; sha256 must equal the signed one
|
||||||
|
* 6. esp_ota_end() (image self-check), gate again, switch boot slot, reboot
|
||||||
|
* 7. next boot: the image is PENDING_VERIFY until tick() confirms it
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "modules/ota_update.h"
|
||||||
|
#include "modules/serial_lock.h"
|
||||||
|
#include "drivers/can_driver.h"
|
||||||
|
#include "protocol/automotive_data.h"
|
||||||
|
#include "config/ota_config.h"
|
||||||
|
#include "modules/display_init.h"
|
||||||
|
#include "modules/tunables.h"
|
||||||
|
#include "display/lvgl_v8_port.h"
|
||||||
|
#include <lvgl.h>
|
||||||
|
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <WiFiClientSecure.h>
|
||||||
|
#include <HTTPClient.h>
|
||||||
|
#include <esp_ota_ops.h>
|
||||||
|
#include <esp_partition.h>
|
||||||
|
#include <mbedtls/sha256.h>
|
||||||
|
#include <mbedtls/pk.h>
|
||||||
|
#include <mbedtls/platform.h>
|
||||||
|
#include <esp_heap_caps.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
// Take over Arduino's rollback hook: by default initArduino() marks a new image
|
||||||
|
// valid before setup() even runs, so a crash in setup would never roll back.
|
||||||
|
// Returning true leaves the image PENDING_VERIFY until Ota::tick() confirms it.
|
||||||
|
extern "C" bool verifyRollbackLater() { return true; }
|
||||||
|
|
||||||
|
namespace Ota {
|
||||||
|
|
||||||
|
#define OTA_CONFIRM_S 30 // healthy uptime before a new image is kept
|
||||||
|
#define TOSTR_(x) #x
|
||||||
|
#define TOSTR(x) TOSTR_(x)
|
||||||
|
static const uint32_t OTA_CONFIRM_MS = OTA_CONFIRM_S * 1000;
|
||||||
|
static const uint32_t BUS_SILENT_MS = 2000; // no frames for this long = ignition off / bench
|
||||||
|
static const uint32_t STALL_TIMEOUT_MS = 15000; // download aborts if no bytes arrive this long
|
||||||
|
static const size_t CHUNK = 4096;
|
||||||
|
// Jobs run inside the Arduino loop task (8 KB internal stack), not a task of
|
||||||
|
// their own: with the display + Wi-Fi up, internal RAM has no block big enough
|
||||||
|
// for another TLS-capable stack (measured 2026-09-26: 15.9 KB free, largest
|
||||||
|
// block 7.6 KB), and the stack can't go to PSRAM because esp_ota_write()
|
||||||
|
// disables the flash cache. The loop (screen value ticks, console) pauses
|
||||||
|
// while a job runs - acceptable: parked, and an install ends in a reboot.
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char tag[32];
|
||||||
|
char target[16];
|
||||||
|
char version[32];
|
||||||
|
uint32_t size;
|
||||||
|
char sha256[65]; // lowercase hex
|
||||||
|
uint8_t sig[80]; // DER ECDSA signature
|
||||||
|
size_t sig_len;
|
||||||
|
} manifest_t;
|
||||||
|
|
||||||
|
enum job_t { JOB_CHECK, JOB_INSTALL, JOB_INSTALL_FORCE };
|
||||||
|
|
||||||
|
static bool g_job_pending = false;
|
||||||
|
static job_t g_job = JOB_CHECK;
|
||||||
|
static bool g_pending_verify = false;
|
||||||
|
|
||||||
|
// What the Settings screen shows. Written by the loop task (jobs) and the LVGL
|
||||||
|
// task (requests), read by the loop task - a spinlock keeps copies consistent.
|
||||||
|
static portMUX_TYPE g_ui_mux = portMUX_INITIALIZER_UNLOCKED;
|
||||||
|
static ui_status_t g_ui = {PHASE_IDLE, "", ""};
|
||||||
|
static char g_last_msg[96] = ""; // last console line, reused as the failure reason
|
||||||
|
|
||||||
|
static void setPhase(phase_t p, const char* latest = NULL, const char* msg = NULL) {
|
||||||
|
portENTER_CRITICAL(&g_ui_mux);
|
||||||
|
g_ui.phase = p;
|
||||||
|
if (latest) { strncpy(g_ui.latest, latest, sizeof(g_ui.latest) - 1); g_ui.latest[sizeof(g_ui.latest) - 1] = 0; }
|
||||||
|
const char* m = msg ? msg : "";
|
||||||
|
strncpy(g_ui.message, m, sizeof(g_ui.message) - 1);
|
||||||
|
g_ui.message[sizeof(g_ui.message) - 1] = 0;
|
||||||
|
portEXIT_CRITICAL(&g_ui_mux);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// Helpers
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
static void vlog(bool remember, const char* fmt, va_list ap) {
|
||||||
|
char buf[220];
|
||||||
|
vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||||
|
SerialLock::lock();
|
||||||
|
Serial.println(buf);
|
||||||
|
SerialLock::unlock();
|
||||||
|
if (remember) {
|
||||||
|
const char* m = strncmp(buf, "[ota] ", 6) == 0 ? buf + 6 : buf;
|
||||||
|
portENTER_CRITICAL(&g_ui_mux);
|
||||||
|
strncpy(g_last_msg, m, sizeof(g_last_msg) - 1);
|
||||||
|
g_last_msg[sizeof(g_last_msg) - 1] = 0;
|
||||||
|
portEXIT_CRITICAL(&g_ui_mux);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Console line; also kept as the reason the screen shows if the job fails. */
|
||||||
|
static void print(const char* fmt, ...) {
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vlog(true, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Console-only diagnostics (heap, stack) that must not replace a failure reason. */
|
||||||
|
static void debug(const char* fmt, ...) {
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vlog(false, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void failPhase() {
|
||||||
|
char m[96];
|
||||||
|
portENTER_CRITICAL(&g_ui_mux);
|
||||||
|
memcpy(m, g_last_msg, sizeof(m));
|
||||||
|
portEXIT_CRITICAL(&g_ui_mux);
|
||||||
|
setPhase(PHASE_FAILED, NULL, m);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char* stateName(esp_ota_img_states_t s) {
|
||||||
|
switch (s) {
|
||||||
|
case ESP_OTA_IMG_NEW: return "new";
|
||||||
|
case ESP_OTA_IMG_PENDING_VERIFY: return "pending-verify";
|
||||||
|
case ESP_OTA_IMG_VALID: return "valid";
|
||||||
|
case ESP_OTA_IMG_INVALID: return "invalid";
|
||||||
|
case ESP_OTA_IMG_ABORTED: return "aborted";
|
||||||
|
default: return "undefined";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The vehicle must be parked to update: installing ends in a reboot that blanks
|
||||||
|
* Controller B's gauges. A silent bus (ignition off, or the bench) counts as
|
||||||
|
* parked. Lever UNKNOWN is allowed so a missing gear frame can't block a bench
|
||||||
|
* update; engine and output shaft are the checks that matter.
|
||||||
|
*/
|
||||||
|
static bool parked(char* why, size_t n) {
|
||||||
|
if (!CANDriver::isActive()) return true;
|
||||||
|
can_stats_t s = CANDriver::getStats();
|
||||||
|
if (millis() - s.last_receive_time > BUS_SILENT_MS) return true;
|
||||||
|
|
||||||
|
driveline_t d = CANDriver::getDriveline();
|
||||||
|
if (d.engine_rpm > 0 || d.engine_run_state == ENGINE_RUN_RUNNING ||
|
||||||
|
d.engine_run_state == ENGINE_RUN_STARTING) {
|
||||||
|
snprintf(why, n, "engine running (%u rpm) - switch the engine off", d.engine_rpm);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (d.output_shaft_raw != 0) {
|
||||||
|
snprintf(why, n, "vehicle moving (output shaft turning)");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (d.lever != GEAR_PARK && d.lever != GEAR_NEUTRAL && d.lever != GEAR_UNKNOWN) {
|
||||||
|
snprintf(why, n, "lever in a drive gear - select P");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool gate(bool need_wifi, bool need_parked = true, char* why_out = NULL, size_t why_n = 0) {
|
||||||
|
char why[96];
|
||||||
|
bool ok = true;
|
||||||
|
if (need_parked && !parked(why, sizeof(why))) {
|
||||||
|
ok = false;
|
||||||
|
} else if (need_wifi && WiFi.status() != WL_CONNECTED) {
|
||||||
|
snprintf(why, sizeof(why), "Wi-Fi not connected - join a network first");
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
print("[ota] refused: %s", why);
|
||||||
|
if (why_out) snprintf(why_out, why_n, "%s", why);
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void toHex(const uint8_t* in, size_t n, char* out) {
|
||||||
|
static const char* d = "0123456789abcdef";
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
out[2 * i] = d[in[i] >> 4];
|
||||||
|
out[2 * i + 1] = d[in[i] & 0x0F];
|
||||||
|
}
|
||||||
|
out[2 * n] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int hexNibble(char c) {
|
||||||
|
if (c >= '0' && c <= '9') return c - '0';
|
||||||
|
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
||||||
|
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool fromHex(const char* s, uint8_t* out, size_t cap, size_t* len) {
|
||||||
|
size_t n = strlen(s);
|
||||||
|
if (n == 0 || (n % 2) || n / 2 > cap) return false;
|
||||||
|
for (size_t i = 0; i < n; i += 2) {
|
||||||
|
int hi = hexNibble(s[i]), lo = hexNibble(s[i + 1]);
|
||||||
|
if (hi < 0 || lo < 0) return false;
|
||||||
|
out[i / 2] = (uint8_t)((hi << 4) | lo);
|
||||||
|
}
|
||||||
|
*len = n / 2;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Tags end up in URLs; accept only [A-Za-z0-9._-]. */
|
||||||
|
static bool safeToken(const char* s) {
|
||||||
|
if (!*s) return false;
|
||||||
|
for (; *s; s++) {
|
||||||
|
if (!isalnum((unsigned char)*s) && *s != '.' && *s != '_' && *s != '-') return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** HTTPS GET of a small text body (API reply, manifest). */
|
||||||
|
static bool httpsGetText(const char* url, String& body, int& code) {
|
||||||
|
WiFiClientSecure client;
|
||||||
|
client.setCACert(OTA_CA_PEM);
|
||||||
|
HTTPClient http;
|
||||||
|
http.setConnectTimeout(10000);
|
||||||
|
http.setTimeout(15000);
|
||||||
|
if (!http.begin(client, url)) {
|
||||||
|
code = -1;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
http.setUserAgent("patrol-a-ota/" FW_VERSION);
|
||||||
|
code = http.GET();
|
||||||
|
bool ok = (code == HTTP_CODE_OK);
|
||||||
|
if (ok) body = http.getString();
|
||||||
|
http.end();
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Pull "key":"value" out of a flat JSON reply without a JSON library. */
|
||||||
|
static bool jsonString(const String& s, const char* key, char* out, size_t n) {
|
||||||
|
String k = String("\"") + key + "\"";
|
||||||
|
int i = s.indexOf(k);
|
||||||
|
if (i < 0) return false;
|
||||||
|
i = s.indexOf(':', i + k.length());
|
||||||
|
if (i < 0) return false;
|
||||||
|
i = s.indexOf('"', i);
|
||||||
|
if (i < 0) return false;
|
||||||
|
int j = s.indexOf('"', i + 1);
|
||||||
|
if (j < 0 || (size_t)(j - i - 1) >= n) return false;
|
||||||
|
s.substring(i + 1, j).toCharArray(out, n);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool fetchManifest(manifest_t& m) {
|
||||||
|
memset(&m, 0, sizeof(m));
|
||||||
|
String body;
|
||||||
|
int code;
|
||||||
|
|
||||||
|
if (!httpsGetText(OTA_LATEST_API_URL, body, code)) {
|
||||||
|
if (code == 404) print("[ota] no release published yet (push a v* tag)");
|
||||||
|
else print("[ota] release lookup failed (HTTP %d)", code);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!jsonString(body, "tag_name", m.tag, sizeof(m.tag)) || !safeToken(m.tag)) {
|
||||||
|
print("[ota] could not read tag_name from the release reply");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String url = String(OTA_DOWNLOAD_BASE) + m.tag + "/manifest.txt";
|
||||||
|
if (!httpsGetText(url.c_str(), body, code)) {
|
||||||
|
print("[ota] release %s has no manifest.txt (HTTP %d)", m.tag, code);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char sig_hex[2 * sizeof(m.sig) + 1] = {0};
|
||||||
|
int start = 0;
|
||||||
|
while (start < (int)body.length()) {
|
||||||
|
int nl = body.indexOf('\n', start);
|
||||||
|
if (nl < 0) nl = body.length();
|
||||||
|
String line = body.substring(start, nl);
|
||||||
|
line.trim();
|
||||||
|
start = nl + 1;
|
||||||
|
int eq = line.indexOf('=');
|
||||||
|
if (eq <= 0) continue;
|
||||||
|
String k = line.substring(0, eq), v = line.substring(eq + 1);
|
||||||
|
if (k == "target") v.toCharArray(m.target, sizeof(m.target));
|
||||||
|
else if (k == "version") v.toCharArray(m.version, sizeof(m.version));
|
||||||
|
else if (k == "size") m.size = (uint32_t)v.toInt();
|
||||||
|
else if (k == "sha256") v.toCharArray(m.sha256, sizeof(m.sha256));
|
||||||
|
else if (k == "sig" && v.length() < sizeof(sig_hex)) v.toCharArray(sig_hex, sizeof(sig_hex));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(m.target, OTA_TARGET) != 0) {
|
||||||
|
print("[ota] manifest is for '%s', not '%s' - refusing", m.target, OTA_TARGET);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (strcmp(m.version, m.tag) != 0 || m.size == 0 || strlen(m.sha256) != 64 ||
|
||||||
|
!fromHex(sig_hex, m.sig, sizeof(m.sig), &m.sig_len)) {
|
||||||
|
print("[ota] manifest for %s is malformed", m.tag);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (char* c = m.sha256; *c; c++) *c = tolower(*c);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ECDSA P-256 over SHA-256("target|version|sha256hex"), checked before downloading. */
|
||||||
|
static bool verifySignature(const manifest_t& m) {
|
||||||
|
char stmt[160];
|
||||||
|
int n = snprintf(stmt, sizeof(stmt), "%s|%s|%s", m.target, m.version, m.sha256);
|
||||||
|
uint8_t h[32];
|
||||||
|
mbedtls_sha256((const unsigned char*)stmt, n, h, 0);
|
||||||
|
|
||||||
|
mbedtls_pk_context pk;
|
||||||
|
mbedtls_pk_init(&pk);
|
||||||
|
int rc = mbedtls_pk_parse_public_key(&pk, (const unsigned char*)OTA_SIGNING_PUBKEY_PEM,
|
||||||
|
sizeof(OTA_SIGNING_PUBKEY_PEM));
|
||||||
|
if (rc == 0) rc = mbedtls_pk_verify(&pk, MBEDTLS_MD_SHA256, h, sizeof(h), m.sig, m.sig_len);
|
||||||
|
mbedtls_pk_free(&pk);
|
||||||
|
if (rc != 0) print("[ota] SIGNATURE INVALID for %s (mbedtls -0x%04X) - refusing", m.tag, -rc);
|
||||||
|
return rc == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// Install
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
/** Download firmware.bin into the idle slot, hashing as it streams; true if it matches the signed manifest. */
|
||||||
|
static bool writeImage(const manifest_t& m, const esp_partition_t* part) {
|
||||||
|
String url = String(OTA_DOWNLOAD_BASE) + m.tag + "/firmware.bin";
|
||||||
|
WiFiClientSecure client;
|
||||||
|
client.setCACert(OTA_CA_PEM);
|
||||||
|
HTTPClient http;
|
||||||
|
http.setConnectTimeout(10000);
|
||||||
|
http.setTimeout(15000);
|
||||||
|
if (!http.begin(client, url)) { print("[ota] bad download URL"); return false; }
|
||||||
|
http.setUserAgent("patrol-a-ota/" FW_VERSION);
|
||||||
|
int code = http.GET();
|
||||||
|
if (code != HTTP_CODE_OK) { print("[ota] download failed (HTTP %d)", code); http.end(); return false; }
|
||||||
|
if (http.getSize() != (int)m.size) {
|
||||||
|
print("[ota] server size %d != manifest size %lu", http.getSize(), (unsigned long)m.size);
|
||||||
|
http.end();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_ota_handle_t h = 0;
|
||||||
|
esp_err_t err = esp_ota_begin(part, OTA_WITH_SEQUENTIAL_WRITES, &h);
|
||||||
|
if (err != ESP_OK) { print("[ota] esp_ota_begin: %s", esp_err_to_name(err)); http.end(); return false; }
|
||||||
|
|
||||||
|
uint8_t* buf = (uint8_t*)malloc(CHUNK);
|
||||||
|
mbedtls_sha256_context sc;
|
||||||
|
mbedtls_sha256_init(&sc);
|
||||||
|
mbedtls_sha256_starts(&sc, 0);
|
||||||
|
|
||||||
|
NetworkClient* stream = http.getStreamPtr();
|
||||||
|
uint32_t got = 0, last_rx = millis();
|
||||||
|
int last_decile = -1;
|
||||||
|
bool ok = (buf != NULL);
|
||||||
|
while (ok && got < m.size) {
|
||||||
|
size_t avail = stream->available();
|
||||||
|
if (avail == 0) {
|
||||||
|
// connected() can read false for a moment between TLS records, so a
|
||||||
|
// drop only counts after 2 s of silence (it aborted a download at
|
||||||
|
// 570 B once, 2026-09-26; the retry went through).
|
||||||
|
uint32_t idle = millis() - last_rx;
|
||||||
|
if ((!http.connected() && idle > 2000) || idle > STALL_TIMEOUT_MS) {
|
||||||
|
print("[ota] download stalled at %lu/%lu bytes", (unsigned long)got, (unsigned long)m.size);
|
||||||
|
ok = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(5));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
size_t want = min(min(avail, CHUNK), (size_t)(m.size - got));
|
||||||
|
int r = stream->read(buf, want);
|
||||||
|
if (r <= 0) continue;
|
||||||
|
last_rx = millis();
|
||||||
|
mbedtls_sha256_update(&sc, buf, r);
|
||||||
|
err = esp_ota_write(h, buf, r);
|
||||||
|
if (err != ESP_OK) { print("[ota] flash write: %s", esp_err_to_name(err)); ok = false; break; }
|
||||||
|
got += r;
|
||||||
|
int decile = (int)((uint64_t)got * 10 / m.size);
|
||||||
|
if (decile != last_decile) { print("[ota] %d%%", decile * 10); last_decile = decile; }
|
||||||
|
}
|
||||||
|
http.end();
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
uint8_t digest[32];
|
||||||
|
char digest_hex[65];
|
||||||
|
mbedtls_sha256_finish(&sc, digest);
|
||||||
|
mbedtls_sha256_free(&sc);
|
||||||
|
toHex(digest, sizeof(digest), digest_hex);
|
||||||
|
|
||||||
|
if (ok && strcmp(digest_hex, m.sha256) != 0) {
|
||||||
|
print("[ota] SHA-256 MISMATCH - image does not match the signed manifest");
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
if (!ok) { esp_ota_abort(h); print("[ota] aborted; still running %s", FW_VERSION); return false; }
|
||||||
|
|
||||||
|
err = esp_ota_end(h); // validates the image structure + its embedded hash
|
||||||
|
if (err != ESP_OK) { print("[ota] image check failed: %s", esp_err_to_name(err)); return false; }
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Full-screen notice on lv_layer_top() (above every screen) ----------------
|
||||||
|
static lv_obj_t* g_notice = NULL;
|
||||||
|
static lv_obj_t* g_notice_lbl = NULL;
|
||||||
|
|
||||||
|
static void showNotice(const char* text) {
|
||||||
|
lvgl_port_lock(-1);
|
||||||
|
if (g_notice == NULL) {
|
||||||
|
g_notice = lv_obj_create(lv_layer_top());
|
||||||
|
lv_obj_remove_style_all(g_notice);
|
||||||
|
lv_obj_set_size(g_notice, LV_PCT(100), LV_PCT(100));
|
||||||
|
lv_obj_set_style_bg_color(g_notice, lv_color_black(), 0);
|
||||||
|
lv_obj_set_style_bg_opa(g_notice, LV_OPA_COVER, 0);
|
||||||
|
lv_obj_add_flag(g_notice, LV_OBJ_FLAG_CLICKABLE); // swallow touches while shown
|
||||||
|
g_notice_lbl = lv_label_create(g_notice);
|
||||||
|
lv_obj_set_style_text_font(g_notice_lbl, &lv_font_montserrat_30, 0);
|
||||||
|
lv_obj_set_style_text_color(g_notice_lbl, lv_color_white(), 0);
|
||||||
|
lv_obj_set_style_text_align(g_notice_lbl, LV_TEXT_ALIGN_CENTER, 0);
|
||||||
|
lv_obj_center(g_notice_lbl);
|
||||||
|
}
|
||||||
|
lv_label_set_text(g_notice_lbl, text);
|
||||||
|
lv_obj_clear_flag(g_notice, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
lvgl_port_unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void hideNotice() {
|
||||||
|
lvgl_port_lock(-1);
|
||||||
|
if (g_notice) lv_obj_add_flag(g_notice, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
lvgl_port_unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void install(bool force) {
|
||||||
|
manifest_t m;
|
||||||
|
if (!fetchManifest(m) || !verifySignature(m)) { failPhase(); return; }
|
||||||
|
|
||||||
|
if (!force && strcmp(m.version, FW_VERSION) == 0) {
|
||||||
|
print("[ota] already running %s - nothing to do (`ota install force` to reinstall)", FW_VERSION);
|
||||||
|
setPhase(PHASE_UP_TO_DATE, m.version);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const esp_partition_t* part = esp_ota_get_next_update_partition(NULL);
|
||||||
|
if (!part) { print("[ota] no idle OTA slot (partition table?)"); failPhase(); return; }
|
||||||
|
if (m.size > part->size) {
|
||||||
|
print("[ota] image %lu B does not fit slot %s (%lu B)",
|
||||||
|
(unsigned long)m.size, part->label, (unsigned long)part->size);
|
||||||
|
failPhase();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print("[ota] installing %s -> %s (%lu bytes)", m.version, part->label, (unsigned long)m.size);
|
||||||
|
|
||||||
|
// Flash writes stall the PSRAM-fed RGB panel (flicker), so the screen is
|
||||||
|
// dark while the image is written, with a notice before and after.
|
||||||
|
char msg[160];
|
||||||
|
snprintf(msg, sizeof(msg), "Updating to %s\n\nThe screen goes dark for about a minute.\nDo not switch off.", m.version);
|
||||||
|
showNotice(msg);
|
||||||
|
delay(3000); // time to read it; LVGL renders on its own task
|
||||||
|
DisplayInit::setBacklight(false);
|
||||||
|
bool ok = writeImage(m, part);
|
||||||
|
DisplayInit::setBacklight(true);
|
||||||
|
|
||||||
|
// The download took a while - the driver may have started the engine since.
|
||||||
|
if (ok && !gate(false)) {
|
||||||
|
print("[ota] new image left inactive in %s; retry when parked", part->label);
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
esp_err_t err = esp_ota_set_boot_partition(part);
|
||||||
|
if (err != ESP_OK) { print("[ota] set boot slot: %s", esp_err_to_name(err)); ok = false; }
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
failPhase();
|
||||||
|
snprintf(msg, sizeof(msg), "Update failed\n\nStill running %s", FW_VERSION);
|
||||||
|
showNotice(msg);
|
||||||
|
delay(5000);
|
||||||
|
hideNotice();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print("[ota] verified and installed %s. Rebooting in 3 s; it confirms itself after %lu s of uptime.",
|
||||||
|
m.version, (unsigned long)(OTA_CONFIRM_MS / 1000));
|
||||||
|
snprintf(msg, sizeof(msg), "Installed %s\n\nRestarting...", m.version);
|
||||||
|
showNotice(msg);
|
||||||
|
Tunables::flush();
|
||||||
|
delay(3000);
|
||||||
|
esp_restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void check() {
|
||||||
|
manifest_t m;
|
||||||
|
if (!fetchManifest(m) || !verifySignature(m)) { failPhase(); return; }
|
||||||
|
bool same = strcmp(m.version, FW_VERSION) == 0;
|
||||||
|
print("[ota] running %s | latest release %s (%lu bytes, signature OK)%s",
|
||||||
|
FW_VERSION, m.version, (unsigned long)m.size,
|
||||||
|
same ? " - up to date" : " - `ota install` to update");
|
||||||
|
setPhase(same ? PHASE_UP_TO_DATE : PHASE_AVAILABLE, m.version);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This core's mbedtls is built with CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC: every TLS
|
||||||
|
// session wants ~40 KB of *internal* RAM, which the display + Wi-Fi leave no
|
||||||
|
// room for. Route mbedtls to PSRAM (internal as fallback) while a job runs.
|
||||||
|
// Both allocators free with heap_caps_free(), so swapping them is always safe.
|
||||||
|
static void* tlsCallocPsram(size_t n, size_t size) {
|
||||||
|
return heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT,
|
||||||
|
MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||||
|
}
|
||||||
|
static void* tlsCallocInternal(size_t n, size_t size) {
|
||||||
|
return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void printHeap(const char* when) {
|
||||||
|
debug("[ota] heap %s: internal free %u (largest block %u), PSRAM free %u", when,
|
||||||
|
(unsigned)heap_caps_get_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT),
|
||||||
|
(unsigned)heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT),
|
||||||
|
(unsigned)heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void runJob(job_t job) {
|
||||||
|
mbedtls_platform_set_calloc_free(tlsCallocPsram, heap_caps_free);
|
||||||
|
if (job == JOB_CHECK) check();
|
||||||
|
else install(job == JOB_INSTALL_FORCE);
|
||||||
|
mbedtls_platform_set_calloc_free(tlsCallocInternal, heap_caps_free);
|
||||||
|
debug("[ota] loop stack headroom after job: %u B", (unsigned)uxTaskGetStackHighWaterMark(NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool startJob(job_t job, char* why = NULL, size_t why_n = 0) {
|
||||||
|
if (g_job_pending) {
|
||||||
|
if (why) snprintf(why, why_n, "busy");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!gate(true, job != JOB_CHECK, why, why_n)) return false; // checking is harmless; installing needs parked
|
||||||
|
setPhase(job == JOB_CHECK ? PHASE_CHECKING : PHASE_INSTALLING);
|
||||||
|
g_job = job;
|
||||||
|
g_job_pending = true; // runs on the next tick(), in the loop task
|
||||||
|
print("[ota] working - console and screen values pause until done");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// Status / rollback
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
static void status() {
|
||||||
|
const esp_partition_t* run = esp_ota_get_running_partition();
|
||||||
|
const esp_partition_t* other = esp_ota_get_next_update_partition(NULL);
|
||||||
|
esp_ota_img_states_t st = ESP_OTA_IMG_UNDEFINED;
|
||||||
|
esp_ota_get_state_partition(run, &st);
|
||||||
|
print("[ota] version %s (built %s %s), slot %s, state %s%s", FW_VERSION, __DATE__, __TIME__,
|
||||||
|
run ? run->label : "?", stateName(st),
|
||||||
|
g_pending_verify ? " - confirms after " TOSTR(OTA_CONFIRM_S) " s uptime" : "");
|
||||||
|
if (other) {
|
||||||
|
esp_app_desc_t d;
|
||||||
|
esp_ota_img_states_t ost = ESP_OTA_IMG_UNDEFINED;
|
||||||
|
esp_ota_get_state_partition(other, &ost);
|
||||||
|
if (esp_ota_get_partition_description(other, &d) == ESP_OK) {
|
||||||
|
print("[ota] other slot %s: image built %s %s, state %s", other->label, d.date, d.time, stateName(ost));
|
||||||
|
} else {
|
||||||
|
print("[ota] other slot %s: empty", other->label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print("[ota] updates from %s/%s/releases (%s)", OTA_SERVER, OTA_REPO, OTA_TARGET);
|
||||||
|
printHeap("now");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rollback() {
|
||||||
|
if (!gate(false)) return;
|
||||||
|
if (g_pending_verify) {
|
||||||
|
print("[ota] rejecting this unconfirmed image; rebooting into the previous one");
|
||||||
|
Tunables::flush();
|
||||||
|
delay(500);
|
||||||
|
esp_ota_mark_app_invalid_rollback_and_reboot();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const esp_partition_t* other = esp_ota_get_next_update_partition(NULL);
|
||||||
|
esp_app_desc_t d;
|
||||||
|
esp_ota_img_states_t ost = ESP_OTA_IMG_UNDEFINED;
|
||||||
|
if (!other || esp_ota_get_partition_description(other, &d) != ESP_OK) {
|
||||||
|
print("[ota] no previous image to roll back to");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
esp_ota_get_state_partition(other, &ost);
|
||||||
|
if (ost == ESP_OTA_IMG_INVALID || ost == ESP_OTA_IMG_ABORTED) {
|
||||||
|
print("[ota] previous image in %s is marked %s - refusing", other->label, stateName(ost));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
esp_err_t err = esp_ota_set_boot_partition(other);
|
||||||
|
if (err != ESP_OK) { print("[ota] set boot slot: %s", esp_err_to_name(err)); return; }
|
||||||
|
print("[ota] booting %s in 2 s", other->label);
|
||||||
|
Tunables::flush();
|
||||||
|
delay(2000);
|
||||||
|
esp_restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void help() {
|
||||||
|
print("ota status running version, slot, rollback state");
|
||||||
|
print("ota check ask Gitea for the latest release (needs Wi-Fi)");
|
||||||
|
print("ota install [force] download + verify + flash idle slot + reboot (parked only)");
|
||||||
|
print("ota rollback boot the previous slot (parked only)");
|
||||||
|
print("Tip: `diag raw off` first so CANRAW lines don't bury the progress output.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// Public API
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
const char* version() { return FW_VERSION; }
|
||||||
|
|
||||||
|
ui_status_t getStatus() {
|
||||||
|
ui_status_t s;
|
||||||
|
portENTER_CRITICAL(&g_ui_mux);
|
||||||
|
s = g_ui;
|
||||||
|
portEXIT_CRITICAL(&g_ui_mux);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool requestCheck(char* why, size_t n) { return startJob(JOB_CHECK, why, n); }
|
||||||
|
bool requestInstall(char* why, size_t n) { return startJob(JOB_INSTALL, why, n); }
|
||||||
|
|
||||||
|
void init() {
|
||||||
|
const esp_partition_t* run = esp_ota_get_running_partition();
|
||||||
|
esp_ota_img_states_t st = ESP_OTA_IMG_UNDEFINED;
|
||||||
|
if (run && esp_ota_get_state_partition(run, &st) == ESP_OK && st == ESP_OTA_IMG_PENDING_VERIFY) {
|
||||||
|
g_pending_verify = true;
|
||||||
|
}
|
||||||
|
print("[ota] firmware %s, slot %s%s", FW_VERSION, run ? run->label : "?",
|
||||||
|
g_pending_verify ? " - NEW IMAGE, unconfirmed (a reset in the next " TOSTR(OTA_CONFIRM_S) " s rolls back)" : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
void tick() {
|
||||||
|
if (g_job_pending) {
|
||||||
|
g_job_pending = false;
|
||||||
|
runJob(g_job);
|
||||||
|
}
|
||||||
|
if (g_pending_verify && millis() > OTA_CONFIRM_MS) {
|
||||||
|
esp_ota_mark_app_valid_cancel_rollback();
|
||||||
|
g_pending_verify = false;
|
||||||
|
print("[ota] firmware %s confirmed - rollback cancelled", FW_VERSION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool handleCommand(const char* line) {
|
||||||
|
char buf[48];
|
||||||
|
strncpy(buf, line, sizeof(buf) - 1);
|
||||||
|
buf[sizeof(buf) - 1] = 0;
|
||||||
|
char* argv[4] = {0};
|
||||||
|
int argc = 0;
|
||||||
|
for (char* t = strtok(buf, " \t"); t && argc < 4; t = strtok(NULL, " \t")) argv[argc++] = t;
|
||||||
|
if (argc == 0 || strcmp(argv[0], "ota") != 0) return false;
|
||||||
|
|
||||||
|
if (argc == 1 || !strcmp(argv[1], "help")) help();
|
||||||
|
else if (!strcmp(argv[1], "status")) status();
|
||||||
|
else if (!strcmp(argv[1], "check")) startJob(JOB_CHECK);
|
||||||
|
else if (!strcmp(argv[1], "install")) startJob(argc > 2 && !strcmp(argv[2], "force") ? JOB_INSTALL_FORCE : JOB_INSTALL);
|
||||||
|
else if (!strcmp(argv[1], "rollback")) rollback();
|
||||||
|
else help();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Ota
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
/**
|
||||||
|
* ota_update.h - pull firmware updates from this repo's Gitea releases.
|
||||||
|
*
|
||||||
|
* Manual only: nothing checks or installs by itself. Driven from the Settings
|
||||||
|
* screen (Updates section: check, then install behind a confirm dialog) and the
|
||||||
|
* `ota` serial console.
|
||||||
|
*
|
||||||
|
* ota status running version, slot, rollback state
|
||||||
|
* ota check ask Gitea for the latest release, compare versions
|
||||||
|
* ota install [force] download, verify signature, flash idle slot, reboot
|
||||||
|
* ota rollback boot the previous slot
|
||||||
|
*
|
||||||
|
* Safety:
|
||||||
|
* - refused unless the vehicle is parked (engine off, output shaft still, lever
|
||||||
|
* not in a drive gear) - checked before the download AND again before the
|
||||||
|
* boot slot is switched. Silent bus (bench / ignition off) counts as parked.
|
||||||
|
* - image must match the signed manifest (sha256 + ECDSA P-256 over
|
||||||
|
* "target|version|sha256"); otherwise the idle slot is never activated.
|
||||||
|
* - a new image must run OTA_CONFIRM_MS before it is marked valid; a reset
|
||||||
|
* or crash before that makes the bootloader fall back to the old slot.
|
||||||
|
*
|
||||||
|
* Needs Wi-Fi joined to a network with internet (Settings screen). Joining an
|
||||||
|
* AP moves the radio channel; the ESP-NOW link to Controller B follows it.
|
||||||
|
* See wiki/pages/ota-updates.md.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OTA_UPDATE_H
|
||||||
|
#define OTA_UPDATE_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
namespace Ota {
|
||||||
|
|
||||||
|
/** Log version/slot; note if this boot is an unconfirmed new image. Call early in setup(). */
|
||||||
|
void init();
|
||||||
|
|
||||||
|
/** Confirms a freshly installed image once it has run long enough. Call from loop(). */
|
||||||
|
void tick();
|
||||||
|
|
||||||
|
/** Console entry point (`ota ...`). Returns false if the line isn't an ota command. */
|
||||||
|
bool handleCommand(const char* line);
|
||||||
|
|
||||||
|
/** Firmware version baked in at build time ("dev" for local builds). */
|
||||||
|
const char* version();
|
||||||
|
|
||||||
|
// ---- Settings screen -------------------------------------------------------
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
PHASE_IDLE, // nothing asked yet this boot
|
||||||
|
PHASE_CHECKING,
|
||||||
|
PHASE_UP_TO_DATE, // latest == running
|
||||||
|
PHASE_AVAILABLE, // latest != running
|
||||||
|
PHASE_INSTALLING,
|
||||||
|
PHASE_FAILED // message says why
|
||||||
|
} phase_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
phase_t phase;
|
||||||
|
char latest[32]; // latest release tag, once known
|
||||||
|
char message[96]; // failure reason
|
||||||
|
} ui_status_t;
|
||||||
|
|
||||||
|
ui_status_t getStatus();
|
||||||
|
|
||||||
|
/** Queue a check / install (runs in the loop task). False + reason if refused now. */
|
||||||
|
bool requestCheck(char* why, size_t n);
|
||||||
|
bool requestInstall(char* why, size_t n);
|
||||||
|
|
||||||
|
} // namespace Ota
|
||||||
|
|
||||||
|
#endif // OTA_UPDATE_H
|
||||||
@@ -0,0 +1,789 @@
|
|||||||
|
/*
|
||||||
|
* Settings Screen Module Implementation - see settings_screen.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "settings_screen.h"
|
||||||
|
#include "ui_kit.h"
|
||||||
|
#include "driveline_screen.h"
|
||||||
|
#include "wifi_manager.h"
|
||||||
|
#include "ota_update.h"
|
||||||
|
#include "uart_manager.h"
|
||||||
|
#include "espnow_link.h"
|
||||||
|
#include "settings_manager.h"
|
||||||
|
#include "ui_state_manager.h"
|
||||||
|
#include "drivers/can_driver.h"
|
||||||
|
#include "display/lvgl_v8_port.h"
|
||||||
|
#include "config/ota_config.h"
|
||||||
|
#include <esp_ota_ops.h>
|
||||||
|
#include <esp_heap_caps.h>
|
||||||
|
|
||||||
|
namespace SettingsScreen {
|
||||||
|
|
||||||
|
using namespace UiKit;
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// LAYOUT
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
static const lv_coord_t NAV_X = 16, NAV_W = 240, NAV_H = 100;
|
||||||
|
static const lv_coord_t TOP_Y = 88;
|
||||||
|
static const lv_coord_t PAGE_X = 272, PAGE_W = 736, PAGE_H = 600 - TOP_Y - 28; // version label below
|
||||||
|
|
||||||
|
typedef enum { PAGE_WIFI, PAGE_UPDATES, PAGE_SYSTEM, PAGE_COUNT } page_t;
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// MODULE STATE
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
static lv_obj_t* g_screen = NULL;
|
||||||
|
static lv_obj_t* g_nav[PAGE_COUNT];
|
||||||
|
static lv_obj_t* g_nav_sub[PAGE_COUNT];
|
||||||
|
static lv_obj_t* g_page[PAGE_COUNT];
|
||||||
|
static page_t g_cur = PAGE_WIFI;
|
||||||
|
static bool g_refreshing = false; // setting widget states from code: ignore their events
|
||||||
|
|
||||||
|
// Wi-Fi page
|
||||||
|
static lv_obj_t* g_wifi_sw = NULL;
|
||||||
|
static lv_obj_t* g_wifi_off_note = NULL;
|
||||||
|
static lv_obj_t* g_wifi_body = NULL;
|
||||||
|
static lv_obj_t* g_st_icon = NULL;
|
||||||
|
static lv_obj_t* g_st_spinner = NULL;
|
||||||
|
static lv_obj_t* g_st_title = NULL;
|
||||||
|
static lv_obj_t* g_st_detail = NULL;
|
||||||
|
static lv_obj_t* g_st_connect = NULL;
|
||||||
|
static lv_obj_t* g_st_forget = NULL;
|
||||||
|
static lv_obj_t* g_scan_btn = NULL;
|
||||||
|
static lv_obj_t* g_list = NULL;
|
||||||
|
static lv_obj_t* g_list_note = NULL;
|
||||||
|
static WiFiManager::network_t g_rows[WIFI_SCAN_MAX_NETWORKS];
|
||||||
|
static uint8_t g_row_count = 0;
|
||||||
|
static uint32_t g_list_gen = 0xFFFFFFFF;
|
||||||
|
static char g_list_connected[33] = "";
|
||||||
|
static bool g_want_scan = false;
|
||||||
|
|
||||||
|
// Password entry (full-screen overlay on this screen)
|
||||||
|
static lv_obj_t* g_pw = NULL;
|
||||||
|
static lv_obj_t* g_pw_title = NULL;
|
||||||
|
static lv_obj_t* g_pw_ta = NULL;
|
||||||
|
static lv_obj_t* g_pw_show = NULL;
|
||||||
|
static char g_pw_ssid[33] = "";
|
||||||
|
|
||||||
|
// Updates page
|
||||||
|
static lv_obj_t* g_upd_latest = NULL;
|
||||||
|
static lv_obj_t* g_upd_state = NULL;
|
||||||
|
static lv_obj_t* g_upd_check = NULL;
|
||||||
|
static lv_obj_t* g_upd_install = NULL;
|
||||||
|
static lv_obj_t* g_upd_wifi = NULL;
|
||||||
|
static char g_upd_refusal[96] = "";
|
||||||
|
static Ota::phase_t g_upd_refusal_phase = Ota::PHASE_IDLE;
|
||||||
|
|
||||||
|
// System page
|
||||||
|
static lv_obj_t* g_sys_can = NULL;
|
||||||
|
static lv_obj_t* g_sys_link = NULL;
|
||||||
|
static lv_obj_t* g_sys_dbg = NULL;
|
||||||
|
static lv_obj_t* g_sys_info = NULL; // values column; keys are static
|
||||||
|
|
||||||
|
static void refresh(bool force);
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// NAVIGATION
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
static void selectPage(page_t p) {
|
||||||
|
g_cur = p;
|
||||||
|
for (int i = 0; i < PAGE_COUNT; i++) {
|
||||||
|
bool on = (i == p);
|
||||||
|
setVisible(g_page[i], on);
|
||||||
|
lv_obj_set_style_bg_opa(g_nav[i], on ? LV_OPA_COVER : LV_OPA_TRANSP, 0);
|
||||||
|
lv_obj_set_style_border_width(g_nav[i], on ? 5 : 0, 0);
|
||||||
|
}
|
||||||
|
if (p == PAGE_WIFI) g_want_scan = true;
|
||||||
|
refresh(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onNav(lv_event_t* e) {
|
||||||
|
selectPage((page_t)(uintptr_t)lv_event_get_user_data(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onBack(lv_event_t* e) {
|
||||||
|
(void)e;
|
||||||
|
DrivelineScreen::show();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onGesture(lv_event_t* e) {
|
||||||
|
(void)e;
|
||||||
|
if (g_pw && !lv_obj_has_flag(g_pw, LV_OBJ_FLAG_HIDDEN)) return; // typing a password
|
||||||
|
if (lv_indev_get_gesture_dir(lv_indev_get_act()) == LV_DIR_RIGHT) {
|
||||||
|
lv_indev_wait_release(lv_indev_get_act());
|
||||||
|
DrivelineScreen::show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static lv_obj_t* makeNav(lv_obj_t* parent, page_t p, const char* title) {
|
||||||
|
lv_obj_t* n = lv_obj_create(parent);
|
||||||
|
lv_obj_set_size(n, NAV_W, NAV_H);
|
||||||
|
lv_obj_set_pos(n, NAV_X, TOP_Y + p * (NAV_H + 12));
|
||||||
|
lv_obj_set_style_radius(n, 12, 0);
|
||||||
|
lv_obj_set_style_bg_color(n, UI_COL_PANEL, 0);
|
||||||
|
lv_obj_set_style_bg_opa(n, LV_OPA_TRANSP, 0);
|
||||||
|
lv_obj_set_style_bg_color(n, UI_COL_PANEL2, LV_STATE_PRESSED);
|
||||||
|
lv_obj_set_style_bg_opa(n, LV_OPA_COVER, LV_STATE_PRESSED);
|
||||||
|
lv_obj_set_style_border_side(n, LV_BORDER_SIDE_LEFT, 0);
|
||||||
|
lv_obj_set_style_border_color(n, UI_COL_ACCENT, 0);
|
||||||
|
lv_obj_set_style_border_width(n, 0, 0);
|
||||||
|
lv_obj_set_style_shadow_width(n, 0, 0);
|
||||||
|
lv_obj_set_style_pad_left(n, 20, 0);
|
||||||
|
lv_obj_set_style_pad_ver(n, 18, 0);
|
||||||
|
lv_obj_set_flex_flow(n, LV_FLEX_FLOW_COLUMN);
|
||||||
|
lv_obj_set_flex_align(n, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START);
|
||||||
|
lv_obj_set_style_pad_row(n, 6, 0);
|
||||||
|
lv_obj_clear_flag(n, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
lv_obj_add_flag(n, LV_OBJ_FLAG_CLICKABLE);
|
||||||
|
lv_obj_add_event_cb(n, onNav, LV_EVENT_CLICKED, (void*)(uintptr_t)p);
|
||||||
|
|
||||||
|
label(n, title, &lv_font_montserrat_24, UI_COL_TEXT);
|
||||||
|
g_nav_sub[p] = label(n, "", &lv_font_montserrat_20, UI_COL_MUTED);
|
||||||
|
lv_label_set_long_mode(g_nav_sub[p], LV_LABEL_LONG_DOT);
|
||||||
|
lv_obj_set_width(g_nav_sub[p], NAV_W - 40);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
static lv_obj_t* makePage(lv_obj_t* parent) {
|
||||||
|
lv_obj_t* p = box(parent, LV_FLEX_FLOW_COLUMN);
|
||||||
|
lv_obj_set_size(p, PAGE_W, PAGE_H);
|
||||||
|
lv_obj_set_pos(p, PAGE_X, TOP_Y);
|
||||||
|
lv_obj_set_style_pad_row(p, 12, 0);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** "Title" on the left, a widget (switch) on the right, optional sub-line. */
|
||||||
|
static lv_obj_t* makeSettingRow(lv_obj_t* parent, const char* title, const char* sub, lv_obj_t** right_parent) {
|
||||||
|
lv_obj_t* row = box(parent, LV_FLEX_FLOW_ROW);
|
||||||
|
lv_obj_set_size(row, LV_PCT(100), LV_SIZE_CONTENT);
|
||||||
|
lv_obj_set_flex_align(row, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||||
|
lv_obj_set_style_min_height(row, 64, 0);
|
||||||
|
|
||||||
|
lv_obj_t* col = box(row, LV_FLEX_FLOW_COLUMN);
|
||||||
|
lv_obj_set_size(col, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||||
|
lv_obj_set_style_pad_row(col, 4, 0);
|
||||||
|
label(col, title, &lv_font_montserrat_24, UI_COL_TEXT);
|
||||||
|
if (sub) label(col, sub, &lv_font_montserrat_20, UI_COL_MUTED);
|
||||||
|
*right_parent = row;
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// WI-FI PAGE
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
static void onWifiSwitch(lv_event_t* e) {
|
||||||
|
if (g_refreshing) return;
|
||||||
|
bool on = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
|
||||||
|
WiFiManager::setEnabled(on);
|
||||||
|
if (on) g_want_scan = true;
|
||||||
|
refresh(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onScan(lv_event_t* e) {
|
||||||
|
(void)e;
|
||||||
|
WiFiManager::requestScan();
|
||||||
|
refresh(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onConnectSaved(lv_event_t* e) {
|
||||||
|
(void)e;
|
||||||
|
WiFiManager::connectSaved();
|
||||||
|
refresh(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onForgetConfirmed(bool ok, void* user) {
|
||||||
|
(void)user;
|
||||||
|
if (!ok) return;
|
||||||
|
WiFiManager::forget();
|
||||||
|
g_want_scan = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onForget(lv_event_t* e) {
|
||||||
|
(void)e;
|
||||||
|
WiFiManager::status_t s = WiFiManager::getStatus();
|
||||||
|
char text[128];
|
||||||
|
snprintf(text, sizeof(text), "Controller A will no longer join \"%s\" by itself.", s.saved_ssid);
|
||||||
|
confirm("Forget this network?", text, "Forget", onForgetConfirmed, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void openPassword(const char* ssid) {
|
||||||
|
snprintf(g_pw_ssid, sizeof(g_pw_ssid), "%s", ssid);
|
||||||
|
char t[64];
|
||||||
|
snprintf(t, sizeof(t), "Join \"%s\"", ssid);
|
||||||
|
lv_label_set_text(g_pw_title, t);
|
||||||
|
lv_textarea_set_text(g_pw_ta, "");
|
||||||
|
lv_textarea_set_password_mode(g_pw_ta, true);
|
||||||
|
setButtonText(g_pw_show, LV_SYMBOL_EYE_OPEN " Show");
|
||||||
|
setVisible(g_pw, true);
|
||||||
|
lv_obj_move_foreground(g_pw);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void closePassword() {
|
||||||
|
lv_textarea_set_text(g_pw_ta, ""); // don't leave the password in a widget
|
||||||
|
setVisible(g_pw, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void submitPassword() {
|
||||||
|
const char* pw = lv_textarea_get_text(g_pw_ta);
|
||||||
|
if (pw == NULL || pw[0] == 0) return;
|
||||||
|
WiFiManager::connect(g_pw_ssid, pw);
|
||||||
|
closePassword();
|
||||||
|
refresh(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onPwKeyboard(lv_event_t* e) {
|
||||||
|
lv_event_code_t code = lv_event_get_code(e);
|
||||||
|
if (code == LV_EVENT_READY) submitPassword();
|
||||||
|
else if (code == LV_EVENT_CANCEL) closePassword();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onPwConnect(lv_event_t* e) { (void)e; submitPassword(); }
|
||||||
|
static void onPwCancel(lv_event_t* e) { (void)e; closePassword(); }
|
||||||
|
|
||||||
|
static void onPwShow(lv_event_t* e) {
|
||||||
|
(void)e;
|
||||||
|
bool hidden = lv_textarea_get_password_mode(g_pw_ta);
|
||||||
|
lv_textarea_set_password_mode(g_pw_ta, !hidden);
|
||||||
|
setButtonText(g_pw_show, hidden ? LV_SYMBOL_EYE_CLOSE " Hide" : LV_SYMBOL_EYE_OPEN " Show");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onNetworkRow(lv_event_t* e) {
|
||||||
|
uint8_t i = (uint8_t)(uintptr_t)lv_event_get_user_data(e);
|
||||||
|
if (i >= g_row_count) return;
|
||||||
|
const WiFiManager::network_t& n = g_rows[i];
|
||||||
|
if (strcmp(n.ssid, g_list_connected) == 0) return; // already on it
|
||||||
|
if (n.secured) {
|
||||||
|
openPassword(n.ssid);
|
||||||
|
} else {
|
||||||
|
WiFiManager::connect(n.ssid, "");
|
||||||
|
refresh(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char* strengthWord(int rssi) {
|
||||||
|
if (rssi >= -55) return "Strong";
|
||||||
|
if (rssi >= -67) return "Good";
|
||||||
|
if (rssi >= -77) return "Fair";
|
||||||
|
return "Weak";
|
||||||
|
}
|
||||||
|
|
||||||
|
static lv_color_t strengthColour(int rssi) {
|
||||||
|
if (rssi >= -67) return UI_COL_OK;
|
||||||
|
if (rssi >= -77) return UI_COL_AMBER;
|
||||||
|
return UI_COL_WARN;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rebuildList(const WiFiManager::status_t& s) {
|
||||||
|
g_row_count = WiFiManager::getNetworks(g_rows, WIFI_SCAN_MAX_NETWORKS);
|
||||||
|
g_list_gen = s.scan_gen;
|
||||||
|
snprintf(g_list_connected, sizeof(g_list_connected), "%s", s.link == WiFiManager::LINK_CONNECTED ? s.ssid : "");
|
||||||
|
|
||||||
|
lv_obj_clean(g_list);
|
||||||
|
for (uint8_t i = 0; i < g_row_count; i++) {
|
||||||
|
const WiFiManager::network_t& n = g_rows[i];
|
||||||
|
bool connected = strcmp(n.ssid, g_list_connected) == 0;
|
||||||
|
|
||||||
|
lv_obj_t* row = lv_obj_create(g_list);
|
||||||
|
lv_obj_set_size(row, LV_PCT(100), 64);
|
||||||
|
lv_obj_set_style_bg_color(row, UI_COL_PANEL, 0);
|
||||||
|
lv_obj_set_style_bg_color(row, UI_COL_PANEL2, LV_STATE_PRESSED);
|
||||||
|
lv_obj_set_style_border_width(row, 0, 0);
|
||||||
|
lv_obj_set_style_shadow_width(row, 0, 0);
|
||||||
|
lv_obj_set_style_radius(row, 10, 0);
|
||||||
|
lv_obj_set_style_pad_hor(row, 18, 0);
|
||||||
|
lv_obj_set_style_pad_ver(row, 0, 0);
|
||||||
|
lv_obj_set_style_pad_column(row, 16, 0);
|
||||||
|
lv_obj_set_flex_flow(row, LV_FLEX_FLOW_ROW);
|
||||||
|
lv_obj_set_flex_align(row, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||||
|
lv_obj_clear_flag(row, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
lv_obj_add_flag(row, LV_OBJ_FLAG_CLICKABLE);
|
||||||
|
lv_obj_add_event_cb(row, onNetworkRow, LV_EVENT_CLICKED, (void*)(uintptr_t)i);
|
||||||
|
|
||||||
|
label(row, LV_SYMBOL_WIFI, &lv_font_montserrat_24, strengthColour(n.rssi));
|
||||||
|
lv_obj_t* name = label(row, n.ssid, &lv_font_montserrat_24, UI_COL_TEXT);
|
||||||
|
lv_label_set_long_mode(name, LV_LABEL_LONG_DOT);
|
||||||
|
lv_obj_set_flex_grow(name, 1);
|
||||||
|
|
||||||
|
char right[40];
|
||||||
|
if (connected) snprintf(right, sizeof(right), LV_SYMBOL_OK " Connected");
|
||||||
|
else snprintf(right, sizeof(right), "%s %s", strengthWord(n.rssi), n.secured ? "Secured" : "Open");
|
||||||
|
label(row, right, &lv_font_montserrat_20, connected ? UI_COL_OK : UI_COL_MUTED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void refreshWifi() {
|
||||||
|
WiFiManager::status_t s = WiFiManager::getStatus();
|
||||||
|
bool on = s.link != WiFiManager::LINK_OFF;
|
||||||
|
|
||||||
|
setChecked(g_wifi_sw, on);
|
||||||
|
setVisible(g_wifi_off_note, !on);
|
||||||
|
setVisible(g_wifi_body, on);
|
||||||
|
if (!on) return;
|
||||||
|
|
||||||
|
// Scan when the page opens (not while connected: a scan hops channels
|
||||||
|
// under the ESP-NOW link - the Scan button still works then).
|
||||||
|
if (g_want_scan && (s.link == WiFiManager::LINK_IDLE || s.link == WiFiManager::LINK_FAILED)) {
|
||||||
|
g_want_scan = false;
|
||||||
|
WiFiManager::requestScan();
|
||||||
|
s = WiFiManager::getStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- status card
|
||||||
|
char title[80], detail[96];
|
||||||
|
bool spinner = false, show_connect = false, show_forget = s.saved_ssid[0] != 0;
|
||||||
|
const char* icon = LV_SYMBOL_WIFI;
|
||||||
|
lv_color_t icon_col = UI_COL_MUTED;
|
||||||
|
switch (s.link) {
|
||||||
|
case WiFiManager::LINK_CONNECTED:
|
||||||
|
snprintf(title, sizeof(title), "Connected to %s", s.ssid);
|
||||||
|
snprintf(detail, sizeof(detail), "IP %s \xE2\x80\xA2 signal %s (%d dBm)", s.ip, strengthWord(s.rssi), s.rssi);
|
||||||
|
icon_col = UI_COL_OK;
|
||||||
|
break;
|
||||||
|
case WiFiManager::LINK_CONNECTING:
|
||||||
|
snprintf(title, sizeof(title), "Connecting to %s...", s.ssid);
|
||||||
|
snprintf(detail, sizeof(detail), "This takes up to 15 seconds.");
|
||||||
|
spinner = true;
|
||||||
|
show_forget = false;
|
||||||
|
break;
|
||||||
|
case WiFiManager::LINK_FAILED:
|
||||||
|
snprintf(title, sizeof(title), "Couldn't connect to %s", s.ssid);
|
||||||
|
snprintf(detail, sizeof(detail), "%s", s.error);
|
||||||
|
icon = LV_SYMBOL_WARNING;
|
||||||
|
icon_col = UI_COL_WARN;
|
||||||
|
show_connect = s.saved_ssid[0] != 0;
|
||||||
|
break;
|
||||||
|
default: // IDLE
|
||||||
|
if (s.saved_ssid[0]) {
|
||||||
|
snprintf(title, sizeof(title), "Not connected");
|
||||||
|
snprintf(detail, sizeof(detail), "Saved network: %s", s.saved_ssid);
|
||||||
|
show_connect = true;
|
||||||
|
} else {
|
||||||
|
snprintf(title, sizeof(title), "Not connected");
|
||||||
|
snprintf(detail, sizeof(detail), "Pick a network below. It is remembered once it works.");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
setText(g_st_title, title);
|
||||||
|
setText(g_st_detail, detail);
|
||||||
|
setText(g_st_icon, icon);
|
||||||
|
setTextColor(g_st_icon, icon_col);
|
||||||
|
setVisible(g_st_icon, !spinner);
|
||||||
|
setVisible(g_st_spinner, spinner);
|
||||||
|
setVisible(g_st_connect, show_connect);
|
||||||
|
setVisible(g_st_forget, show_forget);
|
||||||
|
|
||||||
|
// ---- scan button + list
|
||||||
|
setButtonText(g_scan_btn, s.scanning ? "Scanning..." : LV_SYMBOL_REFRESH " Scan");
|
||||||
|
if (s.scanning || s.link == WiFiManager::LINK_CONNECTING) lv_obj_add_state(g_scan_btn, LV_STATE_DISABLED);
|
||||||
|
else lv_obj_clear_state(g_scan_btn, LV_STATE_DISABLED);
|
||||||
|
|
||||||
|
const char* connected_now = s.link == WiFiManager::LINK_CONNECTED ? s.ssid : "";
|
||||||
|
if (s.scan_gen != g_list_gen || strcmp(connected_now, g_list_connected) != 0) rebuildList(s);
|
||||||
|
|
||||||
|
if (g_row_count == 0) {
|
||||||
|
setText(g_list_note, s.scanning ? "Looking for networks..." :
|
||||||
|
s.link == WiFiManager::LINK_CONNECTED ? "Tap Scan to see other networks." :
|
||||||
|
"No networks found. Tap Scan to look again.");
|
||||||
|
setVisible(g_list_note, true);
|
||||||
|
} else {
|
||||||
|
setVisible(g_list_note, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void buildWifiPage(lv_obj_t* page) {
|
||||||
|
lv_obj_t* right;
|
||||||
|
makeSettingRow(page, "Wi-Fi", "Used for firmware updates", &right);
|
||||||
|
g_wifi_sw = toggle(right, onWifiSwitch, NULL);
|
||||||
|
|
||||||
|
g_wifi_off_note = label(page,
|
||||||
|
"Wi-Fi is off.\n\nTurn it on to join a network for firmware updates. "
|
||||||
|
"The link to Controller B works without it.",
|
||||||
|
&lv_font_montserrat_20, UI_COL_MUTED);
|
||||||
|
lv_label_set_long_mode(g_wifi_off_note, LV_LABEL_LONG_WRAP);
|
||||||
|
lv_obj_set_width(g_wifi_off_note, LV_PCT(100));
|
||||||
|
|
||||||
|
g_wifi_body = box(page, LV_FLEX_FLOW_COLUMN);
|
||||||
|
lv_obj_set_width(g_wifi_body, LV_PCT(100));
|
||||||
|
lv_obj_set_flex_grow(g_wifi_body, 1);
|
||||||
|
lv_obj_set_style_pad_row(g_wifi_body, 12, 0);
|
||||||
|
|
||||||
|
// status card: [icon|spinner] [title / detail] [Connect] [Forget]
|
||||||
|
lv_obj_t* c = card(g_wifi_body);
|
||||||
|
lv_obj_set_size(c, LV_PCT(100), LV_SIZE_CONTENT);
|
||||||
|
lv_obj_set_flex_flow(c, LV_FLEX_FLOW_ROW);
|
||||||
|
lv_obj_set_flex_align(c, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||||
|
lv_obj_set_style_pad_column(c, 16, 0);
|
||||||
|
lv_obj_set_style_min_height(c, 96, 0);
|
||||||
|
|
||||||
|
g_st_icon = label(c, LV_SYMBOL_WIFI, &lv_font_montserrat_30, UI_COL_MUTED);
|
||||||
|
g_st_spinner = lv_spinner_create(c, 1000, 60);
|
||||||
|
lv_obj_set_size(g_st_spinner, 40, 40);
|
||||||
|
lv_obj_set_style_arc_width(g_st_spinner, 5, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_arc_width(g_st_spinner, 5, LV_PART_INDICATOR);
|
||||||
|
lv_obj_set_style_arc_color(g_st_spinner, UI_COL_ACCENT, LV_PART_INDICATOR);
|
||||||
|
lv_obj_add_flag(g_st_spinner, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
|
||||||
|
lv_obj_t* txt = box(c, LV_FLEX_FLOW_COLUMN);
|
||||||
|
lv_obj_set_height(txt, LV_SIZE_CONTENT);
|
||||||
|
lv_obj_set_flex_grow(txt, 1);
|
||||||
|
lv_obj_set_style_pad_row(txt, 6, 0);
|
||||||
|
g_st_title = label(txt, "", &lv_font_montserrat_24, UI_COL_TEXT);
|
||||||
|
lv_label_set_long_mode(g_st_title, LV_LABEL_LONG_DOT);
|
||||||
|
lv_obj_set_width(g_st_title, LV_PCT(100));
|
||||||
|
g_st_detail = label(txt, "", &lv_font_montserrat_20, UI_COL_MUTED);
|
||||||
|
lv_label_set_long_mode(g_st_detail, LV_LABEL_LONG_WRAP);
|
||||||
|
lv_obj_set_width(g_st_detail, LV_PCT(100));
|
||||||
|
|
||||||
|
g_st_connect = button(c, "Connect", 140, 56, BTN_PRIMARY, onConnectSaved, NULL);
|
||||||
|
g_st_forget = button(c, "Forget", 120, 56, BTN_SECONDARY, onForget, NULL);
|
||||||
|
|
||||||
|
// list header
|
||||||
|
lv_obj_t* hdr = box(g_wifi_body, LV_FLEX_FLOW_ROW);
|
||||||
|
lv_obj_set_size(hdr, LV_PCT(100), LV_SIZE_CONTENT);
|
||||||
|
lv_obj_set_flex_align(hdr, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||||
|
label(hdr, "Networks nearby", &lv_font_montserrat_20, UI_COL_MUTED);
|
||||||
|
g_scan_btn = button(hdr, LV_SYMBOL_REFRESH " Scan", 180, 52, BTN_SECONDARY, onScan, NULL);
|
||||||
|
|
||||||
|
g_list_note = label(g_wifi_body, "", &lv_font_montserrat_20, UI_COL_MUTED);
|
||||||
|
|
||||||
|
g_list = box(g_wifi_body, LV_FLEX_FLOW_COLUMN);
|
||||||
|
lv_obj_set_width(g_list, LV_PCT(100));
|
||||||
|
lv_obj_set_flex_grow(g_list, 1);
|
||||||
|
lv_obj_set_style_pad_row(g_list, 8, 0);
|
||||||
|
lv_obj_add_flag(g_list, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
lv_obj_set_scroll_dir(g_list, LV_DIR_VER);
|
||||||
|
lv_obj_set_scrollbar_mode(g_list, LV_SCROLLBAR_MODE_ACTIVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void buildPasswordOverlay() {
|
||||||
|
g_pw = lv_obj_create(g_screen);
|
||||||
|
lv_obj_remove_style_all(g_pw);
|
||||||
|
lv_obj_set_size(g_pw, 1024, 600);
|
||||||
|
lv_obj_set_style_bg_color(g_pw, UI_COL_BG, 0);
|
||||||
|
lv_obj_set_style_bg_opa(g_pw, LV_OPA_COVER, 0);
|
||||||
|
lv_obj_clear_flag(g_pw, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
lv_obj_add_flag(g_pw, LV_OBJ_FLAG_CLICKABLE); // swallow touches meant for the page below
|
||||||
|
lv_obj_add_flag(g_pw, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
|
||||||
|
g_pw_title = label(g_pw, "", &lv_font_montserrat_30, UI_COL_TEXT);
|
||||||
|
lv_label_set_long_mode(g_pw_title, LV_LABEL_LONG_DOT);
|
||||||
|
lv_obj_set_width(g_pw_title, 760);
|
||||||
|
lv_obj_set_pos(g_pw_title, 24, 22);
|
||||||
|
|
||||||
|
lv_obj_t* cancel = button(g_pw, "Cancel", 180, 56, BTN_SECONDARY, onPwCancel, NULL);
|
||||||
|
lv_obj_align(cancel, LV_ALIGN_TOP_RIGHT, -16, 10);
|
||||||
|
|
||||||
|
g_pw_ta = lv_textarea_create(g_pw);
|
||||||
|
lv_textarea_set_one_line(g_pw_ta, true);
|
||||||
|
lv_textarea_set_password_mode(g_pw_ta, true);
|
||||||
|
lv_textarea_set_placeholder_text(g_pw_ta, "Password");
|
||||||
|
lv_textarea_set_max_length(g_pw_ta, 63);
|
||||||
|
lv_obj_set_style_text_font(g_pw_ta, &lv_font_montserrat_30, 0);
|
||||||
|
lv_obj_set_style_bg_color(g_pw_ta, UI_COL_PANEL, 0);
|
||||||
|
lv_obj_set_style_text_color(g_pw_ta, UI_COL_TEXT, 0);
|
||||||
|
lv_obj_set_style_border_color(g_pw_ta, UI_COL_ACCENT, 0);
|
||||||
|
lv_obj_set_width(g_pw_ta, 640);
|
||||||
|
lv_obj_set_pos(g_pw_ta, 24, 100);
|
||||||
|
lv_obj_add_state(g_pw_ta, LV_STATE_FOCUSED); // keep the cursor visible
|
||||||
|
|
||||||
|
g_pw_show = button(g_pw, LV_SYMBOL_EYE_OPEN " Show", 150, 60, BTN_SECONDARY, onPwShow, NULL);
|
||||||
|
lv_obj_set_pos(g_pw_show, 680, 100);
|
||||||
|
lv_obj_t* go = button(g_pw, "Connect", 170, 60, BTN_PRIMARY, onPwConnect, NULL);
|
||||||
|
lv_obj_set_pos(go, 842, 100);
|
||||||
|
|
||||||
|
lv_obj_t* kb = lv_keyboard_create(g_pw);
|
||||||
|
lv_obj_set_size(kb, 1024, 360);
|
||||||
|
lv_obj_align(kb, LV_ALIGN_BOTTOM_MID, 0, 0);
|
||||||
|
lv_obj_set_style_text_font(kb, &lv_font_montserrat_24, 0);
|
||||||
|
lv_obj_set_style_bg_color(kb, UI_COL_PANEL, 0);
|
||||||
|
lv_obj_set_style_bg_color(kb, UI_COL_PANEL2, LV_PART_ITEMS);
|
||||||
|
lv_obj_set_style_text_color(kb, UI_COL_TEXT, LV_PART_ITEMS);
|
||||||
|
lv_obj_set_style_shadow_width(kb, 0, LV_PART_ITEMS);
|
||||||
|
lv_keyboard_set_textarea(kb, g_pw_ta);
|
||||||
|
lv_obj_add_event_cb(kb, onPwKeyboard, LV_EVENT_READY, NULL);
|
||||||
|
lv_obj_add_event_cb(kb, onPwKeyboard, LV_EVENT_CANCEL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// UPDATES PAGE
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
static void onInstallConfirmed(bool ok, void* user) {
|
||||||
|
(void)user;
|
||||||
|
if (!ok) return;
|
||||||
|
Ota::phase_t before = Ota::getStatus().phase;
|
||||||
|
if (!Ota::requestInstall(g_upd_refusal, sizeof(g_upd_refusal))) g_upd_refusal_phase = before;
|
||||||
|
else g_upd_refusal[0] = 0;
|
||||||
|
refresh(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onInstall(lv_event_t* e) {
|
||||||
|
(void)e;
|
||||||
|
Ota::ui_status_t o = Ota::getStatus();
|
||||||
|
char title[64];
|
||||||
|
snprintf(title, sizeof(title), "Install %s?", o.latest);
|
||||||
|
confirm(title,
|
||||||
|
"The screen goes dark for about a minute while the new firmware is written, "
|
||||||
|
"then Controller A restarts. Controller B's gauges drop out for a few seconds.\n\n"
|
||||||
|
"Only while parked with the engine off.",
|
||||||
|
"Install", onInstallConfirmed, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onCheck(lv_event_t* e) {
|
||||||
|
(void)e;
|
||||||
|
Ota::phase_t before = Ota::getStatus().phase;
|
||||||
|
if (!Ota::requestCheck(g_upd_refusal, sizeof(g_upd_refusal))) g_upd_refusal_phase = before;
|
||||||
|
else g_upd_refusal[0] = 0;
|
||||||
|
refresh(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onGoWifi(lv_event_t* e) {
|
||||||
|
(void)e;
|
||||||
|
selectPage(PAGE_WIFI);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void refreshUpdates() {
|
||||||
|
Ota::ui_status_t o = Ota::getStatus();
|
||||||
|
bool wifi_ok = WiFiManager::getStatus().link == WiFiManager::LINK_CONNECTED;
|
||||||
|
if (g_upd_refusal[0] && o.phase != g_upd_refusal_phase) g_upd_refusal[0] = 0; // superseded
|
||||||
|
|
||||||
|
char msg[140];
|
||||||
|
lv_color_t col = UI_COL_MUTED;
|
||||||
|
switch (o.phase) {
|
||||||
|
case Ota::PHASE_CHECKING: snprintf(msg, sizeof(msg), "Checking for updates..."); break;
|
||||||
|
case Ota::PHASE_INSTALLING: snprintf(msg, sizeof(msg), "Installing %s...", o.latest); break;
|
||||||
|
case Ota::PHASE_UP_TO_DATE: snprintf(msg, sizeof(msg), LV_SYMBOL_OK " You're up to date."); col = UI_COL_OK; break;
|
||||||
|
case Ota::PHASE_AVAILABLE: snprintf(msg, sizeof(msg), "Version %s is available.", o.latest); col = UI_COL_ACCENT; break;
|
||||||
|
case Ota::PHASE_FAILED: snprintf(msg, sizeof(msg), LV_SYMBOL_WARNING " %s", o.message); col = UI_COL_WARN; break;
|
||||||
|
default:
|
||||||
|
snprintf(msg, sizeof(msg), "%s", wifi_ok ? "Tap Check to look for a new version." : "Connect to Wi-Fi to check for updates.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (g_upd_refusal[0]) {
|
||||||
|
snprintf(msg, sizeof(msg), LV_SYMBOL_WARNING " %s", g_upd_refusal);
|
||||||
|
col = UI_COL_WARN;
|
||||||
|
} else if (!wifi_ok && o.phase != Ota::PHASE_IDLE && o.phase != Ota::PHASE_CHECKING) {
|
||||||
|
// keep the last result, but say why the buttons are off
|
||||||
|
size_t n = strlen(msg);
|
||||||
|
snprintf(msg + n, sizeof(msg) - n, "\nConnect to Wi-Fi to check again.");
|
||||||
|
}
|
||||||
|
setText(g_upd_state, msg);
|
||||||
|
setTextColor(g_upd_state, col);
|
||||||
|
|
||||||
|
setText(g_upd_latest, o.latest[0] ? o.latest : "-");
|
||||||
|
|
||||||
|
bool busy = o.phase == Ota::PHASE_CHECKING || o.phase == Ota::PHASE_INSTALLING;
|
||||||
|
setButtonText(g_upd_check, busy ? "Working..." : LV_SYMBOL_REFRESH " Check for updates");
|
||||||
|
if (busy || !wifi_ok) lv_obj_add_state(g_upd_check, LV_STATE_DISABLED);
|
||||||
|
else lv_obj_clear_state(g_upd_check, LV_STATE_DISABLED);
|
||||||
|
|
||||||
|
bool can_install = o.phase == Ota::PHASE_AVAILABLE && wifi_ok;
|
||||||
|
char inst[48];
|
||||||
|
snprintf(inst, sizeof(inst), LV_SYMBOL_DOWNLOAD " Install %s", o.latest);
|
||||||
|
setButtonText(g_upd_install, inst);
|
||||||
|
setVisible(g_upd_install, can_install);
|
||||||
|
setVisible(g_upd_wifi, !wifi_ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void buildUpdatesPage(lv_obj_t* page) {
|
||||||
|
label(page, "Firmware updates", &lv_font_montserrat_24, UI_COL_TEXT);
|
||||||
|
|
||||||
|
lv_obj_t* c = card(page);
|
||||||
|
lv_obj_set_size(c, LV_PCT(100), LV_SIZE_CONTENT);
|
||||||
|
lv_obj_set_flex_flow(c, LV_FLEX_FLOW_ROW);
|
||||||
|
lv_obj_set_style_pad_column(c, 60, 0);
|
||||||
|
|
||||||
|
lv_obj_t* a = box(c, LV_FLEX_FLOW_COLUMN);
|
||||||
|
lv_obj_set_size(a, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||||
|
lv_obj_set_style_pad_row(a, 6, 0);
|
||||||
|
label(a, "Installed", &lv_font_montserrat_20, UI_COL_MUTED);
|
||||||
|
label(a, FW_VERSION, &lv_font_montserrat_30, UI_COL_TEXT);
|
||||||
|
|
||||||
|
lv_obj_t* b = box(c, LV_FLEX_FLOW_COLUMN);
|
||||||
|
lv_obj_set_size(b, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||||
|
lv_obj_set_style_pad_row(b, 6, 0);
|
||||||
|
label(b, "Latest release", &lv_font_montserrat_20, UI_COL_MUTED);
|
||||||
|
g_upd_latest = label(b, "-", &lv_font_montserrat_30, UI_COL_TEXT);
|
||||||
|
|
||||||
|
g_upd_state = label(page, "", &lv_font_montserrat_20, UI_COL_MUTED);
|
||||||
|
lv_label_set_long_mode(g_upd_state, LV_LABEL_LONG_WRAP);
|
||||||
|
lv_obj_set_width(g_upd_state, LV_PCT(100));
|
||||||
|
|
||||||
|
lv_obj_t* btns = box(page, LV_FLEX_FLOW_ROW);
|
||||||
|
lv_obj_set_size(btns, LV_PCT(100), LV_SIZE_CONTENT);
|
||||||
|
lv_obj_set_style_pad_column(btns, 16, 0);
|
||||||
|
g_upd_check = button(btns, LV_SYMBOL_REFRESH " Check for updates", 300, 64, BTN_PRIMARY, onCheck, NULL);
|
||||||
|
g_upd_install = button(btns, "Install", 280, 64, BTN_SUCCESS, onInstall, NULL);
|
||||||
|
g_upd_wifi = button(btns, LV_SYMBOL_WIFI " Wi-Fi settings", 260, 64, BTN_SECONDARY, onGoWifi, NULL);
|
||||||
|
|
||||||
|
lv_obj_t* note = label(page,
|
||||||
|
"Updates come from " OTA_SERVER " and are signed. Installing takes about a minute: "
|
||||||
|
"the screen goes dark while the new firmware is written, then the controller restarts. "
|
||||||
|
"If it doesn't start properly, it goes back to the current version by itself.",
|
||||||
|
&lv_font_montserrat_20, UI_COL_MUTED);
|
||||||
|
lv_label_set_long_mode(note, LV_LABEL_LONG_WRAP);
|
||||||
|
lv_obj_set_width(note, LV_PCT(100));
|
||||||
|
lv_obj_set_style_pad_top(note, 12, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// SYSTEM PAGE
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
static void onCanSwitch(lv_event_t* e) {
|
||||||
|
if (g_refreshing) return;
|
||||||
|
CANDriver::setEnabled(lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onLinkSwitch(lv_event_t* e) {
|
||||||
|
if (g_refreshing) return;
|
||||||
|
UARTManager::setEnabled(lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onDebugSwitch(lv_event_t* e) {
|
||||||
|
if (g_refreshing) return;
|
||||||
|
bool on = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
|
||||||
|
SettingsManager::saveDebugState(on);
|
||||||
|
UIStateManager::setDebugEnabled(on);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void refreshSystem(bool force) {
|
||||||
|
setChecked(g_sys_can, CANDriver::isActive());
|
||||||
|
setChecked(g_sys_link, UARTManager::getState() != UARTManager::UART_STATE_OFF);
|
||||||
|
setChecked(g_sys_dbg, UIStateManager::isDebugEnabled());
|
||||||
|
|
||||||
|
static uint32_t last = 0; // the figures below change slowly; 1 Hz is plenty
|
||||||
|
if (!force && millis() - last < 1000) return;
|
||||||
|
last = millis();
|
||||||
|
|
||||||
|
can_stats_t cs = CANDriver::getStats();
|
||||||
|
const esp_partition_t* run = esp_ota_get_running_partition();
|
||||||
|
uint32_t up = millis() / 1000;
|
||||||
|
char buf[400];
|
||||||
|
snprintf(buf, sizeof(buf),
|
||||||
|
"%s (slot %s)\n"
|
||||||
|
"ESP-NOW %s, %lu frames sent, %lu failed\n"
|
||||||
|
"%lu frames received\n"
|
||||||
|
"%u KB internal free, %u KB PSRAM free\n"
|
||||||
|
"%lu h %02lu min",
|
||||||
|
FW_VERSION, run ? run->label : "?",
|
||||||
|
EspNowLink::isReady() ? "up" : "DOWN",
|
||||||
|
(unsigned long)EspNowLink::sentCount(), (unsigned long)EspNowLink::failCount(),
|
||||||
|
(unsigned long)cs.messages_received,
|
||||||
|
(unsigned)(heap_caps_get_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT) / 1024),
|
||||||
|
(unsigned)(heap_caps_get_free_size(MALLOC_CAP_SPIRAM) / 1024),
|
||||||
|
(unsigned long)(up / 3600), (unsigned long)((up / 60) % 60));
|
||||||
|
setText(g_sys_info, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void buildSystemPage(lv_obj_t* page) {
|
||||||
|
lv_obj_t* c = card(page);
|
||||||
|
lv_obj_set_size(c, LV_PCT(100), LV_SIZE_CONTENT);
|
||||||
|
lv_obj_set_flex_flow(c, LV_FLEX_FLOW_COLUMN);
|
||||||
|
lv_obj_set_style_pad_row(c, 10, 0);
|
||||||
|
|
||||||
|
lv_obj_t* right;
|
||||||
|
makeSettingRow(c, "CAN bus", "Read the car's data bus", &right);
|
||||||
|
g_sys_can = toggle(right, onCanSwitch, NULL);
|
||||||
|
makeSettingRow(c, "Send to Controller B", "Gauge data over the wire and ESP-NOW", &right);
|
||||||
|
g_sys_link = toggle(right, onLinkSwitch, NULL);
|
||||||
|
makeSettingRow(c, "Performance overlay", "Frame rate and CPU load in the corner", &right);
|
||||||
|
g_sys_dbg = toggle(right, onDebugSwitch, NULL);
|
||||||
|
|
||||||
|
// two labels side by side, same line spacing, so keys and values line up
|
||||||
|
lv_obj_t* info = card(page);
|
||||||
|
lv_obj_set_size(info, LV_PCT(100), LV_SIZE_CONTENT);
|
||||||
|
lv_obj_set_flex_flow(info, LV_FLEX_FLOW_ROW);
|
||||||
|
lv_obj_set_style_pad_column(info, 24, 0);
|
||||||
|
lv_obj_t* keys = label(info, "Firmware\nLink to B\nCAN bus\nMemory\nUptime", &lv_font_montserrat_20, UI_COL_MUTED);
|
||||||
|
lv_obj_set_style_text_line_space(keys, 6, 0);
|
||||||
|
g_sys_info = label(info, "", &lv_font_montserrat_20, UI_COL_TEXT);
|
||||||
|
lv_obj_set_style_text_line_space(g_sys_info, 6, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// BUILD / REFRESH
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
static void build() {
|
||||||
|
if (g_screen != NULL) return;
|
||||||
|
|
||||||
|
g_screen = screen();
|
||||||
|
lv_obj_add_event_cb(g_screen, onGesture, LV_EVENT_GESTURE, NULL);
|
||||||
|
header(g_screen, "SETTINGS", onBack);
|
||||||
|
|
||||||
|
g_nav[PAGE_WIFI] = makeNav(g_screen, PAGE_WIFI, "Wi-Fi");
|
||||||
|
g_nav[PAGE_UPDATES] = makeNav(g_screen, PAGE_UPDATES, "Updates");
|
||||||
|
g_nav[PAGE_SYSTEM] = makeNav(g_screen, PAGE_SYSTEM, "System");
|
||||||
|
|
||||||
|
for (int i = 0; i < PAGE_COUNT; i++) g_page[i] = makePage(g_screen);
|
||||||
|
buildWifiPage(g_page[PAGE_WIFI]);
|
||||||
|
buildUpdatesPage(g_page[PAGE_UPDATES]);
|
||||||
|
buildSystemPage(g_page[PAGE_SYSTEM]);
|
||||||
|
buildPasswordOverlay();
|
||||||
|
|
||||||
|
ESP_LOGI("Settings", "Settings screen built");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void refreshNav() {
|
||||||
|
WiFiManager::status_t s = WiFiManager::getStatus();
|
||||||
|
const char* w = "Not connected";
|
||||||
|
if (s.link == WiFiManager::LINK_OFF) w = "Off";
|
||||||
|
else if (s.link == WiFiManager::LINK_CONNECTED) w = s.ssid;
|
||||||
|
else if (s.link == WiFiManager::LINK_CONNECTING) w = "Connecting...";
|
||||||
|
setText(g_nav_sub[PAGE_WIFI], w);
|
||||||
|
setTextColor(g_nav_sub[PAGE_WIFI], s.link == WiFiManager::LINK_CONNECTED ? UI_COL_OK : UI_COL_MUTED);
|
||||||
|
|
||||||
|
Ota::ui_status_t o = Ota::getStatus();
|
||||||
|
bool avail = o.phase == Ota::PHASE_AVAILABLE;
|
||||||
|
setText(g_nav_sub[PAGE_UPDATES], avail ? "Update available" : FW_VERSION);
|
||||||
|
setTextColor(g_nav_sub[PAGE_UPDATES], avail ? UI_COL_ACCENT : UI_COL_MUTED);
|
||||||
|
|
||||||
|
char sys[40];
|
||||||
|
snprintf(sys, sizeof(sys), "CAN %s \xE2\x80\xA2 Link %s", CANDriver::isActive() ? "on" : "off",
|
||||||
|
UARTManager::getState() != UARTManager::UART_STATE_OFF ? "on" : "off");
|
||||||
|
setText(g_nav_sub[PAGE_SYSTEM], sys);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Caller holds the LVGL lock. */
|
||||||
|
static void refresh(bool force) {
|
||||||
|
g_refreshing = true;
|
||||||
|
refreshNav();
|
||||||
|
switch (g_cur) {
|
||||||
|
case PAGE_WIFI: refreshWifi(); break;
|
||||||
|
case PAGE_UPDATES: refreshUpdates(); break;
|
||||||
|
case PAGE_SYSTEM: refreshSystem(force); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
g_refreshing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// PUBLIC API
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
void show() {
|
||||||
|
bool first = (g_screen == NULL);
|
||||||
|
build();
|
||||||
|
if (first) selectPage(PAGE_WIFI);
|
||||||
|
else if (g_cur == PAGE_WIFI) g_want_scan = true;
|
||||||
|
refresh(true);
|
||||||
|
lv_scr_load_anim(g_screen, LV_SCR_LOAD_ANIM_NONE, 0, 0, false); // instant: fades stutter at 1024x600
|
||||||
|
}
|
||||||
|
|
||||||
|
void tick() {
|
||||||
|
if (g_screen == NULL || lv_scr_act() != g_screen) return;
|
||||||
|
static uint32_t last = 0;
|
||||||
|
if (millis() - last < 250) return;
|
||||||
|
last = millis();
|
||||||
|
lvgl_port_lock(-1);
|
||||||
|
refresh(false);
|
||||||
|
lvgl_port_unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace SettingsScreen
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Settings Screen Module
|
||||||
|
*
|
||||||
|
* Hand-coded (replaces the SquareLine Settings screen, 2026-09-27). Sidebar
|
||||||
|
* with three sections:
|
||||||
|
* Wi-Fi - switch, connection status, networks nearby, full-screen password
|
||||||
|
* entry; the joined network is remembered (WiFiManager)
|
||||||
|
* Updates - installed vs latest release, Check, Install behind a confirm
|
||||||
|
* dialog (Ota)
|
||||||
|
* System - CAN bus / link to Controller B / performance overlay switches,
|
||||||
|
* live link and memory figures
|
||||||
|
*
|
||||||
|
* Reached by swiping LEFT on the Driveline screen; swipe right or the
|
||||||
|
* Driveline button goes back. Built once and kept (never deleted), so nothing
|
||||||
|
* elsewhere ever holds a pointer into a destroyed screen.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <lvgl.h>
|
||||||
|
|
||||||
|
namespace SettingsScreen {
|
||||||
|
|
||||||
|
/** Build (idempotent), refresh and load. Caller holds the LVGL lock. */
|
||||||
|
void show();
|
||||||
|
|
||||||
|
/** Refresh live values while the screen is shown. Call from loop(); takes its own lock. */
|
||||||
|
void tick();
|
||||||
|
|
||||||
|
} // namespace SettingsScreen
|
||||||
@@ -43,6 +43,18 @@ static void save() {
|
|||||||
prefs.end();
|
prefs.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Every flash write briefly stalls the PSRAM-fed RGB panel (flicker), so edits
|
||||||
|
// are applied + pushed to B at once but written to NVS only after the user
|
||||||
|
// stops tapping (SAVE_IDLE_MS), on leaving the Tuning screen, or before reboot.
|
||||||
|
static const uint32_t SAVE_IDLE_MS = 3000;
|
||||||
|
static bool g_dirty = false;
|
||||||
|
static uint32_t g_dirty_ms = 0;
|
||||||
|
|
||||||
|
static void markDirty() { // call with the mutex held
|
||||||
|
g_dirty = true;
|
||||||
|
g_dirty_ms = millis();
|
||||||
|
}
|
||||||
|
|
||||||
static bool load() {
|
static bool load() {
|
||||||
Preferences prefs;
|
Preferences prefs;
|
||||||
prefs.begin(NVS_NAMESPACE, true);
|
prefs.begin(NVS_NAMESPACE, true);
|
||||||
@@ -113,7 +125,7 @@ static bool setField(const char* name, long v) {
|
|||||||
if (ok) {
|
if (ok) {
|
||||||
g_cfg.cfg_version++;
|
g_cfg.cfg_version++;
|
||||||
if (g_cfg.cfg_version == 0) g_cfg.cfg_version = 1;
|
if (g_cfg.cfg_version == 0) g_cfg.cfg_version = 1;
|
||||||
save();
|
markDirty();
|
||||||
}
|
}
|
||||||
unlock();
|
unlock();
|
||||||
return ok;
|
return ok;
|
||||||
@@ -159,7 +171,7 @@ void set(const link_config_t& cfg) {
|
|||||||
uint8_t v = g_cfg.cfg_version + 1;
|
uint8_t v = g_cfg.cfg_version + 1;
|
||||||
g_cfg = cfg;
|
g_cfg = cfg;
|
||||||
g_cfg.cfg_version = v ? v : 1;
|
g_cfg.cfg_version = v ? v : 1;
|
||||||
save();
|
markDirty();
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +180,7 @@ void resetDefaults() {
|
|||||||
uint8_t v = g_cfg.cfg_version + 1;
|
uint8_t v = g_cfg.cfg_version + 1;
|
||||||
link_config_defaults(&g_cfg);
|
link_config_defaults(&g_cfg);
|
||||||
g_cfg.cfg_version = v ? v : 1;
|
g_cfg.cfg_version = v ? v : 1;
|
||||||
save();
|
markDirty();
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +215,7 @@ bool handleCommand(const char* line) {
|
|||||||
if (!strcmp(argv[1], "set") && argc == 4) {
|
if (!strcmp(argv[1], "set") && argc == 4) {
|
||||||
long v = strtol(argv[3], NULL, 0);
|
long v = strtol(argv[3], NULL, 0);
|
||||||
if (setField(argv[2], v)) {
|
if (setField(argv[2], v)) {
|
||||||
print("[cfg] %s = %ld (version %u, saved)", argv[2], v, version());
|
print("[cfg] %s = %ld (version %u, saved to NVS in 3 s)", argv[2], v, version());
|
||||||
} else {
|
} else {
|
||||||
print("[cfg] unknown field '%s'", argv[2]);
|
print("[cfg] unknown field '%s'", argv[2]);
|
||||||
help();
|
help();
|
||||||
@@ -247,7 +259,22 @@ void setExtraCommandHandler(bool (*handler)(const char* line)) {
|
|||||||
g_extra_handler = handler;
|
g_extra_handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void flush() {
|
||||||
|
lock();
|
||||||
|
if (g_dirty) {
|
||||||
|
save();
|
||||||
|
g_dirty = false;
|
||||||
|
}
|
||||||
|
unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isDirty() {
|
||||||
|
return g_dirty;
|
||||||
|
}
|
||||||
|
|
||||||
void pollSerial() {
|
void pollSerial() {
|
||||||
|
if (g_dirty && millis() - g_dirty_ms > SAVE_IDLE_MS) flush();
|
||||||
|
|
||||||
while (Serial.available()) {
|
while (Serial.available()) {
|
||||||
char c = (char)Serial.read();
|
char c = (char)Serial.read();
|
||||||
if (c == '\r' || c == '\n') {
|
if (c == '\r' || c == '\n') {
|
||||||
|
|||||||
@@ -58,6 +58,16 @@ bool handleCommand(const char* line);
|
|||||||
*/
|
*/
|
||||||
void pollSerial();
|
void pollSerial();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write pending edits to NVS now. Edits are otherwise saved SAVE_IDLE_MS after
|
||||||
|
* the last change (each flash write flickers the RGB panel). Call before a
|
||||||
|
* reboot or when leaving the Tuning screen.
|
||||||
|
*/
|
||||||
|
void flush();
|
||||||
|
|
||||||
|
/** True while edits are waiting for their deferred NVS write. */
|
||||||
|
bool isDirty();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a second console command handler (e.g. DiagProbe::handleCommand)
|
* Register a second console command handler (e.g. DiagProbe::handleCommand)
|
||||||
* that gets lines `cfg` does not recognise. Returns true if it consumed the line.
|
* that gets lines `cfg` does not recognise. Returns true if it consumed the line.
|
||||||
|
|||||||
+339
-356
@@ -1,35 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
* Gauge Tuning Screen Module Implementation
|
* Gauge Tuning Screen Module Implementation
|
||||||
|
*
|
||||||
|
* Four tabs (Tachometer / Coolant gauge / Alerts / Simulation), one value per
|
||||||
|
* row with a plain-language hint, car-sized -/+ buttons (hold to repeat,
|
||||||
|
* speeding up the longer you hold). Tabs are plain buttons + hidden panels:
|
||||||
|
* no sliding tabview animation, which re-renders the whole panel per frame.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tuning_screen.h"
|
#include "tuning_screen.h"
|
||||||
#include "tunables.h"
|
#include "tunables.h"
|
||||||
|
#include "ui_kit.h"
|
||||||
#include "driveline_screen.h"
|
#include "driveline_screen.h"
|
||||||
#include "display/lvgl_v8_port.h"
|
#include "display/lvgl_v8_port.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#include "ui.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace TuningScreen
|
namespace TuningScreen
|
||||||
{
|
{
|
||||||
|
using namespace UiKit;
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// THEME
|
// FIELD TABLE - one row per numeric tunable
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
#define COL_BG lv_color_hex(0x101418)
|
|
||||||
#define COL_PANEL lv_color_hex(0x1B2128)
|
|
||||||
#define COL_TEXT lv_color_hex(0xE8EDF2)
|
|
||||||
#define COL_MUTED lv_color_hex(0x6E7B88)
|
|
||||||
#define COL_ACCENT lv_color_hex(0x3DA9FC)
|
|
||||||
#define COL_OK lv_color_hex(0x3DD68C)
|
|
||||||
#define COL_WARN lv_color_hex(0xE5484D)
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// FIELD TABLE — one row per numeric tunable
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
@@ -48,11 +38,14 @@ namespace TuningScreen
|
|||||||
F_COUNT
|
F_COUNT
|
||||||
} field_t;
|
} field_t;
|
||||||
|
|
||||||
|
typedef enum { TAB_TACH, TAB_COOLANT, TAB_ALERTS, TAB_SIM, TAB_COUNT } tab_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
field_t id;
|
field_t id;
|
||||||
|
tab_t tab;
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *unit;
|
const char *hint;
|
||||||
int32_t step;
|
int32_t step;
|
||||||
int32_t min;
|
int32_t min;
|
||||||
int32_t max;
|
int32_t max;
|
||||||
@@ -60,47 +53,37 @@ namespace TuningScreen
|
|||||||
} row_t;
|
} row_t;
|
||||||
|
|
||||||
static row_t g_rows[F_COUNT] = {
|
static row_t g_rows[F_COUNT] = {
|
||||||
{F_TACH_PPR, "Pulses / rev", "", 1, 1, 32, NULL},
|
{F_TACH_PPR, TAB_TACH, "Pulses per revolution", "Pulses per engine revolution the Patrol tach expects", 1, 1, 32, NULL},
|
||||||
{F_TACH_TRIM, "Trim", "%", 1, -50, 50, NULL},
|
{F_TACH_TRIM, TAB_TACH, "Trim", "Fine correction if the needle reads high or low", 1, -50, 50, NULL},
|
||||||
{F_TACH_MAX_HZ, "Max output", "Hz", 10, 0, 5000, NULL},
|
{F_TACH_MAX_HZ, TAB_TACH, "Maximum output", "Highest tach frequency sent (0 = no limit)", 10, 0, 5000, NULL},
|
||||||
{F_TEMP_HZ, "PWM frequency", "Hz", 50, 20, 20000, NULL},
|
{F_TEMP_HZ, TAB_COOLANT, "PWM frequency", "Drive frequency of the coolant gauge signal", 50, 20, 20000, NULL},
|
||||||
{F_TEMP_SLOPE, "Slope", "x100", 5, 0, 5000, NULL},
|
{F_TEMP_SLOPE, TAB_COOLANT, "Slope", "Duty added per \xC2\xB0" "C of coolant", 5, 0, 5000, NULL},
|
||||||
{F_TEMP_OFFSET, "Offset", "", 1, -1000, 1000, NULL},
|
{F_TEMP_OFFSET, TAB_COOLANT, "Offset", "Duty at 0 \xC2\xB0" "C (duty = slope x temp + offset)", 1, -1000, 1000, NULL},
|
||||||
{F_TEMP_MIN, "Min temp", "C", 1, -50, 200, NULL},
|
{F_TEMP_MIN, TAB_COOLANT, "Minimum temperature", "Needle stays at rest below this", 1, -50, 200, NULL},
|
||||||
{F_TEMP_DUTY_MAX, "Duty clamp", "", 5, 0, 255, NULL},
|
{F_TEMP_DUTY_MAX, TAB_COOLANT, "Duty limit", "Highest duty sent (255 = full scale)", 5, 0, 255, NULL},
|
||||||
{F_COOLANT_HOT, "Coolant hot", "C", 1, 0, 200, NULL},
|
{F_COOLANT_HOT, TAB_ALERTS, "Coolant too hot", "Alarm on Controller B at or above this temperature", 1, 0, 200, NULL},
|
||||||
{F_GEARBOX_HOT, "Gearbox hot", "C", 1, 0, 200, NULL},
|
{F_GEARBOX_HOT, TAB_ALERTS, "Gearbox oil too hot", "Alarm on Controller B at or above this temperature", 1, 0, 200, NULL},
|
||||||
{F_BATT_LOW, "Battery low", "x0.01V", 10, 0, 3000, NULL},
|
{F_BATT_LOW, TAB_ALERTS, "Battery low", "Alarm on Controller B below this voltage", 10, 0, 3000, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const char *TAB_NAMES[TAB_COUNT] = {"Tachometer", "Coolant gauge", "Alerts", "Simulation"};
|
||||||
|
|
||||||
static int32_t getField(const link_config_t &c, field_t f)
|
static int32_t getField(const link_config_t &c, field_t f)
|
||||||
{
|
{
|
||||||
switch (f)
|
switch (f)
|
||||||
{
|
{
|
||||||
case F_TACH_PPR:
|
case F_TACH_PPR: return c.tach_ppr;
|
||||||
return c.tach_ppr;
|
case F_TACH_TRIM: return c.tach_trim_pct;
|
||||||
case F_TACH_TRIM:
|
case F_TACH_MAX_HZ: return c.tach_max_hz;
|
||||||
return c.tach_trim_pct;
|
case F_TEMP_HZ: return c.temp_pwm_hz;
|
||||||
case F_TACH_MAX_HZ:
|
case F_TEMP_SLOPE: return c.temp_slope_x100;
|
||||||
return c.tach_max_hz;
|
case F_TEMP_OFFSET: return c.temp_offset;
|
||||||
case F_TEMP_HZ:
|
case F_TEMP_MIN: return c.temp_min_c;
|
||||||
return c.temp_pwm_hz;
|
case F_TEMP_DUTY_MAX: return c.temp_duty_max;
|
||||||
case F_TEMP_SLOPE:
|
case F_COOLANT_HOT: return c.coolant_hot_c;
|
||||||
return c.temp_slope_x100;
|
case F_GEARBOX_HOT: return c.gearbox_hot_c;
|
||||||
case F_TEMP_OFFSET:
|
case F_BATT_LOW: return c.battery_low_x100;
|
||||||
return c.temp_offset;
|
default: return 0;
|
||||||
case F_TEMP_MIN:
|
|
||||||
return c.temp_min_c;
|
|
||||||
case F_TEMP_DUTY_MAX:
|
|
||||||
return c.temp_duty_max;
|
|
||||||
case F_COOLANT_HOT:
|
|
||||||
return c.coolant_hot_c;
|
|
||||||
case F_GEARBOX_HOT:
|
|
||||||
return c.gearbox_hot_c;
|
|
||||||
case F_BATT_LOW:
|
|
||||||
return c.battery_low_x100;
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,41 +91,36 @@ namespace TuningScreen
|
|||||||
{
|
{
|
||||||
switch (f)
|
switch (f)
|
||||||
{
|
{
|
||||||
case F_TACH_PPR:
|
case F_TACH_PPR: c.tach_ppr = (uint8_t)v; break;
|
||||||
c.tach_ppr = (uint8_t)v;
|
case F_TACH_TRIM: c.tach_trim_pct = (int8_t)v; break;
|
||||||
break;
|
case F_TACH_MAX_HZ: c.tach_max_hz = (uint16_t)v; break;
|
||||||
case F_TACH_TRIM:
|
case F_TEMP_HZ: c.temp_pwm_hz = (uint16_t)v; break;
|
||||||
c.tach_trim_pct = (int8_t)v;
|
case F_TEMP_SLOPE: c.temp_slope_x100 = (uint16_t)v; break;
|
||||||
break;
|
case F_TEMP_OFFSET: c.temp_offset = (int16_t)v; break;
|
||||||
case F_TACH_MAX_HZ:
|
case F_TEMP_MIN: c.temp_min_c = (int16_t)v; break;
|
||||||
c.tach_max_hz = (uint16_t)v;
|
case F_TEMP_DUTY_MAX: c.temp_duty_max = (uint8_t)v; break;
|
||||||
break;
|
case F_COOLANT_HOT: c.coolant_hot_c = (int16_t)v; break;
|
||||||
case F_TEMP_HZ:
|
case F_GEARBOX_HOT: c.gearbox_hot_c = (int16_t)v; break;
|
||||||
c.temp_pwm_hz = (uint16_t)v;
|
case F_BATT_LOW: c.battery_low_x100 = (uint16_t)v; break;
|
||||||
break;
|
default: break;
|
||||||
case F_TEMP_SLOPE:
|
}
|
||||||
c.temp_slope_x100 = (uint16_t)v;
|
}
|
||||||
break;
|
|
||||||
case F_TEMP_OFFSET:
|
static void formatValue(field_t f, int32_t v, char *out, size_t n)
|
||||||
c.temp_offset = (int16_t)v;
|
{
|
||||||
break;
|
switch (f)
|
||||||
|
{
|
||||||
|
case F_TACH_TRIM: snprintf(out, n, "%+ld %%", (long)v); break;
|
||||||
|
case F_TACH_MAX_HZ: if (v == 0) snprintf(out, n, "no limit"); else snprintf(out, n, "%ld Hz", (long)v); break;
|
||||||
|
case F_TEMP_HZ: snprintf(out, n, "%ld Hz", (long)v); break;
|
||||||
|
case F_TEMP_SLOPE: snprintf(out, n, "%ld.%02ld", (long)(v / 100), (long)labs(v % 100)); break;
|
||||||
|
case F_TEMP_OFFSET: snprintf(out, n, "%+ld", (long)v); break;
|
||||||
case F_TEMP_MIN:
|
case F_TEMP_MIN:
|
||||||
c.temp_min_c = (int16_t)v;
|
|
||||||
break;
|
|
||||||
case F_TEMP_DUTY_MAX:
|
|
||||||
c.temp_duty_max = (uint8_t)v;
|
|
||||||
break;
|
|
||||||
case F_COOLANT_HOT:
|
case F_COOLANT_HOT:
|
||||||
c.coolant_hot_c = (int16_t)v;
|
case F_GEARBOX_HOT: snprintf(out, n, "%ld \xC2\xB0" "C", (long)v); break;
|
||||||
break;
|
case F_TEMP_DUTY_MAX: snprintf(out, n, "%ld / 255", (long)v); break;
|
||||||
case F_GEARBOX_HOT:
|
case F_BATT_LOW: snprintf(out, n, "%ld.%02ld V", (long)(v / 100), (long)(v % 100)); break;
|
||||||
c.gearbox_hot_c = (int16_t)v;
|
default: snprintf(out, n, "%ld", (long)v); break;
|
||||||
break;
|
|
||||||
case F_BATT_LOW:
|
|
||||||
c.battery_low_x100 = (uint16_t)v;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,6 +129,12 @@ namespace TuningScreen
|
|||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
static lv_obj_t *g_screen = NULL;
|
static lv_obj_t *g_screen = NULL;
|
||||||
|
static lv_obj_t *g_tab_btn[TAB_COUNT];
|
||||||
|
static lv_obj_t *g_tab_page[TAB_COUNT];
|
||||||
|
static tab_t g_tab = TAB_TACH;
|
||||||
|
static lv_obj_t *g_reset_btn = NULL;
|
||||||
|
static lv_obj_t *g_sim_chip = NULL;
|
||||||
|
static lv_obj_t *g_save_lbl = NULL;
|
||||||
static lv_obj_t *g_tach_en_sw = NULL;
|
static lv_obj_t *g_tach_en_sw = NULL;
|
||||||
static lv_obj_t *g_temp_en_sw = NULL;
|
static lv_obj_t *g_temp_en_sw = NULL;
|
||||||
static lv_obj_t *g_ovr_rpm_sw = NULL;
|
static lv_obj_t *g_ovr_rpm_sw = NULL;
|
||||||
@@ -159,32 +143,34 @@ namespace TuningScreen
|
|||||||
static lv_obj_t *g_ovr_duty_sl = NULL;
|
static lv_obj_t *g_ovr_duty_sl = NULL;
|
||||||
static lv_obj_t *g_ovr_rpm_lbl = NULL;
|
static lv_obj_t *g_ovr_rpm_lbl = NULL;
|
||||||
static lv_obj_t *g_ovr_duty_lbl = NULL;
|
static lv_obj_t *g_ovr_duty_lbl = NULL;
|
||||||
static lv_obj_t *g_status_lbl = NULL;
|
|
||||||
static uint8_t g_shown_version = 0;
|
static uint8_t g_shown_version = 0;
|
||||||
static bool g_refreshing = false; // suppress event handlers while we set widget values
|
static bool g_refreshing = false; // suppress event handlers while we set widget values
|
||||||
|
static uint16_t g_repeats = 0; // long-press repeat count of the button being held
|
||||||
|
|
||||||
|
static const int32_t RPM_MAX = 6000, RPM_STEP = 100;
|
||||||
|
static const int32_t DUTY_MAX = 255, DUTY_STEP = 5;
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// HELPERS
|
// REFRESH
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
static void formatValue(const row_t &r, int32_t v, char *out, size_t n)
|
static void refreshSaveState()
|
||||||
{
|
{
|
||||||
if (r.id == F_TEMP_SLOPE)
|
link_config_t c = Tunables::get();
|
||||||
{
|
const char *txt;
|
||||||
snprintf(out, n, "%ld.%02ld", (long)(v / 100), (long)labs(v % 100));
|
lv_color_t col = UI_COL_MUTED;
|
||||||
}
|
if (g_tab == TAB_SIM)
|
||||||
else if (r.id == F_BATT_LOW)
|
txt = "Simulation values are never saved - a restart returns to live data";
|
||||||
{
|
else if (Tunables::isDirty())
|
||||||
snprintf(out, n, "%ld.%02ld V", (long)(v / 100), (long)(v % 100));
|
txt = "Saving...";
|
||||||
}
|
|
||||||
else if (r.unit[0])
|
|
||||||
{
|
|
||||||
snprintf(out, n, "%ld %s", (long)v, r.unit);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
snprintf(out, n, "%ld", (long)v);
|
txt = LV_SYMBOL_OK " All changes saved";
|
||||||
|
col = UI_COL_OK;
|
||||||
}
|
}
|
||||||
|
setText(g_save_lbl, txt);
|
||||||
|
setTextColor(g_save_lbl, col);
|
||||||
|
setVisible(g_sim_chip, c.override_mode != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void refreshFromTunables()
|
static void refreshFromTunables()
|
||||||
@@ -192,58 +178,38 @@ namespace TuningScreen
|
|||||||
link_config_t c = Tunables::get();
|
link_config_t c = Tunables::get();
|
||||||
g_refreshing = true;
|
g_refreshing = true;
|
||||||
|
|
||||||
char buf[24];
|
char buf[32];
|
||||||
for (int i = 0; i < F_COUNT; i++)
|
for (int i = 0; i < F_COUNT; i++)
|
||||||
{
|
{
|
||||||
if (g_rows[i].value_lbl == NULL)
|
if (g_rows[i].value_lbl == NULL)
|
||||||
continue;
|
continue;
|
||||||
formatValue(g_rows[i], getField(c, g_rows[i].id), buf, sizeof(buf));
|
formatValue(g_rows[i].id, getField(c, g_rows[i].id), buf, sizeof(buf));
|
||||||
lv_label_set_text(g_rows[i].value_lbl, buf);
|
setText(g_rows[i].value_lbl, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto setSw = [](lv_obj_t *sw, bool on)
|
setChecked(g_tach_en_sw, c.out_enable & OUT_ENABLE_TACH);
|
||||||
{
|
setChecked(g_temp_en_sw, c.out_enable & OUT_ENABLE_TEMP);
|
||||||
if (sw == NULL)
|
setChecked(g_ovr_rpm_sw, c.override_mode & OVERRIDE_TACH);
|
||||||
return;
|
setChecked(g_ovr_duty_sw, c.override_mode & OVERRIDE_TEMP);
|
||||||
if (on)
|
|
||||||
lv_obj_add_state(sw, LV_STATE_CHECKED);
|
|
||||||
else
|
|
||||||
lv_obj_clear_state(sw, LV_STATE_CHECKED);
|
|
||||||
};
|
|
||||||
setSw(g_tach_en_sw, c.out_enable & OUT_ENABLE_TACH);
|
|
||||||
setSw(g_temp_en_sw, c.out_enable & OUT_ENABLE_TEMP);
|
|
||||||
setSw(g_ovr_rpm_sw, c.override_mode & OVERRIDE_TACH);
|
|
||||||
setSw(g_ovr_duty_sw, c.override_mode & OVERRIDE_TEMP);
|
|
||||||
|
|
||||||
if (g_ovr_rpm_sl)
|
if (g_ovr_rpm_sl && !lv_obj_has_state(g_ovr_rpm_sl, LV_STATE_PRESSED))
|
||||||
lv_slider_set_value(g_ovr_rpm_sl, c.override_rpm, LV_ANIM_OFF);
|
lv_slider_set_value(g_ovr_rpm_sl, c.override_rpm, LV_ANIM_OFF);
|
||||||
if (g_ovr_duty_sl)
|
if (g_ovr_duty_sl && !lv_obj_has_state(g_ovr_duty_sl, LV_STATE_PRESSED))
|
||||||
lv_slider_set_value(g_ovr_duty_sl, c.override_duty, LV_ANIM_OFF);
|
lv_slider_set_value(g_ovr_duty_sl, c.override_duty, LV_ANIM_OFF);
|
||||||
if (g_ovr_rpm_lbl)
|
|
||||||
{
|
|
||||||
snprintf(buf, sizeof(buf), "%u rpm", c.override_rpm);
|
snprintf(buf, sizeof(buf), "%u rpm", c.override_rpm);
|
||||||
lv_label_set_text(g_ovr_rpm_lbl, buf);
|
setText(g_ovr_rpm_lbl, buf);
|
||||||
}
|
|
||||||
if (g_ovr_duty_lbl)
|
|
||||||
{
|
|
||||||
snprintf(buf, sizeof(buf), "%u / 255", c.override_duty);
|
snprintf(buf, sizeof(buf), "%u / 255", c.override_duty);
|
||||||
lv_label_set_text(g_ovr_duty_lbl, buf);
|
setText(g_ovr_duty_lbl, buf);
|
||||||
}
|
|
||||||
|
|
||||||
if (g_status_lbl)
|
|
||||||
{
|
|
||||||
snprintf(buf, sizeof(buf), "config v%u", c.cfg_version);
|
|
||||||
lv_label_set_text(g_status_lbl, buf);
|
|
||||||
lv_obj_set_style_text_color(g_status_lbl, c.override_mode ? COL_WARN : COL_MUTED, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
refreshSaveState();
|
||||||
g_shown_version = c.cfg_version;
|
g_shown_version = c.cfg_version;
|
||||||
g_refreshing = false;
|
g_refreshing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- event handlers --------------------------------------------------------
|
// ============================================================================
|
||||||
|
// EVENT HANDLERS
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
// user_data = row pointer; the button's own user data (+1/-1) is in lv_event_get_user_data
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
row_t *row;
|
row_t *row;
|
||||||
@@ -251,29 +217,44 @@ namespace TuningScreen
|
|||||||
} step_ctx_t;
|
} step_ctx_t;
|
||||||
static step_ctx_t g_step_ctx[F_COUNT][2];
|
static step_ctx_t g_step_ctx[F_COUNT][2];
|
||||||
|
|
||||||
|
/** 1x for taps and the first second of a hold, then 5x, then 10x. */
|
||||||
|
static int32_t holdMultiplier(lv_event_code_t code)
|
||||||
|
{
|
||||||
|
if (code == LV_EVENT_PRESSED)
|
||||||
|
{
|
||||||
|
g_repeats = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (code == LV_EVENT_LONG_PRESSED_REPEAT)
|
||||||
|
{
|
||||||
|
g_repeats++;
|
||||||
|
return g_repeats > 25 ? 10 : g_repeats > 10 ? 5 : 1;
|
||||||
|
}
|
||||||
|
return 1; // CLICKED
|
||||||
|
}
|
||||||
|
|
||||||
static void onStep(lv_event_t *e)
|
static void onStep(lv_event_t *e)
|
||||||
{
|
{
|
||||||
lv_event_code_t code = lv_event_get_code(e);
|
lv_event_code_t code = lv_event_get_code(e);
|
||||||
if (code != LV_EVENT_CLICKED && code != LV_EVENT_LONG_PRESSED_REPEAT)
|
int32_t mult = holdMultiplier(code);
|
||||||
|
if (mult == 0)
|
||||||
return;
|
return;
|
||||||
|
if (code == LV_EVENT_CLICKED && g_repeats > 0)
|
||||||
|
return; // end of a hold, already applied
|
||||||
step_ctx_t *ctx = (step_ctx_t *)lv_event_get_user_data(e);
|
step_ctx_t *ctx = (step_ctx_t *)lv_event_get_user_data(e);
|
||||||
link_config_t c = Tunables::get();
|
link_config_t c = Tunables::get();
|
||||||
int32_t v = getField(c, ctx->row->id) + ctx->dir * ctx->row->step;
|
int32_t v = getField(c, ctx->row->id) + ctx->dir * ctx->row->step * mult;
|
||||||
if (v < ctx->row->min)
|
v = constrain(v, ctx->row->min, ctx->row->max);
|
||||||
v = ctx->row->min;
|
|
||||||
if (v > ctx->row->max)
|
|
||||||
v = ctx->row->max;
|
|
||||||
setField(c, ctx->row->id, v);
|
setField(c, ctx->row->id, v);
|
||||||
Tunables::set(c); // saves + bumps version -> CONFIG frame goes out
|
Tunables::set(c); // bumps version -> CONFIG frame goes out; NVS write after 3 s idle
|
||||||
refreshFromTunables();
|
refreshFromTunables();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onEnableSwitch(lv_event_t *e)
|
static void onEnableSwitch(lv_event_t *e)
|
||||||
{
|
{
|
||||||
if (g_refreshing || lv_event_get_code(e) != LV_EVENT_VALUE_CHANGED)
|
if (g_refreshing)
|
||||||
return;
|
return;
|
||||||
lv_obj_t *sw = lv_event_get_target(e);
|
bool on = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
|
||||||
bool on = lv_obj_has_state(sw, LV_STATE_CHECKED);
|
|
||||||
uint8_t bit = (uint8_t)(uintptr_t)lv_event_get_user_data(e);
|
uint8_t bit = (uint8_t)(uintptr_t)lv_event_get_user_data(e);
|
||||||
link_config_t c = Tunables::get();
|
link_config_t c = Tunables::get();
|
||||||
c.out_enable = on ? (c.out_enable | bit) : (c.out_enable & ~bit);
|
c.out_enable = on ? (c.out_enable | bit) : (c.out_enable & ~bit);
|
||||||
@@ -283,22 +264,20 @@ namespace TuningScreen
|
|||||||
|
|
||||||
static void pushOverride()
|
static void pushOverride()
|
||||||
{
|
{
|
||||||
link_config_t c = Tunables::get();
|
|
||||||
uint8_t mode = 0;
|
uint8_t mode = 0;
|
||||||
if (g_ovr_rpm_sw && lv_obj_has_state(g_ovr_rpm_sw, LV_STATE_CHECKED))
|
if (lv_obj_has_state(g_ovr_rpm_sw, LV_STATE_CHECKED))
|
||||||
mode |= OVERRIDE_TACH;
|
mode |= OVERRIDE_TACH;
|
||||||
if (g_ovr_duty_sw && lv_obj_has_state(g_ovr_duty_sw, LV_STATE_CHECKED))
|
if (lv_obj_has_state(g_ovr_duty_sw, LV_STATE_CHECKED))
|
||||||
mode |= OVERRIDE_TEMP;
|
mode |= OVERRIDE_TEMP;
|
||||||
uint16_t rpm = g_ovr_rpm_sl ? (uint16_t)lv_slider_get_value(g_ovr_rpm_sl) : c.override_rpm;
|
Tunables::setOverride(mode, (uint16_t)lv_slider_get_value(g_ovr_rpm_sl),
|
||||||
uint8_t duty = g_ovr_duty_sl ? (uint8_t)lv_slider_get_value(g_ovr_duty_sl) : c.override_duty;
|
(uint8_t)lv_slider_get_value(g_ovr_duty_sl)); // pushed to B, never saved
|
||||||
Tunables::setOverride(mode, rpm, duty); // pushed to B, never saved
|
|
||||||
refreshFromTunables();
|
refreshFromTunables();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onOverrideSwitch(lv_event_t *e)
|
static void onOverrideSwitch(lv_event_t *e)
|
||||||
{
|
{
|
||||||
if (g_refreshing || lv_event_get_code(e) != LV_EVENT_VALUE_CHANGED)
|
(void)e;
|
||||||
return;
|
if (!g_refreshing)
|
||||||
pushOverride();
|
pushOverride();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,21 +286,21 @@ namespace TuningScreen
|
|||||||
if (g_refreshing)
|
if (g_refreshing)
|
||||||
return;
|
return;
|
||||||
lv_event_code_t code = lv_event_get_code(e);
|
lv_event_code_t code = lv_event_get_code(e);
|
||||||
// Update the readout while dragging; push to B on release so we don't
|
lv_obj_t *sl = lv_event_get_target(e);
|
||||||
// flood the link with CONFIG frames at touch rate.
|
// Readout follows the finger; push to B on release so we don't flood
|
||||||
|
// the link with CONFIG frames at touch rate.
|
||||||
if (code == LV_EVENT_VALUE_CHANGED)
|
if (code == LV_EVENT_VALUE_CHANGED)
|
||||||
{
|
{
|
||||||
char buf[24];
|
char buf[24];
|
||||||
lv_obj_t *sl = lv_event_get_target(e);
|
if (sl == g_ovr_rpm_sl)
|
||||||
if (sl == g_ovr_rpm_sl && g_ovr_rpm_lbl)
|
|
||||||
{
|
{
|
||||||
snprintf(buf, sizeof(buf), "%d rpm", (int)lv_slider_get_value(sl));
|
snprintf(buf, sizeof(buf), "%d rpm", (int)lv_slider_get_value(sl));
|
||||||
lv_label_set_text(g_ovr_rpm_lbl, buf);
|
setText(g_ovr_rpm_lbl, buf);
|
||||||
}
|
}
|
||||||
else if (sl == g_ovr_duty_sl && g_ovr_duty_lbl)
|
else
|
||||||
{
|
{
|
||||||
snprintf(buf, sizeof(buf), "%d / 255", (int)lv_slider_get_value(sl));
|
snprintf(buf, sizeof(buf), "%d / 255", (int)lv_slider_get_value(sl));
|
||||||
lv_label_set_text(g_ovr_duty_lbl, buf);
|
setText(g_ovr_duty_lbl, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (code == LV_EVENT_RELEASED)
|
else if (code == LV_EVENT_RELEASED)
|
||||||
@@ -330,249 +309,252 @@ namespace TuningScreen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Fine -/+ next to a slider; user data = +/-1, slider picked by the button's parent row. */
|
||||||
|
static void onSimStep(lv_event_t *e)
|
||||||
|
{
|
||||||
|
lv_event_code_t code = lv_event_get_code(e);
|
||||||
|
int32_t mult = holdMultiplier(code);
|
||||||
|
if (mult == 0 || (code == LV_EVENT_CLICKED && g_repeats > 0))
|
||||||
|
return;
|
||||||
|
int dir = (int)(intptr_t)lv_event_get_user_data(e);
|
||||||
|
lv_obj_t *btn = lv_event_get_target(e);
|
||||||
|
bool rpm = lv_obj_get_parent(btn) == lv_obj_get_parent(g_ovr_rpm_sl);
|
||||||
|
lv_obj_t *sl = rpm ? g_ovr_rpm_sl : g_ovr_duty_sl;
|
||||||
|
int32_t v = lv_slider_get_value(sl) + dir * (rpm ? RPM_STEP : DUTY_STEP) * mult;
|
||||||
|
lv_slider_set_value(sl, constrain(v, 0, rpm ? RPM_MAX : DUTY_MAX), LV_ANIM_OFF);
|
||||||
|
pushOverride();
|
||||||
|
}
|
||||||
|
|
||||||
static void onBack(lv_event_t *e)
|
static void onBack(lv_event_t *e)
|
||||||
{
|
{
|
||||||
if (lv_event_get_code(e) != LV_EVENT_CLICKED)
|
(void)e;
|
||||||
return;
|
Tunables::flush(); // write pending edits now rather than after the idle delay
|
||||||
DrivelineScreen::show();
|
DrivelineScreen::show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void onGesture(lv_event_t *e)
|
||||||
|
{
|
||||||
|
(void)e;
|
||||||
|
if (lv_indev_get_gesture_dir(lv_indev_get_act()) == LV_DIR_LEFT)
|
||||||
|
{
|
||||||
|
lv_indev_wait_release(lv_indev_get_act());
|
||||||
|
Tunables::flush();
|
||||||
|
DrivelineScreen::show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void onResetConfirmed(bool ok, void *user)
|
||||||
|
{
|
||||||
|
if (!ok)
|
||||||
|
return;
|
||||||
|
tab_t tab = (tab_t)(uintptr_t)user;
|
||||||
|
link_config_t d, c = Tunables::get();
|
||||||
|
link_config_defaults(&d);
|
||||||
|
for (int i = 0; i < F_COUNT; i++)
|
||||||
|
if (g_rows[i].tab == tab)
|
||||||
|
setField(c, g_rows[i].id, getField(d, g_rows[i].id));
|
||||||
|
uint8_t bit = tab == TAB_TACH ? OUT_ENABLE_TACH : tab == TAB_COOLANT ? OUT_ENABLE_TEMP : 0;
|
||||||
|
c.out_enable = (c.out_enable & ~bit) | (d.out_enable & bit);
|
||||||
|
Tunables::set(c);
|
||||||
|
refreshFromTunables();
|
||||||
|
}
|
||||||
|
|
||||||
static void onReset(lv_event_t *e)
|
static void onReset(lv_event_t *e)
|
||||||
{
|
{
|
||||||
if (lv_event_get_code(e) != LV_EVENT_CLICKED)
|
(void)e;
|
||||||
return;
|
char title[64];
|
||||||
Tunables::resetDefaults();
|
snprintf(title, sizeof(title), "Reset %s?", TAB_NAMES[g_tab]);
|
||||||
refreshFromTunables();
|
confirm(title, "Every value on this tab goes back to its default. The other tabs are not touched.",
|
||||||
|
"Reset", onResetConfirmed, (void *)(uintptr_t)g_tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- builders --------------------------------------------------------------
|
static void selectTab(tab_t t)
|
||||||
|
|
||||||
static lv_obj_t *makePanel(lv_obj_t *parent, const char *title, lv_coord_t w)
|
|
||||||
{
|
{
|
||||||
lv_obj_t *p = lv_obj_create(parent);
|
g_tab = t;
|
||||||
lv_obj_set_size(p, w, LV_SIZE_CONTENT);
|
for (int i = 0; i < TAB_COUNT; i++)
|
||||||
lv_obj_set_style_bg_color(p, COL_PANEL, 0);
|
{
|
||||||
lv_obj_set_style_border_width(p, 0, 0);
|
bool on = (i == t);
|
||||||
lv_obj_set_style_radius(p, 12, 0);
|
setVisible(g_tab_page[i], on);
|
||||||
lv_obj_set_style_pad_all(p, 12, 0);
|
lv_obj_set_style_bg_color(g_tab_btn[i], on ? UI_COL_ACCENT : UI_COL_PANEL, 0);
|
||||||
lv_obj_set_style_pad_row(p, 6, 0);
|
lv_obj_set_style_text_color(g_tab_btn[i], on ? lv_color_hex(0x0B1620) : UI_COL_TEXT, 0);
|
||||||
lv_obj_set_flex_flow(p, LV_FLEX_FLOW_COLUMN);
|
}
|
||||||
lv_obj_clear_flag(p, LV_OBJ_FLAG_SCROLLABLE);
|
setVisible(g_reset_btn, t != TAB_SIM);
|
||||||
|
refreshSaveState();
|
||||||
lv_obj_t *t = lv_label_create(p);
|
|
||||||
lv_label_set_text(t, title);
|
|
||||||
lv_obj_set_style_text_font(t, &lv_font_montserrat_14, 0);
|
|
||||||
lv_obj_set_style_text_color(t, COL_ACCENT, 0);
|
|
||||||
lv_obj_set_style_pad_bottom(t, 4, 0);
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static lv_obj_t *makeStepBtn(lv_obj_t *parent, const char *txt, step_ctx_t *ctx)
|
static void onTab(lv_event_t *e)
|
||||||
{
|
{
|
||||||
lv_obj_t *b = lv_btn_create(parent);
|
selectTab((tab_t)(uintptr_t)lv_event_get_user_data(e));
|
||||||
lv_obj_set_size(b, 44, 36);
|
}
|
||||||
lv_obj_set_style_bg_color(b, COL_BG, 0);
|
|
||||||
lv_obj_set_style_radius(b, 8, 0);
|
// ============================================================================
|
||||||
lv_obj_add_event_cb(b, onStep, LV_EVENT_CLICKED, ctx);
|
// BUILDERS
|
||||||
lv_obj_add_event_cb(b, onStep, LV_EVENT_LONG_PRESSED_REPEAT, ctx);
|
// ============================================================================
|
||||||
lv_obj_t *l = lv_label_create(b);
|
|
||||||
lv_label_set_text(l, txt);
|
static lv_obj_t *makeStepBtn(lv_obj_t *parent, const char *txt, lv_event_cb_t cb, void *ctx)
|
||||||
lv_obj_set_style_text_font(l, &lv_font_montserrat_14, 0);
|
{
|
||||||
lv_obj_center(l);
|
lv_obj_t *b = button(parent, txt, 76, 56, BTN_SECONDARY, NULL, NULL);
|
||||||
|
lv_obj_set_style_text_font(lv_obj_get_child(b, 0), &lv_font_montserrat_24, 0);
|
||||||
|
lv_obj_add_event_cb(b, cb, LV_EVENT_PRESSED, ctx);
|
||||||
|
lv_obj_add_event_cb(b, cb, LV_EVENT_CLICKED, ctx);
|
||||||
|
lv_obj_add_event_cb(b, cb, LV_EVENT_LONG_PRESSED_REPEAT, ctx);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void makeRow(lv_obj_t *panel, field_t f)
|
/** [name / hint] ... [-] value [+] */
|
||||||
|
static void makeRow(lv_obj_t *page, field_t f)
|
||||||
{
|
{
|
||||||
row_t *r = &g_rows[f];
|
row_t *r = &g_rows[f];
|
||||||
lv_obj_t *row = lv_obj_create(panel);
|
lv_obj_t *row = box(page, LV_FLEX_FLOW_ROW);
|
||||||
lv_obj_remove_style_all(row);
|
lv_obj_set_size(row, LV_PCT(100), 62);
|
||||||
lv_obj_set_size(row, LV_PCT(100), 36);
|
|
||||||
lv_obj_set_flex_flow(row, LV_FLEX_FLOW_ROW);
|
|
||||||
lv_obj_set_flex_align(row, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
lv_obj_set_flex_align(row, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||||
lv_obj_set_style_pad_column(row, 6, 0);
|
lv_obj_set_style_pad_column(row, 12, 0);
|
||||||
lv_obj_clear_flag(row, LV_OBJ_FLAG_SCROLLABLE);
|
|
||||||
|
|
||||||
lv_obj_t *name = lv_label_create(row);
|
lv_obj_t *txt = box(row, LV_FLEX_FLOW_COLUMN);
|
||||||
lv_label_set_text(name, r->name);
|
lv_obj_set_height(txt, LV_SIZE_CONTENT);
|
||||||
lv_obj_set_style_text_font(name, &lv_font_montserrat_14, 0);
|
lv_obj_set_flex_grow(txt, 1);
|
||||||
lv_obj_set_style_text_color(name, COL_MUTED, 0);
|
lv_obj_set_style_pad_row(txt, 2, 0);
|
||||||
lv_obj_set_width(name, 118);
|
label(txt, r->name, &lv_font_montserrat_24, UI_COL_TEXT);
|
||||||
|
label(txt, r->hint, &lv_font_montserrat_14, UI_COL_MUTED);
|
||||||
|
|
||||||
g_step_ctx[f][0] = {r, -1};
|
g_step_ctx[f][0] = {r, -1};
|
||||||
g_step_ctx[f][1] = {r, +1};
|
g_step_ctx[f][1] = {r, +1};
|
||||||
makeStepBtn(row, LV_SYMBOL_MINUS, &g_step_ctx[f][0]);
|
makeStepBtn(row, LV_SYMBOL_MINUS, onStep, &g_step_ctx[f][0]);
|
||||||
|
r->value_lbl = label(row, "--", &lv_font_montserrat_30, UI_COL_TEXT);
|
||||||
r->value_lbl = lv_label_create(row);
|
|
||||||
lv_label_set_text(r->value_lbl, "--");
|
|
||||||
lv_obj_set_style_text_font(r->value_lbl, &lv_font_montserrat_14, 0);
|
|
||||||
lv_obj_set_style_text_color(r->value_lbl, COL_TEXT, 0);
|
|
||||||
lv_obj_set_style_text_align(r->value_lbl, LV_TEXT_ALIGN_CENTER, 0);
|
lv_obj_set_style_text_align(r->value_lbl, LV_TEXT_ALIGN_CENTER, 0);
|
||||||
lv_obj_set_width(r->value_lbl, 82);
|
lv_obj_set_width(r->value_lbl, 190);
|
||||||
|
makeStepBtn(row, LV_SYMBOL_PLUS, onStep, &g_step_ctx[f][1]);
|
||||||
makeStepBtn(row, LV_SYMBOL_PLUS, &g_step_ctx[f][1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static lv_obj_t *makeSwitchRow(lv_obj_t *panel, const char *text, lv_event_cb_t cb, void *user)
|
static lv_obj_t *makeSwitchRow(lv_obj_t *page, const char *name, const char *hint, lv_event_cb_t cb, void *user)
|
||||||
{
|
{
|
||||||
lv_obj_t *row = lv_obj_create(panel);
|
lv_obj_t *row = box(page, LV_FLEX_FLOW_ROW);
|
||||||
lv_obj_remove_style_all(row);
|
lv_obj_set_size(row, LV_PCT(100), 62);
|
||||||
lv_obj_set_size(row, LV_PCT(100), 36);
|
|
||||||
lv_obj_set_flex_flow(row, LV_FLEX_FLOW_ROW);
|
|
||||||
lv_obj_set_flex_align(row, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
lv_obj_set_flex_align(row, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||||
lv_obj_clear_flag(row, LV_OBJ_FLAG_SCROLLABLE);
|
lv_obj_t *txt = box(row, LV_FLEX_FLOW_COLUMN);
|
||||||
|
lv_obj_set_size(txt, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||||
lv_obj_t *l = lv_label_create(row);
|
lv_obj_set_style_pad_row(txt, 2, 0);
|
||||||
lv_label_set_text(l, text);
|
label(txt, name, &lv_font_montserrat_24, UI_COL_TEXT);
|
||||||
lv_obj_set_style_text_font(l, &lv_font_montserrat_14, 0);
|
label(txt, hint, &lv_font_montserrat_14, UI_COL_MUTED);
|
||||||
lv_obj_set_style_text_color(l, COL_MUTED, 0);
|
lv_obj_t *sw = toggle(row, cb, user);
|
||||||
|
lv_obj_set_style_pad_right(row, 70, 0); // line the switch up under the value column
|
||||||
lv_obj_t *sw = lv_switch_create(row);
|
|
||||||
lv_obj_set_style_bg_color(sw, COL_ACCENT, (lv_style_selector_t)LV_PART_INDICATOR | (lv_style_selector_t)LV_STATE_CHECKED);
|
|
||||||
lv_obj_add_event_cb(sw, cb, LV_EVENT_VALUE_CHANGED, user);
|
|
||||||
return sw;
|
return sw;
|
||||||
}
|
}
|
||||||
|
|
||||||
static lv_obj_t *makeSliderRow(lv_obj_t *panel, const char *text, int32_t max, lv_obj_t **readout)
|
/** Simulation card: title + readout + switch, then [-] slider [+]. */
|
||||||
|
static lv_obj_t *makeSimCard(lv_obj_t *page, const char *title, int32_t max, lv_obj_t **sw, lv_obj_t **readout)
|
||||||
{
|
{
|
||||||
lv_obj_t *head = lv_obj_create(panel);
|
lv_obj_t *c = card(page);
|
||||||
lv_obj_remove_style_all(head);
|
lv_obj_set_size(c, LV_PCT(100), LV_SIZE_CONTENT);
|
||||||
lv_obj_set_size(head, LV_PCT(100), 20);
|
lv_obj_set_flex_flow(c, LV_FLEX_FLOW_COLUMN);
|
||||||
lv_obj_set_flex_flow(head, LV_FLEX_FLOW_ROW);
|
lv_obj_set_style_pad_row(c, 14, 0);
|
||||||
lv_obj_set_flex_align(head, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
||||||
lv_obj_clear_flag(head, LV_OBJ_FLAG_SCROLLABLE);
|
|
||||||
|
|
||||||
lv_obj_t *l = lv_label_create(head);
|
lv_obj_t *top = box(c, LV_FLEX_FLOW_ROW);
|
||||||
lv_label_set_text(l, text);
|
lv_obj_set_size(top, LV_PCT(100), LV_SIZE_CONTENT);
|
||||||
lv_obj_set_style_text_font(l, &lv_font_montserrat_14, 0);
|
lv_obj_set_flex_align(top, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||||
lv_obj_set_style_text_color(l, COL_MUTED, 0);
|
lv_obj_t *t = label(top, title, &lv_font_montserrat_24, UI_COL_TEXT);
|
||||||
|
lv_obj_set_flex_grow(t, 1);
|
||||||
|
*readout = label(top, "--", &lv_font_montserrat_30, UI_COL_TEXT);
|
||||||
|
lv_obj_set_style_pad_right(*readout, 24, 0);
|
||||||
|
*sw = toggle(top, onOverrideSwitch, NULL);
|
||||||
|
|
||||||
*readout = lv_label_create(head);
|
lv_obj_t *bottom = box(c, LV_FLEX_FLOW_ROW);
|
||||||
lv_label_set_text(*readout, "--");
|
lv_obj_set_size(bottom, LV_PCT(100), LV_SIZE_CONTENT);
|
||||||
lv_obj_set_style_text_font(*readout, &lv_font_montserrat_14, 0);
|
lv_obj_set_flex_align(bottom, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||||
lv_obj_set_style_text_color(*readout, COL_TEXT, 0);
|
lv_obj_set_style_pad_column(bottom, 24, 0);
|
||||||
|
makeStepBtn(bottom, LV_SYMBOL_MINUS, onSimStep, (void *)(intptr_t)-1);
|
||||||
lv_obj_t *sl = lv_slider_create(panel);
|
lv_obj_t *sl = lv_slider_create(bottom);
|
||||||
lv_obj_set_width(sl, LV_PCT(96));
|
lv_obj_set_height(sl, 16);
|
||||||
|
lv_obj_set_flex_grow(sl, 1);
|
||||||
lv_slider_set_range(sl, 0, max);
|
lv_slider_set_range(sl, 0, max);
|
||||||
lv_obj_set_style_bg_color(sl, COL_BG, 0);
|
lv_obj_set_style_bg_color(sl, UI_COL_PANEL2, 0);
|
||||||
lv_obj_set_style_bg_color(sl, COL_ACCENT, LV_PART_INDICATOR);
|
lv_obj_set_style_bg_color(sl, UI_COL_ACCENT, LV_PART_INDICATOR);
|
||||||
lv_obj_set_style_bg_color(sl, COL_TEXT, LV_PART_KNOB);
|
lv_obj_set_style_bg_color(sl, UI_COL_TEXT, LV_PART_KNOB);
|
||||||
|
lv_obj_set_style_pad_all(sl, 12, LV_PART_KNOB); // big knob
|
||||||
|
lv_obj_set_style_anim_time(sl, 0, 0);
|
||||||
|
lv_obj_clear_flag(sl, LV_OBJ_FLAG_GESTURE_BUBBLE); // dragging must not change screens
|
||||||
lv_obj_add_event_cb(sl, onOverrideSlider, LV_EVENT_VALUE_CHANGED, NULL);
|
lv_obj_add_event_cb(sl, onOverrideSlider, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
lv_obj_add_event_cb(sl, onOverrideSlider, LV_EVENT_RELEASED, NULL);
|
lv_obj_add_event_cb(sl, onOverrideSlider, LV_EVENT_RELEASED, NULL);
|
||||||
|
lv_obj_set_style_pad_ver(bottom, 12, 0); // room for the knob
|
||||||
|
makeStepBtn(bottom, LV_SYMBOL_PLUS, onSimStep, (void *)(intptr_t)1);
|
||||||
return sl;
|
return sl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static lv_obj_t *makeTabPage()
|
||||||
|
{
|
||||||
|
lv_obj_t *p = box(g_screen, LV_FLEX_FLOW_COLUMN);
|
||||||
|
lv_obj_set_size(p, 1024 - 48, 600 - 150 - 36);
|
||||||
|
lv_obj_set_pos(p, 24, 150);
|
||||||
|
lv_obj_set_style_pad_row(p, 6, 0);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
static void build()
|
static void build()
|
||||||
{
|
{
|
||||||
if (g_screen != NULL)
|
if (g_screen != NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g_screen = lv_obj_create(NULL);
|
g_screen = screen();
|
||||||
lv_obj_set_style_bg_color(g_screen, COL_BG, 0);
|
lv_obj_add_event_cb(g_screen, onGesture, LV_EVENT_GESTURE, NULL);
|
||||||
lv_obj_clear_flag(g_screen, LV_OBJ_FLAG_SCROLLABLE);
|
header(g_screen, "GAUGE TUNING", onBack);
|
||||||
// No swipe gesture on this screen: dragging the override sliders would
|
|
||||||
// otherwise change screens. Leave via the Driveline button (top right).
|
|
||||||
|
|
||||||
lv_obj_t *title = lv_label_create(g_screen);
|
g_sim_chip = label(g_screen, "SIMULATION ON", &lv_font_montserrat_20, UI_COL_TEXT);
|
||||||
lv_label_set_text(title, "GAUGE TUNING");
|
lv_obj_set_style_bg_color(g_sim_chip, UI_COL_WARN, 0);
|
||||||
lv_obj_set_style_text_font(title, &lv_font_montserrat_30, 0);
|
lv_obj_set_style_bg_opa(g_sim_chip, LV_OPA_COVER, 0);
|
||||||
lv_obj_set_style_text_color(title, COL_TEXT, 0);
|
lv_obj_set_style_radius(g_sim_chip, 8, 0);
|
||||||
lv_obj_align(title, LV_ALIGN_TOP_LEFT, 24, 16);
|
lv_obj_set_style_pad_hor(g_sim_chip, 12, 0);
|
||||||
|
lv_obj_set_style_pad_ver(g_sim_chip, 6, 0);
|
||||||
|
lv_obj_align(g_sim_chip, LV_ALIGN_TOP_LEFT, 290, 22);
|
||||||
|
lv_obj_add_flag(g_sim_chip, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
|
||||||
lv_obj_t *back = lv_btn_create(g_screen);
|
g_reset_btn = button(g_screen, LV_SYMBOL_REFRESH " Reset tab", 190, 56, BTN_SECONDARY, onReset, NULL);
|
||||||
lv_obj_set_size(back, 150, 36);
|
lv_obj_align(g_reset_btn, LV_ALIGN_TOP_RIGHT, -16 - 200 - 12, 10);
|
||||||
lv_obj_align(back, LV_ALIGN_TOP_RIGHT, -24, 18);
|
|
||||||
lv_obj_set_style_bg_color(back, COL_ACCENT, 0);
|
|
||||||
lv_obj_add_event_cb(back, onBack, LV_EVENT_CLICKED, NULL);
|
|
||||||
lv_obj_t *bl = lv_label_create(back);
|
|
||||||
lv_label_set_text(bl, LV_SYMBOL_HOME " Driveline");
|
|
||||||
lv_obj_set_style_text_font(bl, &lv_font_montserrat_14, 0);
|
|
||||||
lv_obj_center(bl);
|
|
||||||
|
|
||||||
lv_obj_t *reset = lv_btn_create(g_screen);
|
// tab bar
|
||||||
lv_obj_set_size(reset, 150, 36);
|
for (int i = 0; i < TAB_COUNT; i++)
|
||||||
lv_obj_align(reset, LV_ALIGN_TOP_RIGHT, -24 - 150 - 12, 18);
|
{
|
||||||
lv_obj_set_style_bg_color(reset, COL_PANEL, 0);
|
g_tab_btn[i] = button(g_screen, TAB_NAMES[i], 232, 58, BTN_SECONDARY, onTab, (void *)(uintptr_t)i);
|
||||||
lv_obj_add_event_cb(reset, onReset, LV_EVENT_CLICKED, NULL);
|
lv_obj_set_pos(g_tab_btn[i], 24 + i * (232 + 12), 80);
|
||||||
lv_obj_t *rl = lv_label_create(reset);
|
g_tab_page[i] = makeTabPage();
|
||||||
lv_label_set_text(rl, LV_SYMBOL_REFRESH " Defaults");
|
}
|
||||||
lv_obj_set_style_text_font(rl, &lv_font_montserrat_14, 0);
|
|
||||||
lv_obj_center(rl);
|
|
||||||
|
|
||||||
// Three columns of panels
|
// ---- Tachometer ----
|
||||||
lv_obj_t *cols = lv_obj_create(g_screen);
|
makeRow(g_tab_page[TAB_TACH], F_TACH_PPR);
|
||||||
lv_obj_remove_style_all(cols);
|
makeRow(g_tab_page[TAB_TACH], F_TACH_TRIM);
|
||||||
lv_obj_set_size(cols, 1024 - 48, 600 - 70 - 30);
|
makeRow(g_tab_page[TAB_TACH], F_TACH_MAX_HZ);
|
||||||
lv_obj_align(cols, LV_ALIGN_TOP_LEFT, 24, 66);
|
g_tach_en_sw = makeSwitchRow(g_tab_page[TAB_TACH], "Tachometer output", "IO7 on Controller B. Off = no signal",
|
||||||
lv_obj_set_flex_flow(cols, LV_FLEX_FLOW_ROW);
|
onEnableSwitch, (void *)(uintptr_t)OUT_ENABLE_TACH);
|
||||||
lv_obj_set_flex_align(cols, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START);
|
|
||||||
lv_obj_clear_flag(cols, LV_OBJ_FLAG_SCROLLABLE);
|
|
||||||
|
|
||||||
const lv_coord_t W = 320;
|
// ---- Coolant gauge ----
|
||||||
|
makeRow(g_tab_page[TAB_COOLANT], F_TEMP_HZ);
|
||||||
|
makeRow(g_tab_page[TAB_COOLANT], F_TEMP_SLOPE);
|
||||||
|
makeRow(g_tab_page[TAB_COOLANT], F_TEMP_OFFSET);
|
||||||
|
makeRow(g_tab_page[TAB_COOLANT], F_TEMP_MIN);
|
||||||
|
makeRow(g_tab_page[TAB_COOLANT], F_TEMP_DUTY_MAX);
|
||||||
|
g_temp_en_sw = makeSwitchRow(g_tab_page[TAB_COOLANT], "Coolant gauge output", "IO8 on Controller B. Off = no signal",
|
||||||
|
onEnableSwitch, (void *)(uintptr_t)OUT_ENABLE_TEMP);
|
||||||
|
|
||||||
// ---- column 1: tach + alerts ----
|
// ---- Alerts ----
|
||||||
lv_obj_t *c1 = lv_obj_create(cols);
|
makeRow(g_tab_page[TAB_ALERTS], F_COOLANT_HOT);
|
||||||
lv_obj_remove_style_all(c1);
|
makeRow(g_tab_page[TAB_ALERTS], F_GEARBOX_HOT);
|
||||||
lv_obj_set_size(c1, W, LV_SIZE_CONTENT);
|
makeRow(g_tab_page[TAB_ALERTS], F_BATT_LOW);
|
||||||
lv_obj_set_flex_flow(c1, LV_FLEX_FLOW_COLUMN);
|
|
||||||
lv_obj_set_style_pad_row(c1, 12, 0);
|
|
||||||
lv_obj_clear_flag(c1, LV_OBJ_FLAG_SCROLLABLE);
|
|
||||||
|
|
||||||
lv_obj_t *tach = makePanel(c1, "TACHOMETER(IO7)", W);
|
// ---- Simulation ----
|
||||||
makeRow(tach, F_TACH_PPR);
|
lv_obj_t *sim = g_tab_page[TAB_SIM];
|
||||||
makeRow(tach, F_TACH_TRIM);
|
lv_obj_set_style_pad_row(sim, 14, 0);
|
||||||
makeRow(tach, F_TACH_MAX_HZ);
|
lv_obj_t *intro = label(sim,
|
||||||
g_tach_en_sw = makeSwitchRow(tach, "Output enabled", onEnableSwitch, (void *)(uintptr_t)OUT_ENABLE_TACH);
|
"Forces fixed values on the gauge outputs so the needles can be calibrated "
|
||||||
|
"against the cluster. Switch off when done.",
|
||||||
|
&lv_font_montserrat_20, UI_COL_MUTED);
|
||||||
|
lv_label_set_long_mode(intro, LV_LABEL_LONG_WRAP);
|
||||||
|
lv_obj_set_width(intro, LV_PCT(100));
|
||||||
|
g_ovr_rpm_sl = makeSimCard(sim, "Force tachometer", RPM_MAX, &g_ovr_rpm_sw, &g_ovr_rpm_lbl);
|
||||||
|
g_ovr_duty_sl = makeSimCard(sim, "Force coolant gauge", DUTY_MAX, &g_ovr_duty_sw, &g_ovr_duty_lbl);
|
||||||
|
|
||||||
lv_obj_t *alerts = makePanel(c1, "ALERT THRESHOLDS", W);
|
g_save_lbl = label(g_screen, "", &lv_font_montserrat_20, UI_COL_MUTED);
|
||||||
makeRow(alerts, F_COOLANT_HOT);
|
lv_obj_align(g_save_lbl, LV_ALIGN_BOTTOM_LEFT, 24, -8);
|
||||||
makeRow(alerts, F_GEARBOX_HOT);
|
|
||||||
makeRow(alerts, F_BATT_LOW);
|
|
||||||
|
|
||||||
// ---- column 2: coolant gauge ----
|
|
||||||
lv_obj_t *temp = makePanel(cols, "COOLANT GAUGE(IO8)", W);
|
|
||||||
makeRow(temp, F_TEMP_HZ);
|
|
||||||
makeRow(temp, F_TEMP_SLOPE);
|
|
||||||
makeRow(temp, F_TEMP_OFFSET);
|
|
||||||
makeRow(temp, F_TEMP_MIN);
|
|
||||||
makeRow(temp, F_TEMP_DUTY_MAX);
|
|
||||||
g_temp_en_sw = makeSwitchRow(temp, "Output enabled", onEnableSwitch, (void *)(uintptr_t)OUT_ENABLE_TEMP);
|
|
||||||
|
|
||||||
// lv_obj_t* note = lv_label_create(temp);
|
|
||||||
// lv_label_set_text(note, "duty = slope x T + offset\n(defaults: 1.5 x T + 50, from the\nCANNY program)");
|
|
||||||
// lv_obj_set_style_text_font(note, &lv_font_montserrat_14, 0);
|
|
||||||
// lv_obj_set_style_text_color(note, COL_MUTED, 0);
|
|
||||||
|
|
||||||
// ---- column 3: calibration override ----
|
|
||||||
lv_obj_t *ovr = makePanel(cols, "SIMULATION", 300);
|
|
||||||
g_ovr_rpm_sw = makeSwitchRow(ovr, "Force tach rpm", onOverrideSwitch, NULL);
|
|
||||||
g_ovr_rpm_sl = makeSliderRow(ovr, "RPM", 6000, &g_ovr_rpm_lbl);
|
|
||||||
g_ovr_duty_sw = makeSwitchRow(ovr, "Force coolant duty", onOverrideSwitch, NULL);
|
|
||||||
g_ovr_duty_sl = makeSliderRow(ovr, "Duty", 255, &g_ovr_duty_lbl);
|
|
||||||
|
|
||||||
// lv_obj_t* howto = lv_label_create(ovr);
|
|
||||||
// lv_label_set_text(howto,
|
|
||||||
// "Tach: force 1000 rpm, fix Pulses/rev until\n"
|
|
||||||
// "the needle reads 1000; force 3000, fix Trim.\n"
|
|
||||||
// "Temp: force a duty, note the needle, repeat;\n"
|
|
||||||
// "derive Slope/Offset from two marks.\n"
|
|
||||||
// "Switch overrides OFF when done.");
|
|
||||||
// lv_obj_set_style_text_font(howto, &lv_font_montserrat_14, 0);
|
|
||||||
// lv_obj_set_style_text_color(howto, COL_MUTED, 0);
|
|
||||||
|
|
||||||
// lv_obj_t *hint = lv_label_create(g_screen);
|
|
||||||
// lv_label_set_text(hint, LV_SYMBOL_LEFT " swipe left: back to Driveline");
|
|
||||||
// lv_obj_set_style_text_font(hint, &lv_font_montserrat_14, 0);
|
|
||||||
// lv_obj_set_style_text_color(hint, COL_MUTED, 0);
|
|
||||||
// lv_obj_align(hint, LV_ALIGN_BOTTOM_RIGHT, -24, -10);
|
|
||||||
|
|
||||||
g_status_lbl = lv_label_create(g_screen);
|
|
||||||
lv_label_set_text(g_status_lbl, "config v-");
|
|
||||||
lv_obj_set_style_text_font(g_status_lbl, &lv_font_montserrat_14, 0);
|
|
||||||
lv_obj_set_style_text_color(g_status_lbl, COL_MUTED, 0);
|
|
||||||
lv_obj_align(g_status_lbl, LV_ALIGN_BOTTOM_RIGHT, -24, -10);
|
|
||||||
|
|
||||||
|
selectTab(TAB_TACH);
|
||||||
ESP_LOGI("Tuning", "Gauge tuning screen built");
|
ESP_LOGI("Tuning", "Gauge tuning screen built");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -584,7 +566,7 @@ namespace TuningScreen
|
|||||||
{
|
{
|
||||||
build();
|
build();
|
||||||
refreshFromTunables();
|
refreshFromTunables();
|
||||||
lv_scr_load_anim(g_screen, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0, false);
|
lv_scr_load_anim(g_screen, LV_SCR_LOAD_ANIM_NONE, 0, 0, false); // instant: fades stutter at 1024x600
|
||||||
}
|
}
|
||||||
|
|
||||||
void tick()
|
void tick()
|
||||||
@@ -595,10 +577,11 @@ namespace TuningScreen
|
|||||||
if (millis() - last < 500)
|
if (millis() - last < 500)
|
||||||
return;
|
return;
|
||||||
last = millis();
|
last = millis();
|
||||||
if (Tunables::version() == g_shown_version)
|
|
||||||
return; // nothing changed elsewhere
|
|
||||||
lvgl_port_lock(-1);
|
lvgl_port_lock(-1);
|
||||||
refreshFromTunables();
|
if (Tunables::version() != g_shown_version)
|
||||||
|
refreshFromTunables(); // changed from the console
|
||||||
|
else
|
||||||
|
refreshSaveState(); // "Saving..." -> "saved" after the deferred write
|
||||||
lvgl_port_unlock();
|
lvgl_port_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,10 @@
|
|||||||
* bench override (force an rpm / a duty) so the needles can be calibrated
|
* bench override (force an rpm / a duty) so the needles can be calibrated
|
||||||
* from the touchscreen while watching the cluster.
|
* from the touchscreen while watching the cluster.
|
||||||
*
|
*
|
||||||
* Lives in src/ (never touched by SquareLine exports), like DrivelineScreen.
|
* Four tabs: Tachometer / Coolant gauge / Alerts / Simulation.
|
||||||
* Reached by swiping RIGHT on the Driveline screen; the Driveline button (top
|
* Reached by swiping RIGHT on the Driveline screen; swipe left or the Driveline
|
||||||
* right) goes back. No swipe gesture on this screen (it would fight the sliders).
|
* button (top right) goes back. The Simulation sliders don't bubble gestures,
|
||||||
|
* so dragging them never changes screens.
|
||||||
* Every change goes through Tunables, so it is saved to NVS (overrides
|
* Every change goes through Tunables, so it is saved to NVS (overrides
|
||||||
* excepted) and pushed to Controller B in the next CONFIG frame.
|
* excepted) and pushed to Controller B in the next CONFIG frame.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -323,15 +323,8 @@ void linkToCANState(bool can_active) {
|
|||||||
// EVENT HANDLERS
|
// EVENT HANDLERS
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
void onUARTToggle(lv_event_t *e)
|
void setEnabled(bool state)
|
||||||
{
|
{
|
||||||
lv_obj_t *target = lv_event_get_target(e);
|
|
||||||
if (target == NULL) {
|
|
||||||
ESP_LOGE("UARTMgr", "ERROR: UART toggle target is NULL!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool state = lv_obj_has_state(target, LV_STATE_CHECKED);
|
|
||||||
|
|
||||||
ESP_LOGI("UARTMgr", "===== UART Toggle Event =====");
|
ESP_LOGI("UARTMgr", "===== UART Toggle Event =====");
|
||||||
ESP_LOGI("UARTMgr", "UART Toggle State: %s", state ? "ON" : "OFF");
|
ESP_LOGI("UARTMgr", "UART Toggle State: %s", state ? "ON" : "OFF");
|
||||||
|
|||||||
@@ -116,15 +116,10 @@ void setDebugEnabled(bool enabled);
|
|||||||
*/
|
*/
|
||||||
void linkToCANState(bool can_active);
|
void linkToCANState(bool can_active);
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// EVENT HANDLERS (Called from SquareLine Studio UI)
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief UART toggle event handler
|
* @brief Settings-screen switch: start/stop sending to Controller B (UART1 +
|
||||||
* @param e LVGL event object
|
* ESP-NOW) and remember the choice in NVS.
|
||||||
* @note This function is registered in SquareLine Studio UI
|
|
||||||
*/
|
*/
|
||||||
void onUARTToggle(lv_event_t *e);
|
void setEnabled(bool enabled);
|
||||||
|
|
||||||
} // namespace UARTManager
|
} // namespace UARTManager
|
||||||
|
|||||||
@@ -0,0 +1,177 @@
|
|||||||
|
/*
|
||||||
|
* UI kit implementation - see ui_kit.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ui_kit.h"
|
||||||
|
|
||||||
|
namespace UiKit {
|
||||||
|
|
||||||
|
lv_obj_t* screen() {
|
||||||
|
lv_obj_t* s = lv_obj_create(NULL);
|
||||||
|
lv_obj_set_style_bg_color(s, UI_COL_BG, 0);
|
||||||
|
lv_obj_set_style_bg_opa(s, LV_OPA_COVER, 0);
|
||||||
|
lv_obj_clear_flag(s, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void header(lv_obj_t* scr, const char* title, lv_event_cb_t back_cb) {
|
||||||
|
lv_obj_t* t = label(scr, title, &lv_font_montserrat_30, UI_COL_TEXT);
|
||||||
|
lv_obj_align(t, LV_ALIGN_TOP_LEFT, 24, 18);
|
||||||
|
|
||||||
|
lv_obj_t* back = button(scr, LV_SYMBOL_LEFT " Driveline", 200, 56, BTN_SECONDARY, back_cb, NULL);
|
||||||
|
lv_obj_align(back, LV_ALIGN_TOP_RIGHT, -16, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_obj_t* label(lv_obj_t* parent, const char* text, const lv_font_t* font, lv_color_t color) {
|
||||||
|
lv_obj_t* l = lv_label_create(parent);
|
||||||
|
lv_label_set_text(l, text);
|
||||||
|
lv_obj_set_style_text_font(l, font, 0);
|
||||||
|
lv_obj_set_style_text_color(l, color, 0);
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void styleButton(lv_obj_t* b, btn_style_t style) {
|
||||||
|
lv_color_t bg = UI_COL_PANEL2, fg = UI_COL_TEXT;
|
||||||
|
switch (style) {
|
||||||
|
case BTN_PRIMARY: bg = UI_COL_ACCENT; fg = lv_color_hex(0x0B1620); break;
|
||||||
|
case BTN_SECONDARY: bg = UI_COL_PANEL2; fg = UI_COL_TEXT; break;
|
||||||
|
case BTN_DANGER: bg = UI_COL_WARN; fg = UI_COL_TEXT; break;
|
||||||
|
case BTN_SUCCESS: bg = UI_COL_OK; fg = lv_color_hex(0x0B1620); break;
|
||||||
|
}
|
||||||
|
lv_obj_set_style_bg_color(b, bg, 0);
|
||||||
|
lv_obj_set_style_bg_opa(b, LV_OPA_COVER, 0);
|
||||||
|
lv_obj_set_style_text_color(b, fg, 0);
|
||||||
|
lv_obj_set_style_radius(b, 10, 0);
|
||||||
|
lv_obj_set_style_shadow_width(b, 0, 0);
|
||||||
|
lv_obj_set_style_bg_color(b, lv_color_hex(0x3A4450), LV_STATE_DISABLED);
|
||||||
|
lv_obj_set_style_text_color(b, UI_COL_MUTED, LV_STATE_DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_obj_t* button(lv_obj_t* parent, const char* text, lv_coord_t w, lv_coord_t h,
|
||||||
|
btn_style_t style, lv_event_cb_t cb, void* user) {
|
||||||
|
lv_obj_t* b = lv_btn_create(parent);
|
||||||
|
lv_obj_set_size(b, w, h);
|
||||||
|
styleButton(b, style);
|
||||||
|
if (cb) lv_obj_add_event_cb(b, cb, LV_EVENT_CLICKED, user);
|
||||||
|
lv_obj_t* l = lv_label_create(b);
|
||||||
|
lv_label_set_text(l, text);
|
||||||
|
lv_obj_set_style_text_font(l, &lv_font_montserrat_20, 0);
|
||||||
|
lv_obj_center(l);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setButtonText(lv_obj_t* btn, const char* text) {
|
||||||
|
setText(lv_obj_get_child(btn, 0), text);
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_obj_t* toggle(lv_obj_t* parent, lv_event_cb_t cb, void* user) {
|
||||||
|
lv_obj_t* sw = lv_switch_create(parent);
|
||||||
|
lv_obj_set_size(sw, 92, 48);
|
||||||
|
lv_obj_set_style_bg_color(sw, UI_COL_PANEL2, 0);
|
||||||
|
lv_obj_set_style_bg_color(sw, UI_COL_ACCENT, (lv_style_selector_t)LV_PART_INDICATOR | (lv_style_selector_t)LV_STATE_CHECKED);
|
||||||
|
lv_obj_set_style_anim_time(sw, 0, 0); // no knob slide animation: one redraw per flip
|
||||||
|
if (cb) lv_obj_add_event_cb(sw, cb, LV_EVENT_VALUE_CHANGED, user);
|
||||||
|
return sw;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setChecked(lv_obj_t* obj, bool on) {
|
||||||
|
if (obj == NULL || lv_obj_has_state(obj, LV_STATE_CHECKED) == on) return;
|
||||||
|
if (on) lv_obj_add_state(obj, LV_STATE_CHECKED);
|
||||||
|
else lv_obj_clear_state(obj, LV_STATE_CHECKED);
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_obj_t* box(lv_obj_t* parent, lv_flex_flow_t flow) {
|
||||||
|
lv_obj_t* b = lv_obj_create(parent);
|
||||||
|
lv_obj_remove_style_all(b);
|
||||||
|
lv_obj_set_flex_flow(b, flow);
|
||||||
|
lv_obj_clear_flag(b, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_obj_t* card(lv_obj_t* parent) {
|
||||||
|
lv_obj_t* c = lv_obj_create(parent);
|
||||||
|
lv_obj_set_style_bg_color(c, UI_COL_PANEL, 0);
|
||||||
|
lv_obj_set_style_border_width(c, 0, 0);
|
||||||
|
lv_obj_set_style_radius(c, 12, 0);
|
||||||
|
lv_obj_set_style_pad_all(c, 16, 0);
|
||||||
|
lv_obj_set_style_shadow_width(c, 0, 0);
|
||||||
|
lv_obj_clear_flag(c, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setText(lv_obj_t* lbl, const char* text) {
|
||||||
|
if (lbl == NULL) return;
|
||||||
|
const char* cur = lv_label_get_text(lbl);
|
||||||
|
if (cur && strcmp(cur, text) == 0) return;
|
||||||
|
lv_label_set_text(lbl, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTextColor(lv_obj_t* lbl, lv_color_t c) {
|
||||||
|
if (lbl == NULL) return;
|
||||||
|
if (lv_obj_get_style_text_color(lbl, LV_PART_MAIN).full == c.full) return;
|
||||||
|
lv_obj_set_style_text_color(lbl, c, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setVisible(lv_obj_t* obj, bool visible) {
|
||||||
|
if (obj == NULL || lv_obj_has_flag(obj, LV_OBJ_FLAG_HIDDEN) == !visible) return;
|
||||||
|
if (visible) lv_obj_clear_flag(obj, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
else lv_obj_add_flag(obj, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- confirm dialog --------------------------------------------------------
|
||||||
|
|
||||||
|
static const char* g_btn_map[3] = {"Cancel", "OK", ""};
|
||||||
|
static char g_ok_text[32];
|
||||||
|
static void (*g_confirm_cb)(bool, void*) = NULL;
|
||||||
|
static void* g_confirm_user = NULL;
|
||||||
|
|
||||||
|
static void onConfirm(lv_event_t* e) {
|
||||||
|
lv_obj_t* mb = lv_event_get_current_target(e);
|
||||||
|
uint16_t id = lv_msgbox_get_active_btn(mb);
|
||||||
|
if (id == LV_BTNMATRIX_BTN_NONE) return;
|
||||||
|
lv_msgbox_close_async(mb);
|
||||||
|
void (*cb)(bool, void*) = g_confirm_cb;
|
||||||
|
g_confirm_cb = NULL;
|
||||||
|
if (cb) cb(id == 1, g_confirm_user);
|
||||||
|
}
|
||||||
|
|
||||||
|
void confirm(const char* title, const char* text, const char* ok_text,
|
||||||
|
void (*cb)(bool ok, void* user), void* user) {
|
||||||
|
snprintf(g_ok_text, sizeof(g_ok_text), "%s", ok_text);
|
||||||
|
g_btn_map[1] = g_ok_text;
|
||||||
|
g_confirm_cb = cb;
|
||||||
|
g_confirm_user = user;
|
||||||
|
|
||||||
|
lv_obj_t* mb = lv_msgbox_create(NULL, title, text, g_btn_map, false);
|
||||||
|
lv_obj_set_width(mb, 640);
|
||||||
|
lv_obj_set_style_bg_color(mb, UI_COL_PANEL, 0);
|
||||||
|
lv_obj_set_style_border_width(mb, 0, 0);
|
||||||
|
lv_obj_set_style_shadow_width(mb, 0, 0);
|
||||||
|
lv_obj_set_style_radius(mb, 14, 0);
|
||||||
|
lv_obj_set_style_pad_all(mb, 24, 0);
|
||||||
|
lv_obj_set_style_pad_row(mb, 16, 0);
|
||||||
|
lv_obj_set_style_text_color(mb, UI_COL_TEXT, 0);
|
||||||
|
lv_obj_set_style_text_font(lv_msgbox_get_title(mb), &lv_font_montserrat_24, 0);
|
||||||
|
lv_obj_set_style_text_font(lv_msgbox_get_text(mb), &lv_font_montserrat_20, 0);
|
||||||
|
|
||||||
|
lv_obj_t* btns = lv_msgbox_get_btns(mb);
|
||||||
|
lv_obj_set_size(btns, LV_PCT(100), 64);
|
||||||
|
lv_obj_set_style_text_font(btns, &lv_font_montserrat_20, 0);
|
||||||
|
lv_obj_set_style_pad_column(btns, 16, 0);
|
||||||
|
lv_obj_set_style_bg_color(btns, UI_COL_PANEL2, LV_PART_ITEMS);
|
||||||
|
lv_obj_set_style_text_color(btns, UI_COL_TEXT, LV_PART_ITEMS);
|
||||||
|
lv_obj_set_style_radius(btns, 10, LV_PART_ITEMS);
|
||||||
|
lv_obj_set_style_shadow_width(btns, 0, LV_PART_ITEMS);
|
||||||
|
lv_btnmatrix_set_btn_ctrl(btns, 1, LV_BTNMATRIX_CTRL_CHECKED); // highlight the action
|
||||||
|
lv_obj_set_style_bg_color(btns, UI_COL_ACCENT, (lv_style_selector_t)LV_PART_ITEMS | (lv_style_selector_t)LV_STATE_CHECKED);
|
||||||
|
lv_obj_set_style_text_color(btns, lv_color_hex(0x0B1620), (lv_style_selector_t)LV_PART_ITEMS | (lv_style_selector_t)LV_STATE_CHECKED);
|
||||||
|
|
||||||
|
lv_obj_t* backdrop = lv_obj_get_parent(mb);
|
||||||
|
lv_obj_set_style_bg_color(backdrop, lv_color_black(), 0);
|
||||||
|
lv_obj_set_style_bg_opa(backdrop, LV_OPA_70, 0);
|
||||||
|
|
||||||
|
lv_obj_center(mb);
|
||||||
|
lv_obj_add_event_cb(mb, onConfirm, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace UiKit
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* UI kit - shared look for the hand-coded screens (Settings, Gauge Tuning).
|
||||||
|
*
|
||||||
|
* Car-sized touch targets (>= 56 px), 20/24 px body text, no shadows or
|
||||||
|
* animated transitions (every extra redraw of this 1024x600 PSRAM framebuffer
|
||||||
|
* costs frame time). All functions need the LVGL lock, like any LVGL call.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <lvgl.h>
|
||||||
|
|
||||||
|
#define UI_COL_BG lv_color_hex(0x101418)
|
||||||
|
#define UI_COL_PANEL lv_color_hex(0x1B2128)
|
||||||
|
#define UI_COL_PANEL2 lv_color_hex(0x252D36) // pressed / selected rows
|
||||||
|
#define UI_COL_TEXT lv_color_hex(0xE8EDF2)
|
||||||
|
#define UI_COL_MUTED lv_color_hex(0x8894A0)
|
||||||
|
#define UI_COL_ACCENT lv_color_hex(0x3DA9FC)
|
||||||
|
#define UI_COL_OK lv_color_hex(0x3DD68C)
|
||||||
|
#define UI_COL_WARN lv_color_hex(0xE5484D)
|
||||||
|
#define UI_COL_AMBER lv_color_hex(0xF5A524)
|
||||||
|
|
||||||
|
namespace UiKit {
|
||||||
|
|
||||||
|
typedef enum { BTN_PRIMARY, BTN_SECONDARY, BTN_DANGER, BTN_SUCCESS } btn_style_t;
|
||||||
|
|
||||||
|
/** Plain full-screen background object. */
|
||||||
|
lv_obj_t* screen();
|
||||||
|
|
||||||
|
/** Title top-left and a "< Driveline" button top-right that calls back_cb. */
|
||||||
|
void header(lv_obj_t* scr, const char* title, lv_event_cb_t back_cb);
|
||||||
|
|
||||||
|
lv_obj_t* label(lv_obj_t* parent, const char* text, const lv_font_t* font, lv_color_t color);
|
||||||
|
|
||||||
|
/** Button with a centred label; the label is the button's first child. */
|
||||||
|
lv_obj_t* button(lv_obj_t* parent, const char* text, lv_coord_t w, lv_coord_t h,
|
||||||
|
btn_style_t style, lv_event_cb_t cb, void* user);
|
||||||
|
void setButtonText(lv_obj_t* btn, const char* text);
|
||||||
|
|
||||||
|
lv_obj_t* toggle(lv_obj_t* parent, lv_event_cb_t cb, void* user);
|
||||||
|
void setChecked(lv_obj_t* obj, bool on);
|
||||||
|
|
||||||
|
/** Transparent flex row/column container without padding or scrolling. */
|
||||||
|
lv_obj_t* box(lv_obj_t* parent, lv_flex_flow_t flow);
|
||||||
|
|
||||||
|
/** Rounded panel (card). */
|
||||||
|
lv_obj_t* card(lv_obj_t* parent);
|
||||||
|
|
||||||
|
/** lv_label_set_text only when the text changed - avoids needless redraws. */
|
||||||
|
void setText(lv_obj_t* lbl, const char* text);
|
||||||
|
void setTextColor(lv_obj_t* lbl, lv_color_t c);
|
||||||
|
void setVisible(lv_obj_t* obj, bool visible);
|
||||||
|
|
||||||
|
/** Modal Cancel / OK dialog; cb(true, user) on OK, cb(false, user) on Cancel. */
|
||||||
|
void confirm(const char* title, const char* text, const char* ok_text,
|
||||||
|
void (*cb)(bool ok, void* user), void* user);
|
||||||
|
|
||||||
|
} // namespace UiKit
|
||||||
@@ -4,19 +4,7 @@
|
|||||||
|
|
||||||
#include "ui_state_manager.h"
|
#include "ui_state_manager.h"
|
||||||
#include "display/lvgl_v8_port.h"
|
#include "display/lvgl_v8_port.h"
|
||||||
#include "settings_manager.h"
|
|
||||||
#include "wifi_manager.h"
|
|
||||||
#include "uart_manager.h"
|
#include "uart_manager.h"
|
||||||
#include "drivers/can_driver.h"
|
|
||||||
|
|
||||||
// External UI element references (from ui_Settings_Screen.c)
|
|
||||||
extern "C" {
|
|
||||||
extern lv_obj_t *uic_Main_Container;
|
|
||||||
extern lv_obj_t *uic_Toggle_Wifi_Switch;
|
|
||||||
extern lv_obj_t *uic_Toggle_UART_Switch;
|
|
||||||
extern lv_obj_t *uic_Toggle_CAN_Bus_Switch;
|
|
||||||
extern lv_obj_t *uic_Toggle_Debug_Switch;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace UIStateManager {
|
namespace UIStateManager {
|
||||||
|
|
||||||
@@ -24,9 +12,6 @@ namespace UIStateManager {
|
|||||||
// PRIVATE MODULE STATE
|
// PRIVATE MODULE STATE
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
// Track which screen instance we synced (to prevent redundant syncing)
|
|
||||||
static lv_obj_t* g_last_synced_screen = NULL;
|
|
||||||
|
|
||||||
// Debug mode state
|
// Debug mode state
|
||||||
static bool g_debug_enabled = false;
|
static bool g_debug_enabled = false;
|
||||||
|
|
||||||
@@ -36,85 +21,9 @@ static bool g_debug_enabled = false;
|
|||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
Serial.println("[UIStateManager] Initialized");
|
Serial.println("[UIStateManager] Initialized");
|
||||||
g_last_synced_screen = NULL;
|
|
||||||
g_debug_enabled = false;
|
g_debug_enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void applySavedStatesToUI() {
|
|
||||||
// Wait for UI widgets to be created
|
|
||||||
if (uic_Toggle_Wifi_Switch == NULL || uic_Toggle_UART_Switch == NULL || uic_Toggle_CAN_Bus_Switch == NULL) {
|
|
||||||
// Reset last synced screen when widgets are NULL (screen unloaded)
|
|
||||||
g_last_synced_screen = NULL;
|
|
||||||
return; // Settings screen not loaded yet
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uic_Main_Container == NULL) {
|
|
||||||
return; // UI not ready
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the Settings screen pointer (parent of Main Container)
|
|
||||||
lv_obj_t* settings_screen = lv_obj_get_parent(uic_Main_Container);
|
|
||||||
if (settings_screen == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if we've already synced this screen instance
|
|
||||||
if (g_last_synced_screen == settings_screen) {
|
|
||||||
return; // Already synced this instance
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.println("Settings screen detected - syncing toggle states with services...");
|
|
||||||
|
|
||||||
// Sync UI with the actual running state of services
|
|
||||||
bool current_wifi_state = WiFiManager::getState() != WiFiManager::WIFI_STATE_OFF;
|
|
||||||
bool current_uart_state = UARTManager::getState() != UARTManager::UART_STATE_OFF;
|
|
||||||
bool current_can_state = CANDriver::isActive();
|
|
||||||
bool current_debug_state = g_debug_enabled;
|
|
||||||
|
|
||||||
lvgl_port_lock(-1);
|
|
||||||
|
|
||||||
// Apply WiFi state
|
|
||||||
if (current_wifi_state) {
|
|
||||||
lv_obj_add_state(uic_Toggle_Wifi_Switch, LV_STATE_CHECKED);
|
|
||||||
} else {
|
|
||||||
lv_obj_clear_state(uic_Toggle_Wifi_Switch, LV_STATE_CHECKED);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply UART state
|
|
||||||
if (current_uart_state) {
|
|
||||||
lv_obj_add_state(uic_Toggle_UART_Switch, LV_STATE_CHECKED);
|
|
||||||
} else {
|
|
||||||
lv_obj_clear_state(uic_Toggle_UART_Switch, LV_STATE_CHECKED);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply CAN Bus state
|
|
||||||
if (current_can_state) {
|
|
||||||
lv_obj_add_state(uic_Toggle_CAN_Bus_Switch, LV_STATE_CHECKED);
|
|
||||||
} else {
|
|
||||||
lv_obj_clear_state(uic_Toggle_CAN_Bus_Switch, LV_STATE_CHECKED);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply Debug state
|
|
||||||
if (uic_Toggle_Debug_Switch != NULL) {
|
|
||||||
if (current_debug_state) {
|
|
||||||
lv_obj_add_state(uic_Toggle_Debug_Switch, LV_STATE_CHECKED);
|
|
||||||
} else {
|
|
||||||
lv_obj_clear_state(uic_Toggle_Debug_Switch, LV_STATE_CHECKED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lvgl_port_unlock();
|
|
||||||
|
|
||||||
// Mark this screen instance as synced
|
|
||||||
g_last_synced_screen = settings_screen;
|
|
||||||
|
|
||||||
Serial.printf("Toggle states synced: WiFi=%s, UART=%s, CAN=%s, Debug=%s\n",
|
|
||||||
current_wifi_state ? "ON" : "OFF",
|
|
||||||
current_uart_state ? "ON" : "OFF",
|
|
||||||
current_can_state ? "ON" : "OFF",
|
|
||||||
current_debug_state ? "ON" : "OFF");
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDebugEnabled(bool enabled) {
|
void setDebugEnabled(bool enabled) {
|
||||||
g_debug_enabled = enabled;
|
g_debug_enabled = enabled;
|
||||||
|
|
||||||
@@ -149,31 +58,4 @@ bool isDebugEnabled() {
|
|||||||
return g_debug_enabled;
|
return g_debug_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// EVENT HANDLERS
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
void onDebugToggle(lv_event_t *e)
|
|
||||||
{
|
|
||||||
lv_obj_t *target = lv_event_get_target(e);
|
|
||||||
|
|
||||||
if (target == NULL) {
|
|
||||||
Serial.println("ERROR: Debug toggle target is NULL!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool state = lv_obj_has_state(target, LV_STATE_CHECKED);
|
|
||||||
|
|
||||||
Serial.printf("===== Debug Toggle Event =====\n");
|
|
||||||
Serial.printf("Debug Mode: %s\n", state ? "ON" : "OFF");
|
|
||||||
|
|
||||||
// Save state to NVS
|
|
||||||
SettingsManager::saveDebugState(state);
|
|
||||||
|
|
||||||
// Update global state and enable/disable monitors
|
|
||||||
setDebugEnabled(state);
|
|
||||||
|
|
||||||
Serial.printf("==============================\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace UIStateManager
|
} // namespace UIStateManager
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* UI State Manager Module
|
* UI State Manager Module
|
||||||
*
|
*
|
||||||
* Handles UI state synchronization:
|
* Holds the debug flag (sent to Controller B, shows LVGL's performance overlay).
|
||||||
* - Syncs toggle switches with actual service states when screens change
|
* The screen-sync logic for the SquareLine Settings screen went with that
|
||||||
* - Handles SquareLine Studio screen lifecycle (destroy/recreate)
|
* screen (2026-09-27): the hand-coded Settings screen reads live state itself.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@@ -25,18 +25,6 @@ namespace UIStateManager {
|
|||||||
*/
|
*/
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Apply saved states to UI switches
|
|
||||||
*
|
|
||||||
* This function is called continuously in loop() to sync UI toggle switches
|
|
||||||
* with the actual running state of services when the Settings screen loads.
|
|
||||||
* It handles the SquareLine Studio screen lifecycle where screens get
|
|
||||||
* destroyed/recreated when swiping between screens.
|
|
||||||
*
|
|
||||||
* @note This function is thread-safe and uses LVGL locks internally
|
|
||||||
*/
|
|
||||||
void applySavedStatesToUI();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enable or disable debug mode (LVGL performance and memory monitors)
|
* @brief Enable or disable debug mode (LVGL performance and memory monitors)
|
||||||
* @param enabled True to enable debug monitors, false to disable
|
* @param enabled True to enable debug monitors, false to disable
|
||||||
@@ -49,15 +37,4 @@ void setDebugEnabled(bool enabled);
|
|||||||
*/
|
*/
|
||||||
bool isDebugEnabled();
|
bool isDebugEnabled();
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// EVENT HANDLERS (Called from SquareLine Studio UI)
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Debug toggle event handler
|
|
||||||
* @param e LVGL event object
|
|
||||||
* @note This function is registered in SquareLine Studio UI
|
|
||||||
*/
|
|
||||||
void onDebugToggle(lv_event_t *e);
|
|
||||||
|
|
||||||
} // namespace UIStateManager
|
} // namespace UIStateManager
|
||||||
|
|||||||
+446
-665
File diff suppressed because it is too large
Load Diff
+53
-122
@@ -1,154 +1,85 @@
|
|||||||
/*
|
/*
|
||||||
* WiFi Manager Module
|
* WiFi Manager Module
|
||||||
*
|
*
|
||||||
* Handles WiFi functionality for the Waveshare ESP32-S3-Touch-LCD-5B:
|
* Joins one remembered network (for OTA updates) and scans on request. Owns no
|
||||||
* - WiFi scanning and network discovery
|
* LVGL objects: the Settings screen polls getStatus()/getNetworks() and calls
|
||||||
* - Connection management with password entry
|
* the request functions, so screen lifetimes can never leave dangling pointers
|
||||||
* - Dynamic SSID button generation
|
* here.
|
||||||
* - FreeRTOS task on Core 0 for async WiFi operations
|
*
|
||||||
* - Thread-safe UI updates via LVGL lock
|
* Radio rules (the ESP-NOW link to Controller B shares the radio):
|
||||||
* - Auto-restore WiFi state from NVS
|
* - the radio stays in STA mode forever; "off" only stops association/scans.
|
||||||
|
* Never WiFi.disconnect(true) / WiFi.mode(WIFI_OFF) - that kills ESP-NOW.
|
||||||
|
* - scans only when asked (each one hops every channel);
|
||||||
|
* - no endless auto-reconnect: one attempt at boot, one after a drop, then
|
||||||
|
* idle on ESPNOW_CHANNEL until the user asks again.
|
||||||
|
*
|
||||||
|
* The network is remembered in NVS (namespace "wifi") after a successful join.
|
||||||
|
* The password is never printed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <lvgl.h>
|
|
||||||
#include <freertos/FreeRTOS.h>
|
|
||||||
#include <freertos/task.h>
|
|
||||||
#include <freertos/queue.h>
|
|
||||||
|
|
||||||
namespace WiFiManager {
|
namespace WiFiManager {
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// CONFIGURATION
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
#define WIFI_SCAN_MAX_NETWORKS 20
|
#define WIFI_SCAN_MAX_NETWORKS 20
|
||||||
#define WIFI_SCAN_INTERVAL_MS 10000 // Rescan every 10 seconds when WiFi is ON
|
#define WIFI_CONNECT_TIMEOUT_MS 15000
|
||||||
#define WIFI_TASK_STACK_SIZE 4096
|
#define WIFI_TASK_STACK_SIZE 4096
|
||||||
#define WIFI_TASK_PRIORITY 1
|
#define WIFI_TASK_PRIORITY 1
|
||||||
#define WIFI_TASK_CORE 0 // Run WiFi task on Core 0 (LVGL runs on Core 1)
|
#define WIFI_TASK_CORE 0
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// PUBLIC TYPES
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief WiFi state machine states
|
|
||||||
*/
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
WIFI_STATE_OFF = 0,
|
LINK_OFF = 0, // Wi-Fi switched off
|
||||||
WIFI_STATE_SCANNING,
|
LINK_IDLE, // on, not connected, not trying
|
||||||
WIFI_STATE_SCAN_COMPLETE,
|
LINK_CONNECTING,
|
||||||
WIFI_STATE_CONNECTED,
|
LINK_CONNECTED,
|
||||||
WIFI_STATE_CONNECTING,
|
LINK_FAILED // last attempt failed; see status_t::error
|
||||||
WIFI_STATE_ERROR
|
} link_t;
|
||||||
} wifi_state_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief WiFi scan result structure
|
|
||||||
*/
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
String ssid;
|
link_t link;
|
||||||
int32_t rssi;
|
char ssid[33]; // network being joined / joined / that failed
|
||||||
wifi_auth_mode_t auth;
|
char ip[16];
|
||||||
} wifi_network_t;
|
int rssi; // dBm, when connected
|
||||||
|
char error[48]; // human-readable reason when LINK_FAILED
|
||||||
|
char saved_ssid[33]; // remembered network ("" = none)
|
||||||
|
bool scanning;
|
||||||
|
uint32_t scan_gen; // bumps each time a scan completes
|
||||||
|
} status_t;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief WiFi connection credentials
|
|
||||||
*/
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char ssid[32];
|
char ssid[33];
|
||||||
char password[64];
|
int8_t rssi;
|
||||||
} wifi_credentials_t;
|
bool secured;
|
||||||
|
} network_t;
|
||||||
|
|
||||||
/**
|
/** Start the Wi-Fi task. If enabled and a network is saved, joins it. */
|
||||||
* @brief WiFi event types for FreeRTOS queue
|
void init(bool enabled);
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
WIFI_UI_EVENT_TOGGLE_ON,
|
|
||||||
WIFI_UI_EVENT_TOGGLE_OFF,
|
|
||||||
WIFI_UI_EVENT_SCAN_START,
|
|
||||||
WIFI_UI_EVENT_SCAN_DONE,
|
|
||||||
WIFI_UI_EVENT_UPDATE_UI,
|
|
||||||
WIFI_UI_EVENT_CONNECT,
|
|
||||||
WIFI_UI_EVENT_DISCONNECT
|
|
||||||
} wifi_ui_event_type_t;
|
|
||||||
|
|
||||||
/**
|
/** Wi-Fi switch: persisted. On joins the saved network; off disconnects. */
|
||||||
* @brief WiFi queue event structure
|
void setEnabled(bool on);
|
||||||
*/
|
bool isEnabled();
|
||||||
typedef struct {
|
|
||||||
wifi_ui_event_type_t type;
|
|
||||||
void* data;
|
|
||||||
} wifi_queue_event_t;
|
|
||||||
|
|
||||||
// ============================================================================
|
/** Scan once (ignored while off or already scanning). */
|
||||||
// PUBLIC API
|
void requestScan();
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
/**
|
/** Join a network; remembered if it works. pass may be NULL/"" for open networks. */
|
||||||
* @brief Initialize the WiFi manager subsystem
|
void connect(const char* ssid, const char* pass);
|
||||||
*
|
|
||||||
* This function:
|
|
||||||
* - Creates FreeRTOS mutex and queue
|
|
||||||
* - Spawns WiFi task on Core 0
|
|
||||||
* - Optionally auto-starts WiFi based on saved state
|
|
||||||
*
|
|
||||||
* @param auto_start If true, automatically start WiFi based on NVS saved state
|
|
||||||
*/
|
|
||||||
void init(bool auto_start);
|
|
||||||
|
|
||||||
/**
|
/** Join the remembered network again. */
|
||||||
* @brief Get current WiFi state
|
void connectSaved();
|
||||||
* @return Current wifi_state_t value
|
|
||||||
*/
|
|
||||||
wifi_state_t getState();
|
|
||||||
|
|
||||||
/**
|
/** Drop the remembered network and disconnect. */
|
||||||
* @brief Get WiFi network count from last scan
|
void forget();
|
||||||
* @return Number of networks found
|
|
||||||
*/
|
|
||||||
uint8_t getNetworkCount();
|
|
||||||
|
|
||||||
// ============================================================================
|
status_t getStatus();
|
||||||
// EVENT HANDLERS (Called from SquareLine Studio UI)
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
/**
|
/** Copy of the last scan (strongest first, one row per SSID). Returns the count. */
|
||||||
* @brief WiFi toggle event handler
|
uint8_t getNetworks(network_t* out, uint8_t max);
|
||||||
* @param e LVGL event object
|
|
||||||
* @note This function is registered in SquareLine Studio UI
|
|
||||||
*/
|
|
||||||
void onWifiToggle(lv_event_t *e);
|
|
||||||
|
|
||||||
/**
|
/** Console: `wifi status | join <ssid> [pass] | forget | on | off`. */
|
||||||
* @brief SSID button click handler
|
bool handleCommand(const char* line);
|
||||||
* @param e LVGL event object
|
|
||||||
* @note Shows password entry for secured networks
|
|
||||||
*/
|
|
||||||
void onSSIDButtonClick(lv_event_t *e);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Keyboard event handler for password entry
|
|
||||||
* @param e LVGL event object
|
|
||||||
* @note Handles READY (connect) and CANCEL events
|
|
||||||
*/
|
|
||||||
void onKeyboardEvent(lv_event_t *e);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Manual rescan request handler
|
|
||||||
* @param e LVGL event object
|
|
||||||
*/
|
|
||||||
void onRescanRequest(lv_event_t *e);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Legacy SquareLine Studio compatibility function
|
|
||||||
* @param e LVGL event object
|
|
||||||
* @note Kept for compatibility, but dynamic buttons handle clicks now
|
|
||||||
*/
|
|
||||||
void onSelectSSID(lv_event_t *e);
|
|
||||||
|
|
||||||
} // namespace WiFiManager
|
} // namespace WiFiManager
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
"""Scan a BMW KWP identifier space via A's `diag bmw` console command.
|
||||||
|
|
||||||
|
Sends one read-only request per identifier value (00..FF), waits for the
|
||||||
|
probe's reply line, and prints a summary of everything that answered
|
||||||
|
positively. Full console stream goes to wiki/raw/diagscan-<timestamp>.log.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
python tools/diag_scan.py COM10 21 # scan `21 xx` (readDataByLocalIdentifier)
|
||||||
|
python tools/diag_scan.py COM10 22D1 # scan `22 D1 xx` (readDataByCommonIdentifier)
|
||||||
|
python tools/diag_scan.py COM10 22D1 40 60 # optional sub-range [0x40..0x60)
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
import serial
|
||||||
|
|
||||||
|
port = sys.argv[1]
|
||||||
|
space = sys.argv[2].upper() # "21" or "22D1"
|
||||||
|
lo = int(sys.argv[3], 16) if len(sys.argv) > 3 else 0x00
|
||||||
|
hi = int(sys.argv[4], 16) if len(sys.argv) > 4 else 0x100
|
||||||
|
|
||||||
|
raw_dir = os.path.join(os.path.dirname(__file__), "..", "wiki", "raw")
|
||||||
|
log_path = os.path.join(raw_dir, time.strftime("diagscan-%%s-%Y%m%d-%H%M%S.log") % space)
|
||||||
|
log = open(log_path, "wb")
|
||||||
|
|
||||||
|
s = serial.Serial(port, 115200, timeout=0.05)
|
||||||
|
print("port open, waiting for boot...")
|
||||||
|
time.sleep(4)
|
||||||
|
s.reset_input_buffer()
|
||||||
|
|
||||||
|
hits = []
|
||||||
|
|
||||||
|
|
||||||
|
def txn(cmd, wait_s=1.5):
|
||||||
|
"""Send one diag command, return the probe's reply lines."""
|
||||||
|
s.write((cmd + "\n").encode())
|
||||||
|
s.flush()
|
||||||
|
log.write(("\n>>> %s\n" % cmd).encode())
|
||||||
|
end = time.time() + wait_s
|
||||||
|
pending = b""
|
||||||
|
replies = []
|
||||||
|
done = False
|
||||||
|
while time.time() < end and not done:
|
||||||
|
chunk = s.read(4096)
|
||||||
|
if not chunk:
|
||||||
|
continue
|
||||||
|
log.write(chunk)
|
||||||
|
pending += chunk
|
||||||
|
while b"\n" in pending:
|
||||||
|
line, pending = pending.split(b"\n", 1)
|
||||||
|
text = line.decode("utf-8", "replace").rstrip()
|
||||||
|
if "[diag]" in text:
|
||||||
|
replies.append(text)
|
||||||
|
if "<- 0x" in text or "no reply within" in text or "refused" in text:
|
||||||
|
done = True
|
||||||
|
return replies
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
txn("diag raw off", wait_s=1.0)
|
||||||
|
for v in range(lo, hi):
|
||||||
|
if space == "21":
|
||||||
|
cmd = "diag bmw 12 21 %02X" % v
|
||||||
|
label = "21 %02X" % v
|
||||||
|
else:
|
||||||
|
cmd = "diag bmw 12 22 %s %02X" % (space[2:], v)
|
||||||
|
label = "22 %s %02X" % (space[2:], v)
|
||||||
|
replies = txn(cmd)
|
||||||
|
got = [r for r in replies if "<- 0x" in r]
|
||||||
|
if not got:
|
||||||
|
replies = txn(cmd) # one retry if the line got mangled
|
||||||
|
got = [r for r in replies if "<- 0x" in r]
|
||||||
|
if not got:
|
||||||
|
print("%s (no reply)" % label)
|
||||||
|
continue
|
||||||
|
r = got[-1]
|
||||||
|
if "7F" in r and "negative" not in r.lower() and "NRC" not in r:
|
||||||
|
pass
|
||||||
|
if re.search(r"7F \d\d [0-9A-F]{2}", r) or "NRC" in r or "negative" in r:
|
||||||
|
# negative response - only note interesting NRCs (not 0x12)
|
||||||
|
if "0x12" not in r and "NRC 0x12" not in r:
|
||||||
|
print("%s NEG: %s" % (label, r))
|
||||||
|
else:
|
||||||
|
print("%s HIT: %s" % (label, r))
|
||||||
|
hits.append((label, replies))
|
||||||
|
time.sleep(0.15)
|
||||||
|
finally:
|
||||||
|
txn("diag raw on", wait_s=1.0)
|
||||||
|
log.close()
|
||||||
|
s.close()
|
||||||
|
print("\n%d positive hits" % len(hits))
|
||||||
|
for label, replies in hits:
|
||||||
|
print("== " + label)
|
||||||
|
for r in replies:
|
||||||
|
print(" " + r)
|
||||||
|
print("log saved: " + os.path.abspath(log_path))
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
"""Run the Route A OBD-II diag probe sequence on Controller A and log everything.
|
||||||
|
|
||||||
|
Opens the port once (one reboot), waits for boot, then sends each diag command
|
||||||
|
with a generous wait, echoing replies and saving the full console stream
|
||||||
|
(CANRAW + CANTX + diag output) to wiki/raw/diag-<timestamp>.log.
|
||||||
|
|
||||||
|
Usage: python tools/diag_session.py COM10 [cmd [cmd ...]]
|
||||||
|
Default sequence: pids, pid 0C, pid 05, pid 0B, pid 70, vin, ecu, status.
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
import serial
|
||||||
|
|
||||||
|
port = sys.argv[1] if len(sys.argv) > 1 else "COM10"
|
||||||
|
cmds = ["diag " + c for c in sys.argv[2:]] if len(sys.argv) > 2 else [
|
||||||
|
"diag pids",
|
||||||
|
"diag pid 0C",
|
||||||
|
"diag pid 05",
|
||||||
|
"diag pid 0B",
|
||||||
|
"diag pid 70",
|
||||||
|
"diag vin",
|
||||||
|
"diag ecu",
|
||||||
|
"diag status",
|
||||||
|
]
|
||||||
|
|
||||||
|
# pids walks up to 8 blocks with 500 ms timeouts each; give it room.
|
||||||
|
WAITS = {"diag pids": 15.0, "diag vin": 6.0, "diag ecu": 6.0}
|
||||||
|
DEFAULT_WAIT = 4.0
|
||||||
|
|
||||||
|
raw_dir = os.path.join(os.path.dirname(__file__), "..", "wiki", "raw")
|
||||||
|
log_path = os.path.join(raw_dir, time.strftime("diag-%Y%m%d-%H%M%S.log"))
|
||||||
|
log = open(log_path, "wb")
|
||||||
|
|
||||||
|
s = serial.Serial(port, 115200, timeout=0.1)
|
||||||
|
print("port open, waiting for boot...")
|
||||||
|
time.sleep(4)
|
||||||
|
|
||||||
|
|
||||||
|
def pump(seconds, echo_all=False):
|
||||||
|
"""Read for `seconds`, log everything, echo non-CANRAW lines."""
|
||||||
|
end = time.time() + seconds
|
||||||
|
pending = b""
|
||||||
|
while time.time() < end:
|
||||||
|
chunk = s.read(4096)
|
||||||
|
if not chunk:
|
||||||
|
continue
|
||||||
|
log.write(chunk)
|
||||||
|
pending += chunk
|
||||||
|
while b"\n" in pending:
|
||||||
|
line, pending = pending.split(b"\n", 1)
|
||||||
|
text = line.decode("utf-8", "replace").rstrip()
|
||||||
|
if echo_all or not text.startswith("CANRAW,"):
|
||||||
|
print(text)
|
||||||
|
log.flush()
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
pump(2) # drain boot output
|
||||||
|
for cmd in cmds:
|
||||||
|
print("\n>>> " + cmd)
|
||||||
|
log.write(("\n>>> %s\n" % cmd).encode())
|
||||||
|
s.write((cmd + "\n").encode())
|
||||||
|
s.flush()
|
||||||
|
pump(WAITS.get(cmd, DEFAULT_WAIT))
|
||||||
|
finally:
|
||||||
|
log.close()
|
||||||
|
s.close()
|
||||||
|
print("\nlog saved: " + os.path.abspath(log_path))
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
"""Capture N seconds from two serial ports in parallel and print what arrived."""
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import threading
|
||||||
|
|
||||||
|
import serial
|
||||||
|
|
||||||
|
PORTS = sys.argv[1].split(",") if len(sys.argv) > 1 else ["COM8", "COM9"]
|
||||||
|
SECONDS = float(sys.argv[2]) if len(sys.argv) > 2 else 6.0
|
||||||
|
MAX_LINES = 40
|
||||||
|
|
||||||
|
|
||||||
|
def cap(port, out):
|
||||||
|
try:
|
||||||
|
s = serial.Serial(port, 115200, timeout=0.5)
|
||||||
|
end = time.time() + SECONDS
|
||||||
|
buf = b""
|
||||||
|
while time.time() < end:
|
||||||
|
buf += s.read(4096)
|
||||||
|
s.close()
|
||||||
|
out[port] = buf
|
||||||
|
except Exception as e:
|
||||||
|
out[port] = ("ERR: %s" % e).encode()
|
||||||
|
|
||||||
|
|
||||||
|
out = {}
|
||||||
|
threads = [threading.Thread(target=cap, args=(p, out)) for p in PORTS]
|
||||||
|
for t in threads:
|
||||||
|
t.start()
|
||||||
|
for t in threads:
|
||||||
|
t.join()
|
||||||
|
|
||||||
|
for p in PORTS:
|
||||||
|
data = out.get(p, b"")
|
||||||
|
print("=" * 20, p, "bytes:", len(data), "=" * 20)
|
||||||
|
lines = data.decode("utf-8", "replace").splitlines()
|
||||||
|
for ln in lines[:MAX_LINES]:
|
||||||
|
print(ln)
|
||||||
|
if len(lines) > MAX_LINES:
|
||||||
|
print("... (%d more lines)" % (len(lines) - MAX_LINES))
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
-----BEGIN PUBLIC KEY-----
|
||||||
|
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE496tys+NeIrdDLNaGHLzr6L4oGmF
|
||||||
|
Y9brIfDTgn8IOWBm8J4nmLUef7zU4ydPM5BKXqUrTshJEpLd74GJIIOtkg==
|
||||||
|
-----END PUBLIC KEY-----
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
"""Send a command line to a serial port and print the reply.
|
||||||
|
|
||||||
|
Usage: python tools/serial_cmd.py COM10 "cfg show" [read_seconds]
|
||||||
|
"""
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
import serial
|
||||||
|
|
||||||
|
port = sys.argv[1]
|
||||||
|
cmd = sys.argv[2]
|
||||||
|
secs = float(sys.argv[3]) if len(sys.argv) > 3 else 3.0
|
||||||
|
|
||||||
|
s = serial.Serial(port, 115200, timeout=0.5)
|
||||||
|
s.reset_input_buffer()
|
||||||
|
s.write((cmd + "\n").encode())
|
||||||
|
s.flush()
|
||||||
|
end = time.time() + secs
|
||||||
|
buf = b""
|
||||||
|
while time.time() < end:
|
||||||
|
buf += s.read(4096)
|
||||||
|
s.close()
|
||||||
|
print(buf.decode("utf-8", "replace"))
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
"""Log one or more serial ports to timestamped files until Ctrl+C.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
python tools/serial_logger.py COM9 # one port
|
||||||
|
python tools/serial_logger.py COM8,COM9 # several ports
|
||||||
|
python tools/serial_logger.py COM9 logs/ # custom output dir (default: wiki/raw/)
|
||||||
|
|
||||||
|
Each port gets its own file, e.g. wiki/raw/serial-COM9-20260922-141503.log.
|
||||||
|
Lines are echoed to the console prefixed with the port name. Read-only:
|
||||||
|
nothing is ever written to the port, so it is safe next to a live bus.
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import threading
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
import serial
|
||||||
|
|
||||||
|
ports = sys.argv[1].split(",") if len(sys.argv) > 1 else ["COM9"]
|
||||||
|
out_dir = sys.argv[2] if len(sys.argv) > 2 else os.path.join("wiki", "raw")
|
||||||
|
os.makedirs(out_dir, exist_ok=True)
|
||||||
|
|
||||||
|
stop = threading.Event()
|
||||||
|
print_lock = threading.Lock()
|
||||||
|
|
||||||
|
|
||||||
|
def log_port(port):
|
||||||
|
stamp = datetime.now().strftime("%Y%m%d-%H%M%S")
|
||||||
|
path = os.path.join(out_dir, "serial-%s-%s.log" % (port, stamp))
|
||||||
|
with print_lock:
|
||||||
|
print("[%s] logging to %s" % (port, path))
|
||||||
|
try:
|
||||||
|
s = serial.Serial(port, 115200, timeout=0.5)
|
||||||
|
except Exception as e:
|
||||||
|
with print_lock:
|
||||||
|
print("[%s] ERROR opening port: %s" % (port, e))
|
||||||
|
return
|
||||||
|
with open(path, "wb") as f:
|
||||||
|
pending = b""
|
||||||
|
while not stop.is_set():
|
||||||
|
data = s.read(4096)
|
||||||
|
if not data:
|
||||||
|
continue
|
||||||
|
f.write(data)
|
||||||
|
f.flush()
|
||||||
|
pending += data
|
||||||
|
while b"\n" in pending:
|
||||||
|
line, pending = pending.split(b"\n", 1)
|
||||||
|
with print_lock:
|
||||||
|
print("[%s] %s" % (port, line.decode("utf-8", "replace").rstrip()))
|
||||||
|
s.close()
|
||||||
|
with print_lock:
|
||||||
|
print("[%s] closed, log saved: %s" % (port, path))
|
||||||
|
|
||||||
|
|
||||||
|
threads = [threading.Thread(target=log_port, args=(p,)) for p in ports]
|
||||||
|
for t in threads:
|
||||||
|
t.start()
|
||||||
|
try:
|
||||||
|
while any(t.is_alive() for t in threads):
|
||||||
|
time.sleep(0.2)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
stop.set()
|
||||||
|
for t in threads:
|
||||||
|
t.join()
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
"""Sweep the tach via A's override: 800 -> 3500 -> 800 rpm, then override off.
|
||||||
|
|
||||||
|
Usage: python tools/tach_ramp.py COM10 [step_rpm] [step_ms]
|
||||||
|
Sends 'cfg override rpm N' lines over A's console; A pushes each as a CONFIG
|
||||||
|
frame to B. Ctrl+C aborts and switches the override off.
|
||||||
|
"""
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
import serial
|
||||||
|
|
||||||
|
port = sys.argv[1] if len(sys.argv) > 1 else "COM10"
|
||||||
|
step = int(sys.argv[2]) if len(sys.argv) > 2 else 50
|
||||||
|
dwell = (int(sys.argv[3]) if len(sys.argv) > 3 else 150) / 1000.0
|
||||||
|
|
||||||
|
s = serial.Serial(port, 115200, timeout=0.1)
|
||||||
|
# Native-USB boards reset when the port opens - give A time to boot.
|
||||||
|
time.sleep(4)
|
||||||
|
s.reset_input_buffer()
|
||||||
|
|
||||||
|
|
||||||
|
def send(cmd):
|
||||||
|
s.write((cmd + "\n").encode())
|
||||||
|
s.flush()
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
points = list(range(800, 3501, step)) + list(range(3500, 799, -step))
|
||||||
|
print("ramp: %d points, %d ms each (~%.0f s total)" % (len(points), dwell * 1000, len(points) * dwell))
|
||||||
|
for rpm in points:
|
||||||
|
send("cfg override rpm %d" % rpm)
|
||||||
|
time.sleep(dwell)
|
||||||
|
finally:
|
||||||
|
send("cfg override off")
|
||||||
|
time.sleep(0.5)
|
||||||
|
s.close()
|
||||||
|
print("done, override off")
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
"""Ramp tach override 800 -> 6000 rpm, hold 5 s, ramp back down, override off.
|
||||||
|
|
||||||
|
Usage: python tools/tach_ramp2.py COM10 [step_rpm] [step_ms]
|
||||||
|
"""
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
import serial
|
||||||
|
|
||||||
|
port = sys.argv[1] if len(sys.argv) > 1 else "COM10"
|
||||||
|
step = int(sys.argv[2]) if len(sys.argv) > 2 else 25
|
||||||
|
dwell = (int(sys.argv[3]) if len(sys.argv) > 3 else 40) / 1000.0
|
||||||
|
|
||||||
|
s = serial.Serial(port, 115200, timeout=0.1)
|
||||||
|
time.sleep(4) # native-USB reset on port open
|
||||||
|
s.reset_input_buffer()
|
||||||
|
|
||||||
|
|
||||||
|
def send(cmd):
|
||||||
|
s.write((cmd + "\n").encode())
|
||||||
|
s.flush()
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
up = list(range(800, 6001, step))
|
||||||
|
down = list(range(6000, 799, -step))
|
||||||
|
print("up %d pts, hold 5 s at 6000, down %d pts" % (len(up), len(down)))
|
||||||
|
for rpm in up:
|
||||||
|
send("cfg override rpm %d" % rpm)
|
||||||
|
time.sleep(dwell)
|
||||||
|
send("cfg override rpm 6000")
|
||||||
|
time.sleep(5)
|
||||||
|
for rpm in down:
|
||||||
|
send("cfg override rpm %d" % rpm)
|
||||||
|
time.sleep(dwell)
|
||||||
|
finally:
|
||||||
|
send("cfg override off")
|
||||||
|
time.sleep(0.5)
|
||||||
|
s.close()
|
||||||
|
print("done, override off")
|
||||||
+9
-3
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
type: index
|
type: index
|
||||||
updated: 2026-09-21
|
updated: 2026-09-27
|
||||||
---
|
---
|
||||||
|
|
||||||
# Index
|
# Index
|
||||||
@@ -9,19 +9,22 @@ Catalog of every page in the wiki. Read this first when answering questions. Kee
|
|||||||
|
|
||||||
## Entities
|
## Entities
|
||||||
|
|
||||||
|
- [[patrol-instrument-cluster]] — **what the Patrol cluster expects on its inputs**: tach = 2 pulses/rev (verified by calibration), temp = NTC sender 2.1–2.9 kΩ cold → ~250 Ω at 90 °C; the 1 kHz PWM needle-flutter problem and the mitigation ladder (fixed-duty test → 20 kHz → hardware damping)
|
||||||
- [[bmw-m57n-engine]] — the 3.0L BMW diesel whose CAN bus we read; E60/E65 donor (confirmed), DDE ECU, auto box with EGS on bus
|
- [[bmw-m57n-engine]] — the 3.0L BMW diesel whose CAN bus we read; E60/E65 donor (confirmed), DDE ECU, auto box with EGS on bus
|
||||||
- [[nissan-patrol-swap]] — the target vehicle: Patrol receiving the M57N + BMW auto; the tapped bus is a BMW island in a Nissan
|
- [[nissan-patrol-swap]] — the target vehicle: Patrol receiving the M57N + BMW auto; the tapped bus is a BMW island in a Nissan
|
||||||
- [[esp32-s3-touch-lcd-5b]] — Waveshare 5" display board (Controller A); onboard TJA1051 CAN transceiver, 7–36 V input, pinout, PSRAM/LCD gotchas
|
- [[esp32-s3-touch-lcd-5b]] — Waveshare 5" display board (Controller A); onboard TJA1051 CAN transceiver, 7–36 V input, pinout, PSRAM/LCD gotchas — **flash writes flicker the RGB panel, full-screen fades stutter, internal RAM nearly full, opening the serial port resets the board unless DTR/RTS are low**
|
||||||
|
|
||||||
## Concepts
|
## Concepts
|
||||||
|
|
||||||
- [[can-bus-integration]] — the core challenge; current firmware ID map flagged as placeholder, verification plan
|
- [[can-bus-integration]] — the core challenge; current firmware ID map flagged as placeholder, verification plan
|
||||||
- [[driveline-speed-signals]] — **engine / turbine / output-shaft speeds**: turbine speed as physical proof of gear engagement, and the output-shaft field that is our **only road-speed source** (no DSC on this bus) — the feedback variable for a future cruise-control PoC, with the safety envelope that would require
|
- [[driveline-speed-signals]] — **engine / turbine / output-shaft speeds**: turbine speed as physical proof of gear engagement, and the output-shaft field that is our **only road-speed source** (no DSC on this bus) — the feedback variable for a future cruise-control PoC, with the safety envelope that would require
|
||||||
- [[dual-controller-architecture]] — Controller A → UART1 + ESP-NOW, protocol v2 → Controller B (1.3" display + Patrol gauge outputs); A owns alerts and the gauge tunables (`cfg` console)
|
- [[dual-controller-architecture]] — Controller A → UART1 + ESP-NOW, protocol v2 → Controller B (1.3" display + Patrol gauge outputs); A owns alerts and the gauge tunables (`cfg` console)
|
||||||
- [[obd-diagnostic-polling]] — **why boost / MAF / rail / injection / DTCs never appear on the sniffer** and how a tester gets them: Route A generic OBD-II mode 01 on `0x7DF` (PID table, `01 00` bitmap as the first test — **implemented as the `diag pids` console probe**), Route B BMW addressing (tester `0x6F1` → DDE replies on `0x612`), DDE6 vs DDE7.3 variants, the capture-with-Launch procedure, and why polling is a transmit-on-the-bus design decision
|
- [[obd-diagnostic-polling]] — **why boost / MAF / rail / injection / DTCs never appear on the sniffer** and how a tester gets them: Route A generic OBD-II mode 01 on `0x7DF` and Route B BMW KWP on `0x6F1` → `0x612` — **BOTH VERIFIED WORKING 2026-09-23** (minimal PID set, no boost PID, mode 09 silent; `1A 86` ident identifies the donor; DTCs read via mode 03), the capture-with-Launch procedure (still wanted for the `22 D1xx` live-data identifiers), and why polling is a transmit-on-the-bus design decision
|
||||||
|
- [[ota-updates]] — **Controller A updates itself from Gitea releases**: tag `v*` → CI builds + signs (ECDSA P-256) → `ota install` (manual, parked, Wi-Fi) pulls over HTTPS from the public repo, verifies, flashes the idle slot, 30 s confirm-or-rollback; **verified end-to-end 2026-09-26 (dev → v0.1.1 → v0.1.2; v0.1.3 published)**, release with `git push --follow-tags origin main`; dual-slot partition table; plan for updating Controller B through A over ESP-NOW
|
||||||
|
|
||||||
## Synthesis
|
## Synthesis
|
||||||
|
|
||||||
|
- [[canny-5-3-pico-gauge-drive]] — **why the CANNY-based setup moves the Patrol needles and our ESP32 doesn't**: CANNY "negative output" = 12 V-domain low-side switch, ESP32 IO7/IO8 = 3.3 V push-pull; the low-side transistor fix, and why it's not firmware PWM polarity
|
||||||
- [[can-id-candidates]] — **the E60/E65 CAN ID map — now decoded end-to-end**: gear (lever + engaged + mode), coolant, gearbox temp (raw−40), battery (12-bit ×0.015), RPM, turbine speed, engine state all verified; placeholder IDs verified absent; fault codes and boost not passively broadcast
|
- [[can-id-candidates]] — **the E60/E65 CAN ID map — now decoded end-to-end**: gear (lever + engaged + mode), coolant, gearbox temp (raw−40), battery (12-bit ×0.015), RPM, turbine speed, engine state all verified; placeholder IDs verified absent; fault codes and boost not passively broadcast
|
||||||
- [[open-questions]] — the research frontier: bench-verify the candidate IDs, operating temp, transient protection, fault-code design decision
|
- [[open-questions]] — the research frontier: bench-verify the candidate IDs, operating temp, transient protection, fault-code design decision
|
||||||
|
|
||||||
@@ -36,4 +39,7 @@ Catalog of every page in the wiki. Read this first when answering questions. Kee
|
|||||||
- [[e65-reverse-engineering-repo]] — **E65 per-ID DBC-style docs (ingested 2026-07-17)** — the highest-value source yet: settled the gearbox-temp offset (raw−40) and battery layout (12-bit ×0.015), proved the engine was running in our capture, and revealed turbine speed, output shaft, pedal position and cruise state
|
- [[e65-reverse-engineering-repo]] — **E65 per-ID DBC-style docs (ingested 2026-07-17)** — the highest-value source yet: settled the gearbox-temp offset (raw−40) and battery layout (12-bit ×0.015), proved the engine was running in our capture, and revealed turbine speed, output shaft, pedal position and cruise state
|
||||||
- [[esp32-s3-touch-lcd-5-intro-photo]] — Waveshare annotated board photo (moved into `raw/` 2026-09-21): terminal-block signal order (VIN/GND/VOUT · SDA/SCL · CAN · RS485 A/B · DO0/DO1 · DI), shared CAN/RS485 120 Ω switch, IO0/IO3/IO4/IO46 strapping pads
|
- [[esp32-s3-touch-lcd-5-intro-photo]] — Waveshare annotated board photo (moved into `raw/` 2026-09-21): terminal-block signal order (VIN/GND/VOUT · SDA/SCL · CAN · RS485 A/B · DO0/DO1 · DI), shared CAN/RS485 120 Ω switch, IO0/IO3/IO4/IO46 strapping pads
|
||||||
- [[google-ai-dde7m57-pids]] — Google AI Mode clipping on "dde7m57 pids" (ingested 2026-09-21, raw in `Clippings/`): uncited; its `0x612`-as-request claim is **contradicted**, its D1xx identifiers are `(unverified)`; kept for the Ediabas value names and the user's own observation that `0x612` appears with the Launch connected
|
- [[google-ai-dde7m57-pids]] — Google AI Mode clipping on "dde7m57 pids" (ingested 2026-09-21, raw in `Clippings/`): uncited; its `0x612`-as-request claim is **contradicted**, its D1xx identifiers are `(unverified)`; kept for the Ediabas value names and the user's own observation that `0x612` appears with the Launch connected
|
||||||
|
- [[diag-route-a-2026-09-23]] — **first live Route A probe run (2026-09-23)**: DDE serves generic OBD mode 01 on `0x7E8` (verified: rpm + coolant cross-checked against the broadcast IDs); supported-PID list; MAF/IAT values implausible (explained by Route B session: sensor faults); mode 09 silent (no VIN); **5 stored DTCs, MIL off**; raw at `raw/diag-20260923-1117*.log`
|
||||||
|
- [[launch-capture-2026-09-23]] — **rail pressure decoded via Launch capture (2026-09-23)**: the DDE serves live data through service `2C` (`2C 10 00 DF` → `6C 10 HHLL`); **rail pressure bar = HHLL × 0.03**, verified two-point against the Launch (idle 305 / 2500 rpm 430); recipe generalises to any Launch-visible value; self-poll needs the session handshake (design decision); raw at `raw/serial-COM10-20260923-163511.log`
|
||||||
|
- [[diag-route-b-2026-09-23]] — **Route B verified + DTCs read (same day)**: `0x6F1 [12]` → `0x612` confirmed live; `1A 86` ident = **VIN prefix WBANC92090 (E60 530d), DDE part numbers 7799764/7799765/7793887, 2006-03, KWP2000 not UDS**; `diag dtc` = P0101/P0113/P0500/P0545/P0030 (all disconnected-sensor swap leftovers); raw at `raw/diag-20260923-124*.log`
|
||||||
- [[dwr-335d-torque-pids]] — **DWR's "Extended BMW 335d PIDs for Torque"** (thread page 1 + `raw/BMW 335d.csv`, ingested 2026-09-21): a gauge-checked set of **generic J1979 mode-01 PIDs** from an M57 diesel (2009 335d, DDE7.3) — boost via PID 70, exhaust pressure, EGTs, MAF, fuel rate; nothing BMW-proprietary. Basis for the "try generic OBD first" route; the diesel-specific PIDs are probably absent on our EDC16
|
- [[dwr-335d-torque-pids]] — **DWR's "Extended BMW 335d PIDs for Torque"** (thread page 1 + `raw/BMW 335d.csv`, ingested 2026-09-21): a gauge-checked set of **generic J1979 mode-01 PIDs** from an M57 diesel (2009 335d, DDE7.3) — boost via PID 70, exhaust pressure, EGTs, MAF, fuel rate; nothing BMW-proprietary. Basis for the "try generic OBD first" route; the diesel-specific PIDs are probably absent on our EDC16
|
||||||
|
|||||||
+85
-21
@@ -1,4 +1,4 @@
|
|||||||
# Log
|
# Log
|
||||||
|
|
||||||
Append-only. `grep "^## \[" log.md | tail -5` for recent activity.
|
Append-only. `grep "^## \[" log.md | tail -5` for recent activity.
|
||||||
|
|
||||||
@@ -8,15 +8,15 @@ Created schema (`CLAUDE.md`), `index.md`, `log.md`, and five seed pages built fr
|
|||||||
|
|
||||||
## [2026-07-15] ingest | Waveshare ESP32-S3-Touch-LCD-5 product wiki
|
## [2026-07-15] ingest | Waveshare ESP32-S3-Touch-LCD-5 product wiki
|
||||||
|
|
||||||
Re-clipped `raw/ESP32-S3-Touch-LCD-5B.md` ingested → [[esp32-s3-touch-lcd-5b-waveshare-wiki]]. Answered two open questions: CAN transceiver is onboard (TJA1051T/3/1J, terminal block, 120 Ω termination switch off by default) and power is solved by the 7–36 V DC wide input (vehicle 12 V direct). New concern raised: operating temp spec is 0–65 °C, marginal for automotive. Updated [[esp32-s3-touch-lcd-5b]] and [[open-questions]]; added schematic PDF to sourcing wishlist.
|
Re-clipped `raw/ESP32-S3-Touch-LCD-5B.md` ingested → [[esp32-s3-touch-lcd-5b-waveshare-wiki]]. Answered two open questions: CAN transceiver is onboard (TJA1051T/3/1J, terminal block, 120 Ω termination switch off by default) and power is solved by the 7–36 V DC wide input (vehicle 12 V direct). New concern raised: operating temp spec is 0–65 °C, marginal for automotive. Updated [[esp32-s3-touch-lcd-5b]] and [[open-questions]]; added schematic PDF to sourcing wishlist.
|
||||||
|
|
||||||
## [2026-07-15] ingest | E60 VFL CAN codes spreadsheet + Listen_and_send_PID Arduino sketch
|
## [2026-07-15] ingest | E60 VFL CAN codes spreadsheet + Listen_and_send_PID Arduino sketch
|
||||||
|
|
||||||
Two raw sources ingested. (1) `E60 VFL CAN-Bus Codes.xlsx` (community table, ~130 ID blocks from a real pre-facelift E60) → [[e60-vfl-can-codes-xlsx]]: independently confirms 0x1D0 coolant raw−48 (0x7A→74 °C) and 0x3B4 battery voltage (leaning 12-bit LE layout, factor ≈0.0147–0.015), adds 0x304 as a 2-byte gear-lever candidate (P=E3/R=C2/N=D1/M=C9, D value suspect), engine-running flag in 0x3B4 byte 3; contains no oil-temp or gearbox-temp rows. (2) `Listen_and_send_PID_009c` (Arduino MCP2515+ELM327, 2013) → [[listen-and-send-pid-arduino]]: transmits E46 cluster frames from OBD PID polling — filed as technique reference for a future diagnostic-request mode; no map changes. [[can-id-candidates]] updated: coolant now "very high" confidence; oil/gearbox temps flagged as weakest signals.
|
Two raw sources ingested. (1) `E60 VFL CAN-Bus Codes.xlsx` (community table, ~130 ID blocks from a real pre-facelift E60) → [[e60-vfl-can-codes-xlsx]]: independently confirms 0x1D0 coolant raw−48 (0x7A→74 °C) and 0x3B4 battery voltage (leaning 12-bit LE layout, factor ≈0.0147–0.015), adds 0x304 as a 2-byte gear-lever candidate (P=E3/R=C2/N=D1/M=C9, D value suspect), engine-running flag in 0x3B4 byte 3; contains no oil-temp or gearbox-temp rows. (2) `Listen_and_send_PID_009c` (Arduino MCP2515+ELM327, 2013) → [[listen-and-send-pid-arduino]]: transmits E46 cluster frames from OBD PID polling — filed as technique reference for a future diagnostic-request mode; no map changes. [[can-id-candidates]] updated: coolant now "very high" confidence; oil/gearbox temps flagged as weakest signals.
|
||||||
|
|
||||||
## [2026-07-15] query | Deep research: E60/E65 CAN IDs for M57N + ZF EGS
|
## [2026-07-15] query | Deep research: E60/E65 CAN IDs for M57N + ZF EGS
|
||||||
|
|
||||||
Deep-research workflow ran (interrupted twice by session task-loss on Windows; ~82 agents total, 95 claims, 30 adversarial verifications completed; synthesis done manually from the journal). Result: [[can-id-candidates]] — coolant/oil temp on **0x1D0** (raw−48, DDE, 100 ms; confirmed live on a real E60), gear on **0x1D2** (EGS, 200 ms, two generation dialects that likely reconcile), gearbox oil temp on **0x0B5** byte 7 (offset disputed 0 vs +40 — bench-critical), battery voltage on **0x3B4** (layout disputed 12-bit×0.015 vs 24-bit×0.001). Fault codes are NOT passively broadcast — require 0x6F1/0x612 diagnostic requests; firmware `fault_codes` field needs a design decision. Firmware's placeholder IDs contradicted by every source. Updated [[can-bus-integration]]; index updated. Cost note: bulk of tokens spent in the initial (pre-interruption) run; resumes replayed from cache.
|
Deep-research workflow ran (interrupted twice by session task-loss on Windows; ~82 agents total, 95 claims, 30 adversarial verifications completed; synthesis done manually from the journal). Result: [[can-id-candidates]] — coolant/oil temp on **0x1D0** (raw−48, DDE, 100 ms; confirmed live on a real E60), gear on **0x1D2** (EGS, 200 ms, two generation dialects that likely reconcile), gearbox oil temp on **0x0B5** byte 7 (offset disputed 0 vs +40 — bench-critical), battery voltage on **0x3B4** (layout disputed 12-bit×0.015 vs 24-bit×0.001). Fault codes are NOT passively broadcast — require 0x6F1/0x612 diagnostic requests; firmware `fault_codes` field needs a design decision. Firmware's placeholder IDs contradicted by every source. Updated [[can-bus-integration]]; index updated. Cost note: bulk of tokens spent in the initial (pre-interruption) run; resumes replayed from cache.
|
||||||
|
|
||||||
## [2026-07-15] update | Donor and target vehicle confirmed by user
|
## [2026-07-15] update | Donor and target vehicle confirmed by user
|
||||||
|
|
||||||
@@ -24,35 +24,35 @@ User confirmed: donor chassis is **E60/E65 (2003+)**, transmission is a **BMW au
|
|||||||
|
|
||||||
## [2026-07-16] ingest | Gear lever fully decoded & VERIFIED (0x1D2)
|
## [2026-07-16] ingest | Gear lever fully decoded & VERIFIED (0x1D2)
|
||||||
|
|
||||||
User captured steady byte values per lever detent (`raw/gear_box_can_revealings.csv`) → [[gear-box-can-revealings]]. **0x1D2 verified as the gear source**: byte0 = P `0xE1` / R `0xD2` / N `0xB4` / D `0x78` (all match documented codes exactly); byte0 can't split D from S/M (shared `0x78`) so byte4 does it (`0xF0` auto / `0xF1` Sport-Manual / `0xF2` downshift −); byte1 is a drive-gate flag (`0x0F`→`0x5F`); byte3 = rolling counter (confirms prediction). 0x0BA also tracks the lever but is messier (D/S-M collide) — don't use. Promoted 0x1D2 gear row to VERIFIED and rewrote the encoding-dispute section in [[can-id-candidates]]; updated index. Still open: actual engaged gear number (needs a drive capture) and the manual up-shift (+) value. Next: rewrite firmware gear map to 0x1D2 byte0 (+byte4).
|
User captured steady byte values per lever detent (`raw/gear_box_can_revealings.csv`) → [[gear-box-can-revealings]]. **0x1D2 verified as the gear source**: byte0 = P `0xE1` / R `0xD2` / N `0xB4` / D `0x78` (all match documented codes exactly); byte0 can't split D from S/M (shared `0x78`) so byte4 does it (`0xF0` auto / `0xF1` Sport-Manual / `0xF2` downshift −); byte1 is a drive-gate flag (`0x0F`→`0x5F`); byte3 = rolling counter (confirms prediction). 0x0BA also tracks the lever but is messier (D/S-M collide) — don't use. Promoted 0x1D2 gear row to VERIFIED and rewrote the encoding-dispute section in [[can-id-candidates]]; updated index. Still open: actual engaged gear number (needs a drive capture) and the manual up-shift (+) value. Next: rewrite firmware gear map to 0x1D2 byte0 (+byte4).
|
||||||
|
|
||||||
## [2026-07-17] update | Driveline screen live; torque decoded; output-shaft scaling revised
|
## [2026-07-17] update | Driveline screen live; torque decoded; output-shaft scaling revised
|
||||||
|
|
||||||
Firmware flashed and running on the car. Built a hand-coded Driveline screen (src/, boot screen, swipe to reach Home) showing gear + coolant + gearbox temp + RPM + torque + turbine + output-shaft + status chips. Three findings from the user testing it: (1) **Torque decoded & verified** — on **0x0A8 TORQ_AVL** (available engine torque; user-identified the ID). User's Excel `(D2*256+D1)/32` is algebraically bits12-23 ×0.5; confirmed against the repo's 0x0A8 worked example (24 Nm, ALIV=8 in D1 low nibble), ~27-28 Nm at idle. Firmware masks D1's low nibble (alive counter, not torque) and sign-extends. Note 0x0AA TORQ_DVCH is the same layout but driver *demand* — identical at idle, diverges under load. → [[can-id-candidates]], [[driveline-speed-signals]]. (2) **Output-shaft scaling revised**: a direct Launch reference (output speed 128 rpm at our raw 1192) **contradicts the earlier ×0.125** (would predict 149) and points to ~0.107. One eyeballed cross-tool point, so not adopted — but 0.125 is downgraded, and the Launch now gives a direct rpm reference so calibration is just a multi-point sweep + linear fit. Firmware keeps raw counts. (3) Fixed a latent display bug: main.cpp showed DEFAULT_* placeholder temps/voltage as if measured; now gated on valid_flags. Ignition decoded from 0x3B4 byte2 (user: 0x00=on/0x09=off, tracks ignition not engine — both published sources wrong here).
|
Firmware flashed and running on the car. Built a hand-coded Driveline screen (src/, boot screen, swipe to reach Home) showing gear + coolant + gearbox temp + RPM + torque + turbine + output-shaft + status chips. Three findings from the user testing it: (1) **Torque decoded & verified** — on **0x0A8 TORQ_AVL** (available engine torque; user-identified the ID). User's Excel `(D2*256+D1)/32` is algebraically bits12-23 ×0.5; confirmed against the repo's 0x0A8 worked example (24 Nm, ALIV=8 in D1 low nibble), ~27-28 Nm at idle. Firmware masks D1's low nibble (alive counter, not torque) and sign-extends. Note 0x0AA TORQ_DVCH is the same layout but driver *demand* — identical at idle, diverges under load. → [[can-id-candidates]], [[driveline-speed-signals]]. (2) **Output-shaft scaling revised**: a direct Launch reference (output speed 128 rpm at our raw 1192) **contradicts the earlier ×0.125** (would predict 149) and points to ~0.107. One eyeballed cross-tool point, so not adopted — but 0.125 is downgraded, and the Launch now gives a direct rpm reference so calibration is just a multi-point sweep + linear fit. Firmware keeps raw counts. (3) Fixed a latent display bug: main.cpp showed DEFAULT_* placeholder temps/voltage as if measured; now gated on valid_flags. Ignition decoded from 0x3B4 byte2 (user: 0x00=on/0x09=off, tracks ignition not engine — both published sources wrong here).
|
||||||
|
|
||||||
## [2026-07-17] ingest | First drive capture — 0x0BA gear ladder verified, output-shaft scaling narrowed
|
## [2026-07-17] ingest | First drive capture — 0x0BA gear ladder verified, output-shaft scaling narrowed
|
||||||
|
|
||||||
`raw/log_20260717_145930.txt` (CANNY 5.3 Pico, 1,857 frames / ~34 s, filtered to 0x0BA + 0x1D2) → [[can-capture-2026-07-17-drive]]. **First capture with the vehicle actually moving.** Closes the inference left open yesterday: **`ST_GR_GRB` values 6/7/8/9/A observed directly** (238/77/93/127/94 frames) = 2nd–6th, so **`0x0BA` D0's low nibble is a complete gear source on its own** — P/R/N + 1st–6th, reverse included; `0x1D2` is now needed only for lever + mode. Also caught `ST_CCLT` (converter lockup) live — 422 frames "controlling" in the higher gears, which matters because a locked clutch makes turbine = engine exactly, so the engagement-ratio test needs to read it before trusting a ratio ≈ 1.0 at road speed. **Output shaft identification VERIFIED** (rises monotonically 1139→16702 across gears 1→6, zero whenever the output is held). **Scaling narrowed to ×0.125** `(unverified)`: implies a coherent 901→1872 rpm upshift schedule across five independent ratios, vs 7,200–15,000 rpm for raw-as-rpm against a ~4,500 redline. User confirmed the box is a **ZF 6HP26X** — same gearset as 6HP26 so the ratio table holds, and the xDrive output variant **dates the donor to E60/E61, not E65** (partly answers open Q#2). New question #11: was the transfer case retained? The X box measures output **upstream** of it, so a Patrol transfer case in the path would make road speed high/low-range dependent. Remaining assumption on the scaling: max-output-per-gear = upshift point — **one capture including `0x1A2` closes it** (turbine ÷ output = ratio directly). Updated [[driveline-speed-signals]], [[gear-box-can-revealings]], [[can-id-candidates]], [[nissan-patrol-swap]], [[open-questions]], index.
|
`raw/log_20260717_145930.txt` (CANNY 5.3 Pico, 1,857 frames / ~34 s, filtered to 0x0BA + 0x1D2) → [[can-capture-2026-07-17-drive]]. **First capture with the vehicle actually moving.** Closes the inference left open yesterday: **`ST_GR_GRB` values 6/7/8/9/A observed directly** (238/77/93/127/94 frames) = 2nd–6th, so **`0x0BA` D0's low nibble is a complete gear source on its own** — P/R/N + 1st–6th, reverse included; `0x1D2` is now needed only for lever + mode. Also caught `ST_CCLT` (converter lockup) live — 422 frames "controlling" in the higher gears, which matters because a locked clutch makes turbine = engine exactly, so the engagement-ratio test needs to read it before trusting a ratio ≈ 1.0 at road speed. **Output shaft identification VERIFIED** (rises monotonically 1139→16702 across gears 1→6, zero whenever the output is held). **Scaling narrowed to ×0.125** `(unverified)`: implies a coherent 901→1872 rpm upshift schedule across five independent ratios, vs 7,200–15,000 rpm for raw-as-rpm against a ~4,500 redline. User confirmed the box is a **ZF 6HP26X** — same gearset as 6HP26 so the ratio table holds, and the xDrive output variant **dates the donor to E60/E61, not E65** (partly answers open Q#2). New question #11: was the transfer case retained? The X box measures output **upstream** of it, so a Patrol transfer case in the path would make road speed high/low-range dependent. Remaining assumption on the scaling: max-output-per-gear = upshift point — **one capture including `0x1A2` closes it** (turbine ÷ output = ratio directly). Updated [[driveline-speed-signals]], [[gear-box-can-revealings]], [[can-id-candidates]], [[nissan-patrol-swap]], [[open-questions]], index.
|
||||||
|
|
||||||
## [2026-07-17] ingest | E65_ReverseEngineering repo — both disputes resolved, driveline speeds discovered
|
## [2026-07-17] ingest | E65_ReverseEngineering repo — both disputes resolved, driveline speeds discovered
|
||||||
|
|
||||||
User pointed at `HeinrichG-V12/E65_ReverseEngineering` (per-ID DBC-style docs, worked example on every page) → [[e65-reverse-engineering-repo]]. Highest-value source to date; combined with re-analysis of our own `raw/can-capture-2026-07-15-gearshift.csv` it closed most of the frontier. **Resolved**: gearbox oil temp = **raw − 40** (source example + our own gearbox-31 °C-vs-coolant-37 °C warm-up cross-check; my earlier "leaning offset 0" was wrong); battery = **12-bit LE × 0.015**; engine **was running** in the 2026-07-15 capture (`ST_ENGINE_RUN`=2 in 397/397) — **cold-start capture no longer needed**; RPM = `0x0AA` ×0.25 (679–684 idle). **Discovered**: `0x1A2` `RPM_GRB_TURB` turbine speed — a *physical* engagement proof (P/N ≈634/628 free-spinning vs D ≈70, R ≈0 stalled — textbook converter behaviour), plus `0x0BA` bits 20–39 output shaft (undocumented anywhere; zero in every stationary frame incl. engaged-in-D, non-zero once wheels turn), plus `ANG_ACPD` pedal % and `ST_CLCTR_V` cruise state. New page [[driveline-speed-signals]] — emphasized per user: **no DSC on this bus ⇒ output shaft is our only road-speed source**, hence the feedback variable for a future cruise-control PoC (safety envelope documented; actuation = transmitting torque requests, a different risk class from everything read-only so far). **Corrected three of my own 2026-07-16 claims**: `0x1D2` D1 is the *engaged gear* (not a "drive-gate flag" — it read 1 because the car was stationary); D4 `0xF2` is a persistent *Manual mode* (not a "downshift event" — it holds across gears 2–6); `0x0BA` is **not** to be dismissed (I'd read D7, an alive counter, instead of D0's `ST_GR_GRB` — which is the only source of engaged **reverse**, `0x1D2` D1 staying `0x0F` in R). Also: boost is **not** broadcast (`AIP_ENG` caps at 1108 hPa = barometric) — confirms the Launch must poll. Updated [[can-id-candidates]], [[gear-box-can-revealings]], [[open-questions]], index. Next: firmware pass over the whole verified map.
|
User pointed at `HeinrichG-V12/E65_ReverseEngineering` (per-ID DBC-style docs, worked example on every page) → [[e65-reverse-engineering-repo]]. Highest-value source to date; combined with re-analysis of our own `raw/can-capture-2026-07-15-gearshift.csv` it closed most of the frontier. **Resolved**: gearbox oil temp = **raw − 40** (source example + our own gearbox-31 °C-vs-coolant-37 °C warm-up cross-check; my earlier "leaning offset 0" was wrong); battery = **12-bit LE × 0.015**; engine **was running** in the 2026-07-15 capture (`ST_ENGINE_RUN`=2 in 397/397) — **cold-start capture no longer needed**; RPM = `0x0AA` ×0.25 (679–684 idle). **Discovered**: `0x1A2` `RPM_GRB_TURB` turbine speed — a *physical* engagement proof (P/N ≈634/628 free-spinning vs D ≈70, R ≈0 stalled — textbook converter behaviour), plus `0x0BA` bits 20–39 output shaft (undocumented anywhere; zero in every stationary frame incl. engaged-in-D, non-zero once wheels turn), plus `ANG_ACPD` pedal % and `ST_CLCTR_V` cruise state. New page [[driveline-speed-signals]] — emphasized per user: **no DSC on this bus ⇒ output shaft is our only road-speed source**, hence the feedback variable for a future cruise-control PoC (safety envelope documented; actuation = transmitting torque requests, a different risk class from everything read-only so far). **Corrected three of my own 2026-07-16 claims**: `0x1D2` D1 is the *engaged gear* (not a "drive-gate flag" — it read 1 because the car was stationary); D4 `0xF2` is a persistent *Manual mode* (not a "downshift event" — it holds across gears 2–6); `0x0BA` is **not** to be dismissed (I'd read D7, an alive counter, instead of D0's `ST_GR_GRB` — which is the only source of engaged **reverse**, `0x1D2` D1 staying `0x0F` in R). Also: boost is **not** broadcast (`AIP_ENG` caps at 1108 hPa = barometric) — confirms the Launch must poll. Updated [[can-id-candidates]], [[gear-box-can-revealings]], [[open-questions]], index. Next: firmware pass over the whole verified map.
|
||||||
|
|
||||||
## [2026-07-16] ingest | First live CAN capture — research map CONFIRMED
|
## [2026-07-16] ingest | First live CAN capture — research map CONFIRMED
|
||||||
|
|
||||||
First real dump off the swap's bus, taken with the board's **own new raw-frame logger** (`(repo)`; USB-CDC stream, serial mutex, ~486 frame/s, ~1.4% line loss). Raw filed at `raw/can-capture-2026-07-15-gearshift.csv` (20,596 frames) → [[can-capture-2026-07-15]]. Findings: 15 IDs live incl. **all four researched signal IDs** (0x1D0, 0x1D2, 0x0B5, 0x3B4) + bonus 0x0AA/0x0BA; firmware's placeholder IDs (0x4F/0x55/0x201/0x1001/0x101F) **verified absent**; researched-but-absent: 0x130/0x304/0x192. **0x1D0 b0** drifts 0x55→0x58 (coolant −48, ~37→40 °C); **0x1D0 b1 = 0xFF** (oil temp unpopulated). **0x1D2 gear encoding resolved**: DLC 6, byte0 whole-byte codes (0xE1=P, 0xB4=N, 0x78=D seen live). **0x3B4** at ~5 s rate but payload dormant (0xFF) — engine state unconfirmed. Updated [[can-id-candidates]], [[can-bus-integration]], [[esp32-s3-touch-lcd-5b]], [[open-questions]], index. Also corrected a firmware fact across pages: driver runs **`TWAI_MODE_NORMAL` (ACKs the bus), not LISTEN_ONLY**; TJA1051 is non-isolated → must share vehicle ground. Next: cold-start + confirmed-engine-running capture to lock coolant/battery scaling; use differential (per-position) captures for gear.
|
First real dump off the swap's bus, taken with the board's **own new raw-frame logger** (`(repo)`; USB-CDC stream, serial mutex, ~486 frame/s, ~1.4% line loss). Raw filed at `raw/can-capture-2026-07-15-gearshift.csv` (20,596 frames) → [[can-capture-2026-07-15]]. Findings: 15 IDs live incl. **all four researched signal IDs** (0x1D0, 0x1D2, 0x0B5, 0x3B4) + bonus 0x0AA/0x0BA; firmware's placeholder IDs (0x4F/0x55/0x201/0x1001/0x101F) **verified absent**; researched-but-absent: 0x130/0x304/0x192. **0x1D0 b0** drifts 0x55→0x58 (coolant −48, ~37→40 °C); **0x1D0 b1 = 0xFF** (oil temp unpopulated). **0x1D2 gear encoding resolved**: DLC 6, byte0 whole-byte codes (0xE1=P, 0xB4=N, 0x78=D seen live). **0x3B4** at ~5 s rate but payload dormant (0xFF) — engine state unconfirmed. Updated [[can-id-candidates]], [[can-bus-integration]], [[esp32-s3-touch-lcd-5b]], [[open-questions]], index. Also corrected a firmware fact across pages: driver runs **`TWAI_MODE_NORMAL` (ACKs the bus), not LISTEN_ONLY**; TJA1051 is non-isolated → must share vehicle ground. Next: cold-start + confirmed-engine-running capture to lock coolant/battery scaling; use differential (per-position) captures for gear.
|
||||||
|
|
||||||
## [2026-09-21] update | .docs folder retired; UART spec moved to docs/; board photo ingested
|
## [2026-09-21] update | .docs folder retired; UART spec moved to docs/; board photo ingested
|
||||||
|
|
||||||
The repo's `.docs/` folder was deleted (user decision). `CAN_BUS_INTEGRATION.md` documented the dead placeholder IDs and an external transceiver the board does not need — superseded by [[can-id-candidates]] and [[can-bus-integration]]. `UART_PROTOCOL.md` (the packet spec, shared with Controller B) moved to `docs/UART_PROTOCOL.md` as the single copy; Controller B's duplicate was removed. The annotated board photo moved to `raw/` → [[esp32-s3-touch-lcd-5-intro-photo]]: confirms the terminal-block order, that GPIO 44 exits only as the RS485 A/B pair, and that one 120 Ω switch serves both CAN and RS485. Root `CLAUDE.md` corrected: verified CAN ID list replaces the placeholders, `TWAI_MODE_NORMAL` replaces "LISTEN_ONLY", UART TX is GPIO 44 (was written as 43), dummy-data references removed.
|
The repo's `.docs/` folder was deleted (user decision). `CAN_BUS_INTEGRATION.md` documented the dead placeholder IDs and an external transceiver the board does not need — superseded by [[can-id-candidates]] and [[can-bus-integration]]. `UART_PROTOCOL.md` (the packet spec, shared with Controller B) moved to `docs/UART_PROTOCOL.md` as the single copy; Controller B's duplicate was removed. The annotated board photo moved to `raw/` → [[esp32-s3-touch-lcd-5-intro-photo]]: confirms the terminal-block order, that GPIO 44 exits only as the RS485 A/B pair, and that one 120 Ω switch serves both CAN and RS485. Root `CLAUDE.md` corrected: verified CAN ID list replaces the placeholders, `TWAI_MODE_NORMAL` replaces "LISTEN_ONLY", UART TX is GPIO 44 (was written as 43), dummy-data references removed.
|
||||||
|
|
||||||
**Missing source**: the schematic PDF (`ESP32-S3-Touch-LCD-5-Sch.pdf`) was in `.docs/` at the start of the 2026-09-21 session and was not on disk by the time of this cleanup (never git-tracked). Its net list was read earlier that session and is reflected in [[esp32-s3-touch-lcd-5b]]; re-download it into `raw/` — still on the sourcing wishlist in [[open-questions]].
|
**Missing source**: the schematic PDF (`ESP32-S3-Touch-LCD-5-Sch.pdf`) was in `.docs/` at the start of the 2026-09-21 session and was not on disk by the time of this cleanup (never git-tracked). Its net list was read earlier that session and is reflected in [[esp32-s3-touch-lcd-5b]]; re-download it into `raw/` — still on the sourcing wishlist in [[open-questions]].
|
||||||
|
|
||||||
Sibling wiki instantiated today at `../../ESP32-S3-LCD-1.3/wiki/` for Controller B (link, redundancy, gauge outputs). Cross-references from there use the text form `(sibling: 5B wiki → page)`.
|
Sibling wiki instantiated today at `../../ESP32-S3-LCD-1.3/wiki/` for Controller B (link, redundancy, gauge outputs). Cross-references from there use the text form `(sibling: 5B wiki → page)`.
|
||||||
|
|
||||||
## [2026-09-21] update | Link protocol v2: ESP-NOW second transport, gear/rpm/alerts on the wire, tunables console
|
## [2026-09-21] update | Link protocol v2: ESP-NOW second transport, gear/rpm/alerts on the wire, tunables console
|
||||||
|
|
||||||
Firmware (not yet committed): shared header v2 with typed DATA/CONFIG frames; `Tunables` module (gauge calibration + alert thresholds in NVS, `cfg show|set|override|reset` on the USB console); `EspNowLink` broadcasts every frame alongside UART1 (radio now stays in STA mode — WiFiManager's off no longer calls `WIFI_OFF`); CAN driver publishes lever + target/engaged gear nibbles and rpm, and evaluates coolant/gearbox/battery/cooling-demand alerts against the tunables. Bench-verified with Controller B: both transports alive, every frame deduplicated, `cfg override rpm 2000` drove B's tach output at 133.3 Hz. `docs/UART_PROTOCOL.md` rewritten for v2. [[dual-controller-architecture]] and index updated. Build note: IDF 5.5's ESP-NOW send callback takes `wifi_tx_info_t*`; and the two repos must not be built concurrently (shared penv).
|
Firmware (not yet committed): shared header v2 with typed DATA/CONFIG frames; `Tunables` module (gauge calibration + alert thresholds in NVS, `cfg show|set|override|reset` on the USB console); `EspNowLink` broadcasts every frame alongside UART1 (radio now stays in STA mode — WiFiManager's off no longer calls `WIFI_OFF`); CAN driver publishes lever + target/engaged gear nibbles and rpm, and evaluates coolant/gearbox/battery/cooling-demand alerts against the tunables. Bench-verified with Controller B: both transports alive, every frame deduplicated, `cfg override rpm 2000` drove B's tach output at 133.3 Hz. `docs/UART_PROTOCOL.md` rewritten for v2. [[dual-controller-architecture]] and index updated. Build note: IDF 5.5's ESP-NOW send callback takes `wifi_tx_info_t*`; and the two repos must not be built concurrently (shared penv).
|
||||||
|
|
||||||
## [2026-09-21] update | Gauge Tuning screen
|
## [2026-09-21] update | Gauge Tuning screen
|
||||||
|
|
||||||
@@ -62,14 +62,78 @@ New hand-coded screen `src/modules/tuning_screen.cpp` (swipe right from Drivelin
|
|||||||
|
|
||||||
User decision: the Home screen (three arc meters + battery) is not needed. Deleted `include/ui/screens/ui_Home_Screen.c/h`, its four image assets and `src/modules/meters_manager.*`; `ui_init()` now loads an empty placeholder and `display_init.cpp` shows the hand-coded Driveline screen; the generated Settings screen's right-swipe calls a new C entry point `app_show_driveline()`; Driveline swipes left to Settings and right to Gauge Tuning; Tuning swipes left back. Firmware flash shrank ~100 KB. If SquareLine re-exports a Home screen it must be deleted from the SquareLine project, not wired back in. Built and flashed.
|
User decision: the Home screen (three arc meters + battery) is not needed. Deleted `include/ui/screens/ui_Home_Screen.c/h`, its four image assets and `src/modules/meters_manager.*`; `ui_init()` now loads an empty placeholder and `display_init.cpp` shows the hand-coded Driveline screen; the generated Settings screen's right-swipe calls a new C entry point `app_show_driveline()`; Driveline swipes left to Settings and right to Gauge Tuning; Tuning swipes left back. Firmware flash shrank ~100 KB. If SquareLine re-exports a Home screen it must be deleted from the SquareLine project, not wired back in. Built and flashed.
|
||||||
|
|
||||||
## [2026-09-21] ingest | Google AI clipping "dde7m57 pids" — diagnostic-polling page created, 0x612 direction corrected
|
## [2026-09-21] ingest | Google AI clipping "dde7m57 pids" — diagnostic-polling page created, 0x612 direction corrected
|
||||||
|
|
||||||
User clipped a Google AI Mode conversation into `Clippings/` (Obsidian Web Clipper default folder; schema updated to treat it like `raw/`) → [[google-ai-dde7m57-pids]]. Uncited generative summary, filed `(unverified)` throughout. Two things of value: the Ediabas result names for boost/rail/MAF/injection, and the user's own observation embedded in it — **`0x612` appears on the tapped bus while the Launch is connected**, proving diagnostic traffic reaches our tap. The clipping calls `0x612` the *tester request* and `0x6F2` the reply; that contradicts dieslg8 (real M57 code) and the BMW `0x6F1` → `0x600+address` convention — flagged, and the wiki keeps **tester `0x6F1` → DDE `0x612`** until our own capture shows the pair. Its `22 D1 xx` identifiers are uncited and must not be implemented from. Created the long-dangling [[obd-diagnostic-polling]] page (broadcast vs polled, addressing table, DDE6 vs DDE7.3 variant table, capture-with-Launch procedure, firmware implications: polling = transmitting on PT-CAN, a design decision). Side finding: the search term "dde7 m57" describes DDE7.3/EDC17CP09 on the later M57N2 (E90/E70); our E60/E61 donor with a 6HP26X should carry a DDE6/EDC16 — the Launch's ECU-identification page closes [[open-questions]] #2 in one screen. Updated [[bmw-m57n-engine]] (E60/E61, 6HP26X, stale firmware-placeholder warning removed), [[open-questions]] #2/#7 + wishlist, index.
|
User clipped a Google AI Mode conversation into `Clippings/` (Obsidian Web Clipper default folder; schema updated to treat it like `raw/`) → [[google-ai-dde7m57-pids]]. Uncited generative summary, filed `(unverified)` throughout. Two things of value: the Ediabas result names for boost/rail/MAF/injection, and the user's own observation embedded in it — **`0x612` appears on the tapped bus while the Launch is connected**, proving diagnostic traffic reaches our tap. The clipping calls `0x612` the *tester request* and `0x6F2` the reply; that contradicts dieslg8 (real M57 code) and the BMW `0x6F1` → `0x600+address` convention — flagged, and the wiki keeps **tester `0x6F1` → DDE `0x612`** until our own capture shows the pair. Its `22 D1 xx` identifiers are uncited and must not be implemented from. Created the long-dangling [[obd-diagnostic-polling]] page (broadcast vs polled, addressing table, DDE6 vs DDE7.3 variant table, capture-with-Launch procedure, firmware implications: polling = transmitting on PT-CAN, a design decision). Side finding: the search term "dde7 m57" describes DDE7.3/EDC17CP09 on the later M57N2 (E90/E70); our E60/E61 donor with a 6HP26X should carry a DDE6/EDC16 — the Launch's ECU-identification page closes [[open-questions]] #2 in one screen. Updated [[bmw-m57n-engine]] (E60/E61, 6HP26X, stale firmware-placeholder warning removed), [[open-questions]] #2/#7 + wishlist, index.
|
||||||
|
|
||||||
## [2026-09-21] ingest | DWR's 335d Torque PID set — generic OBD-II route documented
|
## [2026-09-21] ingest | DWR's 335d Torque PID set — generic OBD-II route documented
|
||||||
|
|
||||||
User dropped `raw/BMW 335d.csv` and clipped page 1 of the e90post/6post thread "Extended BMW 335d PIDs for Torque" (DWR, 2009 335d = M57N2 on DDE7.3/EDC17CP09) → [[dwr-335d-torque-pids]]. **Every entry is a generic SAE J1979 mode-01 PID** (DWR says so in post 21; header `Auto` = `0x7DF`); nothing BMW-proprietary, nothing broadcast. Two revisions compared: the CSV in `raw/` is the corrected 2017 one (boost ×0.3125 = the J1979 0.03125 kPa/bit; fuel rate ×0.0938 lb/hr; post-#2's ×0.296 and ×5.64 were wrong); residual typos noted (`000031` for 0.0000305, one `+33`). Decoded his table back to SI with the J1979 byte positions. Consequence for us: the generic route is the **cheapest polling experiment** — one `01 00` supported-PID query on `0x7DF` tells whether our DDE answers EOBD on the PT-CAN and which PIDs it has — but the diesel-specific PIDs he relies on for boost (`70`), exhaust pressure (`73`), EGT (`78`), DPF (`7A`), NOx (`83`) are 2007+ J1979 additions an EDC16 almost certainly lacks `(unverified)`, and PID `0B` clips at 255 kPa. [[obd-diagnostic-polling]] restructured into Route A (generic, PID table, first test) and Route B (BMW `0x6F1`/`0x612`). Wishlist: DWR's Testo parameter list (post 175 of the Testo thread). Updated [[open-questions]] #7 + wishlist, index.
|
User dropped `raw/BMW 335d.csv` and clipped page 1 of the e90post/6post thread "Extended BMW 335d PIDs for Torque" (DWR, 2009 335d = M57N2 on DDE7.3/EDC17CP09) → [[dwr-335d-torque-pids]]. **Every entry is a generic SAE J1979 mode-01 PID** (DWR says so in post 21; header `Auto` = `0x7DF`); nothing BMW-proprietary, nothing broadcast. Two revisions compared: the CSV in `raw/` is the corrected 2017 one (boost ×0.3125 = the J1979 0.03125 kPa/bit; fuel rate ×0.0938 lb/hr; post-#2's ×0.296 and ×5.64 were wrong); residual typos noted (`000031` for 0.0000305, one `+33`). Decoded his table back to SI with the J1979 byte positions. Consequence for us: the generic route is the **cheapest polling experiment** — one `01 00` supported-PID query on `0x7DF` tells whether our DDE answers EOBD on the PT-CAN and which PIDs it has — but the diesel-specific PIDs he relies on for boost (`70`), exhaust pressure (`73`), EGT (`78`), DPF (`7A`), NOx (`83`) are 2007+ J1979 additions an EDC16 almost certainly lacks `(unverified)`, and PID `0B` clips at 255 kPa. [[obd-diagnostic-polling]] restructured into Route A (generic, PID table, first test) and Route B (BMW `0x6F1`/`0x612`). Wishlist: DWR's Testo parameter list (post 175 of the Testo thread). Updated [[open-questions]] #7 + wishlist, index.
|
||||||
|
|
||||||
## [2026-09-21] update | `diag` console probe: Controller A can now send OBD-II requests
|
## [2026-09-21] update | `diag` console probe: Controller A can now send OBD-II requests
|
||||||
|
|
||||||
User decision: build the Route A probe. New module `src/modules/diag_probe.cpp` and a single sanctioned transmit function `CANDriver::transmit()` (single-shot frames, `CANTX,` console echo mirroring `CANRAW,`). Console: `diag pids` (mode-01 supported-PID bitmap scan, blocks 00/20/40…, per-responder summary with PID names), `diag pid <hex>` (one request, decoded for the Route A table incl. PID 70 boost and 78 EGT), `diag vin`, `diag ecu` (mode 09), `diag status`. ISO-TP single/first/consecutive frames reassembled with a `30 00 00` flow control to the responder's physical ID. Guards: one request in flight, refused for 3 s after any foreign tester frame (`0x7DF`/`0x7E0–7`/`0x6F1`), services 01 and 09 only. Console dispatch chained through `Tunables::setExtraCommandHandler()`. Built (1.49 MB) and flashed to COM11; bench check with no bus attached: `diag pids` sent `02 01 00` on `0x7DF`, the TWAI controller reported the single-shot frame un-ACKed, and the probe reported "not ACKed - no other node saw it" rather than blaming the ECU (the summary distinguishes un-ACKed from ACKed-but-silent). CAN-task warnings now take the serial lock so they no longer splice into `CANTX` lines. The wiki's "firmware never transmits" statements are now qualified on [[can-bus-integration]] and [[obd-diagnostic-polling]] (test-day procedure and the three possible outcomes written there). Root `CLAUDE.md` and `docs/UART_PROTOCOL.md` console section updated. Procedure rewritten as numbered steps with all four outcomes (un-ACKed / ACKed-silent / one responder / two responders) and the log-capture command.
|
User decision: build the Route A probe. New module `src/modules/diag_probe.cpp` and a single sanctioned transmit function `CANDriver::transmit()` (single-shot frames, `CANTX,` console echo mirroring `CANRAW,`). Console: `diag pids` (mode-01 supported-PID bitmap scan, blocks 00/20/40…, per-responder summary with PID names), `diag pid <hex>` (one request, decoded for the Route A table incl. PID 70 boost and 78 EGT), `diag vin`, `diag ecu` (mode 09), `diag status`. ISO-TP single/first/consecutive frames reassembled with a `30 00 00` flow control to the responder's physical ID. Guards: one request in flight, refused for 3 s after any foreign tester frame (`0x7DF`/`0x7E0–7`/`0x6F1`), services 01 and 09 only. Console dispatch chained through `Tunables::setExtraCommandHandler()`. Built (1.49 MB) and flashed to COM11; bench check with no bus attached: `diag pids` sent `02 01 00` on `0x7DF`, the TWAI controller reported the single-shot frame un-ACKed, and the probe reported "not ACKed - no other node saw it" rather than blaming the ECU (the summary distinguishes un-ACKed from ACKed-but-silent). CAN-task warnings now take the serial lock so they no longer splice into `CANTX` lines. The wiki's "firmware never transmits" statements are now qualified on [[can-bus-integration]] and [[obd-diagnostic-polling]] (test-day procedure and the three possible outcomes written there). Root `CLAUDE.md` and `docs/UART_PROTOCOL.md` console section updated. Procedure rewritten as numbered steps with all four outcomes (un-ACKed / ACKed-silent / one responder / two responders) and the log-capture command.
|
||||||
|
|
||||||
|
## [2026-09-22] query | CANNY 5.3 pico vs ESP32 gauge drive - tach dead / temp frozen explained
|
||||||
|
|
||||||
|
First in-car test of the dual-controller rig: A reads the bus fine, B receives fine, but the Patrol tach never moves and the temp needle parks mid-scale ignoring the override slider. User disclosed the known-good reference: the same cluster works from a CANNY 5.3 pico using "Default Negative Output" (DIO mode, ch 7). Researched the CANNY docs (cannylogic.com/canny.ru): its channels are 12V-domain configurable-polarity switches - "negative output" = low-side sink to GND, letting the cluster's internal pull-up define the ~12V high level. Our ESP32 IO7/IO8 push-pull 3.3V output can't reach the tach's input threshold and biases the temp sender line to a fixed level. Not a firmware PWM polarity issue (50% square is its own inverse). Fix: logic-level N-MOSFET/NPN low-side stage per channel, temp duty law re-derived after (logic inverts). Filed [[canny-5-3-pico-gauge-drive]]; user corrected the channel to 8 (contact 4, the HR-PWM-capable one), matching the 5.3 pico docs. Index updated.
|
||||||
|
|
||||||
|
## [2026-09-22] query | Patrol cluster signal research - tach 2 ppr verified, temp sender curve, flutter plan
|
||||||
|
|
||||||
|
First day driving the real cluster from Controller B through the 2SK3069 low-side stage. Tach: needle tracked at double with ppr=4; user set ppr=2 -> tracks correctly (verified). 2 ppr matches an ECU-driven 4-cyl-style tach input (ZD30-era Y61 hint, unverified) rather than the TD42 alternator-W-terminal scheme. Temp gauge on IO8: needle flutters at temp_pwm_hz=1 kHz. Researched: stock Patrol sender is an NTC (2.1-2.9k @ 20C, 0.68-1k @ 50C, 236-260R @ 90C; patrol4x4/sensorgal), gauge is current-measuring; community PWM-gauge experience says flutter dies at ~40-50 kHz. Mitigation ladder filed: fixed-duty override test (data vs electrical), cfg set temp_hz 20000 (firmware clamp), then raise clamp / series drain resistor (~100-240R, also bounds full-on beyond-hot short) / gauge-side cap. Temp law must be re-derived after (FET inverts duty sense). Filed [[patrol-instrument-cluster]]; index updated. Earlier same day: [[canny-5-3-pico-gauge-drive]] hypothesis effectively confirmed by the needles moving through the FET; gauge-output disable bits found off during bench test (B console "disabled") - re-enabled via tuning screen.
|
||||||
|
|
||||||
|
## [2026-09-22] update | Temp gauge flutter resolved: temp_hz 1 kHz -> 20 kHz
|
||||||
|
|
||||||
|
User raised temp_pwm_hz to 20000 via the tuning screen; needle now steady at fixed override duty (verified). A confusing intermediate "gauge dead at 20 kHz" turned out to be a disconnected car-ground during rewiring - grounds first, then debug. [[patrol-instrument-cluster]] updated (flutter section marked resolved; drain series resistor kept as optional hardening). Remaining gauge work: re-derive temp_slope/temp_offset against the real needle through the FET stage (duty sense inverted vs the old direct-drive law).
|
||||||
|
|
||||||
|
## [2026-09-23] update | Tach steppy-needle saga resolved; trim -13; temp gauge stable
|
||||||
|
|
||||||
|
Full day of override-ramp experiments (ignition on, engine off; tools/tach_ramp.py + tach_ramp2.py drive A over serial). Four-layer diagnosis on B, all firmware in the 1.3 repo: (1) 5 Hz staircase -> slew limiter; (2) Arduino ledcChangeFrequency() re-inits the timer mid-period -> replaced LEDC with esp_timer toggle; (3) esp_timer task jitter from WiFi bursts -> hardware-timer ISR, phase-continuous; (4) the floor: the cluster counts pulses in ~150 rpm quanta (alternating +100/+200 needle steps on a clean ramp) -> random dither +/-45 rpm with an adaptive envelope that fades at steady rpm. Scale: cluster over-reads x1.20 low / x1.15 high (nonlinear); user settled tach_trim = -13%. Also found mid-session: user trim change via touchscreen had never registered (B stayed on cfg v99) - config state now verified over serial before every test. [[patrol-instrument-cluster]] rewritten with the saga; new tools: serial_logger.py, serial_cmd.py, tach_ramp*.py, dual_serial_capture.py. Status: RPM and temp gauges "fairly good", tach dither constants may get a future pass.
|
||||||
|
|
||||||
|
## [2026-09-23] ingest | Route A OBD probe - first live run: the DDE answers
|
||||||
|
|
||||||
|
The deferred test-day mission finally executed. `tools/diag_session.py` (new: one serial session, full console log into `wiki/raw/`) ran the `diag` sequence with the engine idling, Launch unplugged. Result: **Route A verified** - the DDE serves generic OBD-II mode 01 on `0x7E8`. Supported PIDs `01,04,05,0B,0C,0D,0F,10,1C,20,21`; rpm and coolant cross-checked live against the broadcast IDs (681 rpm / 64 C, matching). Boost PID `70` absent, mode 09 (VIN/ECU name) silent, MAF/IAT scalings implausible under J1979 (flagged unverified). PID 01: MIL off, **5 stored DTCs** - reading them needs mode 03 (probe extension or Launch). Probe counters clean: 15 req / 12 replies / 3 timeouts / 0 tx failures, no retry storms. Wrote sources/diag-route-a-2026-09-23.md; updated obd-diagnostic-polling (Route A section), open-questions #2 (OBD cannot identify the donor; EDC16 hints) and #7 (DTC path now concrete); raw logs diag-20260923-111737.log + diag-20260923-111851.log.
|
||||||
|
|
||||||
|
## [2026-09-23] ingest | Route B verified, DTCs read, donor identified (E60 530d)
|
||||||
|
|
||||||
|
Second session of the day, no Launch needed. Extended the diag probe (read-only: mode 03 `diag dtc`, BMW KWP `diag ident` / `diag bmw` on 0x6F1 with a 1A/18/21/22 service whitelist; MAX_PAYLOAD 64->384). Results, all on the tapped bus: (1) `diag dtc` read the 5 stored codes - P0101 MAF, P0113 IAT, P0500 VSS, P0545 EGT, P0030 O2 heater - all disconnected-sensor swap leftovers; the "implausible MAF/IAT scaling" flags from the morning are withdrawn (sensor faults). (2) BMW addressing verified live: 0x6F1 [12] -> reply on 0x612; the google-ai clipping's reversed claim is dead. (3) `1A 86` ident (65 B): part numbers 7799764/7799765/7793887, date 2006-03, VIN prefix WBANC92090 -> E60 530d (unverified decode); 22 F190 rejected -> KWP2000 not UDS -> DDE6/EDC16-era. 1A 90 (full VIN) always answers busyRepeatRequest to single-shots. Wrote sources/diag-route-b-2026-09-23.md; updated obd-diagnostic-polling (Route B verified, warning callout resolved), open-questions #2 (donor mostly identified - part-number lookup remains) and #7 (DTCs read), bmw-m57n-engine; raw logs diag-20260923-1241*/1242*/1243*/1245*/1246*.log. Firmware change in src/modules/diag_probe.cpp+.h (design rule kept: still the single transmit path, human-typed, single-shot).
|
||||||
|
|
||||||
|
## [2026-09-23] ingest | Identifier scans: 22 D1xx dead, 21 xx session-locked
|
||||||
|
|
||||||
|
Third session. Added `diag raw on|off` (CANRAW mute) and tools/diag_scan.py (identifier-space sweeper). Scanned `22 D100-D1FF`: every DID NRC 0x12 - the google-ai clipping identifiers are confirmed wrong for this DDE. Scanned `21 00-FF`: hits only at 21 20 (ASCII " O_269962 " - Bosch SW ref candidate), 21 06/08 (byte 0x05), 21 10 (empty); refusals 21 90 busy / 21 91 conditions-not-correct / 21 F0 security-access-denied show the measurement blocks are gated behind a diagnostic session (10 xx) and partly security access (27) - both outside the read-only whitelist by design. Conclusion: blind Route B probing is exhausted; live data needs the capture-with-Launch session. Updated sources/diag-route-b-2026-09-23.md and obd-diagnostic-polling; raw logs diagscan-22D1-*.log + diagscan-21-*.log.
|
||||||
|
|
||||||
|
## [2026-09-23] ingest | Launch capture: rail pressure decoded (service 2C)
|
||||||
|
|
||||||
|
The capture-with-Launch session, finally run (engine idling, our read-only serial_logger recording CANRAW while the Launch polled the DDE; user selected Rail Pressure actual, blipped to 2500 rpm for a second point). Result: live data on this DDE comes via KWP service 2C (dynamicallyDefineLocalIdentifier), NOT the 22 D1xx identifiers (which do not exist here) and not the session-gated 21 blocks the blind scan hit. Poll 2C 10 00 DF -> reply 6C 10 HHLL. Rail pressure VERIFIED two-point against the Launch display: bar = HHLL x 0.03 (idle raw 0x27EF=307 bar vs ~305 shown; 2500 rpm raw 0x3768=425 bar vs ~430 shown; transient spikes to 0x4E31~600 bar at tip-in). Recipe generalises to any Launch-visible value. Self-polling needs the connect-time session/define handshake (captured, but a transmit-on-the-bus design decision - deferred). Wrote sources/launch-capture-2026-09-23.md; updated obd-diagnostic-polling, open-questions #7, index; raw at serial-COM10-20260923-163511.log.
|
||||||
|
|
||||||
|
## [2026-09-23] lint | Clarify self-poll requirements; record Diagnostics-screen plan
|
||||||
|
|
||||||
|
Tightened the live-data findings after checking the full capture: the Launch used only 1A/2C/22/23 - NO 10 (session), 27 (security), or 3E (tester-present). So self-polling a 2C value (e.g. rail pressure) needs only the 2C 10 15E0 define + 2C 10 00DF poll, no secret; the earlier 21-block NRCs (0x22/0x33) are a different mechanism and do not gate 2C. Corrected the "needs session/define handshake" wording in launch-capture-2026-09-23.md and obd-diagnostic-polling. Recorded the design decision (user, 2026-09-23): active polling, if built, lives behind a password-protected Diagnostics screen (authorized-tech gate, manual, refuses while scan tool connected, read-oriented services) - open-questions #12, and a project memory so the capability is not re-researched later.
|
||||||
|
|
||||||
|
## [2026-09-26] build | OTA updates for Controller A
|
||||||
|
|
||||||
|
Repartitioned A to dual OTA slots (2 x 7.9 MB, SPIFFS dropped, nvs/otadata offsets kept - tunables v150 survived the one-time USB flash on COM10, verified). New src/modules/ota_update.cpp + include/config/ota_config.h: manual `ota status|check|install|rollback` console; HTTPS pull from the (now public) Gitea repo's latest release, ECDSA P-256 signature over "patrol-a|version|sha256" checked before download, image hashed while streaming, parked gate before download and before slot switch, rollback via verifyRollbackLater() override + 30 s confirm. TLS trusts ISRG Root X1 + Root YR (both verified against the server chain). CI: .gitea/workflows/firmware.yml (main -> rolling unsigned pre-release main-latest; v* tag -> signed release with manifest.txt). Decisions: manual trigger (future Diagnostics screen), public repos instead of a device token, Controller B to be updated by A over ESP-NOW (wire is one-way). Wrote pages/ota-updates.md. Pending: BMW_NISSAN_FIRMWARE_SIGNING_KEY repo secret, enable repo Actions, first v* tag to test end-to-end.
|
||||||
|
|
||||||
|
## [2026-09-26] build | OTA bring-up: Wi-Fi switch, ESP-NOW, memory
|
||||||
|
|
||||||
|
First CI runs green (main-latest built with version main-1ec93dc baked in; v0.1.0 signed release verified off-device: sha256 + signature + /releases/latest). Bring-up on the board found: (1) the Settings Wi-Fi switch has been LV_STATE_DISABLED since the first SquareLine export - re-enabled at runtime; (2) WiFi.disconnect(true) in the Wi-Fi task powered the radio off and killed ESP-NOW whenever Wi-Fi was used - fixed + ESP-NOW self-heal; (3) internal RAM has 15.9 KB free / 7.6 KB largest block with Wi-Fi up, so neither a TLS task stack nor mbedtls's internal-only buffers fit - OTA jobs now run in the loop task with mbedtls routed to PSRAM; `ota check` then worked on-device (signature verified on the board, 3.6 KB stack headroom). Added `wifi join|status|off` console. v0.1.0 must not be installed (pre-fix OTA can't run once installed). Updated pages/ota-updates.md, CLAUDE.md.
|
||||||
|
|
||||||
|
## [2026-09-26] verify | First OTA update end-to-end
|
||||||
|
|
||||||
|
Bench (home, both controllers on laptop USB, no car): A running USB-flashed `dev` ran `ota install` -> v0.1.1 from the signed CI release: 1.65 MB in ~60 s, verified, rebooted into app1, confirmed after 30 s (rollback cancelled). v0.1.1 then passed `ota check` ("up to date"), so OTA-from-OTA works. ota-updates.md marked VERIFIED.
|
||||||
|
|
||||||
|
## [2026-09-26] build | Display quick fixes (v0.1.2)
|
||||||
|
|
||||||
|
User reported heavy flicker during OTA and on Gauge Tuning taps, and laggy swipes. Diagnosis: flash and PSRAM share the MSPI cache; every flash write (OTA, or the NVS save on each Tuning tap) stalls the PSRAM framebuffer the RGB panel streams from, with no bounce buffer (ESP_PANEL_LCD_RGB_BOUNCE_BUF_SIZE=0) - a known ESP32-S3 RGB issue. Swipes: every transition was LV_SCR_LOAD_ANIM_FADE_ON 100 ms - a full 1024x600 software re-render + alpha blend per frame. Also: the Debug "FPS" counts loop() passes (loop sleeps 100 ms), not rendering - real render FPS has never been measured. Quick fixes: instant screen switches; Tunables NVS writes deferred to 3 s idle / leaving Tuning; backlight off during OTA writes with before/after notices; firmware version label bottom-right on every screen. Real cure (bounce buffers + SPIRAM_XIP_FROM_PSRAM via custom_sdkconfig, needs internal RAM freed first) is planned as one measured bench session with open-questions #13.
|
||||||
|
|
||||||
|
## [2026-09-26] build | CI: no duplicate / docs-only builds; v0.1.3
|
||||||
|
|
||||||
|
v0.1.3 released (OTA download loop no longer aborts on a momentary TLS connected()==false; a forced reinstall had stalled at 570 B once, retry succeeded). Pushing main then the tag ran two identical builds, and every wiki commit rebuilt firmware: the workflow's new "Skip?" step makes a main push skip itself when its commit carries a v* tag or only touches wiki/** / *.md (in-job, so tag builds are never path-filtered). Release with `git push --follow-tags origin main`. Logic dry-run locally against the real remote (tagged/untagged/docs/mixed cases).
|
||||||
|
|
||||||
|
## [2026-09-27] lint | Session sweep: OTA status, board gotchas, Wi-Fi follow-ups
|
||||||
|
|
||||||
|
Brought the wiki in line with the whole 2026-09-26 session. ota-updates: status table of every cycle (dev->v0.1.1->v0.1.2, forced reinstall with the 570 B abort + clean failure path, v0.1.3 published but not installed), "installs are done by the running firmware" rule, flicker cause marked verified, Wi-Fi lost on reboot, console-without-reset recipe, B repo now public. esp32-s3-touch-lcd-5b: removed the unmeasured "~50 FPS" claim, USB serial is native CDC (not UART0) with the DTR/RTS reset gotcha, new lessons (flash-write flicker, fade stutter, internal RAM, never power the radio off, dual-slot partitions). dual-controller-architecture: ESP-NOW/Wi-Fi radio sharing + the disconnect(true) bug, B updates via A over ESP-NOW. open-questions #14: Wi-Fi UX redesign, remember network, delete v0.1.0 release. Pending user confirmations: dark-screen OTA shows no flicker; version label placement; instant swipes; Tuning taps.
|
||||||
|
|
||||||
|
## [2026-09-27] build | UI freeze + reboots fixed: LVGL pool to PSRAM, dangling SSID buttons, scans (v0.1.4)
|
||||||
|
|
||||||
|
User: swiping main<->Settings 3x froze the UI; random flickering dots on all screens. Board state while frozen: link task alive (UART+ESP-NOW), loop()/console dead -> LVGL lock held forever. Causes found: (1) LV_ASSERT_HANDLER `while(1);` spins inside the task holding the LVGL lock; (2) g_ssid_buttons[] dangled after SquareLine deleted the Settings screen -> lv_obj_del() on freed objects; (3) with (1) replaced by abort(), the next run rebooted after ~5 round trips and the decoded backtrace showed the real limit: lv_mem_buf_get() failing in a label draw - the 48 KB LVGL pool at 87% / 31% frag / 4.5 KB biggest block; (4) Wi-Fi scanned every 10 s on every screen, connected or not. Fixes: abort() handler, LV_EVENT_DELETE clears button slots, scanning only with the list on screen and not connected, LVGL pool 512 KB in PSRAM (frees 48 KB internal: internal free 16 -> 69 KB), `mem` console command. Verified: 10 Settings visits + 9 list rebuilds, pool peak 4%, 0 crashes; user: swipes better, no dots, no freeze, no reboot. Updated esp32-s3-touch-lcd-5b, open-questions #13/#14, ota-updates, CLAUDE.md.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
type: entity
|
type: entity
|
||||||
tags: [engine, bmw, can-bus]
|
tags: [engine, bmw, can-bus]
|
||||||
updated: 2026-09-21
|
updated: 2026-09-23
|
||||||
---
|
---
|
||||||
|
|
||||||
# BMW M57N Engine
|
# BMW M57N Engine
|
||||||
@@ -10,7 +10,7 @@ The engine at the heart of the project: the display reads its CAN bus and shows
|
|||||||
|
|
||||||
## This specific engine (verified — user, 2026-07-15)
|
## This specific engine (verified — user, 2026-07-15)
|
||||||
|
|
||||||
- Donor chassis: **E60/E61 (2003+)** — narrowed from E60/E65 by the 6HP26X gearbox (xDrive output; the 7-series never had M57N + xDrive) — so a DDE6-generation ECU (Bosch EDC16C31/C35) is the expectation `(unverified)`; the DDE7.3 / EDC17CP09 that Google searches for "dde7 m57" describe is the later M57N2 in the E90/E70. Exact variant still TBD — the Launch's ECU-identification page names it (`D60M57D0`/`D62M57B0` vs `D73N57C0`). → [[obd-diagnostic-polling]]
|
- Donor chassis: **E60/E61 (2003+)** — narrowed from E60/E65 by the 6HP26X gearbox (xDrive output; the 7-series never had M57N + xDrive). **2026-09-23: the DDE identified itself over KWP** ([[diag-route-b-2026-09-23]]): VIN prefix **`WBANC92090` → E60 530d** `(unverified decode)`, ident date 2006-03, part numbers 7 799 764 / 7 799 765 / 7 793 887, and it speaks **KWP2000 not UDS** — all consistent with a DDE6-generation ECU (Bosch EDC16); a 2006 build would mean the **M57N2 231 hp** revision `(unverified)`. Remaining: look up the part numbers to name the exact variant. → [[obd-diagnostic-polling]]
|
||||||
- Transmission: **ZF 6HP26X** (user-confirmed 2026-07-17) with its EGS ECU wired into the CAN bus — gearbox temp and gear position have a real data source ([[gear-box-can-revealings]]).
|
- Transmission: **ZF 6HP26X** (user-confirmed 2026-07-17) with its EGS ECU wired into the CAN bus — gearbox temp and gear position have a real data source ([[gear-box-can-revealings]]).
|
||||||
|
|
||||||
## Overview (unverified)
|
## Overview (unverified)
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
---
|
||||||
|
type: synthesis
|
||||||
|
tags: [hardware, gauges, nissan-patrol, controller-b, electronics]
|
||||||
|
updated: 2026-09-22
|
||||||
|
---
|
||||||
|
|
||||||
|
# CANNY 5.3 pico vs ESP32-S3: driving the Patrol cluster
|
||||||
|
|
||||||
|
Why the user's old CANNY-based setup moves the Patrol tach and our ESP32 (Controller B, IO7) does not. Researched 2026-09-22 after the first in-car test of the dual-controller rig: temp needle parked mid-scale, tach dead ([[dual-controller-architecture]]).
|
||||||
|
|
||||||
|
## The working reference setup `(verified)`
|
||||||
|
|
||||||
|
The user previously drove this same instrument cluster with a **CANNY 5.3 pico** (Russian visual-PLC automotive controller, cannylogic.com / canny.ru), using **"Default Negative Output" in DIO mode on IO channel 8** (contact 4 — the channel that also carries the high-resolution PWM function). The cluster's needles respond in that setup — this is our known-good electrical reference.
|
||||||
|
|
||||||
|
## What the CANNY output stage is (source: cannylogic.com/docs/c53pico, canny.ru)
|
||||||
|
|
||||||
|
- Channels are **12 V-domain**: "output operating voltage on the controller channels matches the supply voltage" (7–16 V, 18 V abs max).
|
||||||
|
- Each channel is a **configurable-polarity switch**: "positive" mode connects the line to +12 V (high-side source), **"negative" mode connects the line to GND (low-side sink)**. Two strengths: weak ~1 mA (pull) and strong 100 mA.
|
||||||
|
- Rated for inductive/resistive/capacitive loads, 100 mA per channel, 300 mA total, automatic shutoff on over-current.
|
||||||
|
- "Negative output" therefore produces the classic automotive sender signal: the line is **pulled to ground when active and floats up to the cluster's own internal pull-up (~battery) when released** — a 0 ↔ ~12 V swing without the controller ever sourcing voltage.
|
||||||
|
|
||||||
|
## What our ESP32-S3 GPIO is
|
||||||
|
|
||||||
|
- **3.3 V push-pull** logic pin, absolute max ~3.6 V, source/sink a few tens of mA, no protection `(unverified — standard ESP32-S3 datasheet values)`.
|
||||||
|
- LEDC PWM on B's IO7 (tach square wave) and IO8 (temp duty) drives the line **actively to 3.3 V and 0 V** `(repo)`.
|
||||||
|
|
||||||
|
## Why this explains the test-day symptoms `(verified 2026-09-22 for the tach — needle tracks rpm through the 2SK3069 low-side stage; see [[patrol-instrument-cluster]] for calibration)`
|
||||||
|
|
||||||
|
- The Patrol tach input expects negative-going pulses on a line it pulls up internally toward battery. With the ESP32 push-pull output attached, the "high" half of every cycle is **3.3 V instead of ~12 V** — likely below the input threshold, so the tach sees no edges at all → dead needle, exactly what the CANNY's negative output provides and we don't.
|
||||||
|
- The temp gauge input is a sender-resistance-to-ground circuit. A 3.3 V push-pull PWM can bias it to some fixed effective level — a needle that parks at one position and ignores duty changes is consistent with this (mid-scale at 89 °C may have been coincidence, not the duty law working). Re-test after the drive stage is fixed before trusting the temp calibration in [[dual-controller-architecture]].
|
||||||
|
- **It is not PWM polarity in firmware**: a 50 % square wave is its own inverse, and inverted temp duty would move the needle backwards, not freeze it.
|
||||||
|
|
||||||
|
## The fix (per channel): replicate "negative output"
|
||||||
|
|
||||||
|
Small low-side switch between the ESP32 pin and the gauge line:
|
||||||
|
|
||||||
|
```
|
||||||
|
gauge line ──────────────┬──── (cluster's internal pull-up to ~12 V)
|
||||||
|
│
|
||||||
|
D (drain/collector)
|
||||||
|
ESP32 IOx ──[R ~1k]── G/B N-MOSFET (logic-level, e.g. 2N7002/AO3400) or NPN (2N2222 + base R)
|
||||||
|
S (source/emitter)
|
||||||
|
│
|
||||||
|
GND (common with cluster!)
|
||||||
|
```
|
||||||
|
|
||||||
|
- ESP32 high → line pulled to GND; ESP32 low → line released to the cluster's pull-up. This **inverts the logic**: tach unaffected (50 % square), temp duty becomes 255 − duty at the gauge — recalibrate `temp_slope`/`temp_offset` ([[dual-controller-architecture]] tunables) or invert in B's firmware.
|
||||||
|
- If the cluster input turns out to have no internal pull-up, add an external ~4.7–10 kΩ to +12 V.
|
||||||
|
- On hand (2026-09-22): a **2SK3069** (N-ch, 60 V / 75 A, 4 V-drive class) — hugely oversized but suitable; planned for the tach channel with 220 Ω gate series + 10 kΩ gate pulldown `(source: alltransistors.com 2SK3069)`.
|
||||||
|
- **Never** connect the 12 V-pulled gauge line directly to an ESP32 pin, including in open-drain mode — the pin is not 12 V tolerant.
|
||||||
|
- Grounds must be common: cluster GND ↔ Controller B GND.
|
||||||
|
|
||||||
|
## Open items
|
||||||
|
|
||||||
|
- Scope or multimeter the tach line at rest: does it float high (~12 V) with nothing attached? Confirms the internal pull-up assumption.
|
||||||
|
- After the transistor stage: re-run the override test (Force tach rpm / Force coolant duty on A's tuning screen) and re-derive the temp duty law; promote this page's hypothesis to `(verified)`.
|
||||||
|
|
||||||
|
## Related
|
||||||
|
|
||||||
|
[[dual-controller-architecture]] · [[nissan-patrol-swap]] · [[open-questions]]
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
type: concept
|
type: concept
|
||||||
tags: [architecture, uart]
|
tags: [architecture, uart]
|
||||||
updated: 2026-09-21
|
updated: 2026-09-27
|
||||||
---
|
---
|
||||||
|
|
||||||
# Dual-Controller Architecture
|
# Dual-Controller Architecture
|
||||||
@@ -21,6 +21,8 @@ BMW M57N CAN bus ──▶ Controller A ──UART1 + ESP-NOW, 5 Hz──▶ Con
|
|||||||
|
|
||||||
`0xAA | 0x02 | type | length | payload | XOR | 0x55`, identical on UART1 (GPIO 44 → SP3485 → `485_A`/`485_B`) and ESP-NOW broadcast (channel 1). DATA frames (lever, target/engaged gear nibbles, rpm, temps, battery, alert bitmap, valid flags) every 200 ms; CONFIG frames (`link_config_t`: Patrol gauge calibration + alert thresholds, edited on A via the `cfg` serial console and stored in NVS) on change and every 5 s. Alerts are decided here; B only renders them. Spec: `docs/UART_PROTOCOL.md`. Bench-verified with both transports live and B deduplicating every frame `(verified 2026-09-21)`.
|
`0xAA | 0x02 | type | length | payload | XOR | 0x55`, identical on UART1 (GPIO 44 → SP3485 → `485_A`/`485_B`) and ESP-NOW broadcast (channel 1). DATA frames (lever, target/engaged gear nibbles, rpm, temps, battery, alert bitmap, valid flags) every 200 ms; CONFIG frames (`link_config_t`: Patrol gauge calibration + alert thresholds, edited on A via the `cfg` serial console and stored in NVS) on change and every 5 s. Alerts are decided here; B only renders them. Spec: `docs/UART_PROTOCOL.md`. Bench-verified with both transports live and B deduplicating every frame `(verified 2026-09-21)`.
|
||||||
|
|
||||||
|
**ESP-NOW and Wi-Fi share the radio** `(verified 2026-09-26)`. When A joins a Wi-Fi network (for OTA), its channel follows the AP (seen: 6, 9, 11) and B hops to find it; ESP-NOW kept running (6,410 frames, 0 failed). Until 2026-09-26 the Wi-Fi code powered the radio off on connect/disconnect (`WiFi.disconnect(true)`), which silently killed ESP-NOW and left B on the wire only — fixed, and `EspNowLink::send()` now re-initialises ESP-NOW if the driver drops it. Planned: **Controller B's firmware updates will travel from A over ESP-NOW** (bidirectional, unlike the one-way wire) → [[ota-updates]].
|
||||||
|
|
||||||
Controller B's side of this (receiver, ESP-NOW channel hopping, gauge outputs, bench wiring) is documented in the sibling wiki: `../../ESP32-S3-LCD-1.3/wiki/pages/controller-link.md` and `patrol-gauge-outputs.md`.
|
Controller B's side of this (receiver, ESP-NOW channel hopping, gauge outputs, bench wiring) is documented in the sibling wiki: `../../ESP32-S3-LCD-1.3/wiki/pages/controller-link.md` and `patrol-gauge-outputs.md`.
|
||||||
|
|
||||||
## Why it matters for the wiki
|
## Why it matters for the wiki
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
type: entity
|
type: entity
|
||||||
tags: [hardware, waveshare, display]
|
tags: [hardware, waveshare, display]
|
||||||
updated: 2026-07-16
|
updated: 2026-09-27
|
||||||
---
|
---
|
||||||
|
|
||||||
# Waveshare ESP32-S3-Touch-LCD-5B
|
# Waveshare ESP32-S3-Touch-LCD-5B
|
||||||
@@ -13,7 +13,7 @@ Controller A of the [[dual-controller-architecture]] — the main in-cabin displ
|
|||||||
- ESP32-S3-WROOM-1-N16R8 module: dual-core LX7 @ 240 MHz, 16 MB flash, 8 MB OPI PSRAM
|
- ESP32-S3-WROOM-1-N16R8 module: dual-core LX7 @ 240 MHz, 16 MB flash, 8 MB OPI PSRAM
|
||||||
- 5" IPS 1024×600, 65K colors (16-bit), 550 cd/m², GT911 5-point capacitive touch, tempered glass
|
- 5" IPS 1024×600, 65K colors (16-bit), 550 cd/m², GT911 5-point capacitive touch, tempered glass
|
||||||
- 2.4 GHz Wi-Fi + BLE 5, onboard antenna (keep metal away from antenna area)
|
- 2.4 GHz Wi-Fi + BLE 5, onboard antenna (keep metal away from antenna area)
|
||||||
- Runs LVGL 8.4.0 at ~50 FPS via ESP32_Display_Panel v1.0.4 `(repo)`
|
- Runs LVGL 8.4.0 via ESP32_Display_Panel v1.0.4 `(repo)`. Real render FPS has **never been measured**: the Debug-panel "FPS" counts `loop()` passes (and `loop()` sleeps 100 ms), and the old "~50 FPS" figure had no measurement behind it `(verified 2026-09-26)`
|
||||||
|
|
||||||
## Power (source: waveshare-wiki)
|
## Power (source: waveshare-wiki)
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ Controller A of the [[dual-controller-architecture]] — the main in-cabin displ
|
|||||||
| I2C | External header; CH422G expander occupies 0x20–0x27 & 0x30–0x3F, GT911 touch at 0x5D — avoid these addresses |
|
| I2C | External header; CH422G expander occupies 0x20–0x27 & 0x30–0x3F, GT911 touch at 0x5D — avoid these addresses |
|
||||||
| RTC | PCF85063 + CR927 coin cell |
|
| RTC | PCF85063 + CR927 coin cell |
|
||||||
| TF card | SD_CS driven via CH422G EXIO4 |
|
| TF card | SD_CS driven via CH422G EXIO4 |
|
||||||
| USB Serial | UART0, debug @ 115200 `(repo)` |
|
| USB Serial | Native USB-CDC (`Serial`, enumerates 303A:1001, ~1 MB/s), console + CANRAW `(repo)`. **Opening the port with default DTR/RTS resets the board** (`rst:0x15`) — set both low before opening (`--dtr 0 --rts 0`) to attach without a reboot `(verified 2026-09-26)` |
|
||||||
|
|
||||||
Note: the screen occupies most GPIOs; auxiliary functions (backlight, reset, SD_CS) route through the CH422G IO expander — spare native GPIOs are scarce.
|
Note: the screen occupies most GPIOs; auxiliary functions (backlight, reset, SD_CS) route through the CH422G IO expander — spare native GPIOs are scarce.
|
||||||
|
|
||||||
@@ -52,7 +52,15 @@ Note: the screen occupies most GPIOs; auxiliary functions (backlight, reset, SD_
|
|||||||
- LCD wants a 16 MHz pixel clock with correct PCLK polarity.
|
- LCD wants a 16 MHz pixel clock with correct PCLK polarity.
|
||||||
- Backlight must be manually sequenced at boot to avoid a white flash.
|
- Backlight must be manually sequenced at boot to avoid a white flash.
|
||||||
- Flashing: use the Type-C port labeled UART; hold BOOT while connecting if the port isn't recognized (source: waveshare-wiki).
|
- Flashing: use the Type-C port labeled UART; hold BOOT while connecting if the port isn't recognized (source: waveshare-wiki).
|
||||||
|
- **Flash writes flicker the screen** `(verified 2026-09-26)`: flash and PSRAM share the MSPI cache, so every flash write/erase (NVS save, OTA) briefly cuts off the PSRAM framebuffer the RGB panel streams from; there is no bounce buffer (`ESP_PANEL_LCD_RGB_BOUNCE_BUF_SIZE=0`). `CONFIG_LCD_RGB_RESTART_IN_VSYNC=y` resyncs next frame → flicker, not permanent drift. Mitigated (v0.1.2): Tuning edits saved to NVS once after 3 s idle, backlight off during OTA writes. Real cure: bounce buffers + `CONFIG_SPIRAM_XIP_FROM_PSRAM` → [[open-questions]] #13.
|
||||||
|
- **Full-screen transitions stutter** `(verified 2026-09-26)`: a fade re-renders and alpha-blends all 614k px in software every frame into the PSRAM framebuffer. Screen switches are instant (`LV_SCR_LOAD_ANIM_NONE`) since v0.1.2.
|
||||||
|
- **Internal RAM was nearly full** `(verified 2026-09-26)`: 15.9 KB free, largest block 7.6 KB with display + Wi-Fi up. Half the cause was LVGL's own 48 KB widget pool (`LV_MEM_SIZE`) sitting in internal `.bss`. **Moved to PSRAM and enlarged to 512 KB (2026-09-27)**: internal free now **69 KB, largest block 31.7 KB** `(verified)`. The 60-line LVGL draw buffer (~120 KB) is still internal, by design (render speed).
|
||||||
|
- **LVGL's widget pool ran out** `(verified 2026-09-27)`: Settings + its Wi-Fi list is ~15 KB; screen churn + list rebuilds took the 48 KB pool to 87% used / 31% fragmented / 4.5 KB biggest block, then a label draw failed `lv_mem_buf_get()` (backtrace decoded with addr2line). With the 512 KB PSRAM pool: 10 Settings visits + 9 list rebuilds, peak 4%, 0 crashes; swipes feel better (user).
|
||||||
|
- **LVGL asserts used to freeze the board**: `LV_ASSERT_HANDLER` was `while(1);`, which spins inside the calling task *while it holds the LVGL lock* — UI frozen, `loop()`/console blocked on the lock, only the link task alive. Now `abort()`: backtrace on the console, core dump to flash (ELF), reboot. Decode with `xtensa-esp32s3-elf-addr2line -pfiaC -e firmware.elf <addrs>` (CI attaches `firmware.elf` to every release).
|
||||||
|
- **Background Wi-Fi scans caused the random flickering dots** `(verified by elimination 2026-09-27)`: the Wi-Fi task scanned every 10 s forever, connected or not, on any screen; Wi-Fi buffers live in PSRAM next to the framebuffer. Scanning is now limited to "network list on screen and not connected" — the dots are gone (user).
|
||||||
|
- **Never power the Wi-Fi radio off** (`WiFi.disconnect(true)`, `WiFi.mode(WIFI_OFF)`): it de-initialises ESP-NOW, the wireless leg of the link to B → [[dual-controller-architecture]].
|
||||||
|
- **Partition table is dual-slot OTA** since 2026-09-26 (2 × 7.9 MB, no SPIFFS, NVS offset unchanged) → [[ota-updates]].
|
||||||
|
|
||||||
## Related
|
## Related
|
||||||
|
|
||||||
[[dual-controller-architecture]] · [[can-bus-integration]] · [[esp32-s3-touch-lcd-5b-waveshare-wiki]]
|
[[dual-controller-architecture]] · [[can-bus-integration]] · [[ota-updates]] · [[esp32-s3-touch-lcd-5b-waveshare-wiki]]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
type: concept
|
type: concept
|
||||||
tags: [can-bus, dde, egs, diagnostics, kwp2000, uds, obd, design-decision]
|
tags: [can-bus, dde, egs, diagnostics, kwp2000, uds, obd, design-decision, rail-pressure]
|
||||||
updated: 2026-09-21
|
updated: 2026-09-23
|
||||||
---
|
---
|
||||||
|
|
||||||
# OBD / Diagnostic Polling
|
# OBD / Diagnostic Polling
|
||||||
@@ -25,12 +25,23 @@ E60-generation BMWs use one shared diagnostic ID pair with an ECU address in the
|
|||||||
|
|
||||||
- **What the user saw (2026-09-21):** `0x612` appears on the tapped bus only while the Launch is connected. That is the DDE *answering* — consistent with the table. The requests should be present in the same capture as `0x6F1`; the user's recollection of "`0x6F2`" is almost certainly `0x6F1`.
|
- **What the user saw (2026-09-21):** `0x612` appears on the tapped bus only while the Launch is connected. That is the DDE *answering* — consistent with the table. The requests should be present in the same capture as `0x6F1`; the user's recollection of "`0x6F2`" is almost certainly `0x6F1`.
|
||||||
|
|
||||||
> [!warning]
|
> [!note]
|
||||||
> The [[google-ai-dde7m57-pids]] clipping states the opposite (`0x612` = request, `0x6F2` = response). Two sources (dieslg8's working code on a real M57, and the `0x6xx` = ECU-address convention) against one uncited AI summary: **we go with tester `0x6F1` → DDE `0x612`** until our own capture shows the pair. Nothing is verified until then.
|
> **Resolved 2026-09-23**: our own probe sent `0x6F1 [12] 1A 86` and the DDE answered on `0x612` `(verified)` — dieslg8's scheme was right, the [[google-ai-dde7m57-pids]] clipping's reversed claim is dead. See [[diag-route-b-2026-09-23]].
|
||||||
|
|
||||||
- **Generic EOBD** (`0x7DF` functional / `0x7E0` physical → reply `0x7E8`, mode `01`) is a second, standard route `(unverified)` — early E60s served EOBD over K-line, later ones over CAN. See the next section: it is the cheaper experiment and needs no BMW knowledge.
|
- **Generic EOBD** (`0x7DF` functional → reply `0x7E8`, mode `01`) is a second, standard route — **`(verified 2026-09-23)`: the DDE answers it on the PT-CAN.** See Route A results below.
|
||||||
|
|
||||||
## Route A — generic OBD-II mode 01 (try this first)
|
## Route A — generic OBD-II mode 01 — **VERIFIED WORKING (2026-09-23)**
|
||||||
|
|
||||||
|
First live run done, engine idling, probe on the tapped bus: **the DDE replies on `0x7E8`** (and only the DDE — the EGS stays silent on generic OBD). Full readings, raw logs and the two scaling warnings: [[diag-route-a-2026-09-23]].
|
||||||
|
|
||||||
|
- Supported PIDs (bitmap scan): `01, 04, 05, 0B, 0C, 0D, 0F, 10, 1C, 20, 21` — a minimal EOBD set, consistent with EDC16/DDE6 `(unverified)`. No boost `70`, no EGT `78`, no baro `33`, no fuel rate `5E`.
|
||||||
|
- Cross-checked live: rpm 681 (CAN said 678–682) and coolant 64 °C (CAN said 63–64) — request path and decode both `(verified)`.
|
||||||
|
- MAP `0B` = 104 kPa at idle; the 255 kPa clip question needs a drive with boost.
|
||||||
|
- MAF `10` and IAT `0F` reply with implausible values (258 g/s, 155 °C at idle) — **explained the same afternoon: those are sensor faults (P0101, P0113), not scalings** ([[diag-route-b-2026-09-23]]).
|
||||||
|
- **Mode 09 (VIN, ECU name) is ACKed but never answered** — the donor could not be identified via generic OBD; Route B's `1A 86` did it instead.
|
||||||
|
- **PID `01` reports MIL off with 5 stored DTCs** — read the same day via the new `diag dtc` (mode 03): P0101, P0113, P0500, P0545, P0030, all swap leftovers ([[diag-route-b-2026-09-23]]).
|
||||||
|
|
||||||
|
The original pre-test notes and PID reference table follow.
|
||||||
|
|
||||||
The [[dwr-335d-torque-pids]] source is a worked, gauge-checked set of J1979 mode-01 PIDs from an M57 diesel (a 2009 335d, DDE7.3). They are ECU-agnostic by design, so whichever subset our DDE supports can be read with standard frames and no reverse-engineering:
|
The [[dwr-335d-torque-pids]] source is a worked, gauge-checked set of J1979 mode-01 PIDs from an M57 diesel (a 2009 335d, DDE7.3). They are ECU-agnostic by design, so whichever subset our DDE supports can be read with standard frames and no reverse-engineering:
|
||||||
|
|
||||||
@@ -51,7 +62,11 @@ The [[dwr-335d-torque-pids]] source is a worked, gauge-checked set of J1979 mode
|
|||||||
- **Implemented on Controller A (2026-09-21) `(repo)`** as the `diag` console command — see *Firmware: the `diag` probe* below. The whole test is `diag pids` typed on the USB console.
|
- **Implemented on Controller A (2026-09-21) `(repo)`** as the `diag` console command — see *Firmware: the `diag` probe* below. The whole test is `diag pids` typed on the USB console.
|
||||||
- Route A cannot give fault codes beyond generic mode `03` DTCs (P0xxx) — BMW-specific codes need Route B.
|
- Route A cannot give fault codes beyond generic mode `03` DTCs (P0xxx) — BMW-specific codes need Route B.
|
||||||
|
|
||||||
## Route B — BMW proprietary (KWP2000 / UDS on `0x6F1` → `0x612`)
|
## Route B — BMW proprietary (KWP2000 on `0x6F1` → `0x612`) — **VERIFIED WORKING (2026-09-23)**
|
||||||
|
|
||||||
|
First live exchange without any scan tool: `diag bmw 12 1A 86` → 65-byte multi-frame ident from `0x612`, containing DDE part numbers (7 799 764 / 7 799 765 / 7 793 887), a 2006-03 date, and the **VIN prefix `WBANC92090` → E60 530d** `(verified bytes / unverified decode)` — full breakdown in [[diag-route-b-2026-09-23]]. `22 F1 90` (UDS) is rejected: the DDE speaks **KWP2000, not UDS** — pointing at DDE6/EDC16. `1A 90` (full VIN) answers busyRepeatRequest to a single-shot probe. **Same day, identifier scans**: the clipping's `22 D1xx` identifiers are confirmed wrong (whole block NRCs), and a `21 xx` sweep shows the measurement blocks are **gated behind a diagnostic session / security access** (NRC 0x22/0x33) — outside the probe's read-only whitelist by design.
|
||||||
|
|
||||||
|
**Capture-with-Launch done, and it worked — [[launch-capture-2026-09-23]].** The Launch reads live values via service **`2C`** (dynamicallyDefineLocalIdentifier), not `21`/`22`: poll `2C 10 00 DF` → reply `6C 10 HHLL`. **Rail pressure actual is fully decoded and verified: bar = HHLL × 0.03** (two points against the Launch display: idle 305, 2500 rpm 430). The method generalises to any value the Launch will display. Crucially, the capture shows the DDE served this in its **default state — no `10` session, no `27` security, no `3E` tester-present** ([[launch-capture-2026-09-23]]); self-polling needs only the `2C 10 15 E0` define + `2C 10 00 DF` poll, no secret. What gates it is our own policy, not the ECU (see *Beyond the probe*).
|
||||||
|
|
||||||
|
|
||||||
This depends on the DDE variant, which is still open ([[open-questions]] #2, [[bmw-m57n-engine]]):
|
This depends on the DDE variant, which is still open ([[open-questions]] #2, [[bmw-m57n-engine]]):
|
||||||
@@ -82,11 +97,16 @@ Controller A now has **one** transmit path onto the PT-CAN: `CANDriver::transmit
|
|||||||
| `diag pid <hex>` | one mode-01 request | raw reply bytes + a decoded value for the PIDs in the Route A table |
|
| `diag pid <hex>` | one mode-01 request | raw reply bytes + a decoded value for the PIDs in the Route A table |
|
||||||
| `diag vin` | mode 09 PID 02 | the VIN as text — identifies the donor ([[open-questions]] #2) |
|
| `diag vin` | mode 09 PID 02 | the VIN as text — identifies the donor ([[open-questions]] #2) |
|
||||||
| `diag ecu` | mode 09 PID 0A | the ECU name string |
|
| `diag ecu` | mode 09 PID 0A | the ECU name string |
|
||||||
|
| `diag dtc` | mode 03 on `0x7DF` | the stored generic DTCs, decoded (added 2026-09-23) |
|
||||||
|
| `diag ident [addr]` | BMW KWP `1A 80` on `0x6F1` (default addr `12` = DDE) | ECU identification, full hex+ASCII dump (added 2026-09-23) |
|
||||||
|
| `diag bmw <addr> <hex...>` | one raw BMW-addressed request | reply dump; **whitelisted read-only services only** (`1A` ident, `18` DTCs, `21`/`22` read data — never session control or writes) |
|
||||||
| `diag status` | nothing | request/reply/timeout counters, responders seen, tester-guard timer |
|
| `diag status` | nothing | request/reply/timeout counters, responders seen, tester-guard timer |
|
||||||
|
|
||||||
Safety rules baked in: one request in flight at a time; frames are **single-shot** (no retransmit storm if nobody ACKs, the failure is just counted); **refused for 3 s after any foreign tester frame** (`0x7DF`, `0x7E0–7`, `0x6F1`), so it cannot collide with the Launch; only services `01` and `09`, never session control or writes; multi-frame replies are reassembled with a standard flow-control frame (`30 00 00`) to the responder's physical ID. Every transmitted frame is echoed as `CANTX,<ts>,<id>,0,<dlc>,<hex>` next to the `CANRAW` lines, so a saved console log holds both halves of every exchange.
|
Safety rules baked in: one request in flight at a time; frames are **single-shot** (no retransmit storm if nobody ACKs, the failure is just counted); **refused for 3 s after any foreign tester frame** (`0x7DF`, `0x7E0–7`, `0x6F1`), so it cannot collide with the Launch; only services `01` and `09`, never session control or writes; multi-frame replies are reassembled with a standard flow-control frame (`30 00 00`) to the responder's physical ID. Every transmitted frame is echoed as `CANTX,<ts>,<id>,0,<dlc>,<hex>` next to the `CANRAW` lines, so a saved console log holds both halves of every exchange.
|
||||||
|
|
||||||
### Test-day procedure (Route A probe)
|
### Test-day procedure (Route A probe) — executed 2026-09-23, outcome: Route A works
|
||||||
|
|
||||||
|
Run via `tools/diag_session.py` (one serial session, logs straight into `wiki/raw/`); results in [[diag-route-a-2026-09-23]]. Procedure kept for re-runs (e.g. the boost-clip drive test):
|
||||||
|
|
||||||
1. Engine running, **Launch unplugged** (the probe refuses to send for 3 s after any tester frame, and the Launch keeps polling while attached).
|
1. Engine running, **Launch unplugged** (the probe refuses to send for 3 s after any tester frame, and the Launch keeps polling while attached).
|
||||||
2. Laptop on the 5B's USB, console at 115200 with the output saved to a file, e.g. from the repo root:
|
2. Laptop on the 5B's USB, console at 115200 with the output saved to a file, e.g. from the repo root:
|
||||||
@@ -105,7 +125,10 @@ Safety rules baked in: one request in flight at a time; frames are **single-shot
|
|||||||
|
|
||||||
## Beyond the probe `(repo)`
|
## Beyond the probe `(repo)`
|
||||||
|
|
||||||
- A continuous poller (Route A or B) would reuse the same transmit path with a fixed request list: one request per ≥100 ms, one identifier at a time, only while no scan tool is connected, never a session-control or write service. Still a design decision: a request storm or a malformed frame can disturb the DDE/EGS, and diagnostic sessions can change what an ECU broadcasts.
|
- **The decode recipe (proven 2026-09-23):** log `CANRAW` while the Launch shows a live value → find the `2C 10 <id>` / `6C 10 <data>` pair whose data tracks the reading → calibrate scale against the display at two operating points (idle + a blip). One session per parameter. Boost, MAF, injection quantity, EGTs all reachable this way. Worked example: [[launch-capture-2026-09-23]] (rail pressure).
|
||||||
|
- A continuous poller (Route A or B) would reuse the same transmit path with a fixed request list: one request per ≥100 ms, one identifier at a time, only while no scan tool is connected, never a session-control or write service. Still a design decision: a request storm or a malformed frame can disturb the DDE/EGS.
|
||||||
|
- **What Route B self-polling actually requires (settled 2026-09-23):** just the `2C 10 15 E0` define then the `2C 10 <id>` poll — **no diagnostic session (`10`), no security access (`27`), no tester-present (`3E`)**, proven from the full Launch capture ([[launch-capture-2026-09-23]]). The `21`-block NRCs (0x22/0x33) that earlier looked like a session/security wall are a *different mechanism* and do not gate the `2C` path. `2C` is not strictly read-only (it writes a dynamic-identifier definition — harmless), so it stays out of the probe whitelist by policy.
|
||||||
|
- **Design decision — the "Diagnostics" screen (2026-09-23):** if active polling is ever built, it lives behind a **password-protected Diagnostics screen** on Controller A (authorized-technician gate), triggered manually, only while no scan tool is connected, read-oriented services only. This is the deliberate on/off switch for transmit-on-the-bus — not a background poller. Not built yet; captured here so the capability and its guard rails are not re-researched later.
|
||||||
- Protocol v2 dropped the `fault_codes` field in favour of the alert bitmap ([[dual-controller-architecture]]); polled values would need new DATA fields.
|
- Protocol v2 dropped the `fault_codes` field in favour of the alert bitmap ([[dual-controller-architecture]]); polled values would need new DATA fields.
|
||||||
- The same request path would also be the only way to read DTCs (service `0x18`/`0x19`, variant-dependent) → [[open-questions]] #7.
|
- The same request path would also be the only way to read DTCs (service `0x18`/`0x19`, variant-dependent) → [[open-questions]] #7.
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
type: synthesis
|
type: synthesis
|
||||||
tags: [meta, todo]
|
tags: [meta, todo]
|
||||||
updated: 2026-09-21
|
updated: 2026-09-27
|
||||||
---
|
---
|
||||||
|
|
||||||
# Open Questions
|
# Open Questions
|
||||||
@@ -22,9 +22,13 @@ The research frontier. Answering any of these should trigger updates across the
|
|||||||
|
|
||||||
10. **What are the Patrol's final drive ratio and tyre size?** Needed to turn output-shaft rpm into road speed. Swap-specific — not in any donor documentation. → [[nissan-patrol-swap]]
|
10. **What are the Patrol's final drive ratio and tyre size?** Needed to turn output-shaft rpm into road speed. Swap-specific — not in any donor documentation. → [[nissan-patrol-swap]]
|
||||||
|
|
||||||
|
## Design decisions (parked, not blocking)
|
||||||
|
|
||||||
|
12. **The "Diagnostics" screen (planned 2026-09-23).** Active diagnostic polling — replaying the `2C` live-data reads we decoded ([[launch-capture-2026-09-23]]) so values like rail pressure appear on Controller A without the Launch — is now technically unblocked (no session/security needed). Intended design when built: a **password-protected Diagnostics screen**, authorized-technician access only, manual trigger, refuses while a scan tool is connected, read-oriented services only. The same gate covers the general transmit-on-the-bus decision. This is deliberately deferred, but the capability, the byte sequences, and these guard rails are recorded so the work resumes from here, not from scratch. **Also the home of the OTA "check / install" controls (2026-09-26)** — today they are the `ota` console; the password must be stored as a salted hash in NVS because the firmware is public. → [[obd-diagnostic-polling]], [[dual-controller-architecture]], [[ota-updates]]
|
||||||
|
|
||||||
## Project context
|
## Project context
|
||||||
|
|
||||||
2. **Exact donor model year / DDE version and EGS variant?** *Partly answered 2026-07-17.* The gearbox is a **ZF 6HP26X** (user-confirmed) — the X is the xDrive output variant, which means the donor is an **E60/E61, not an E65**: the 7-series never took M57N + xDrive. Remaining: model year and DDE version. **Cheap to close (2026-09-21):** the Launch scanner's ECU-identification page (or any INPA "control unit found" string) names the variant — `D60M57D0`/`D62M57B0` = DDE6 (EDC16), `D73N57C0` = DDE7.3 (EDC17). → [[bmw-m57n-engine]], [[obd-diagnostic-polling]]
|
2. **Exact donor model year / DDE version and EGS variant?** *Partly answered 2026-07-17.* The gearbox is a **ZF 6HP26X** (user-confirmed) — the X is the xDrive output variant, which means the donor is an **E60/E61, not an E65**: the 7-series never took M57N + xDrive. Remaining: model year and DDE version. **Cheap to close (2026-09-21):** the Launch scanner's ECU-identification page (or any INPA "control unit found" string) names the variant — `D60M57D0`/`D62M57B0` = DDE6 (EDC16), `D73N57C0` = DDE7.3 (EDC17). **Update 2026-09-23:** generic OBD can NOT close this — mode 09 (VIN `09 02`, ECU name `09 0A`) is ACKed but never answered ([[diag-route-a-2026-09-23]]). **Same afternoon, mostly ANSWERED via Route B**: `1A 86` on `0x6F1` returned the DDE ident — **VIN prefix `WBANC92090` → E60 530d** `(unverified decode)`, DDE part numbers **7 799 764 / 7 799 765 / 7 793 887**, date 2006-03, and the DDE speaks **KWP2000 not UDS** ([[diag-route-b-2026-09-23]]). Remaining sliver: look up the part numbers / NC9x model code online to pin the exact DDE variant (DDE6.1 vs 6.2, M57N vs M57N2) — a web/parts-catalogue task now, no more hardware needed. → [[bmw-m57n-engine]], [[obd-diagnostic-polling]]
|
||||||
3. **Standalone harness or full donor loom? Which BMW modules were retained?** Affects which modules broadcast on the swap's bus. → [[nissan-patrol-swap]]
|
3. **Standalone harness or full donor loom? Which BMW modules were retained?** Affects which modules broadcast on the swap's bus. → [[nissan-patrol-swap]]
|
||||||
4. **Which Patrol generation, and how is the display being mounted/powered?** → [[nissan-patrol-swap]]
|
4. **Which Patrol generation, and how is the display being mounted/powered?** → [[nissan-patrol-swap]]
|
||||||
|
|
||||||
@@ -32,7 +36,7 @@ The research frontier. Answering any of these should trigger updates across the
|
|||||||
|
|
||||||
5. **Operating temperature 0–65 °C** (source: waveshare-wiki) — outside automotive norms at both ends (sub-zero winter cabins, sun-baked dashboards). Is the mounting location temperature-controlled enough? Any mitigation (mounting away from vents/sun, accepting reduced lifespan)?
|
5. **Operating temperature 0–65 °C** (source: waveshare-wiki) — outside automotive norms at both ends (sub-zero winter cabins, sun-baked dashboards). Is the mounting location temperature-controlled enough? Any mitigation (mounting away from vents/sun, accepting reduced lifespan)?
|
||||||
6. **Transient protection on the 7–36 V input**: the board takes vehicle 12 V directly, but ISO 7637 load-dump spikes can exceed 36 V `(unverified)`. Consider an upstream TVS diode / automotive-rated buck. Also: ignition-switched vs constant power (the isolated digital input could sense ignition).
|
6. **Transient protection on the 7–36 V input**: the board takes vehicle 12 V directly, but ISO 7637 load-dump spikes can exceed 36 V `(unverified)`. Consider an upstream TVS diode / automotive-rated buck. Also: ignition-switched vs constant power (the isolated digital input could sense ignition).
|
||||||
7. **Fault codes**: the UART packet reserves a field for fault codes — DDE fault codes are read via diagnostic protocols (KWP2000/UDS over K-line or CAN), not passively broadcast. Is passive reading even possible? `(unverified)` — **update 2026-07-17**: the same barrier explains why the Launch scanner shows boost/gearbox data our dump lacks (it polls; nothing broadcasts them). A capture *while the Launch is connected* would record both request and reply frames, handing us the exact bytes to replay. **Update 2026-09-21**: the user has seen `0x612` appear on the tapped bus while the Launch is connected — that is the DDE *replying* (`0x600` + DDE address `0x12`); the requests go out on `0x6F1`. Diagnostic traffic therefore reaches our tap, so the capture will contain both halves. Page written with the capture procedure and the firmware implications (polling = transmitting on the bus). **Cheapest first experiment** (from [[dwr-335d-torque-pids]]): one generic `01 00` supported-PID query on `0x7DF` — tells whether this DDE answers EOBD on the PT-CAN and which mode-01 PIDs it has, with zero BMW-specific knowledge. → [[obd-diagnostic-polling]]
|
7. **Fault codes**: the UART packet reserves a field for fault codes — DDE fault codes are read via diagnostic protocols (KWP2000/UDS over K-line or CAN), not passively broadcast. Is passive reading even possible? `(unverified)` — **update 2026-07-17**: the same barrier explains why the Launch scanner shows boost/gearbox data our dump lacks (it polls; nothing broadcasts them). A capture *while the Launch is connected* would record both request and reply frames, handing us the exact bytes to replay. **Update 2026-09-21**: the user has seen `0x612` appear on the tapped bus while the Launch is connected — that is the DDE *replying* (`0x600` + DDE address `0x12`); the requests go out on `0x6F1`. Diagnostic traffic therefore reaches our tap, so the capture will contain both halves. Page written with the capture procedure and the firmware implications (polling = transmitting on the bus). **Cheapest first experiment** (from [[dwr-335d-torque-pids]]): one generic `01 00` supported-PID query on `0x7DF` — tells whether this DDE answers EOBD on the PT-CAN and which mode-01 PIDs it has, with zero BMW-specific knowledge. **Update 2026-09-23 — experiment run, answer: YES.** The DDE serves mode 01 on `0x7E8` `(verified)`, and PID `01` shows **MIL off with 5 stored DTCs** ([[diag-route-a-2026-09-23]]). **Same afternoon: `diag dtc` (mode 03) read them** `(verified)`: P0101 (MAF), P0113 (IAT), P0500 (VSS), P0545 (EGT), P0030 (O2 heater) — all disconnected-sensor swap leftovers, and the first two explain the garbage MAF/IAT PID values ([[diag-route-b-2026-09-23]]). Route B addressing also verified live (`0x6F1 [12]` → `0x612`). What remains of this question: BMW-specific (non-P0xxx) codes and the live-data identifiers. **Update 2026-09-23 — Launch capture done ([[launch-capture-2026-09-23]]):** live data comes via service `2C` (not `22 D1xx`, which don't exist here); **rail pressure fully decoded and verified** (`2C 10 00 DF` → `6C 10 HHLL`, bar = HHLL × 0.03). The recipe now generalises to any Launch-visible value (boost, MAF, injection… one capture session each). Reading them *without* the Launch needs replaying the session/define handshake — a transmit-on-the-bus design decision, deferred. → [[obd-diagnostic-polling]]
|
||||||
|
|
||||||
## Answered
|
## Answered
|
||||||
|
|
||||||
@@ -65,3 +69,7 @@ The research frontier. Answering any of these should trigger updates across the
|
|||||||
- ~~Web search on DDE7 M57 PIDs~~ ✅ clipped → [[google-ai-dde7m57-pids]] — uncited AI summary; identifiers `(unverified)`, addressing claim contradicted
|
- ~~Web search on DDE7 M57 PIDs~~ ✅ clipped → [[google-ai-dde7m57-pids]] — uncited AI summary; identifiers `(unverified)`, addressing claim contradicted
|
||||||
- ~~A worked generic-PID set for an M57 diesel~~ ✅ ingested → [[dwr-335d-torque-pids]] (2009 335d, DDE7.3; J1979 mode-01 scalings gauge-checked by the author)
|
- ~~A worked generic-PID set for an M57 diesel~~ ✅ ingested → [[dwr-335d-torque-pids]] (2009 335d, DDE7.3; J1979 mode-01 scalings gauge-checked by the author)
|
||||||
- DWR's **Testo parameter list** (e90post "Testo" thread, post 175, German→English names of the DDE's non-standard values) — the pointer for Route B identifiers if our own Launch capture is not enough
|
- DWR's **Testo parameter list** (e90post "Testo" thread, post 175, German→English names of the DDE's non-standard values) — the pointer for Route B identifiers if our own Launch capture is not enough
|
||||||
|
|
||||||
|
13. **Internal RAM is nearly exhausted (found 2026-09-26) — largely relieved 2026-09-27:** LVGL's 48 KB pool moved to PSRAM (512 KB) → internal free 16 → **69 KB**, largest block 7.6 → **31.7 KB**, enough for bounce buffers to be attempted. Original finding: With display + Wi-Fi up: 15.9 KB internal free, largest block 7.6 KB (PSRAM 7.1 MB free). OTA works around it ([[ota-updates]]), but anything else that needs an internal allocation (another task, a TLS client, a bigger Wi-Fi burst) can fail. Biggest known consumer: the LVGL 60-line DMA draw buffer (~120 KB). Options: shrink it to ~30–40 lines, or measure what else lives in internal RAM first (`heap_caps_print_heap_info`). Not urgent, but it limits every future feature. **Same project as the display flicker/lag (2026-09-26):** flash writes flicker the PSRAM-fed RGB panel (no bounce buffer) and full-screen transitions stutter. Espressif's cure is bounce buffers + `CONFIG_SPIRAM_XIP_FROM_PSRAM` (needs pioarduino `custom_sdkconfig`), and bounce buffers need internal RAM — so free RAM, add bounce buffers, and measure real render FPS (LVGL perf monitor; the Debug "FPS" counts `loop()` passes, not frames) in one bench session. Quick mitigations shipped in v0.1.2 (instant screen switches, deferred NVS saves, dark screen during OTA).
|
||||||
|
|
||||||
|
14. **Wi-Fi UX (found 2026-09-26).** The Settings Wi-Fi screen had never worked (switch shipped disabled) and, now usable, is "a disaster UX" (user): SquareLine-generated, runtime SSID buttons + floating keyboard + loading overlay, **no on-screen confirmation of a successful join**. Also: A **forgets the network on every reboot** (each boot needs `wifi join`). To do: redesign as a hand-coded screen (like Driveline/Tuning, safe from SquareLine re-exports), show connection state, remember the network in NVS and auto-join; consider housing it on the Diagnostics screen (#12) next to the OTA controls, since Wi-Fi now mainly serves updates. Fixed 2026-09-27: the SSID buttons' pointers dangled after SquareLine deleted the Settings screen (use-after-free on the next scan), and scans ran every 10 s on every screen even when connected (flickering dots) — see [[esp32-s3-touch-lcd-5b]]. Housekeeping: **delete the `v0.1.0` release** on Gitea — installing it would strand the board without working OTA (USB only). → [[ota-updates]]
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
---
|
||||||
|
type: concept
|
||||||
|
tags: [ota, firmware, gitea, ci, security, signing, design-decision, controller-a]
|
||||||
|
updated: 2026-09-27
|
||||||
|
---
|
||||||
|
|
||||||
|
# OTA Firmware Updates
|
||||||
|
|
||||||
|
How Controller A updates itself from this repo's Gitea releases, why each piece is the way it is, and what is still to do (Controller B). Built 2026-09-26. Design decisions by the user are marked **(decision)**.
|
||||||
|
|
||||||
|
## The pipeline
|
||||||
|
|
||||||
|
```
|
||||||
|
git push tag vX.Y.Z ──► Gitea Actions (.gitea/workflows/firmware.yml, runner ubuntu-latest)
|
||||||
|
pio run (-DFW_VERSION="vX.Y.Z")
|
||||||
|
sign "patrol-a|vX.Y.Z|<sha256>" with secret BMW_NISSAN_FIRMWARE_SIGNING_KEY
|
||||||
|
release vX.Y.Z: firmware.bin + firmware.elf + manifest.txt
|
||||||
|
│ public repo, HTTPS, no token
|
||||||
|
Controller A `ota install` ◄──────┘ (parked, Wi-Fi joined)
|
||||||
|
GET /api/v1/repos/art/ESP32-S3-Touch-LCD-5B/releases/latest → tag
|
||||||
|
GET /releases/download/<tag>/manifest.txt → verify signature FIRST
|
||||||
|
GET /releases/download/<tag>/firmware.bin → idle slot, hashed while streaming
|
||||||
|
sha256 == signed sha256 → esp_ota_end → parked again? → switch slot → reboot
|
||||||
|
new image PENDING_VERIFY → confirmed after 30 s uptime, else bootloader rolls back
|
||||||
|
```
|
||||||
|
|
||||||
|
**To release:** `git tag -a vX.Y.Z -m "..." && git push --follow-tags origin main` — one push, one (tag) build: a `main` push skips itself when its commit already has a `v*` tag, and when it only changes `wiki/**` or `*.md` (checked inside the job, so a tag build is never skipped by a path filter).
|
||||||
|
|
||||||
|
Push to `main` (no tag) builds a rolling **pre-release `main-latest`** — unsigned, no manifest, for bench/USB testing. `/releases/latest` skips pre-releases, so the car is never offered it `(repo)`.
|
||||||
|
|
||||||
|
## Status: VERIFIED end-to-end `(verified 2026-09-26, bench, USB power, Wi-Fi Personal1)`
|
||||||
|
|
||||||
|
| Cycle (performed by the *running* firmware) | Result |
|
||||||
|
|---|---|
|
||||||
|
| `dev` (USB-flashed) → **v0.1.1**, into `app1` | ✅ 1.65 MB in ~60 s (~27 KB/s), confirmed after 30 s; v0.1.1 then passed `ota check` itself |
|
||||||
|
| v0.1.1 → **v0.1.2**, into `app0` | ✅ slots alternate as designed |
|
||||||
|
| v0.1.2 → v0.1.2 (`ota install force`), attempt 1 | ❌ download aborted at 570 B — the loop treated a momentary TLS `connected()==false` as a drop. The **failure path worked**: aborted cleanly, "Update failed / still running v0.1.2" notice, stayed on v0.1.2 |
|
||||||
|
| same, attempt 2 | ✅ into `app1`, confirmed — first install run by the dark-screen code |
|
||||||
|
| **v0.1.3** (published 2026-09-26) | fixes the 570 B abort (a drop only counts after 2 s of silence); **not yet installed** — the board runs v0.1.2 |
|
||||||
|
|
||||||
|
Always remember: an install is performed by the firmware that is **already running**, so a fix to the install path only takes effect on the update *after* the one that delivers it (v0.1.1 → v0.1.2 still flickered because v0.1.1 did the writing).
|
||||||
|
|
||||||
|
**Dark-screen writes (v0.1.2+).** Flash writes flicker the PSRAM-fed panel (cause below, and [[esp32-s3-touch-lcd-5b]]), so the backlight is off while the image is written: a full-screen notice "Updating to vX — the screen goes dark for about a minute — do not switch off" shows for 3 s first, then "Installed vX / Restarting…" or "Update failed / Still running vY". Ran for real on the forced reinstall; the user's visual confirmation of "no flicker" is still pending `(unverified)`. The running version is always shown bottom-right on every screen (`A v0.1.2`).
|
||||||
|
|
||||||
|
Known quirk: `ota status` shows the *other* slot's "built" date from the framework's precompiled app descriptor (e.g. "Nov 4 2025"), not our build time — ignore it.
|
||||||
|
|
||||||
|
## Decisions and why
|
||||||
|
|
||||||
|
- **Manual trigger only (decision, 2026-09-26).** An install ends in a reboot, which blanks Controller B's gauges; nothing checks or installs in the background. Today the trigger is the `ota` serial console; the intended home is the password-gated **Diagnostics screen** ([[open-questions]] #12), the same gate as active CAN polling.
|
||||||
|
- **Parked gate** `(repo)`: refused if engine rpm > 0 / run state running or starting, output shaft turning, or lever in a drive gear. A silent bus (>2 s no frames: ignition off, bench) counts as parked. Checked before the download **and again** before the slot switch. `ota check` is exempt (read-only).
|
||||||
|
- **HTTPS pull from a public repo (decision).** Both repos were made public 2026-09-26 so the device needs **no token** — the same reasoning as `parking_solution`'s public releases mirror: a read token in shipped firmware leaks with the device. History was scanned before/after going public: no secrets, no full VIN (only the 10-char prefix in ident logs), no SSIDs `(verified 2026-09-26)`.
|
||||||
|
- **Signed images (decision).** HTTPS only proves the file came from the server; the ECDSA P-256 signature proves it came from our CI key. The signed statement is `target|version|sha256`, so a Controller B image can't be installed on A even with a shared key, and the manifest version can't be swapped. The firmware contains no secrets, so public binaries are fine — **keep it that way**: the future Diagnostics-screen password must be a salted hash in NVS, never a literal in source.
|
||||||
|
- **TLS trust = Let's Encrypt roots, not the leaf** `(verified 2026-09-26)`: the server chain is leaf (SAN `git.infra.msai.al`) → YR2 → Root YR (cross-signed by ISRG Root X1). Both ISRG Root X1 (to 2035) and Root YR (to 2045) are embedded in `include/config/ota_config.h`, and each verifies the chain alone. Leaf certs rotate ~90 days — never pin them. The framework's mbedtls has `MBEDTLS_HAVE_TIME_DATE` off, so no NTP is needed (and cert dates aren't checked; the signature is the real guarantee).
|
||||||
|
- **Rollback**: the framework bootloader has `CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y`, but Arduino's `initArduino()` marks a new image valid *before* `setup()`. `ota_update.cpp` overrides `verifyRollbackLater()` → the image stays PENDING_VERIFY until `Ota::tick()` confirms it after 30 s. Consequence: **power off within 30 s of an update's first boot = back to the old version** (by design).
|
||||||
|
|
||||||
|
## Memory: why jobs run in the loop task `(verified 2026-09-26)`
|
||||||
|
|
||||||
|
With the display, Wi-Fi and all tasks up, **internal RAM is nearly exhausted: 15.9 KB free, largest block 7.6 KB** (PSRAM: 7.1 MB free). Two consequences, both handled in `ota_update.cpp`:
|
||||||
|
|
||||||
|
- This framework's mbedtls is built with `CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC=y` (~40 KB internal per TLS session → impossible). During a job, `mbedtls_platform_set_calloc_free()` routes TLS to PSRAM, and restores it after (both sides free with `heap_caps_free`, so the swap is safe).
|
||||||
|
- No room for a dedicated 10–16 KB task stack, and a PSRAM stack is forbidden because `esp_ota_write()` disables the flash cache. So jobs run **inside the Arduino loop task** (8 KB internal stack): `ota check` peaked leaving **3.6 KB headroom**. The console and screen value ticks pause while a job runs.
|
||||||
|
|
||||||
|
Update 2026-09-27: with LVGL's pool moved to PSRAM, internal free is 69 KB (largest block 31.7 KB); jobs still run in the loop task (it works, 3.6 KB headroom). The low internal heap was a system-wide risk beyond OTA (the LVGL 60-line DMA draw buffer alone is ~120 KB of internal SRAM) — see [[open-questions]].
|
||||||
|
|
||||||
|
## Partition table (changed 2026-09-26)
|
||||||
|
|
||||||
|
| Name | Offset | Size |
|
||||||
|
|---|---|---|
|
||||||
|
| nvs | 0x9000 | 20 KB — **unchanged offset, settings survive** |
|
||||||
|
| otadata | 0xE000 | 8 KB |
|
||||||
|
| app0 (ota_0) | 0x10000 | 7.9 MB |
|
||||||
|
| app1 (ota_1) | 0x800000 | 7.9 MB |
|
||||||
|
| coredump | 0xFF0000 | 64 KB |
|
||||||
|
|
||||||
|
SPIFFS (3.4 MB, unused by any code) was dropped. Firmware is ~1.65 MB (19.8 % of a slot). Moving to this layout needed **one USB flash** (done 2026-09-26 on COM10; tunables v150 survived — `(verified)`).
|
||||||
|
|
||||||
|
## Console
|
||||||
|
|
||||||
|
| Command | What |
|
||||||
|
|---|---|
|
||||||
|
| `ota status` | version, build time, running slot + state, other slot's image |
|
||||||
|
| `ota check` | latest release vs running, signature checked (Wi-Fi only, no parked gate) |
|
||||||
|
| `ota install [force]` | full install; `force` reinstalls the same version |
|
||||||
|
| `ota rollback` | boot the other slot (or reject an unconfirmed image) — parked only |
|
||||||
|
|
||||||
|
Wi-Fi must be joined first — `wifi join <ssid> [pass]` on the console (`wifi status`, `wifi off`), or the Settings screen. **Do not install `v0.1.0`**: it predates the loop-task/PSRAM-TLS fix, so once installed it can't run OTA again (it boots fine, so rollback won't save it — USB only). Joining an AP moves the radio channel; the ESP-NOW link to B follows it (B hops). `diag raw off` first keeps CANRAW from burying the progress lines.
|
||||||
|
|
||||||
|
- **Wi-Fi does not survive a reboot** — every boot (including the one that ends an update) needs a new `wifi join`; remembering the network is future work ([[open-questions]] #14).
|
||||||
|
- **Open the console without resetting the board**: `pio device monitor -p COM10 -b 115200 --dtr 0 --rts 0 --echo` (pio lives at `%USERPROFILE%\.platformio\penv\Scripts\pio.exe`). Opening the port with default DTR/RTS resets it (`rst:0x15 USB_UART_CHIP_RESET`), which drops the Wi-Fi join `(verified 2026-09-26)`.
|
||||||
|
- **Flicker cause** `(verified 2026-09-26)`: flash and PSRAM share the MSPI cache; every flash write stalls the PSRAM framebuffer the RGB panel streams from (no bounce buffer). Hence the dark screen above.
|
||||||
|
|
||||||
|
## Secrets and keys
|
||||||
|
|
||||||
|
- `BMW_NISSAN_FIRMWARE_SIGNING_KEY` — Gitea **repo secret** (Settings → Actions → Secrets), the EC P-256 private key PEM. Generated 2026-09-26; keep an offline backup. Losing it means devices only accept updates after one USB flash with a new public key.
|
||||||
|
- Public key: compiled in (`OTA_SIGNING_PUBKEY_PEM`) and in `tools/ota/firmware_signing_pub.pem` (CI self-checks each signature against it before publishing).
|
||||||
|
- Rotating the key: new keypair → update both public-key copies → USB-flash once (a device only trusts the key it was built with).
|
||||||
|
|
||||||
|
## Bugs found while bringing it up (2026-09-26)
|
||||||
|
|
||||||
|
- **Settings Wi-Fi switch was disabled since the first SquareLine export** (`LV_STATE_DISABLED`) — the Wi-Fi UI had never worked. Re-enabled at runtime in `UIStateManager` (survives re-exports; untick "Disabled" in the SquareLine project too).
|
||||||
|
- **Joining Wi-Fi killed ESP-NOW**: the Wi-Fi task used `WiFi.disconnect(true)` (true = radio off), which drops ESP-NOW; B then ran on the wire only. Now `WiFi.disconnect()`, and `EspNowLink::send()` re-initialises ESP-NOW if the driver ever drops it. Verified: joined Personal1 (channel 9), ESP-NOW 195 sent / 0 failed.
|
||||||
|
- `showConnectionResult()` took the LVGL lock with a 0 ms try-lock, ignored the result, and touched widgets that are NULL off the Settings screen — now waits for the lock and null-checks. It still shows **no success feedback** on screen; the Wi-Fi UI needs a redesign (user: "a disaster UX").
|
||||||
|
|
||||||
|
## Controller B (not built yet)
|
||||||
|
|
||||||
|
Plan agreed 2026-09-26: B is updated **by A over ESP-NOW**, not by the RS485 wire (the wire is one-way A→B; ESP-NOW is bidirectional and faster). A downloads B's signed image (target `patrol-b`) from B's repo releases, sends it with acks, B verifies the signature and swaps slots with the same rollback scheme. Prerequisites: B moves off the stock `default.csv` (1.25 MB slots, 1.07 MB firmware → too tight) to a 16 MB layout (confirm B's flash size first; one USB flash); ESP-NOW pairing/encryption so only A can talk to B; protocol frames for the transfer (shared `automotive_data.h` → version bump in both repos). B's repo is public since 2026-09-27 (anonymous API 200). Wire stays for gauge-data redundancy.
|
||||||
|
|
||||||
|
## Related
|
||||||
|
|
||||||
|
[[dual-controller-architecture]] · [[esp32-s3-touch-lcd-5b]] · [[open-questions]] · [[obd-diagnostic-polling]]
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
---
|
||||||
|
type: entity
|
||||||
|
tags: [hardware, gauges, nissan-patrol, controller-b, electronics]
|
||||||
|
updated: 2026-09-22
|
||||||
|
---
|
||||||
|
|
||||||
|
# Patrol instrument cluster — signal expectations
|
||||||
|
|
||||||
|
What the target vehicle's cluster ([[nissan-patrol-swap]]) needs on its tach and temp inputs, from the first day of driving it with Controller B's outputs through the low-side FET stage ([[canny-5-3-pico-gauge-drive]]). Patrol generation still unidentified — Y60/GQ vs Y61/GU matters for gauge internals → [[open-questions]].
|
||||||
|
|
||||||
|
## Tachometer
|
||||||
|
|
||||||
|
- **Empirical calibration `(verified 2026-09-22)`: 2 pulses per revolution.** With the firmware's original `tach_ppr=4` the cluster read double; `cfg` ppr set to 2 makes it track the BMW's CAN rpm. Signal: 50 % square wave, low-side switched (2SK3069), i.e. 3000 rpm → 100 Hz.
|
||||||
|
- Background on what these clusters normally get `(source: patrol4x4.com / nissanpatrol.com.au threads)`:
|
||||||
|
- TD42 diesels had **no factory tach signal**; aftermarket/factory tachs run from the **alternator W terminal** (a phase tap — frequency scales with pulley ratio × pole pairs, far more than 2/rev, usually via an adapter box).
|
||||||
|
- A clean **2 ppr** expectation matches an **ECU-driven 4-cylinder-style tach input** (e.g. ZD30-era Y61) `(unverified)` — a hint the cluster may be from that generation, worth checking against the actual vehicle.
|
||||||
|
- Practical consequence: the doubled reading at ppr=4 was calibration, not a signal-quality problem. The FET stage works.
|
||||||
|
- **Scale calibration `(verified 2026-09-23, override ramps)`**: with ppr=2 the cluster over-reads by a factor that shrinks with rpm — ×1.20 at 1000–2000, ×1.15 at 6000 (commanded 6000 with trim −20 read exactly 5500). The response is mildly nonlinear, so a linear trim cannot be exact everywhere; **`tach_trim = −13 %` chosen as the realistic compromise** (user-tuned on the dial). Saved on A, pushed in CONFIG.
|
||||||
|
|
||||||
|
### The steppy-needle saga (2026-09-22/23) — resolved
|
||||||
|
|
||||||
|
Observed on the road: needle holds then jumps 200–500 rpm. Diagnosis took four firmware iterations on B, each eliminating one layer `(repo, verified by override ramp tests with ignition on / engine off)`:
|
||||||
|
|
||||||
|
1. **5 Hz staircase**: B refreshed the tach frequency once per 200 ms packet. Added a slew limiter (glide 25 %/20 ms). *Result: worse* — because of layer 2.
|
||||||
|
2. **LEDC restarts**: Arduino 2.x `ledcChangeFrequency()` re-inits the timer and truncates the waveform mid-period; calling it 50×/s corrupted the counting window constantly. Replaced LEDC with an esp_timer toggling IO7. *Result: better, not smooth* — because of layer 3.
|
||||||
|
3. **Task-dispatch jitter**: esp_timer callbacks run in a task; WiFi/ESP-NOW bursts on core 0 delay edges by ms and bunch them. Replaced with a **hardware-timer ISR** (1 MHz, auto-reload): phase-continuous, immune to scheduling. *Result: rock-steady at fixed rpm, but ramps still stepped* — because of layer 4, which is the cluster itself.
|
||||||
|
4. **Cluster count quantization** — the floor: on a clean 25 rpm/40 ms synthetic ramp the needle jumped alternately +100/+200 → the cluster counts pulses in **~150 rpm quanta** on a dial that rounds to 100. A perfectly stable synthetic frequency parks on a quantum and snaps to the next; a real engine's pulse jitter straddles the boundary so the damped needle averages in between — factory setups are smooth *because* their signal is dirty. Emulated with **random dither ±45 rpm (±1.2 Hz) per 20 ms tick**, with an **adaptive envelope** (full while the target moves, fades to zero within ~1.2 s at rest) so steady rpm stays flicker-free.
|
||||||
|
|
||||||
|
Final state (2026-09-23): sweep and hold "fairly good" per user; possible future refinement of dither constants (`DITHER_HZ`, envelope times in B's `gauge_outputs.cpp`). Also explains the CANNY's high-rpm jumpiness ([[canny-5-3-pico-gauge-drive]]): a PLC toggling on a ms-resolution timer gets coarse at ≥100 Hz output `(unverified)`.
|
||||||
|
|
||||||
|
## Temperature gauge
|
||||||
|
|
||||||
|
- The stock sender is an **NTC thermistor to ground** `(source: patrol4x4.com forum, sensorgal.com)`:
|
||||||
|
|
||||||
|
| Coolant | Sender resistance |
|
||||||
|
|---|---|
|
||||||
|
| 20 °C | 2.1–2.9 kΩ |
|
||||||
|
| 50 °C | 0.68–1 kΩ |
|
||||||
|
| 90 °C | 236–260 Ω |
|
||||||
|
|
||||||
|
The gauge is a current-measuring device; its useful span is roughly the "tens of Ω to a few kΩ" region. Duty-cycle PWM through a low-side switch emulates an average conductance in this range `(repo)`.
|
||||||
|
- **Needle flutter at `temp_pwm_hz` = 1 kHz — RESOLVED at 20 kHz `(verified 2026-09-22)`.** At 1 kHz the needle fluttered at any duty between the endpoints (steady at 0 and 255 — i.e. it was following the chopping itself); raising `temp_hz` to 20000 (the current firmware clamp) removed the fluctuation completely. Matches community experience that PWM-driven automotive gauges need tens-of-kHz `(source: allaboutcircuits.com, pjrc forum)`.
|
||||||
|
- Lesson from the same session: a **missing chassis/board common ground makes the gauge read nothing at all** — check grounds before debugging frequencies.
|
||||||
|
- Still open as optional hardening: a series resistor in the FET drain (~100–240 Ω) to bound the current swing to the sender's real range (full-on duty = dead short, i.e. "hotter than the sender can ever read").
|
||||||
|
- After the flutter is fixed, re-derive `temp_slope`/`temp_offset` against the sender table above (the FET inverts duty sense vs the direct-drive law used before).
|
||||||
|
|
||||||
|
## Open items
|
||||||
|
|
||||||
|
- Identify the Patrol generation / cluster origin (2 ppr hint above; ask the user / photograph the cluster).
|
||||||
|
- Temp law recalibration table (duty ↔ needle position ↔ implied °C) — gauge works and is stable at 20 kHz; the slope/offset mapping to real °C has not been re-derived since the FET stage inverted the duty sense.
|
||||||
|
- Tach dither constants may deserve another tuning pass ("maybe in the future we will get back to RPMs" — user, 2026-09-23).
|
||||||
|
|
||||||
|
## Related
|
||||||
|
|
||||||
|
[[canny-5-3-pico-gauge-drive]] · [[nissan-patrol-swap]] · [[dual-controller-architecture]] · [[open-questions]]
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,30 @@
|
|||||||
|
[ 8546][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[ 8741][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #25 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=29 fail=0]
|
||||||
|
[ 10025][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[ 13558][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
|
||||||
|
>>> diag dtc
|
||||||
|
CANTX,13676,7DF,0,8,0103000000000000
|
||||||
|
[ 13676][W][can_driver.cpp:554] canTask(): [CANTask] Bus error detected (count: 1)
|
||||||
|
[ 13684][W][can_driver.cpp:563] canTask(): [CANTask] TX failed (no ACK / bus error) - 1 so far
|
||||||
|
[diag] -> 0x7DF 03
|
||||||
|
[ 14024][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #50 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=55 fail=0]
|
||||||
|
[diag] no reply within 500 ms (request 03) - frame was not ACKed by any node
|
||||||
|
[ 15034][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
|
||||||
|
>>> diag ident
|
||||||
|
CANTX,17669,6F1,0,8,12021A8000000000
|
||||||
|
[ 17669][W][can_driver.cpp:554] canTask(): [CANTask] Bus error detected (count: 2)
|
||||||
|
[ 17677][W][can_driver.cpp:563] canTask(): [CANTask] TX failed (no ACK / bus error) - 2 so far
|
||||||
|
[diag] -> 0x6F1 [12] 1A 80 (reply expected on 0x612)
|
||||||
|
[diag] no reply within 500 ms (request 1A 80) - frame was not ACKed by any node
|
||||||
|
[ 18574][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[ 19308][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #75 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=81 fail=0]
|
||||||
|
[ 20114][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
|
||||||
|
>>> diag status
|
||||||
|
[diag] state=idle requests=2 replies=0 timeouts=2 negative=0 | CAN tx=2 tx_failed=2
|
||||||
|
[diag] no foreign tester seen since boot
|
||||||
|
[ 23585][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[ 24591][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #100 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=107 fail=0]
|
||||||
|
[ 25185][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[ 28574][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[ 29850][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #125 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=133 fail=0]
|
||||||
|
[ 30324][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,24 @@
|
|||||||
|
[ 3619][I][main.cpp:187] setup(): [MAIN] - Console: type 'cfg help' to tune the Patrol gauge outputs
|
||||||
|
[ 3628][I][main.cpp:188] setup(): [MAIN] - Screens: Driveline (boot) <- left: Settings | right: Gauge tuning ->
|
||||||
|
[ 3638][I][main.cpp:189] setup(): [MAIN] - Settings screen has WiFi and UART toggles
|
||||||
|
[ 3646][I][main.cpp:190] setup(): [MAIN] - WiFi scan updates every 10 seconds when enabled
|
||||||
|
[ 3654][I][main.cpp:191] setup(): [MAIN] - UART transmits at 5Hz (200ms) when enabled
|
||||||
|
[ 3800][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #2 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=5 fail=0]
|
||||||
|
[ 4027][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #3 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=6 fail=0]
|
||||||
|
[ 4253][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #4 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=7 fail=0]
|
||||||
|
[ 4479][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #5 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=8 fail=0]
|
||||||
|
[ 5006][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[ 8518][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[ 8712][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #25 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=29 fail=0]
|
||||||
|
|
||||||
|
>>> diag raw on
|
||||||
|
[ 9768][I][can_driver.cpp:709] setRawLogging(): [CANDrv] Raw frame logging ENABLED
|
||||||
|
[diag] CANRAW logging on
|
||||||
|
[ 10079][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[ 13531][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
|
||||||
|
>>> diag status
|
||||||
|
[diag] state=idle requests=0 replies=0 timeouts=0 negative=0 | CAN tx=0 tx_failed=0
|
||||||
|
[diag] no foreign tester seen since boot
|
||||||
|
[ 13996][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #50 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=55 fail=0]
|
||||||
|
[ 15142][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,78 @@
|
|||||||
|
[234147][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[235901][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #76 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1149 fail=0]
|
||||||
|
[237817][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[239159][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[241185][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #101 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1175 fail=0]
|
||||||
|
[242880][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[244173][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[246469][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #126 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1201 fail=0]
|
||||||
|
[247945][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[249187][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[251753][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #151 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1227 fail=0]
|
||||||
|
[253006][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[254202][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[257037][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #176 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1253 fail=0]
|
||||||
|
[258096][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[259214][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[262322][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #201 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1279 fail=0]
|
||||||
|
[263178][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[264231][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[267607][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #226 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1305 fail=0]
|
||||||
|
[268243][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[269245][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[272889][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #251 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1331 fail=0]
|
||||||
|
[273334][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[274257][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[278172][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #20 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1357 fail=0]
|
||||||
|
[278382][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[279268][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[283424][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[283459][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #45 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1383 fail=0]
|
||||||
|
[284286][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[288486][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[288741][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #70 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1409 fail=0]
|
||||||
|
[289298][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[293503][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[294025][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #95 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1435 fail=0]
|
||||||
|
[294312][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[298517][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[299309][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #120 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1461 fail=0]
|
||||||
|
[299356][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[303609][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[304386][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[304580][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #145 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1488 fail=0]
|
||||||
|
[308631][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[309397][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[309861][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #170 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1514 fail=0]
|
||||||
|
[313721][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[314410][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[315145][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #195 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1540 fail=0]
|
||||||
|
[318782][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[319423][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[320428][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #220 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1566 fail=0]
|
||||||
|
[323848][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[324438][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[325713][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #245 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1592 fail=0]
|
||||||
|
[328909][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[329451][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[330997][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #14 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1618 fail=0]
|
||||||
|
[333933][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[334465][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[336280][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #39 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1644 fail=0]
|
||||||
|
[338997][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[339479][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[341563][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #64 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1670 fail=0]
|
||||||
|
[344060][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[344491][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[346847][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #89 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1696 fail=0]
|
||||||
|
[349152][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[349504][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[352129][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #114 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1722 fail=0]
|
||||||
|
[354215][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[354516][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[357411][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #139 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1748 fail=0]
|
||||||
|
[359280][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[359529][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
|
[362697][I][uart_manager.cpp:126] sendDataFrame(): [UARTTask] TX #164 gear=P(t0/e0) rpm=0 cool=89.0 gb=85.0 batt=12.45 alerts=0x00 valid=0x3F [27 B uart+espnow, espnow tx=1774 fail=0]
|
||||||
|
[364368][I][main.cpp:201] loop(): [LOOP] Heartbeat - system running
|
||||||
|
[364545][I][uart_manager.cpp:158] sendConfigFrame(): [UARTTask] TX CONFIG v107 (periodic): ppr=2 trim=-13 temp_hz=20000 slope=150 offset=50 min=40 override=0
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,57 @@
|
|||||||
|
---
|
||||||
|
type: source
|
||||||
|
tags: [can-bus, obd, dde, diagnostics, capture]
|
||||||
|
updated: 2026-09-23
|
||||||
|
---
|
||||||
|
|
||||||
|
# Route A probe — first live run (2026-09-23)
|
||||||
|
|
||||||
|
First execution of the [[obd-diagnostic-polling]] Route A test: the `diag` console probe on Controller A, engine idling, Launch unplugged, tapped PT-CAN. Two sessions, raw console logs (CANRAW + CANTX + diag output interleaved):
|
||||||
|
|
||||||
|
- `raw/diag-20260923-111737.log` — `pids`, `pid 0C`, `pid 05`, `pid 0B`, `pid 70`, `vin`, `ecu`, `status`
|
||||||
|
- `raw/diag-20260923-111851.log` — `pid 10`, `pid 04`, `pid 0F`, `pid 0D`, `pid 1C`, `pid 01`, `pid 21`, `status`
|
||||||
|
|
||||||
|
## Headline
|
||||||
|
|
||||||
|
**The DDE answers generic OBD-II (mode 01) on the PT-CAN at `0x7E8`.** `(verified 2026-09-23)` Route A works; no BMW-specific knowledge needed for the PIDs it supports. Only one responder — the EGS does not answer generic OBD (nothing from `0x7E9`).
|
||||||
|
|
||||||
|
## Supported-PID bitmap (`diag pids`)
|
||||||
|
|
||||||
|
Blocks `01 00` and `01 20` answered; bitmap `41 20 80 00 00 00` → no blocks past 0x21. Full supported set:
|
||||||
|
|
||||||
|
`01, 04, 05, 0B, 0C, 0D, 0F, 10, 1C, 20, 21` — a minimal EOBD set. None of the 2007+ diesel PIDs (`70` boost, `78` EGT…), no `33` barometric, no `5E` fuel rate. Consistent with an EDC16-era DDE6 `(unverified)`.
|
||||||
|
|
||||||
|
## Readings at idle, engine warm-ish (coolant 63–66 °C during the runs)
|
||||||
|
|
||||||
|
| PID | Raw reply | Decoded (J1979) | Verdict |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `0C` rpm | `41 0C 0A A4` | **681 rpm** | `(verified)` — CAN `0x0AA` read 678–682 simultaneously |
|
||||||
|
| `05` coolant | `41 05 68` | **64 °C** | `(verified)` — CAN `0x1D0` read 63–64 °C simultaneously |
|
||||||
|
| `0B` MAP | `41 0B 68` | **104 kPa abs** | plausible at idle (baro + a touch); the 255 kPa clip untested — needs a boost run |
|
||||||
|
| `0D` speed | `41 0D 00` | 0 km/h | `(verified)` — parked |
|
||||||
|
| `1C` OBD standard | `41 1C 06` | 6 = **EOBD (Europe)** | as expected |
|
||||||
|
| `10` MAF | `41 10 64 E5` | 258.29 g/s | **implausible** — see warning |
|
||||||
|
| `0F` intake air | `41 0F C3` | 155 °C | **implausible** — see warning |
|
||||||
|
| `04` load | `41 04 43` | 26 % | plausible idle load |
|
||||||
|
| `01` monitor status | `41 01 05 46 80 80` | MIL **off**, **5 stored DTCs** | see below |
|
||||||
|
| `21` distance w/ MIL | `41 21 00 00` | 0 km | consistent with MIL off |
|
||||||
|
| `70` boost | — | no reply (ACKed, silent) | PID absent, as predicted for EDC16 |
|
||||||
|
|
||||||
|
> [!warning]
|
||||||
|
> **MAF and IAT come back with non-standard-looking scalings.** By the book, `0x64E5`/100 = 258 g/s and `0xC3`−40 = 155 °C — both absurd at idle (expect ~20–30 g/s and <60 °C). ×0.1 on the MAF gives a very plausible 25.8 g/s; the IAT law is unknown (BMW's internal 0.75·x−48 would give 98 °C — still hot). Treat both PIDs as **present but unscaled** `(unverified)` until cross-checked against the Launch's live-data page or a cold-engine reading.
|
||||||
|
|
||||||
|
## Mode 09: silent
|
||||||
|
|
||||||
|
`09 02` (VIN) and `09 0A` (ECU name) were ACKed but never answered. **The donor cannot be identified over generic OBD** — [[open-questions]] #2 still needs the Launch's ECU-identification page (or a Route B `0x6F1` capture).
|
||||||
|
|
||||||
|
## The 5 stored DTCs
|
||||||
|
|
||||||
|
PID `01` byte A = `0x05`: MIL off, 5 confirmed DTCs in memory. Reading them is generic mode `03` — a small, read-only extension to the probe (currently services 01/09 only), or one Launch session. Feeds [[open-questions]] #7.
|
||||||
|
|
||||||
|
## Probe behaviour `(repo)`
|
||||||
|
|
||||||
|
Counters across both runs: 15 requests, 12 replies, 3 timeouts (the three unsupported/silent ones), 0 negatives, 0 tx failures, no foreign tester seen. Single-shot + guard logic worked as designed; the bus never saw a retry storm.
|
||||||
|
|
||||||
|
## Related
|
||||||
|
|
||||||
|
[[obd-diagnostic-polling]] · [[dwr-335d-torque-pids]] · [[can-id-candidates]] · [[open-questions]]
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
---
|
||||||
|
type: source
|
||||||
|
tags: [can-bus, obd, dde, diagnostics, kwp2000, dtc, vin, capture]
|
||||||
|
updated: 2026-09-23
|
||||||
|
---
|
||||||
|
|
||||||
|
# Route B probe + DTC read — same day, second session (2026-09-23)
|
||||||
|
|
||||||
|
Follow-up to [[diag-route-a-2026-09-23]], same setup (tapped PT-CAN, no Launch). The `diag` probe gained three read-only commands (`dtc` = generic mode 03, `ident` = BMW KWP `1A 80`, `bmw <addr> <hex>` = raw whitelisted request on `0x6F1`) and they paid off immediately. Raw console logs in `raw/`: `diag-20260923-124138.log` (DTCs), `diag-20260923-124226.log` (first `1A 86` hit), `diag-20260923-124544.log` (full ident dump), `diag-20260923-124331.log` / `-124643.log` (negative-response probes).
|
||||||
|
|
||||||
|
## Headline 1: Route B works — BMW addressing verified on our own bus
|
||||||
|
|
||||||
|
**`(verified 2026-09-23)`** Request `0x6F1` `[12] 02 1A 86` → the DDE answers on **`0x612`** with a 65-byte multi-frame KWP reply (our flow control `[12] 30 00 00` on `0x6F1` accepted). This settles the addressing question from [[google-ai-dde7m57-pids]] in favour of dieslg8's scheme: **tester `0x6F1` + target address byte, ECU replies on `0x600`+address** — from our own exchange now, no longer just sources.
|
||||||
|
|
||||||
|
## Headline 2: the stored DTCs — all five are swap leftovers
|
||||||
|
|
||||||
|
`diag dtc` (generic mode 03 on `0x7DF`, ignition on, engine off) — reply `43 05 00 30 05 00 05 45 01 13 01 01` `(verified)`:
|
||||||
|
|
||||||
|
| Code | Generic meaning | Swap interpretation `(unverified)` |
|
||||||
|
|---|---|---|
|
||||||
|
| **P0101** | MAF circuit range/performance | explains the absurd 258 g/s MAF PID reading — sensor unplugged/failed, not a scaling issue |
|
||||||
|
| **P0113** | intake air temp circuit **high input** | explains the absurd 155 °C IAT PID reading — open circuit reads max |
|
||||||
|
| **P0500** | vehicle speed sensor A | expected: no DSC/ABS module on the swap bus, nothing sends road speed |
|
||||||
|
| **P0545** | EGT sensor 1 circuit low | sensor presumably gone with the donor exhaust |
|
||||||
|
| **P0030** | O2/lambda heater control circuit (B1S1) | lambda presumably gone with the donor exhaust |
|
||||||
|
|
||||||
|
Consequences: the Route A "MAF/IAT non-standard scaling" warning is **withdrawn — they are sensor faults, not scalings**. And with a dead MAF the DDE almost certainly runs its fallback air-mass map (less precise fuelling/EGR) `(unverified)` — worth knowing for how the engine behaves.
|
||||||
|
|
||||||
|
## Headline 3: the donor identifies itself
|
||||||
|
|
||||||
|
`diag bmw 12 1A 86` full reply (65 B):
|
||||||
|
|
||||||
|
```
|
||||||
|
5A 86 40 42 38 39 32 35 32 34 20 06 03 07 00 00 07 79 97 64 00 00 07 79 97 65
|
||||||
|
00 00 07 79 38 87 01 11 11 31 32 33 34 35 00 30 30 38 39 51 35 30 41 39 36 32
|
||||||
|
42 57 42 41 4E 43 39 32 30 39 30 FF FF FF
|
||||||
|
```
|
||||||
|
|
||||||
|
Parsed `(verified bytes; field meanings unverified)`:
|
||||||
|
- ASCII `"B892524"` + BCD `06 03 07` — looks like an ident string and a date (2006-03-07 or 07.03.06).
|
||||||
|
- Three BCD **BMW part numbers**: **7 799 764**, **7 799 765**, **7 793 887** — DDE hardware/software numbers; a parts-catalogue lookup would name the exact DDE variant. → [[open-questions]] #2
|
||||||
|
- Trailing ASCII `"12345"`, `"0089Q50"`, `"A962B"`, then **`"WBANC92090"`** + `FF` padding.
|
||||||
|
- **`WBANC92090` is a VIN prefix**: WBA = BMW, **NC9x = E60 530d** `(unverified model-code decode — check against a VIN table)`. The 7-char serial tail is not in this block. Consistent with everything else known (E60/E61, M57N + 6HP26X); a 2006 build date would make it a **530d LCI-era M57N2 (231 hp), DDE6.2-generation** `(unverified)`.
|
||||||
|
|
||||||
|
## What did NOT answer
|
||||||
|
|
||||||
|
- `1A 80` — ACKed, silent. `1A 88` — NRC 0x12 (not supported). `21 80` — NRC 0x12.
|
||||||
|
- `1A 90` (dedicated VIN read) — NRC **0x21 busyRepeatRequest** on every try (ignition-only *and* engine running once); a single-shot probe won't get it (KWP expects the tester to retry, possibly within a session). Not needed — `1A 86` gave the prefix.
|
||||||
|
- `22 F1 90` (UDS-style VIN DID) — NRC 0x10: **not a UDS ECU**, KWP2000 only — another DDE6/EDC16-era hint `(unverified)`.
|
||||||
|
|
||||||
|
## Third session: identifier scans — live data is session-locked
|
||||||
|
|
||||||
|
Engine idling, `tools/diag_scan.py` (new: sweeps an identifier space via `diag bmw`, CANRAW muted with the new `diag raw off`). Raw: `raw/diagscan-22D1-20260923-155515.log`, `raw/diagscan-21-20260923-155831.log`.
|
||||||
|
|
||||||
|
- **`22 D1 00`–`D1 FF`: nothing.** Every identifier NRCs 0x12 — the [[google-ai-dde7m57-pids]] clipping's `22 D1xx` identifiers (`D10C` boost etc.) are **confirmed wrong for this DDE** `(verified)`. (First scan ran with CANRAW on; its two "hits" are garbled NRC lines.)
|
||||||
|
- **`21 00`–`21 FF`: sparse.** Positive: `21 20` → ASCII **" O_269962 "** (Bosch software reference? — lookup candidate), `21 06`/`21 08` → one byte `05` each, `21 10` → empty reply. Many identifiers ACKed-but-silent.
|
||||||
|
- **The telling refusals:** `21 90` NRC 0x21 (busy), `21 91` NRC 0x22 (conditions not correct), `21 F0` NRC **0x33 security access denied**.
|
||||||
|
|
||||||
|
Conclusion `(verified behaviour, unverified interpretation)`: the DDE's measurement blocks exist but are **gated behind a diagnostic session** (KWP `10 xx` startDiagnosticSession, possibly plus `27` securityAccess for some) — both deliberately outside the probe's read-only whitelist. Blind probing has hit its safe limit; **the Launch capture is now the only sensible next step for live data**: it will reveal the session setup *and* the identifiers, and then replaying them is an informed decision instead of a guess.
|
||||||
|
|
||||||
|
Multi-frame TX flow control on `0x6F1` with extended addressing worked first try; `MAX_PAYLOAD` had to grow 64 → 384 (the first `1A 86` capture clipped at 192 mid-VIN). All requests single-shot, whitelisted read-only services (`1A`/`18`/`21`/`22`), zero TX failures once the bus was awake. Reminder from the first attempt of the day: **a silent bus (ignition off) shows up as "not ACKed by any node" + TWAI bus errors** — check ignition before suspecting wiring.
|
||||||
|
|
||||||
|
## Related
|
||||||
|
|
||||||
|
[[diag-route-a-2026-09-23]] · [[obd-diagnostic-polling]] · [[bmw-m57n-engine]] · [[open-questions]]
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
---
|
||||||
|
type: source
|
||||||
|
tags: [can-bus, obd, dde, kwp2000, launch, rail-pressure, live-data, capture]
|
||||||
|
updated: 2026-09-23
|
||||||
|
---
|
||||||
|
|
||||||
|
# Launch live-data capture — rail pressure decoded (2026-09-23)
|
||||||
|
|
||||||
|
The capture-with-Launch session that [[obd-diagnostic-polling]] had been pointing at since July, finally run. Engine idling, our read-only logger (`tools/serial_logger.py`) on Controller A's USB recording the full `CANRAW` stream while the Launch polled the DDE; then the user selected **Rail Pressure (actual)** and blipped to 2500 rpm for a second calibration point. Raw: `raw/serial-COM10-20260923-163511.log` (~13 MB, both halves of every exchange).
|
||||||
|
|
||||||
|
## Headline: rail pressure actual is decoded and VERIFIED
|
||||||
|
|
||||||
|
**`(verified 2026-09-23, two operating points against the Launch display)`**
|
||||||
|
|
||||||
|
| Direction | CAN ID | Payload | Meaning |
|
||||||
|
|---|---|---|---|
|
||||||
|
| Launch → DDE | `0x6F1` | `12 04 2C 10 00 DF` | target `12` (DDE), 4-byte req, service `2C` local-id `10`, operand `00 DF` |
|
||||||
|
| DDE → Launch | `0x612` | `F1 04 6C 10 HH LL` | `6C` = `2C`+0x40, id `10`, then **16-bit rail value `HHLL`** |
|
||||||
|
|
||||||
|
**Rail pressure (bar) = (HH·256 + LL) × 0.03** — linear through zero, no offset.
|
||||||
|
|
||||||
|
Calibration points (sustained, not transient):
|
||||||
|
- idle: raw `0x27EF` (10223) → 307 bar vs Launch **~305** ✓
|
||||||
|
- 2500 rpm: raw `0x3768` (14184) → 425 bar vs Launch **~430** ✓
|
||||||
|
- factor from the two points: 0.0298 and 0.0303 → adopt **0.03 bar/count** (≈ raw / 33.3)
|
||||||
|
|
||||||
|
Transient spikes to `0x4E31` (20017 → 600 bar) occurred at the instant of throttle tip-in (rail overshoot); they are real but not the steady value the gauge reads.
|
||||||
|
|
||||||
|
## How the Launch reads it — the mechanism `(observed 2026-09-23)`
|
||||||
|
|
||||||
|
The live poll is **service `2C`** (KWP dynamicallyDefineLocalIdentifier family): on connect the Launch sends `2C 10 15 E0` once (define), then polls `2C 10 00 DF` repeatedly (~200 ms), each returning a fresh `6C 10 HHLL`. So the value ID `00 DF` is the rail-pressure block. Interpreting `00 DF` / `15 E0` as memory addresses vs block numbers is unconfirmed — for replay only the request bytes matter. The Launch also runs a constant `1A 80` ident keep-alive and did `22`/`23` (readData / readMemoryByAddress) reads on connect (ident/programming data, ASCII `"090"` etc.).
|
||||||
|
|
||||||
|
### Services the Launch used — and did NOT use `(verified from the full capture)`
|
||||||
|
|
||||||
|
Every `0x6F1` request in the ~13 MB log, by service: **`1A`** (ident keep-alive), **`2C`** (live-data define/read), **`22`/`23`** (connect-time ident/memory), plus flow control. **Absent entirely: `10` StartDiagnosticSession, `27` SecurityAccess, `3E` TesterPresent.**
|
||||||
|
|
||||||
|
This is the key operational finding: **rail pressure is served in the DDE's default state — no diagnostic session, no security seed/key, no tester-present keep-alive.** The earlier `21 xx` NRCs (0x22 conditions-not-correct, 0x33 security-denied) in [[diag-route-b-2026-09-23]] were specific to the `21` read-by-local-id mechanism — a *different door* — and do **not** apply to the `2C` path. There is no secret algorithm between us and this value.
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
- **The method generalises**: any value the Launch will display can be decoded the same way — capture the `2C`/`6C` pair while its screen shows the number, calibrate scale against the display at two points. Boost, MAF, injection quantity, EGTs are each one session away. See [[obd-diagnostic-polling]] "Beyond the probe".
|
||||||
|
- **Self-poll is feasible without any secret.** To read rail pressure ourselves: send the one-time define `2C 10 15 E0`, then poll `2C 10 00 DF` → parse `6C 10 HHLL`. **No `10` session, no `27` security, no `3E` tester-present required** (proven above). The only barriers are our own choices, not the ECU's — see the two below.
|
||||||
|
- **It is still a transmit-on-the-bus action, and `2C` is not strictly read-only** (it writes a definition into the ECU's dynamic-identifier table — harmless, but a state change). So it stays outside the current probe whitelist by policy.
|
||||||
|
- **Intended home (design decision, 2026-09-23):** any active polling belongs behind a **password-protected "Diagnostics" screen** on Controller A — authorized-technician gate — never a background/automatic poller and never while a scan tool is connected. Records [[open-questions]]; not built yet.
|
||||||
|
- No EGS traffic (`0x618`) — only the DDE (`0x612`) answered; the Launch was on an engine page.
|
||||||
|
|
||||||
|
## Related
|
||||||
|
|
||||||
|
[[obd-diagnostic-polling]] · [[diag-route-b-2026-09-23]] · [[diag-route-a-2026-09-23]] · [[bmw-m57n-engine]] · [[open-questions]]
|
||||||
Reference in New Issue
Block a user