Skip to content

Commit b46756b

Browse files
Fullscreen all apps - no more subwindow
1 parent fd0fc30 commit b46756b

File tree

15 files changed

+387
-257
lines changed

15 files changed

+387
-257
lines changed

draft_code/animations.py

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
2+
# Initialize
3+
4+
import display_driver
5+
import lvgl as lv
6+
7+
import lvgl
8+
9+
label = lvgl.label( lvgl.screen_active() )
10+
label.set_text( 'hi' )
11+
12+
animation = lvgl.anim_t()
13+
animation.init()
14+
animation.set_var( label )
15+
animation.set_values( 0, 100 )
16+
animation.set_time( 1000 )
17+
18+
animation.set_custom_exec_cb( lambda not_used, value : label.set_x( value ))
19+
20+
#wait half a second before starting animation
21+
animation.set_delay( 500 )
22+
23+
#play animation backward for 1 second after first play
24+
animation.set_playback_time( 1000 )
25+
#repeat animation infinitely
26+
animation.set_repeat_count( 10 )
27+
#animation.set_repeat_count( lvgl.ANIM_REPEAT.INFINITE )
28+
animation.set_repeat_delay( 500 )
29+
30+
animation.start()
31+
32+
33+
34+
******************************
35+
36+
37+
38+
# Initialize
39+
40+
import display_driver
41+
import lvgl as lv
42+
43+
import lvgl
44+
45+
#create the slow short label
46+
label1 = lvgl.label( lvgl.screen_active() )
47+
label1.set_text( 'hello 1' )
48+
label1.align( lvgl.ALIGN.CENTER, 0, -50 )
49+
50+
anim1 = lvgl.anim_t()
51+
anim1.init()
52+
anim1.set_var( label1 )
53+
#anim1.set_time( lvgl.anim_speed_to_time( 20, 0, 100 ))
54+
anim1.set_time( 2000 )
55+
anim1.set_values( 0, 100 )
56+
anim1.set_repeat_count( 10 )
57+
anim1.set_repeat_delay( 2000 )
58+
anim1.set_custom_exec_cb( lambda not_used, value : label1.set_x( value ))
59+
60+
61+
#create the fast long label
62+
label2 = lvgl.label( lvgl.screen_active() )
63+
label2.set_text('hello 2')
64+
label2.align(lvgl.ALIGN.CENTER,-100,0)
65+
66+
anim2 = lvgl.anim_t()
67+
anim2.init()
68+
anim2.set_var( label2 )
69+
#anim2.set_time( lvgl.anim_speed_to_time( 40, -100, 100 ))
70+
anim2.set_time( 40 * 200 )
71+
anim2.set_values( -100, 100 )
72+
anim2.set_custom_exec_cb( lambda not_used, value : label2.set_x( value ))
73+
anim2.set_repeat_count( 10)
74+
anim2.set_repeat_delay( 2000 )
75+
76+
77+
#Create the fast short label
78+
label3 = lvgl.label( lvgl.screen_active() )
79+
label3.set_text( 'hello 3' )
80+
label3.align( lvgl.ALIGN.CENTER, -100, 50 )
81+
82+
83+
anim3 = lvgl.anim_t()
84+
anim3.init()
85+
anim3.set_var( label3 )
86+
#anim3.set_time( lvgl.anim_speed_to_time( 40, -100, 0 ))
87+
anim3.set_time( 40 * 100)
88+
anim3.set_values( -100, 0)
89+
anim3.set_custom_exec_cb( lambda not_used, value : label3.set_x( value ))
90+
anim3.set_repeat_count( 10 )
91+
anim3.set_repeat_delay( 40 * 100 + 2000 )
92+
#anim3.set_repeat_delay( lvgl.anim_speed_to_time( 40, -100, 0) + 2000 )
93+
#lvgl.anim_speed_to_time( 1, 2, 3)
94+
#anim3.set_repeat_delay( 5000)
95+
#lvgl.anim
96+
97+
anim1.start()
98+
anim2.start()
99+
anim3.start()
100+
101+
102+
103+
104+
105+
106+
107+
108+
109+
******************
110+
111+
112+
113+
114+
# Initialize
115+
116+
import display_driver
117+
import lvgl as lv
118+
119+
import lvgl
120+
121+
import lvgl
122+
123+
#normal animation
124+
label1 = lvgl.label( lvgl.screen_active() )
125+
label1.set_text( 'hello 1' )
126+
label1.align( lvgl.ALIGN.CENTER, -70, -60 )
127+
128+
anim1 = lvgl.anim_t()
129+
anim1.init()
130+
anim1.set_var( label1 )
131+
anim1.set_time( 1000 )
132+
anim1.set_values( -70, 20 )
133+
anim1.set_repeat_count( 100 )
134+
anim1.set_repeat_delay( 2000 )
135+
anim1.set_custom_exec_cb( lambda not_used, value : label1.set_x( value ))
136+
137+
138+
#this animation bounces the label when it ends
139+
label2 = lvgl.label( lvgl.screen_active() )
140+
label2.set_text( 'hello 2' )
141+
label2.align( lvgl.ALIGN.CENTER, 30, -60 )
142+
143+
anim2 = lvgl.anim_t()
144+
anim2.init()
145+
anim2.set_var( label2 )
146+
anim2.set_time( 1000 )
147+
anim2.set_values( 30, 120 )
148+
anim2.set_custom_exec_cb( lambda not_used, value : label2.set_x( value ))
149+
anim2.set_repeat_count( 100)
150+
anim2.set_repeat_delay( 2000 )
151+
anim2.set_path_cb( lvgl.anim_t.path_bounce )
152+
153+
154+
#this animation goes past the end point then comes back
155+
label3 = lvgl.label( lvgl.screen_active() )
156+
label3.set_text( 'hello 3' )
157+
label3.align( lvgl.ALIGN.CENTER, -70, 60 )
158+
159+
anim3 = lvgl.anim_t()
160+
anim3.init()
161+
anim3.set_var( label3 )
162+
anim3.set_time( 1000 )
163+
anim3.set_values( -70, 20 )
164+
anim3.set_custom_exec_cb( lambda not_used, value : label3.set_x( value ))
165+
anim3.set_repeat_count( 100 )
166+
anim3.set_repeat_delay( 2000 )
167+
anim3.set_path_cb( lvgl.anim_t.path_overshoot )
168+
169+
170+
#this animation slowly starts and then slowly ends
171+
label4 = lvgl.label( lvgl.screen_active() )
172+
label4.set_text( 'hello 4' )
173+
label4.align( lvgl.ALIGN.CENTER, 30, 60 )
174+
175+
anim4 = lvgl.anim_t()
176+
anim4.init()
177+
anim4.set_var( label4 )
178+
anim4.set_time( 1000 )
179+
anim4.set_values( 30, 120 )
180+
anim4.set_custom_exec_cb( lambda not_used, value : label4.set_x( value ))
181+
anim4.set_repeat_count( 100 )
182+
anim4.set_repeat_delay( 2000 )
183+
anim4.set_path_cb( lvgl.anim_t.path_ease_in_out )
184+
185+
186+
anim1.start()
187+
anim2.start()
188+
anim3.start()
189+
anim4.start()
190+
191+
192+
193+
********************
194+
195+
196+
197+
198+
# Initialize
199+
200+
import display_driver
201+
import lvgl as lv
202+
203+
import lvgl
204+
205+
button = lvgl.button( lvgl.screen_active() )
206+
button.set_size( 50, 20 )
207+
button.center()
208+
209+
anim1 = lvgl.anim_t()
210+
anim1.init()
211+
anim1.set_var( button )
212+
anim1.set_time( 1000 )
213+
anim1.set_values( -100, 100 )
214+
anim1.set_custom_exec_cb( lambda not_used, value : button.set_x( value ))
215+
216+
anim2 = lvgl.anim_t()
217+
anim2.init()
218+
anim2.set_var( button )
219+
anim2.set_time( 150 )
220+
anim2.set_values( 100, 30 )
221+
anim2.set_custom_exec_cb( lambda not_used, value : button.set_x( value ))
222+
223+
anim3 = lvgl.anim_t()
224+
anim3.init()
225+
anim3.set_var( button )
226+
anim3.set_time( 2000 )
227+
anim3.set_values( 30, -100 )
228+
anim3.set_custom_exec_cb( lambda not_used, value : button.set_x( value ))
229+
230+
time = lvgl.anim_timeline_create()
231+
232+
# somehow this doesn't work:
233+
#lvgl.anim_timeline_add( time, 0, anim1 )
234+
#lvgl.anim_timeline_add( time, 1000, anim2 )
235+
#lvgl.anim_timeline_add( time, 1150, anim3 )
236+
237+
#lvgl.anim_timeline_start( time )
238+

