refactor(vl53l1x): Migrate radar_screen example to steami_screen.#391
refactor(vl53l1x): Migrate radar_screen example to steami_screen.#391
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.
| 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
…screen. Address Copilot review comments on #391: 1. Call screen.gauge() before screen.title() so the title text layers on top of the arc, as documented in gauge()'s docstring. 2. Change subtitle from "Distance" to "Proximity" — the gauge shows proximity (inverted distance: arc grows as object gets closer), so labelling it "Distance" was misleading.
nedseb
left a comment
There was a problem hiding this comment.
Bonne migration Matteo. Le passage de display.framebuf.* manuels vers les widgets steami_screen rend le code beaucoup plus lisible, et les couleurs dynamiques selon la proximité sont un bon ajout.
Copilot avait relevé 3 points. Le premier (sys.path.insert) a été corrigé dans tes commits de cleanup. J'ai poussé un commit (2126edc) pour les deux restants :
1. Ordre d'appel gauge/title — la docstring de gauge() précise qu'il faut l'appeler avant title() pour que le texte se dessine par-dessus l'arc. L'ancien ordre dessinait le titre d'abord, ce qui pouvait le faire recouvrir par l'arc.
2. Subtitle "Distance" �� "Proximity" — la jauge affiche la proximité (valeur inversée : l'arc grandit quand l'objet se rapproche), mais le subtitle disait "Distance". C'était incohérent pour l'utilisateur : "Distance 200 mm" avec un arc presque plein (= très proche) est contre-intuitif. Renommé en "Proximity" pour refléter ce que la jauge montre visuellement.
Prêt à merger.
|
🎉 This PR is included in version 0.20.3 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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