Просмотр исходного кода

add: air8101, camera异步初始化

rongwangwang 8 месяцев назад
Родитель
Сommit
457dd90adb
2 измененных файлов с 37 добавлено и 4 удалено
  1. 2 1
      components/camera/luat_camera.h
  2. 35 3
      components/camera/luat_lib_camera.c

+ 2 - 1
components/camera/luat_camera.h

@@ -63,6 +63,8 @@ typedef struct luat_camera_conf
     uint8_t id_reg;
 	uint8_t id_value;
     uint8_t usb_port;
+    uint8_t stream;
+    uint8_t async;
     size_t init_cmd_size;
     uint8_t *init_cmd;
 #ifdef __LUATOS__
@@ -70,7 +72,6 @@ typedef struct luat_camera_conf
 #else
     void *lcd_conf;
 #endif
-    uint8_t stream;
 } luat_camera_conf_t;
 
 typedef struct

+ 35 - 3
components/camera/luat_lib_camera.c

@@ -24,7 +24,7 @@ typedef struct luat_camera_cb {
     int scanned;
 } luat_camera_cb_t;
 static luat_camera_cb_t camera_cbs[MAX_DEVICE_COUNT + MAX_USB_DEVICE_COUNT];
-
+static uint64_t camera_idp = 0;
 int l_camera_handler(lua_State *L, void* ptr) {
     rtos_msg_t* msg = (rtos_msg_t*)lua_topointer(L, -1);
     lua_pop(L, 1);
@@ -177,6 +177,13 @@ static int l_camera_init(lua_State *L){
         }
         lua_pop(L, 1);
 
+        lua_pushliteral(L, "async");
+        lua_gettable(L, 1);
+        if (lua_isinteger(L, -1)) {
+            conf.async = luaL_checkinteger(L, -1);
+        }
+        lua_pop(L, 1);
+
         lua_pushliteral(L, "init_cmd");
         lua_gettable(L, 1);
         if (lua_istable(L, -1)) {
@@ -231,9 +238,13 @@ static int l_camera_init(lua_State *L){
         lua_pop(L, 1);
         result = luat_camera_init(&conf);
         if (result < 0) {
-        	lua_pushboolean(L, 0);
+            lua_pushboolean(L, 0);
         } else {
-        	lua_pushinteger(L, result);
+            if (conf.async) {
+                camera_idp = luat_pushcwait(L);
+            } else {
+                lua_pushinteger(L, result);
+            }
         }
 
     } else if (lua_isinteger(L, 1)) {
@@ -588,3 +599,24 @@ LUAMOD_API int luaopen_camera( lua_State *L ) {
     return 1;
 }
 
+//------------------------------------------------------
+static int32_t l_camera_callback(lua_State *L, void* ptr) {
+    rtos_msg_t *msg = (rtos_msg_t *)lua_topointer(L, -1);
+    if (camera_idp) {
+        if (msg->arg1 < 0) {
+            lua_pushinteger(L, 0);
+        } else {
+            lua_pushinteger(L, msg->arg1);
+        }
+        luat_cbcwait(L, camera_idp, 1);
+        camera_idp = 0;
+    }
+    return 0;
+}
+
+void luat_camera_async_init_result(int result) {
+    rtos_msg_t msg = {0};
+    msg.handler = l_camera_callback;
+    msg.arg1 = result;
+    luat_msgbus_put(&msg, 0);
+}