draft_code/screen_capture.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import ustruct
2+
import os
3+
#os.mkdir("/flash")
4+
5+
import lvgl as lv
6+
import micropython
7+
import ustruct
8+
9+
# Capture the screen to a buffer
10+
snapshot_buf = lv.snapshot_take(lv.screen_active(), lv.COLOR_FORMAT.NATIVE)
11+
if snapshot_buf is None:
12+
print("Failed to capture snapshot")
13+
else:
14+
print("Snapshot captured successfully")
15+
16+
# Assuming snapshot_buf is from lv.snapshot_take(scr, lv.COLOR_FORMAT.NATIVE)
17+
if snapshot_buf:
18+
# Verify metadata
19+
print("Width:", snapshot_buf.header.w) # Should be 320
20+
print("Height:", snapshot_buf.header.h) # Should be 240
21+
print("Data size:", snapshot_buf.data_size) # Should be 153600
22+
# Get the raw buffer pointer
23+
data_ptr = snapshot_buf.data
24+
data_size = snapshot_buf.data_size
25+
# Use memoryview to access the full buffer
26+
try:
27+
# Create a memoryview of the C buffer
28+
buffer = memoryview(data_ptr)[:data_size]
29+
print("Buffer length:", len(buffer)) # Should be 153600
30+
# Save to flash storage
31+
with open("/flash/snapshot.bin", "wb") as f:
32+
f.write(buffer)
33+
print("Snapshot saved to /flash/snapshot.bin")
34+
except Exception as e:
35+
print("Error accessing or saving buffer:", e)
36+
# Free the snapshot to avoid memory leaks
37+
lv.snapshot_free(snapshot_buf)
38+
else:
39+
print("Snapshot capture failed")
40+
41+
42+
43+
44+
45+
# Assuming snapshot_buf is the lv_img_dsc_t from lv.snapshot_take
46+
if snapshot_buf:
47+
# Get image data and metadata
48+
img_data = snapshot_buf.data # Raw buffer (bytearray)
49+
img_width = snapshot_buf.header.w
50+
img_height = snapshot_buf.header.h
51+
img_data_size = snapshot_buf.data_size
52+
# Save to flash storage
53+
try:
54+
with open("/flash/snapshot.bin", "wb") as f:
55+
f.write(img_data, img_data_size)
56+
print("Snapshot saved to /flash/snapshot.bin")
57+
except OSError as e:
58+
print("Failed to save snapshot:", e)
59+
else:
60+
print("No snapshot to save")
61+
62+
63+
64+
65+
66+
if False:
67+
img_data = snapshot_buf.data
68+
img_width = snapshot_buf.header.w
69+
img_height = snapshot_buf.header.h
70+
img_data_size = snapshot_buf.data_size
71+
color_format = lv.COLOR_FORMAT.NATIVE # Store format for reference
72+
try:
73+
with open("/flash/snapshot.bin", "wb") as f:
74+
# Write header: width (4 bytes), height (4 bytes), format (4 bytes)
75+
f.write(ustruct.pack("III", img_width, img_height, color_format))
76+
# Write image data
77+
f.write(img_data, img_data_size)
78+
print("Snapshot with header saved to /flash/snapshot.bin")
79+
except OSError as e:
80+
print("Failed to save snapshot:", e)

internal_filesystem/apps/com.example.btcticker/assets/bitcoin_price.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
appscreen = lv.screen_active()
2+
13
import usocket
24
import ssl
35
import ubinascii
@@ -175,7 +177,7 @@ def get_price(json_str):
175177
print(f"Error: An unexpected error occurred - {str(e)}")
176178
return None
177179

178-
status = lv.label(subwindow)
180+
status = lv.label(appscreen)
179181
status.align(lv.ALIGN.TOP_LEFT, 5, 10)
180182
status.set_style_text_color(lv.color_hex(0xFFFFFF), 0)
181183

0 commit comments

Comments
 (0)