Skip to content

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

Merged
nedseb merged 5 commits intomainfrom
refactor/vl53l1x-radar-screen
Apr 16, 2026
Merged

refactor(vl53l1x): Migrate radar_screen example to steami_screen.#391
nedseb merged 5 commits intomainfrom
refactor/vl53l1x-radar-screen

Conversation

@MatteoCnda1
Copy link
Copy Markdown
Contributor

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 thread lib/vl53l1x/examples/radar_screen.py Outdated
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.
Comment thread lib/vl53l1x/examples/radar_screen.py Outdated
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
…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.
Copy link
Copy Markdown
Contributor

@nedseb nedseb left a comment

Choose a reason for hiding this comment

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

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.

@nedseb nedseb merged commit 960c44b into main Apr 16, 2026
9 checks passed
@nedseb nedseb deleted the refactor/vl53l1x-radar-screen branch April 16, 2026 19:49
@semantic-release-updater
Copy link
Copy Markdown

🎉 This PR is included in version 0.20.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(vl53l1x): Migrate radar_screen example to steami_screen.

3 participants