Fullscreen all apps - no more subwindow

This commit is contained in:
Thomas Farstrike
2025-05-04 21:51:54 +02:00
parent fd0fc309c5
commit b46756bf03
15 changed files with 387 additions and 257 deletions
+238
View File
@@ -0,0 +1,238 @@
# Initialize
import display_driver
import lvgl as lv
import lvgl
label = lvgl.label( lvgl.screen_active() )
label.set_text( 'hi' )
animation = lvgl.anim_t()
animation.init()
animation.set_var( label )
animation.set_values( 0, 100 )
animation.set_time( 1000 )
animation.set_custom_exec_cb( lambda not_used, value : label.set_x( value ))
#wait half a second before starting animation
animation.set_delay( 500 )
#play animation backward for 1 second after first play
animation.set_playback_time( 1000 )
#repeat animation infinitely
animation.set_repeat_count( 10 )
#animation.set_repeat_count( lvgl.ANIM_REPEAT.INFINITE )
animation.set_repeat_delay( 500 )
animation.start()
******************************
# Initialize
import display_driver
import lvgl as lv
import lvgl
#create the slow short label
label1 = lvgl.label( lvgl.screen_active() )
label1.set_text( 'hello 1' )
label1.align( lvgl.ALIGN.CENTER, 0, -50 )
anim1 = lvgl.anim_t()
anim1.init()
anim1.set_var( label1 )
#anim1.set_time( lvgl.anim_speed_to_time( 20, 0, 100 ))
anim1.set_time( 2000 )
anim1.set_values( 0, 100 )
anim1.set_repeat_count( 10 )
anim1.set_repeat_delay( 2000 )
anim1.set_custom_exec_cb( lambda not_used, value : label1.set_x( value ))
#create the fast long label
label2 = lvgl.label( lvgl.screen_active() )
label2.set_text('hello 2')
label2.align(lvgl.ALIGN.CENTER,-100,0)
anim2 = lvgl.anim_t()
anim2.init()
anim2.set_var( label2 )
#anim2.set_time( lvgl.anim_speed_to_time( 40, -100, 100 ))
anim2.set_time( 40 * 200 )
anim2.set_values( -100, 100 )
anim2.set_custom_exec_cb( lambda not_used, value : label2.set_x( value ))
anim2.set_repeat_count( 10)
anim2.set_repeat_delay( 2000 )
#Create the fast short label
label3 = lvgl.label( lvgl.screen_active() )
label3.set_text( 'hello 3' )
label3.align( lvgl.ALIGN.CENTER, -100, 50 )
anim3 = lvgl.anim_t()
anim3.init()
anim3.set_var( label3 )
#anim3.set_time( lvgl.anim_speed_to_time( 40, -100, 0 ))
anim3.set_time( 40 * 100)
anim3.set_values( -100, 0)
anim3.set_custom_exec_cb( lambda not_used, value : label3.set_x( value ))
anim3.set_repeat_count( 10 )
anim3.set_repeat_delay( 40 * 100 + 2000 )
#anim3.set_repeat_delay( lvgl.anim_speed_to_time( 40, -100, 0) + 2000 )
#lvgl.anim_speed_to_time( 1, 2, 3)
#anim3.set_repeat_delay( 5000)
#lvgl.anim
anim1.start()
anim2.start()
anim3.start()
******************
# Initialize
import display_driver
import lvgl as lv
import lvgl
import lvgl
#normal animation
label1 = lvgl.label( lvgl.screen_active() )
label1.set_text( 'hello 1' )
label1.align( lvgl.ALIGN.CENTER, -70, -60 )
anim1 = lvgl.anim_t()
anim1.init()
anim1.set_var( label1 )
anim1.set_time( 1000 )
anim1.set_values( -70, 20 )
anim1.set_repeat_count( 100 )
anim1.set_repeat_delay( 2000 )
anim1.set_custom_exec_cb( lambda not_used, value : label1.set_x( value ))
#this animation bounces the label when it ends
label2 = lvgl.label( lvgl.screen_active() )
label2.set_text( 'hello 2' )
label2.align( lvgl.ALIGN.CENTER, 30, -60 )
anim2 = lvgl.anim_t()
anim2.init()
anim2.set_var( label2 )
anim2.set_time( 1000 )
anim2.set_values( 30, 120 )
anim2.set_custom_exec_cb( lambda not_used, value : label2.set_x( value ))
anim2.set_repeat_count( 100)
anim2.set_repeat_delay( 2000 )
anim2.set_path_cb( lvgl.anim_t.path_bounce )
#this animation goes past the end point then comes back
label3 = lvgl.label( lvgl.screen_active() )
label3.set_text( 'hello 3' )
label3.align( lvgl.ALIGN.CENTER, -70, 60 )
anim3 = lvgl.anim_t()
anim3.init()
anim3.set_var( label3 )
anim3.set_time( 1000 )
anim3.set_values( -70, 20 )
anim3.set_custom_exec_cb( lambda not_used, value : label3.set_x( value ))
anim3.set_repeat_count( 100 )
anim3.set_repeat_delay( 2000 )
anim3.set_path_cb( lvgl.anim_t.path_overshoot )
#this animation slowly starts and then slowly ends
label4 = lvgl.label( lvgl.screen_active() )
label4.set_text( 'hello 4' )
label4.align( lvgl.ALIGN.CENTER, 30, 60 )
anim4 = lvgl.anim_t()
anim4.init()
anim4.set_var( label4 )
anim4.set_time( 1000 )
anim4.set_values( 30, 120 )
anim4.set_custom_exec_cb( lambda not_used, value : label4.set_x( value ))
anim4.set_repeat_count( 100 )
anim4.set_repeat_delay( 2000 )
anim4.set_path_cb( lvgl.anim_t.path_ease_in_out )
anim1.start()
anim2.start()
anim3.start()
anim4.start()
********************
# Initialize
import display_driver
import lvgl as lv
import lvgl
button = lvgl.button( lvgl.screen_active() )
button.set_size( 50, 20 )
button.center()
anim1 = lvgl.anim_t()
anim1.init()
anim1.set_var( button )
anim1.set_time( 1000 )
anim1.set_values( -100, 100 )
anim1.set_custom_exec_cb( lambda not_used, value : button.set_x( value ))
anim2 = lvgl.anim_t()
anim2.init()
anim2.set_var( button )
anim2.set_time( 150 )
anim2.set_values( 100, 30 )
anim2.set_custom_exec_cb( lambda not_used, value : button.set_x( value ))
anim3 = lvgl.anim_t()
anim3.init()
anim3.set_var( button )
anim3.set_time( 2000 )
anim3.set_values( 30, -100 )
anim3.set_custom_exec_cb( lambda not_used, value : button.set_x( value ))
time = lvgl.anim_timeline_create()
# somehow this doesn't work:
#lvgl.anim_timeline_add( time, 0, anim1 )
#lvgl.anim_timeline_add( time, 1000, anim2 )
#lvgl.anim_timeline_add( time, 1150, anim3 )
#lvgl.anim_timeline_start( time )
+80
View File
@@ -0,0 +1,80 @@
import ustruct
import os
#os.mkdir("/flash")
import lvgl as lv
import micropython
import ustruct
# Capture the screen to a buffer
snapshot_buf = lv.snapshot_take(lv.screen_active(), lv.COLOR_FORMAT.NATIVE)
if snapshot_buf is None:
print("Failed to capture snapshot")
else:
print("Snapshot captured successfully")
# Assuming snapshot_buf is from lv.snapshot_take(scr, lv.COLOR_FORMAT.NATIVE)
if snapshot_buf:
# Verify metadata
print("Width:", snapshot_buf.header.w) # Should be 320
print("Height:", snapshot_buf.header.h) # Should be 240
print("Data size:", snapshot_buf.data_size) # Should be 153600
# Get the raw buffer pointer
data_ptr = snapshot_buf.data
data_size = snapshot_buf.data_size
# Use memoryview to access the full buffer
try:
# Create a memoryview of the C buffer
buffer = memoryview(data_ptr)[:data_size]
print("Buffer length:", len(buffer)) # Should be 153600
# Save to flash storage
with open("/flash/snapshot.bin", "wb") as f:
f.write(buffer)
print("Snapshot saved to /flash/snapshot.bin")
except Exception as e:
print("Error accessing or saving buffer:", e)
# Free the snapshot to avoid memory leaks
lv.snapshot_free(snapshot_buf)
else:
print("Snapshot capture failed")
# Assuming snapshot_buf is the lv_img_dsc_t from lv.snapshot_take
if snapshot_buf:
# Get image data and metadata
img_data = snapshot_buf.data # Raw buffer (bytearray)
img_width = snapshot_buf.header.w
img_height = snapshot_buf.header.h
img_data_size = snapshot_buf.data_size
# Save to flash storage
try:
with open("/flash/snapshot.bin", "wb") as f:
f.write(img_data, img_data_size)
print("Snapshot saved to /flash/snapshot.bin")
except OSError as e:
print("Failed to save snapshot:", e)
else:
print("No snapshot to save")
if False:
img_data = snapshot_buf.data
img_width = snapshot_buf.header.w
img_height = snapshot_buf.header.h
img_data_size = snapshot_buf.data_size
color_format = lv.COLOR_FORMAT.NATIVE # Store format for reference
try:
with open("/flash/snapshot.bin", "wb") as f:
# Write header: width (4 bytes), height (4 bytes), format (4 bytes)
f.write(ustruct.pack("III", img_width, img_height, color_format))
# Write image data
f.write(img_data, img_data_size)
print("Snapshot with header saved to /flash/snapshot.bin")
except OSError as e:
print("Failed to save snapshot:", e)