Spinner test works sortof

This commit is contained in:
Thomas Farstrike
2025-04-22 14:22:37 +02:00
parent a0b0f0581e
commit c5728383f6
+20 -47
View File
@@ -1,21 +1,20 @@
import lvgl as lv
import time
import random
import display_driver # Replace with your display driver (e.g., ILI9341, ST7796)
# Configuration
SPINNER_SIZE = 20 # Size of each spinner in pixels
UPDATE_INTERVAL_MS = 1000 # Add spinner and update metrics every 100ms
UPDATE_INTERVAL_MS = 3000 # Add spinner and update metrics every 100ms
# Global variables
spinner_count = 0
metrics_label = None
def add_spinner_and_update(timer):
"""Add a new spinner and update on-screen metrics."""
canary = lv.obj(lv.screen_active())
canary.add_flag(0x0001) # LV_OBJ_FLAG_HIDDEN is 0x0001
def add_spinner_and_update():
global spinner_count, metrics_label
try:
# Create spinner with only parent argument
spinner = lv.spinner(lv.screen_active())
spinner.set_size(SPINNER_SIZE, SPINNER_SIZE)
spinner.set_pos(
@@ -27,55 +26,29 @@ def add_spinner_and_update(timer):
print(f"Failed to create spinner {spinner_count + 1}: {e}")
return
# Update metrics
if metrics_label:
metrics_label.set_text(f"Spinners: {spinner_count}")
metrics_label.set_text(f"Spinners: {spinner_count}")
print(f"Added spinner {spinner_count}")
def run_benchmark():
global spinner_count, metrics_label
print("Starting LVGL spinner benchmark...")
# Initialize LVGL and screen
try:
lv.init()
except Exception as e:
print(f"Failed to initialize LVGL: {e}")
return
scr = lv.screen_active()
scr.set_style_bg_color(lv.color_black(), 0)
# Create metrics label
try:
metrics_label = lv.label(scr)
metrics_label.set_style_text_color(lv.color_white(), 0)
metrics_label.set_style_bg_color(lv.color_black(), 0)
metrics_label.set_style_bg_opa(lv.OPA.COVER, 0)
metrics_label.set_pos(10, 10)
metrics_label.set_text("Spinners: 0")
except Exception as e:
print(f"Failed to create metrics label: {e}")
return
metrics_label = lv.label(scr)
metrics_label.set_style_text_color(lv.color_white(), 0)
metrics_label.set_style_bg_color(lv.color_black(), 0)
metrics_label.set_style_bg_opa(lv.OPA.COVER, 0)
metrics_label.set_pos(10, 10)
metrics_label.set_text("Spinners: 0")
# Create timer for adding spinners and updating metrics
try:
lv.timer_create(add_spinner_and_update, UPDATE_INTERVAL_MS, None)
except Exception as e:
print(f"Failed to create timer: {e}")
return
# Run indefinitely until user resets the board
try:
while True:
lv.task_handler()
time.sleep_ms(10) # Yield to LVGL tasks
except Exception as e:
print(f"Test failed: {e}")
while canary.get_class():
add_spinner_and_update()
time.sleep_ms(UPDATE_INTERVAL_MS)
if __name__ == "__main__":
try:
run_benchmark()
except Exception as e:
print(f"Error in benchmark: {e}")
try:
run_benchmark()
except Exception as e:
print(f"Error in benchmark: {e}")