Repository navigation
Conversation
The rev_c mock never set sub_revision/rom_version, which are now detected by the hello handshake in the serial driver, so the image tests raised AttributeError before sending anything. The mock now provides the same defaults the handshake detects on a 5-inch C screen (REV_5INCH, rom 87). Six full-screen/partial goldens were recorded before the bitmap-size payload field was added to the display command and were refreshed; the only change in them is that field going from 0x0000 to 0x0E10.
When the producer (stats refresh) is faster than the serial device can transfer, the update queue grew without bound: every intermediate frame was still transmitted, so the screen showed ever older data and shutdown had to drain a stale backlog. The queue writer now works on "transmission units" (TUs) instead of plain FIFO items: Queue items became (fn, args, region_key, tu_id): - Region-based requests (DisplayPILImage/DisplayLineGraph and the window command + data chunks they emit) are tagged with the device-coordinate region they paint and a per-image transmission unit id, by beginning a TU in the driver before queuing and ending it afterwards (LcdComm._begin_tu/_end_tu/_queue_request, mutex-protected, RLock so a nested SendCommand() joins the outer TU). - Everything else (control commands, pacing sleeps, reads) keeps (None, None) and is never reordered or dropped. scheduler._process_update_queue() drains the queue in one go and: - keeps only the newest TU per region, placed at the position where the region first appeared, so regions keep their relative order while stale frames are dropped; - skips a TU whose serialized device payload is byte-identical to the last one transmitted for that region (dedup cache on the driver, _last_sent_payload, cleared by every Clear()/Reset() since the screen content is then lost). Consequences: - Displayed data is at most one in-flight frame old instead of N-frames-behind-and-growing; graph values are rendered from the full sample history each frame, so dropping a superseded frame never skips a sample on the time axis; a region is only skipped when the device already shows exactly the same bytes. - With update_queue unset (direct mode, library API users) nothing is queued at all, so the byte stream to the device is unchanged; existing per-rev golden tests pass untouched. - Only serial revisions use the queue: TUR_USB and SIMU drivers are covered by a source test that they must not gain queue usage. - On SIGINT/SIGTERM the queue is drained to completion (was: 5 s cap on a stale backlog) with the same coalescing, so shutdown is faster. New tests: scheduler unit tests for grouping/supersession/dedup/ stopping (tests/library/test_scheduler.py), per-driver supersession and dedup checks (rev_a), queued sleep handling (rev_b), write+read pair staying in one TU (rev_c), queue-usage source guard. All 54 tests pass; also validated on real hardware (rev A) under sustained CPU/disk load: queue backlog drains in ~0 s at shutdown, RSS flat over 2 minutes.
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.
Summary
This PR bundles three independent improvements; each is self-contained and can be reviewed commit-by-commit (the commits are grouped by topic):
--config/-cCLI option andTURING_CONFIG_FILEenvironment variable, to keep a personal configuration outside the install treemain(hello-handshake attributes missing in the mock)No breaking changes: existing invocations,
config.yaml/ theme schemas and the publicLcdCommAPI keep working unchanged.1. Configuration file selection (
--config/TURING_CONFIG_FILE)Why
The configuration file is hardcoded to
config.yamlnext to the code (library/config.pyloadsMAIN_DIRECTORY / "config.yaml"at import time,configure.pyreads/writes the same path). Packaged/distribution installs (e.g./usr/local/opt/turing-smart-screen/) force users to edit the file inside the install tree, which is clobbered on every update and cannot be kept under personal version control.What
main.py,configure.py,theme-editor.py) accept--config <path>/-c <path>to select the configuration file (and, inconfigure.py, the file to save back).TURING_CONFIG_FILEenvironment variable selects the same file, so systemd services and packaged launchers can set it without command-line plumbing (atools/turing-smart-screen-python.serviceexample is included).--config>TURING_CONFIG_FILE> default (<install>/config.yaml— today's behavior).library/config_path.py, shared by all entry points; it runs inlibrary/config.pybeforeCONFIG_DATAis loaded. An unusable/unreadable/invalid path fails fast with a clear error naming the path and exits non-zero.res/themes/...and bundled fonts.theme-editor.py's strictlen(sys.argv) != 2check became a real argparse parser so the positional theme name coexists with the new option.2. Bounded display lag: coalescing + deduplication in the update queue
Why
Under sustained load the scheduler pushes every redraw into an unbounded FIFO (
config.update_queue) drained by one QueueHandler at the device's physical rate. When redraw demand approaches the drain rate (measured on a 3.5" Rev A / CDC-ACM setup: demand ~111 KB/s vs effective ~135 KB/s), any CPU/GIL contention starts a backlog: every queued frame is a snapshot of the past, lag grows without bound, and stale frames are sent even when newer values already exist.What
config.yamlschema andLcdCommsignatures are untouched.Effect
Displayed data lags at most by the transmission of one current frame per region instead of accumulating; backlog no longer grows memory.
Relation to #1049
#1049 coalesces widget updates for the TUR_USB driver only (full-frame, rate-limited). This change works one level up — in the shared queue/scheduler pipeline — so it benefits the serial revisions (A/B/C/D, WeAct) with region-level freshness guarantees and per-region dedup. The two approaches are complementary, not conflicting.
3. Fix rev_c golden tests
The rev_c test mock never set
sub_revision/rom_version, which are now detected by the hello handshake in the serial driver, so the image tests raisedAttributeErrorbefore sending anything. The mock now provides the same defaults a 5-inch C screen reports (REV_5INCH, rom 87). Six goldens recorded before the bitmap-size payload field existed were refreshed; the only change in them is that field going from0x0000to0x0E10.Test plan
pytest testson Linux: 72 passed, 2 skipped (platform-conditional skips)Development notes
These changes were developed with an AI coding assistant (opencode), under my review and supervision — I read, tested and take responsibility for every line in the diff.