Skip to content

Commit 1bc8540

Browse files
committed
* optimzie app chat & app vlm
1 parent 9575665 commit 1bc8540

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

projects/app_chat/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ def __llm_on_reply(self, obj, resp):
233233

234234
self.llm_last_msg += resp.msg_new
235235

236+
if app.need_exit():
237+
self.llm.cancel()
238+
239+
236240
def __show_load_info(self, text: str, tips: str = '', x:int = 0, y:int = 0, color:image.Color=image.COLOR_WHITE):
237241
if self.disp:
238242
str_size = image.string_size(text)
@@ -321,6 +325,7 @@ class Status:
321325
time.sleep_ms(5)
322326

323327
if self.llm:
328+
self.llm.cancel()
324329
del self.llm
325330
self.llm = None
326331

projects/app_vlm/main.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def __init__(self):
147147
self.vlm_img: image.Image | None = None
148148
self.vlm_thread_lock = threading.Lock()
149149
self.vlm_result:str = ''
150+
self.vlm_thread = None
150151
self.page_text = PagedText(self.disp_w, self.disp_h - self.cam.height())
151152
self.sta = self.Status.IDLE
152153

@@ -250,8 +251,8 @@ def __vlm_thread(self, vlm, img:image.Image, msg: str):
250251

251252
def run_vlm(self, img: image.Image, msg: str):
252253
self.page_text.clear()
253-
t = threading.Thread(target=self.__vlm_thread, args=[self.vlm, img, msg], daemon=True)
254-
t.start()
254+
self.vlm_thread = threading.Thread(target=self.__vlm_thread, args=[self.vlm, img, msg], daemon=True)
255+
self.vlm_thread.start()
255256
# t.run()
256257

257258
def check_exit(self):
@@ -289,24 +290,28 @@ def show_ui(self):
289290
exit_img_y = 0
290291
img.draw_image(exit_img_x, exit_img_y, self.exit_img)
291292
self.check_exit()
292-
293293
# en/zh
294294
size = image.string_size("ZH", scale=2)
295295
if self.language == 'zh':
296296
img.draw_string(self.disp_w - size.width(), 0, "ZH", image.COLOR_WHITE, scale=2)
297297
else:
298298
img.draw_string(self.disp_w - size.width(), 0, "EN", image.COLOR_WHITE, scale=2)
299-
299+
300300
if self.support_zh:
301-
if ts_data[2] and self.disp_w - size.width()*2<=ts_data[0]<=self.disp_w and 0 <=ts_data[1]<=size.height() * 2:
301+
if ts_data[2] and self.disp_w - size.width()*4<=ts_data[0]<=self.disp_w and 0 <=ts_data[1]<=size.height()*4:
302302
if self.language == 'zh':
303303
self.language = 'en'
304304
else:
305305
self.language = 'zh'
306+
if self.vlm:
307+
self.vlm.cancel()
308+
if isinstance(self.vlm_thread, threading.Thread) and self.vlm_thread.is_alive():
309+
self.vlm_thread.join()
310+
self.page_text.clear()
306311
else:
307312
self.language = 'en'
308-
self.disp.show(img)
309313

314+
self.disp.show(img)
310315

311316
def __vlm_on_reply(self, obj, resp):
312317
print(resp.msg_new)

tools/os/maixcam2/gen_sd_os.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,10 @@ main() {
389389
check_exists "$BOOTFS_PATH"
390390
check_exists "$ROOTFS_PATH"
391391
check_root
392-
393-
umount tmp2/sd/sd_boot &> /dev/null
394-
umount tmp2/sd/sd_rootfs &> /dev/null
395-
umount tmp2/sd/ubuntu_rootfs &> /dev/null
396-
umount tmp2/sd/bootfs &> /dev/null
397-
392+
umount tmp2/sd/sd_boot &> /dev/null || echo ""
393+
umount tmp2/sd/sd_rootfs &> /dev/null || echo ""
394+
umount tmp2/sd/ubuntu_rootfs &> /dev/null || echo ""
395+
umount tmp2/sd/bootfs &> /dev/null || echo ""
398396
print_info "Converting $ROOTFS_PATH to $ROOTFS_RAW_PATH..."
399397
if [ $DISABLE_ROOTFS_SIMG2IMG -eq 1 ]; then
400398
print_warning "Skip convert $ROOTFS_PATH to $ROOTFS_RAW_PATH..."
@@ -461,11 +459,11 @@ main() {
461459

462460
print_info "Unmounting..."
463461
sleep 2
464-
umount tmp2/sd/sd_boot &> /dev/null
465-
umount tmp2/sd/sd_rootfs &> /dev/null
466-
umount tmp2/sd/ubuntu_rootfs &> /dev/null
467-
umount tmp2/sd/bootfs &> /dev/null
468-
losetup -d $DEVICE &> /dev/null
462+
umount tmp2/sd/sd_boot &> /dev/null || echo ""
463+
umount tmp2/sd/sd_rootfs &> /dev/null || echo ""
464+
umount tmp2/sd/ubuntu_rootfs &> /dev/null || echo ""
465+
umount tmp2/sd/bootfs &> /dev/null || echo ""
466+
losetup -d $DEVICE &> /dev/null || echo ""
469467

470468
print_info "Compressing sd.img..."
471469
if [ $DISABLE_COMPRESS_IMAGE -eq 1 ]; then

0 commit comments

Comments
 (0)