Skip to content

refactor(vl53l1x): Migrate radar_screen example to steami_screen.#391

Open
MatteoCnda1 wants to merge 4 commits intomainfrom
refactor/vl53l1x-radar-screen
Open

refactor(vl53l1x): Migrate radar_screen example to steami_screen.#391
MatteoCnda1 wants to merge 4 commits intomainfrom
refactor/vl53l1x-radar-screen

Conversation

@MatteoCnda1
Copy link
Copy Markdown

Summary

Migrate the radar_screen.py example from direct SSD1327 usage to the steami_screen widget library. Closes #375

Changes

  • Replaced manual display.framebuf.rect/fill_rect/text calls with steami_screen widgets (screen.gauge(), screen.value(), screen.subtitle(), screen.title())
  • Added @micropython.native decorator on compute_display() for better rendering performance
  • Color changes dynamically based on proximity: gray → light → red as object gets closer
  • Cleaner error handling with screen.clear() / screen.show() in the finally block
  • Removed manual layout constants (BAR_X, BAR_Y, etc.) — layout is now handled by steami_screen

Checklist

  • ruff check passes
  • python -m pytest tests/ -k mock -v passes (no mock test broken)
  • Tested on hardware (STM32WB55 / STeaMi board)
  • README updated (if adding/changing public API) — N/A, example only
  • Examples added/updated (lib/vl53l1x/examples/radar_screen.py)
  • Commit messages follow <scope>: <Description.> format
    IMG_0844

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Screen widgets (title, value, subtitle, gauge) using SSD1327Display.
  • Added a compute_display() helper to map distance → proximity + color.
  • Simplified cleanup by clearing and showing the screen in a finally block.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +8 to +13
import sys

import micropython

sys.path.insert(0, "/remote")

Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
import sys
import micropython
sys.path.insert(0, "/remote")
import micropython

Copilot uses AI. Check for mistakes.
Comment on lines +59 to +66
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")
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
display.show()
screen.gauge(proximity, min_val=0, max_val=MAX_DISTANCE_MM, color=color)
screen.value(str(distance), unit="mm")
screen.subtitle("Distance")
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
screen.subtitle("Distance")
screen.subtitle("Distance (arc=proximity)")

Copilot uses AI. Check for mistakes.
@MatteoCnda1 MatteoCnda1 force-pushed the refactor/vl53l1x-radar-screen branch from 613623e to ccdce32 Compare April 14, 2026 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(vl53l1x): Migrate radar_screen example to steami_screen.

2 participants