Repository navigation
Show firmware update progress and results on the controller screen - #134
Open
zjwhitehead wants to merge 10 commits into
Open
zjwhitehead wants to merge 10 commits into
zjwhitehead wants to merge 10 commits into
Conversation
…sted From an audit against defects found while testing the Rust port: - Never suppress the throttle command unless DISARMED. A relay request reports active as soon as it is queued, before the session rejects it for being armed, so each relay write from a bonded client in flight dropped a throttle frame. - Clear the TWAI transmit queue once frames have been waiting for two 20 ms cycles. With the ESC not acknowledging, about 36 old commands were kept and replayed oldest-first on reconnect while current ones were dropped. - Recover from bus-off. Previously the controller stayed off the bus until the next power cycle. - Guard setESCThrottle when the TWAI driver failed to install. - TWAI receive queue 5 -> 32: one telemetry reply is exactly five frames. - Alert event queue 20 -> 64: an ESC disconnect emits 25 events at once and dropped events leave stale alerts on screen. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
8.1 adds the ESC relay characteristics ahead of telemetry and the update service, which moves every later attribute. A bonded phone caches where attributes were, and nothing told it they had moved, so after updating from 8.0 a phone can subscribe to the wrong attribute and never receive telemetry. Android works around this in the app; iOS has no way to. On the first boot of a new build with a bond present, raise the standard Service Changed indication once. The stack records it against each stored bond and delivers it when that phone reconnects. The build is identified by the image's ELF hash, kept in its own NVS namespace. Bench: fires once on the first boot of a new build and not again; boots cleanly with an existing bond. Not yet verified with a phone, which is the part that matters. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
8.0 requested the faster connection parameters after esp_ota_begin(). The update hardening moved the request ahead of it so the longer supervision timeout would cover the erase. In practice the phone schedules the change while the erase has the radio stalled, the two sides end up on different timing, and the link dies exactly one supervision timeout (6 s) later with the start command unanswered. Bench, Pixel 9 Pro, target slot holding a full image so the erase takes about 2 s: before, 1 of 4 starts got through (and 3 of 4 failed in an earlier mixed set); after, 8 of 8. Starts with a short erase (slot already blank) were not affected. Restores the 8.0 order and keeps the 6 s timeout value. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Ten host tests that replay each loss case mid-transfer (acknowledgement lost, final packet lost, first or middle packet lost, stale packets, re-send after the idle abort) and check the ACK sequence, that the flash image still matches, and that each sector is written exactly once. They pin the behaviour the phone apps' retry rule relies on. No firmware change. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The stored build record misses one case: this build ran on the controller before, 8.0 (which keeps no record) was installed and a phone paired with it, and the same build was then installed again. Nothing looked new, no notice went out, and an iPhone was left on the 8.0 layout until re-paired. Seen on the bench with an iPhone 11. The first boot after any over-the-air update is still unconfirmed when Bluetooth starts, so treat that as a new build too. Bench: the same build installed three times from the iPhone with 8.0 and a fresh pairing in between; the notice printed each time and telemetry was back in about 2.9 s each time. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
When the ESC stopped acknowledging, 6cfb50e cleared the TWAI transmit queue, but twai_clear_transmit_queue() in the pinned ESP-IDF 4.4.7 driver leaves the frame already loaded in the controller's transmit buffer. The controller retries that frame until something acknowledges it, so the throttle command from the moment the ESC went silent was the first thing the ESC acted on when it came back. On a stall the driver is now stopped and restarted instead: twai_stop() puts the controller in reset mode, which halts that transmission (twai_hal_stop), and twai_start() puts it straight back on the bus before the current command is queued. The same reconnect check found a second path. While the controller is off the bus (bus-off, recovering, stopped) twai_transmit() refuses every frame and libcanard keeps them, so after recovery 32 old commands went out first and the current one had been refused because the 1 KiB pool was full. The transport queue is now emptied on a stall or whenever the driver is not running. The pinned CanardAdapter has no call for that, so a node that accepts nothing is registered on it to reach the shared libcanard queue. New native-emu-can environment (added to CI) runs the real esc.cpp with the pinned SINE-ESC-CAN CanardAdapter, SineEsc and libcanard against a model of the IDF 4.4.7 TWAI driver. Before this change 4 of 6 tests failed: on reconnect after 5 s silent at full power the ESC received {19000, 10350} instead of {10350}, and after bus-off recovery it received 32 copies of the bus-off era command and not the current one. Disabling either half of the fix fails its two tests. On reconnect the ESC can still receive the command from the previous 20 ms cycle, the same age as on a healthy bus. Not run against a real ESC. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
BMS_CAN::begin() (Adafruit MCP2515 0.2.1) sets RXB0 to receive any message with rollover off. Per the MCP2515 data sheet (4.2.1 and the receive flowchart), a frame that arrives while RXB0 is still full is then dropped with EFLG.RX0OVR set, and RXB1 is never used. The INT pin is not used and bmsTask drains the chip every 100 ms, so the controller kept only the first BMS frame of each 100 ms window and silently lost the rest, newer values included. The link still reads connected because any frame refreshes it, so the pilot sees pack voltage, current, SOC, power, cell voltages or temperatures that may be older than they look, with no indication. After BMS_CAN::begin(), RXB0CTRL is now written with rollover enabled (the same value Linux's mcp251x driver uses), so a second frame waits in RXB1. On every drain EFLG.RX0OVR/RX1OVR are read, counted and cleared, and the total is logged on USB serial at most every 10 s. BMS_CAN keeps its MCP2515 private, so this uses a second Adafruit_SPIDevice with the library's chip select and SPI settings, inside the same SPI bus mutex. Loss is reduced and now visible, not prevented: a third frame inside one 100 ms window, or frames arriving while the display holds the shared SPI bus, are still dropped by the chip. Preventing it would need the MCP2515 interrupt or a faster drain; the counter is there to show from a real pack whether that is needed. The native-emu-can environment now also runs the pinned Adafruit MCP2515 driver and BMS_CAN against a model of the MCP2515 receive buffers. With the rollover write removed (today's configuration), 2 of 4 tests fail: the second of two frames between drains is lost (highest cell 0 instead of 4.120 V; pack voltage left at the older 50.3 V instead of 50.2 V). With it, all 4 pass. Not run against a real BMS. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
handleThrottle() copied a setpoint from the BLE throttle characteristic straight into the cruise output, so a phone moving cruise from 1100 to 1600 us stepped the motor by 500 us in one 20 ms tick, where the lever is limited to 8 us (chill) or 27 us (sport) per tick up and twice that down. The range check (idle to CRUISE_MAX_PWM) also lived only in the BLE handler, not where the value is used. The cruise branch now calls cruiseOutputTick() in throttle.cpp: the setpoint latches the output being flown on entry as before, a BLE setpoint replaces it only if isCruiseSetpointAllowed() (the same rule the BLE handler now shares), and the output reaches it through applyModeRampClamp(), the ramp and clamp armed throttle uses. Arming state is checked at both ends as before. The performance-mode write is untouched, so changing mode while armed with the throttle off still applies on the next tick. Before the fix, 2 of 4 new test_throttle tests failed: the first tick after a 1600 us setpoint output 1600 instead of 1108 (chill) / 1127 (sport), the first tick back down output 1035 instead of 1584 / 1546, and setpoints 1681, 1950, 1000 and 65535 reached the output. native-test now passes 132 of 132. Not run on hardware. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Port of 7eec357 (PR 134) onto the 8.1 line. While a Bluetooth firmware update runs, the controller shows a full-screen view of the phase (preparing, receiving with a percentage and bar, checking, restarting) and then the result: complete with the new version, or the reason it failed. Where the PR and 8.1 disagreed about update behaviour, 8.1 is kept: the START refusal codes, the deferred reboot, the arming guard, advertising before validation, and the connection-timing request after the flash erase. No wire format, UUID or ACK changes. The update code only publishes a status copy into a one-slot queue; the UI task reads it without taking the update lock, so nothing in the transfer waits on the display. The update screen is published only after the armed check passes and is shown only while disarmed. While it or a result is up, button gestures are swallowed and arming is refused, but the button can always disarm. A one-shot NVS receipt naming the target slot is written just before the post-update reboot, from the timeout task rather than a Bluetooth callback, and only drives the result screen. A rollback is reported only when the bootloader marked the target slot invalid; a stale receipt is cleared silently. Fonts use 8.1's hinted set (20 becomes 18). The 24 update-screen reference images and the two review sheets are rendered with those fonts; each was checked in both themes at 160x128 with every label on one line and nothing clipped or overlapping. No other reference image changed. Host tests cover the status and receipt handling in the BLE update emulation and the stand-alone service tests. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
zjwhitehead
force-pushed
the
codex/ota-update-screen
branch
from
November 16, 2026 16:15
7eec357 to
1d3c13a
Compare
A failed update left its result on screen for 10 seconds, and a successful one for 3.5 seconds after the reboot. During that time every button press was swallowed and arming was refused, so a pilot pressing the button got no response. While a transfer is running (preparing through restarting) nothing changes: every gesture is consumed and arming is refused. On a result screen, the first fresh press now dismisses it. That press is consumed through its release and counts toward no gesture; after it, input is normal and the next arm gesture works at once. A press held since the transfer does not dismiss. A result nobody touches still closes after its timeout, and an armed press is never filtered, so disarming cannot be blocked. The button task's filter moves from main.cpp into otaFilterButton() in the update service, so host tests can drive it. A dismissal stores the result's status revision in an atomic. The UI task reads the atomic through readOtaScreen() and closes the screen on its next tick. Neither task takes the update lock or waits for the other, and a new update publishes a newer revision, so its screen shows again. The throttle, cruise, ESC and BMS code and the update protocol are not touched, and no reference image changed. The new update-emulation tests cover a press on a failure result and on the completion screen, an arm gesture straight after a dismissal, presses during a transfer and the restart window, a button held into a result, untouched results timing out, a new update after a dismissal, and an armed press. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Firmware updates started from Android or iOS previously left the normal flight screen visible. This adds a full-screen update flow with preparation, progress based on bytes successfully written, verification, automatic restart, and readable failure states. After reboot, a brief completion screen shows the running firmware version.
The existing BLE UUIDs, command/sector formats, and acknowledgments are preserved. Screen updates stay in the UI task, progress redraws are limited to 4 Hz, and button gestures are consumed while a transfer is running. On a result screen (a failure, or the completion screen after the update boot) the first press dismisses it and input is normal from the next press; left alone, it still clears after 10 s or 3.5 s. Disarming is never blocked. A persisted target-slot receipt distinguishes successful startup from rollback.
Now targets 8.1
This PR was one commit on
master. It is now the same screen ported to the 8.1 line, as two commits on top of the fixes in #141, and its base isrelease/8.1-rc. Until #141 merges, this PR also lists #141's eight commits; the screen is the last two commits only.Screenshots
Rendered from the production LVGL screen at the device's 160 × 128 resolution, enlarged for review.
Light and dark themes, including error states
Validation
All on a computer, on the head commit:
Not done: flashing a controller and running a live transfer from Android or iOS with this screen. The installed firmware must already contain this UI to display progress during a transfer.
Known
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.