refactor(vl53l1x): Migrate radar_screen example to steami_screen.#391
refactor(vl53l1x): Migrate radar_screen example to steami_screen.#391MatteoCnda1 wants to merge 4 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Migrates the vl53l1x radar screen example from direct SSD1327/framebuf drawing to the higher-level steami_screen widget API, to simplify layout/rendering and align examples with the widget-based display approach.
Changes:
- Replaced manual framebuf drawing with
Screenwidgets (title,value,subtitle,gauge) usingSSD1327Display. - Added a
compute_display()helper to map distance → proximity + color. - Simplified cleanup by clearing and showing the screen in a
finallyblock.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lib/vl53l1x/examples/radar_screen.py
Outdated
| import sys | ||
|
|
||
| import micropython | ||
|
|
||
| sys.path.insert(0, "/remote") | ||
|
|
There was a problem hiding this comment.
sys.path.insert(0, "/remote") is unusual for a library example and can change module resolution (shadowing installed packages) for anyone running this on-device. Since this example already imports from standard locations (vl53l1x, steami_screen, etc.), please remove this path mutation (or gate it behind a clearly documented, opt-in dev-only flag).
| import sys | |
| import micropython | |
| sys.path.insert(0, "/remote") | |
| import micropython |
| screen.clear() | ||
| screen.title("RADAR") | ||
|
|
||
| # Draw the outline box (1 pixel larger than the max bar size) at max brightness | ||
| display.framebuf.rect(BAR_X - 1, BAR_Y - 1, BAR_MAX_WIDTH + 2, BAR_HEIGHT + 2, 15) | ||
| # Draw the distance bar centered: x=24, y=70, max_width=80, height=15 | ||
| display.framebuf.fill_rect(BAR_X, BAR_Y, bar_width, BAR_HEIGHT, brightness) | ||
| proximity, color = compute_display(distance) | ||
|
|
||
| # Display distance or "Out of range" | ||
| if distance > MAX_DISTANCE_MM: | ||
| display.text("Out of range", TEXT_OUT_X, TEXT_VAL_Y, 15) | ||
| if proximity is None: | ||
| screen.gauge(0, min_val=0, max_val=MAX_DISTANCE_MM, color=DARK) | ||
| screen.value("----", unit="mm") |
There was a problem hiding this comment.
Screen.gauge()'s docstring notes it should be called before title() so the title text layers on top of the arc. Here screen.title("RADAR") is drawn first, then screen.gauge(...), which can cause the gauge arc to overwrite the title depending on geometry. Please swap the call order (draw gauge first, then title/value/subtitle).
| display.show() | ||
| screen.gauge(proximity, min_val=0, max_val=MAX_DISTANCE_MM, color=color) | ||
| screen.value(str(distance), unit="mm") | ||
| screen.subtitle("Distance") |
There was a problem hiding this comment.
The gauge min/max labels currently reflect proximity (0..1000) because proximity is passed as the gauge value, but the center value() and subtitle are labeled as distance in mm. This makes the on-screen gauge labels misleading (0 means “far”, not “0 mm”). Consider either (a) passing distance to gauge() and inverting the range (so the arc grows as distance decreases), or (b) updating the labels/subtitle to explicitly indicate proximity rather than distance.
| screen.subtitle("Distance") | |
| screen.subtitle("Distance (arc=proximity)") |
refactor(vl53l1x): Removed unused imports and sys.path modification.
613623e to
ccdce32
Compare
Summary
Migrate the
radar_screen.pyexample from direct SSD1327 usage to thesteami_screenwidget library. Closes #375Changes
display.framebuf.rect/fill_rect/textcalls withsteami_screenwidgets (screen.gauge(),screen.value(),screen.subtitle(),screen.title())@micropython.nativedecorator oncompute_display()for better rendering performancescreen.clear()/screen.show()in thefinallyblockBAR_X,BAR_Y, etc.) — layout is now handled bysteami_screenChecklist
ruff checkpassespython -m pytest tests/ -k mock -vpasses (no mock test broken)lib/vl53l1x/examples/radar_screen.py)<scope>: <Description.>format