@@ -23,7 +23,7 @@ def add_text(self, text):
2323 current_page .append (("" , 0 , 0 )) # 初始化第一行
2424
2525 page_height_used = sum (line [2 ] for line in current_page )
26-
26+
2727 for ch in text :
2828 if ch == '\n ' or ch == '\r ' :
2929 continue
@@ -32,7 +32,7 @@ def add_text(self, text):
3232 size = image .string_size (new_line_text )
3333 ch_w = size [0 ]
3434 ch_h = size [1 ]
35-
35+
3636 # 尝试放到当前行
3737 if ch_w <= self .page_width :
3838 # 更新行
@@ -76,7 +76,7 @@ def draw_last_page_on(self, img:image.Image, color: image.Color = image.COLOR_WH
7676
7777 height = 0
7878 for line_text , _ , line_height in current_page :
79- img .draw_string (0 , height , line_text , color , wrap_space = 0 )
79+ img .draw_string (0 , height , line_text , color , wrap_space = 0 )
8080 height += line_height
8181
8282class App :
@@ -97,6 +97,8 @@ def __init__(self):
9797 self .ts = touchscreen .TouchScreen ()
9898 self .cam = camera .Camera (640 , 360 )
9999
100+ self .check_memory ()
101+
100102 self .exit_img = image .load ('./assets/exit.jpg' )
101103 self .ai_isp = bool (int (app .get_sys_config_kv ("npu" , "ai_isp" , "1" )))
102104 if self .ai_isp is True :
@@ -143,6 +145,34 @@ def __init__(self):
143145 self .page_text = PagedText (self .disp_w , self .disp_h - self .cam .height ())
144146 self .sta = self .Status .IDLE
145147
148+ def check_memory (self ):
149+ from maix import sys
150+ ok = False
151+ font = "sourcehansans"
152+ mem_info = sys .memory_info ()
153+ if "hw_total" in mem_info :
154+ hw_total = mem_info .get ("hw_total" , 0 )
155+ print (f"hw_total: { hw_total } ({ hw_total / 1024 / 1024 / 1024 } G)" )
156+ if hw_total < 4 * 1024 * 1024 * 1024 : # is not 4g version, try release more memory
157+ ok = False
158+ else :
159+ ok = True
160+ if ok == False :
161+ img = image .Image (self .disp_w , self .disp_h , bg = image .COLOR_BLACK )
162+ err_title_msg = "Ops!!!"
163+ err_msg = "You need the 4GB version of the board to run this application."
164+ err_exit_msg = "Tap anywhere on the screen to exit."
165+ img .draw_string (0 , 0 , err_title_msg , image .COLOR_WHITE , 1 , font = font )
166+ img .draw_string (0 , 20 , err_msg , image .COLOR_WHITE , 1 , font = font )
167+ img .draw_string (0 , 200 , err_exit_msg , image .COLOR_WHITE , 0.6 , font = font )
168+ self .disp .show (img )
169+ while not app .need_exit ():
170+ ts_data = self .ts .read ()
171+ if ts_data [2 ]:
172+ app .set_exit_flag (True )
173+ time .sleep_ms (100 )
174+ exit (0 )
175+
146176 def get_vl_model (self ):
147177 model_list = ["internvl" , "qwen3-vl" ]
148178 model_list_num = len (model_list )
@@ -318,7 +348,7 @@ def run(self):
318348 self .sta = self .Status .IDLE
319349
320350 self .show_ui ()
321-
351+
322352 if self .vlm :
323353 self .vlm .cancel ()
324354 time .sleep_ms (500 ) # Make sure the VLM has exited.
@@ -330,7 +360,7 @@ def run(self):
330360 self .disp = None
331361
332362 app .set_sys_config_kv ("npu" , "ai_isp" , "1" if self .ai_isp else "0" )
333-
363+
334364if __name__ == '__main__' :
335365 appication = App ()
336366 appication .run ()
0 commit comments