Skip to content

Commit 5cce924

Browse files
maidang-xingshiliu-yang
authored andcommitted
feat: update Gitee sync workflow and add app_ui_action registration for AI display
1 parent f756fcb commit 5cce924

3 files changed

Lines changed: 220 additions & 2 deletions

File tree

.github/workflows/sync-to-gitee.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55

66
jobs:
77
sync:
8-
if: github.repository == 'tuya/DuckyClaw'
8+
if: github.repository == 'tuya/TuyaOpenClaw'
99
runs-on: ubuntu-latest
1010
name: Git Repo Sync
1111
steps:
@@ -14,6 +14,6 @@ jobs:
1414
fetch-depth: 0
1515
- uses: tuya/TuyaOpen@master
1616
with:
17-
target-url: 'https://gitee.com/tuya-open/DuckyClaw.git'
17+
target-url: 'https://gitee.com/tuya-open/TuyaOpenClaw.git'
1818
target-username: 'flyingcys'
1919
target-token: ${{ secrets.GITEE_TOKEN }}

src/app_ui_action.c

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
/**
2+
* @file app_ui_action.c
3+
* @brief app_ui_action module is used to
4+
* @version 0.1
5+
* @copyright Copyright (c) 2021-2026 Tuya Inc. All Rights Reserved.
6+
*/
7+
#include "tal_api.h"
8+
#include <string.h>
9+
10+
#if defined(ENABLE_COMP_AI_DISPLAY) && (ENABLE_COMP_AI_DISPLAY == 1)
11+
#include "ai_ui_manage.h"
12+
13+
#if defined(ENABLE_COMP_AI_PICTURE) && (ENABLE_COMP_AI_PICTURE == 1)
14+
#include "image_album.h"
15+
#include "ai_picture.h"
16+
#include "ai_picture_input.h"
17+
#endif
18+
19+
#if defined(ENABLE_COMP_AI_VIDEO) && (ENABLE_COMP_AI_VIDEO == 1)
20+
#include "ai_video_input.h"
21+
#endif
22+
23+
#if defined(ENABLE_PRINTER) && (ENABLE_PRINTER == 1)
24+
#include "app_printer.h"
25+
#endif
26+
27+
/***********************************************************
28+
************************macro define************************
29+
***********************************************************/
30+
31+
32+
/***********************************************************
33+
***********************typedef define***********************
34+
***********************************************************/
35+
#if defined(ENABLE_COMP_AI_VIDEO) && (ENABLE_COMP_AI_VIDEO == 1)
36+
static bool sg_ai_vision_enabled = false;
37+
#endif
38+
39+
/***********************************************************
40+
***********************function define**********************
41+
***********************************************************/
42+
#if defined(ENABLE_COMP_AI_VIDEO) && (ENABLE_COMP_AI_VIDEO == 1)
43+
static void __display_camera_yuv_fram(TDL_CAMERA_FRAME_T *frame)
44+
{
45+
AI_UI_VIDEO_T video = {0};
46+
47+
if (NULL == frame) {
48+
return;
49+
}
50+
51+
video.width = frame->width;
52+
video.height = frame->height;
53+
video.yuv422 = frame->data;
54+
video.len = frame->data_len;
55+
56+
ai_ui_disp_msg_sync(AI_UI_DISP_CAMERA_FLUSH, (uint8_t*)&video, sizeof(AI_UI_VIDEO_T));
57+
}
58+
#endif /* ENABLE_COMP_AI_VIDEO */
59+
60+
61+
static void __app_ui_action_handle(AI_UI_ACTION_E action, uint8_t *data, uint32_t len)
62+
{
63+
switch (action) {
64+
#if defined(ENABLE_COMP_AI_VIDEO) && (ENABLE_COMP_AI_VIDEO == 1)
65+
case AI_UI_ACT_OPEN_CAMERA:
66+
sg_ai_vision_enabled = false;
67+
ai_video_set_yuv_frame_flush_cb(__display_camera_yuv_fram);
68+
ai_video_start();
69+
ai_ui_disp_msg_sync(AI_UI_DISP_CAMERA_OPEN, NULL, 0);
70+
break;
71+
72+
case AI_UI_ACT_TAKE_PHOTO: {
73+
uint8_t *jpeg = NULL;
74+
uint32_t jpeg_len = 0;
75+
ai_video_get_jpeg_frame(&jpeg, &jpeg_len);
76+
77+
if (jpeg && jpeg_len) {
78+
#if defined(ENABLE_COMP_AI_PICTURE) && (ENABLE_COMP_AI_PICTURE == 1)
79+
char name[AI_PICTURE_NAME_MAX_LEN + 1] = {0};
80+
ai_picture_save_to_album(jpeg, jpeg_len, NULL, name);
81+
ai_ui_disp_msg_sync(AI_UI_DISP_CAMERA_THUMB, jpeg, jpeg_len);
82+
#endif
83+
if (sg_ai_vision_enabled) {
84+
/* Close camera so the user sees the AI response in chat */
85+
ai_video_stop();
86+
ai_video_set_yuv_frame_flush_cb(NULL);
87+
ai_ui_disp_msg_sync(AI_UI_DISP_CAMERA_CLOSE, NULL, 0);
88+
#if defined(ENABLE_COMP_AI_PICTURE) && (ENABLE_COMP_AI_PICTURE == 1)
89+
ai_ui_disp_msg(AI_UI_DISP_USER_IMAGE_LINK, (uint8_t *)name, strlen(name));
90+
91+
ai_picture_input_recognize(jpeg, jpeg_len);
92+
#endif
93+
} else {
94+
ai_ui_disp_msg_sync(AI_UI_DISP_CAMERA_THUMB, jpeg, jpeg_len);
95+
}
96+
97+
ai_video_jpeg_image_free(&jpeg);
98+
}
99+
} break;
100+
101+
case AI_UI_ACT_CLOSE_CAMER:
102+
ai_video_stop();
103+
ai_video_set_yuv_frame_flush_cb(NULL);
104+
ai_ui_disp_msg_sync(AI_UI_DISP_CAMERA_CLOSE, NULL, 0);
105+
break;
106+
107+
case AI_UI_ACT_CAMERA_AI_ON:
108+
sg_ai_vision_enabled = true;
109+
break;
110+
111+
case AI_UI_ACT_CAMERA_AI_OFF:
112+
sg_ai_vision_enabled = false;
113+
break;
114+
#endif /* ENABLE_COMP_AI_VIDEO */
115+
116+
#if defined(ENABLE_COMP_AI_PICTURE) && (ENABLE_COMP_AI_PICTURE == 1)
117+
case AI_UI_ACT_OPEN_ALBUM: {
118+
char *album_name = ai_picture_get_album_name();
119+
if (album_name) {
120+
ai_ui_disp_msg_sync(AI_UI_DISP_ALBUM_OPEN, (uint8_t*)album_name, strlen(album_name));
121+
}
122+
} break;
123+
124+
case AI_UI_ACT_VIEW_PREV_IMG:
125+
ai_ui_disp_msg_sync(AI_UI_DISP_ALBUM_VIEW_PREV, NULL, 0);
126+
break;
127+
128+
case AI_UI_ACT_VIEW_NEXT_IMG:
129+
ai_ui_disp_msg_sync(AI_UI_DISP_ALBUM_VIEW_NEXT, NULL, 0);
130+
break;
131+
132+
case AI_UI_ACT_VIEW_ALL_IMG:
133+
ai_ui_disp_msg_sync(AI_UI_DISP_ALBUM_VIEW_ALL, NULL, 0);
134+
break;
135+
136+
case AI_UI_ACT_DELETE_IMG: {
137+
char *name = (char *)data;
138+
if (NULL == name) {
139+
PR_ERR("image name is null");
140+
break;
141+
}
142+
IMAGE_ALBUM_HANDLE hdl = image_album_find_by_name(ai_picture_get_album_name());
143+
image_album_delete(hdl, name);
144+
ai_ui_disp_msg_sync(AI_UI_DISP_ALBUM_RELOAD, NULL, 0);
145+
} break;
146+
147+
case AI_UI_ACT_BATCH_DELETE_IMG: {
148+
if (NULL == data || len < sizeof(AI_UI_BATCH_DELETE_T)) {
149+
break;
150+
}
151+
IMAGE_ALBUM_HANDLE hdl = image_album_find_by_name(ai_picture_get_album_name());
152+
if (NULL == hdl) {
153+
PR_ERR("album not found for batch delete");
154+
break;
155+
}
156+
AI_UI_BATCH_DELETE_T *batch = (AI_UI_BATCH_DELETE_T *)data;
157+
uint32_t i;
158+
for (i = 0; i < batch->count && i < AI_UI_BATCH_DELETE_MAX; i++) {
159+
image_album_delete(hdl, batch->names[i]);
160+
}
161+
} break;
162+
163+
case AI_UI_ACT_CLOSE_ALBUM:
164+
ai_ui_disp_msg_sync(AI_UI_DISP_ALBUM_CLOSE, NULL, 0);
165+
break;
166+
167+
case AI_UI_ACT_OPEN_IMG_ATTACH_LIST:
168+
ai_ui_disp_msg_sync(AI_UI_DISP_ALBUM_SELECT_IMG, NULL, 0);
169+
break;
170+
171+
case AI_UI_ACT_ADD_IMG_ATTACH: {
172+
ai_ui_disp_msg_sync(AI_UI_DISP_ADD_CHAT_ATTACH_IMG, data, strlen((char *)data));
173+
ai_picture_input_add_from_album((char *)data, NULL);
174+
} break;
175+
176+
case AI_UI_ACT_DEL_IMG_ATTACH: {
177+
ai_picture_input_del_from_album((char *)data);
178+
} break;
179+
180+
#if defined(ENABLE_PRINTER) && (ENABLE_PRINTER == 1)
181+
case AI_UI_ACT_PRINT_IMG: {
182+
if (NULL == data || 0 == len) {
183+
PR_ERR("print: filename is null");
184+
break;
185+
}
186+
OPERATE_RET print_rt = app_print_img_from_album((const char *)data);
187+
int32_t result = (int32_t)print_rt;
188+
ai_ui_disp_msg(AI_UI_DISP_PRINT_RESULT, (uint8_t *)&result, sizeof(result));
189+
} break;
190+
#endif /* ENABLE_PRINTER */
191+
192+
#endif /* ENABLE_IMAGE_ALBUM */
193+
default:
194+
break;
195+
}
196+
}
197+
198+
199+
void app_ui_action_register(void)
200+
{
201+
ai_ui_action_cb_register(__app_ui_action_handle);
202+
}
203+
204+
#endif

