From c8e220669552cee81842393343c33b0d89972b4a Mon Sep 17 00:00:00 2001 From: MatteoCnda1 Date: Tue, 14 Apr 2026 09:50:02 +0200 Subject: [PATCH 1/5] refactor(vl53l1x): Migrate radar_screen example to steami_screen. --- lib/vl53l1x/examples/radar_screen.py | 93 ++++++++++++++-------------- 1 file changed, 48 insertions(+), 45 deletions(-) diff --git a/lib/vl53l1x/examples/radar_screen.py b/lib/vl53l1x/examples/radar_screen.py index 4965ef66..24dd44bf 100644 --- a/lib/vl53l1x/examples/radar_screen.py +++ b/lib/vl53l1x/examples/radar_screen.py @@ -2,77 +2,80 @@ Displays a real-time distance bar on the screen. The closer the object, the longer and brighter the bar, similar to a car parking sensor. -Adapted for a round display bezel. +Adapted for a round display bezel using steami_screen widgets. """ +import sys + +import micropython + +sys.path.insert(0, "/remote") + from time import sleep_ms import ssd1327 from machine import I2C, SPI, Pin +from steami_screen import DARK, GRAY, LIGHT, RED, Screen, SSD1327Display from vl53l1x import VL53L1X +# === Constants === MAX_DISTANCE_MM = 1000 -# Layout constants for the round screen -BAR_X = 24 -BAR_Y = 70 -BAR_MAX_WIDTH = 80 -BAR_HEIGHT = 15 -TEXT_LBL_X = 28 -TEXT_LBL_Y = 35 -TEXT_VAL_X = 36 -TEXT_VAL_Y = 50 -TEXT_OUT_X = 16 # Shifted left to fit the longer "Out of range" text - -i2c = I2C(1) -tof = VL53L1X(i2c) - +# === Display === spi = SPI(1) dc = Pin("DATA_COMMAND_DISPLAY") res = Pin("RST_DISPLAY") cs = Pin("CS_DISPLAY") +display = SSD1327Display(ssd1327.WS_OLED_128X128_SPI(spi, dc, res, cs)) +screen = Screen(display) + +# === Sensor === +i2c = I2C(1) +tof = VL53L1X(i2c) -display = ssd1327.WS_OLED_128X128_SPI(spi, dc, res, cs) -try: - while True: - distance = tof.read() +@micropython.native +def compute_display(distance): + """Compute proximity and color from distance value. - # Clear the display frame buffer - display.fill(0) + Returns (proximity, color) or (None, None) if out of range. + """ + if distance > MAX_DISTANCE_MM: + return None, None + proximity = MAX_DISTANCE_MM - distance + if proximity > 700: + color = RED + elif proximity > 400: + color = LIGHT + else: + color = GRAY + return proximity, color - # Clamp distance to maximum range and compute integer proximity - clamped_dist = max(0, min(distance, MAX_DISTANCE_MM)) - proximity = MAX_DISTANCE_MM - clamped_dist - # Map proximity to bar width (max 80px) and brightness (max 15) - bar_width = (80 * proximity) // MAX_DISTANCE_MM - brightness = (15 * proximity) // MAX_DISTANCE_MM +try: + while True: + distance = tof.read() - # If the object is within the detection range, ensure minimum visibility - if distance <= MAX_DISTANCE_MM: - bar_width = max(1, bar_width) - brightness = max(1, brightness) + 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") + screen.subtitle("Out of range") else: - display.text("{} mm".format(distance), TEXT_VAL_X, TEXT_VAL_Y, 15) - - # Send the buffer to the physical screen - display.show() + screen.gauge(proximity, min_val=0, max_val=MAX_DISTANCE_MM, color=color) + screen.value(str(distance), unit="mm") + screen.subtitle("Distance") + screen.show() sleep_ms(50) except KeyboardInterrupt: pass + finally: - # Clear the screen on exit or error - display.fill(0) - display.show() + screen.clear() + screen.show() From ca8306196b5c98a2d2a386c253c4f85fa42ccbda Mon Sep 17 00:00:00 2001 From: MatteoCnda1 Date: Tue, 14 Apr 2026 10:27:47 +0200 Subject: [PATCH 2/5] refactor(vl53l1x): Clean up radar_screen.py by removing imports. refactor(vl53l1x): Removed unused imports and sys.path modification. --- lib/vl53l1x/examples/radar_screen.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/vl53l1x/examples/radar_screen.py b/lib/vl53l1x/examples/radar_screen.py index 24dd44bf..13b6dc65 100644 --- a/lib/vl53l1x/examples/radar_screen.py +++ b/lib/vl53l1x/examples/radar_screen.py @@ -5,12 +5,8 @@ Adapted for a round display bezel using steami_screen widgets. """ -import sys - import micropython -sys.path.insert(0, "/remote") - from time import sleep_ms import ssd1327 From 88119c7e4e60b30c769ebf12d02b6081af2588a9 Mon Sep 17 00:00:00 2001 From: MatteoCnda1 Date: Tue, 14 Apr 2026 10:34:20 +0200 Subject: [PATCH 3/5] refactor(vl53l1x): Reorder micropython import statement. --- lib/vl53l1x/examples/radar_screen.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/vl53l1x/examples/radar_screen.py b/lib/vl53l1x/examples/radar_screen.py index 13b6dc65..ff3da05b 100644 --- a/lib/vl53l1x/examples/radar_screen.py +++ b/lib/vl53l1x/examples/radar_screen.py @@ -5,10 +5,9 @@ Adapted for a round display bezel using steami_screen widgets. """ -import micropython - from time import sleep_ms +import micropython import ssd1327 from machine import I2C, SPI, Pin from steami_screen import DARK, GRAY, LIGHT, RED, Screen, SSD1327Display From ccdce326b29666f376d27dd6003261d5c9e9c630 Mon Sep 17 00:00:00 2001 From: MatteoCnda1 Date: Tue, 14 Apr 2026 10:52:24 +0200 Subject: [PATCH 4/5] ci: Trigger checks rerun. From 2126edc9fc28697b214498039ab72650b5033fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Thu, 16 Apr 2026 21:46:58 +0200 Subject: [PATCH 5/5] fix(vl53l1x): Fix gauge/title draw order and subtitle label in radar_screen. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- lib/vl53l1x/examples/radar_screen.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/vl53l1x/examples/radar_screen.py b/lib/vl53l1x/examples/radar_screen.py index ff3da05b..ca1c9c2e 100644 --- a/lib/vl53l1x/examples/radar_screen.py +++ b/lib/vl53l1x/examples/radar_screen.py @@ -52,18 +52,23 @@ def compute_display(distance): distance = tof.read() screen.clear() - screen.title("RADAR") proximity, color = compute_display(distance) + # Draw gauge first so that title/value text layers on top of the arc if proximity is None: screen.gauge(0, min_val=0, max_val=MAX_DISTANCE_MM, color=DARK) + else: + screen.gauge(proximity, min_val=0, max_val=MAX_DISTANCE_MM, color=color) + + screen.title("RADAR") + + if proximity is None: screen.value("----", unit="mm") screen.subtitle("Out of range") else: - screen.gauge(proximity, min_val=0, max_val=MAX_DISTANCE_MM, color=color) screen.value(str(distance), unit="mm") - screen.subtitle("Distance") + screen.subtitle("Proximity") screen.show() sleep_ms(50)