src/tuyaopen_claw_chat.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ static void __ai_chat_handle_event(AI_NOTIFY_EVENT_T *event)
222222
}
223223
}
224224

225+
#if defined(ENABLE_COMP_AI_DISPLAY) && (ENABLE_COMP_AI_DISPLAY == 1)
226+
extern void app_ui_action_register(void);
227+
#endif
228+
225229
OPERATE_RET tuyaopen_claw_chat_init(void)
226230
{
227231
OPERATE_RET rt = OPRT_OK;
@@ -233,6 +237,11 @@ OPERATE_RET tuyaopen_claw_chat_init(void)
233237
};
234238
TUYA_CALL_ERR_RETURN(ai_chat_init(&ai_chat_cfg));
235239

240+
#if defined(ENABLE_COMP_AI_DISPLAY) && (ENABLE_COMP_AI_DISPLAY == 1)
241+
/* Register popup (+ button) action handler: camera / album / add-image attach */
242+
app_ui_action_register();
243+
#endif
244+
236245
#if defined(ENABLE_COMP_AI_VIDEO) && (ENABLE_COMP_AI_VIDEO == 1)
237246
TUYA_CALL_ERR_LOG(ai_video_init());
238247
TUYA_CALL_ERR_LOG(ai_video_set_yuv_frame_flush_cb(__ai_video_display_flush));
@@ -242,6 +251,11 @@ OPERATE_RET tuyaopen_claw_chat_init(void)
242251
TUYA_CALL_ERR_RETURN(ai_mcp_init());
243252
#endif
244253

254+
#if defined(ENABLE_COMP_AI_PICTURE) && (ENABLE_COMP_AI_PICTURE == 1)
255+
/* Create/register the "ai_picture" album so album + add-image popup actions resolve */
256+
TUYA_CALL_ERR_RETURN(ai_picture_init());
257+
#endif
258+
245259
// Free heap size
246260
tal_sw_timer_create(__printf_free_heap_tm_cb, NULL, &sg_printf_heap_tm);
247261
tal_sw_timer_start(sg_printf_heap_tm, PRINTF_FREE_HEAP_TTIME, TAL_TIMER_CYCLE);

0 commit comments

Comments
 (0)