alienwalker 2 лет назад
Родитель
Сommit
e5d6954c2b
2 измененных файлов с 34 добавлено и 26 удалено
  1. 18 16
      components/camera/luat_camera.h
  2. 16 10
      components/camera/luat_lib_camera.c

+ 18 - 16
components/camera/luat_camera.h

@@ -78,30 +78,19 @@ int l_camera_handler(lua_State *L, void* ptr);
  * @param conf camera相关配置
  * @param conf camera相关配置
  * @param callback camera接收中断回调,注意这是在中断里的回调
  * @param callback camera接收中断回调,注意这是在中断里的回调
  * @param param 中断回调时用户的参数
  * @param param 中断回调时用户的参数
- * @return 0成功,其他失败
+ * @return >=0成功,其他失败
  */
  */
 int luat_camera_setup(int id, luat_spi_camera_t *conf, void* callback, void *param);
 int luat_camera_setup(int id, luat_spi_camera_t *conf, void* callback, void *param);
 
 
 int luat_camera_set_image_w_h(int id, uint16_t w, uint16_t h);
 int luat_camera_set_image_w_h(int id, uint16_t w, uint16_t h);
 
 
 /**
 /**
- * @brief 配置camera并且初始化camera
+ * @brief 配置camera并且初始化camera,spi camera不要使用这个
  * @param conf camera相关配置
  * @param conf camera相关配置
  * @return 0成功,其他失败
  * @return 0成功,其他失败
  */
  */
 int luat_camera_init(luat_camera_conf_t *conf);
 int luat_camera_init(luat_camera_conf_t *conf);
-/**
- * @brief 开始接收camera数据
- * @param id camera接收数据总线ID
- * @return 0成功,其他失败
- */
-int luat_camera_start(int id);
-/**
- * @brief 停止接收camera数据
- * @param id camera接收数据总线ID
- * @return 0成功,其他失败
- */
-int luat_camera_stop(int id);
+
 /**
 /**
  * @brief 关闭camera并且释放资源
  * @brief 关闭camera并且释放资源
  * @param id camera接收数据总线ID
  * @param id camera接收数据总线ID
@@ -110,14 +99,14 @@ int luat_camera_stop(int id);
 int luat_camera_close(int id);
 int luat_camera_close(int id);
 
 
 /**
 /**
- * @brief 摄像头启动开始接收数据
+ * @brief 摄像头启动开始接收数据,csdk专用
  * @param id camera接收数据总线ID
  * @param id camera接收数据总线ID
  * @param buf 用户区地址,如果为NULL,则表示不存放到用户区
  * @param buf 用户区地址,如果为NULL,则表示不存放到用户区
  * @return 0成功,其他失败
  * @return 0成功,其他失败
  */
  */
 int luat_camera_start_with_buffer(int id, void *buf);
 int luat_camera_start_with_buffer(int id, void *buf);
 /**
 /**
- * @brief 摄像头切换接收数据缓冲区
+ * @brief 摄像头切换接收数据缓冲区,csdk专用
  * @param id camera接收数据总线ID
  * @param id camera接收数据总线ID
  * @param buf 用户区地址,如果为NULL,则表示不存放到用户区
  * @param buf 用户区地址,如果为NULL,则表示不存放到用户区
  * @return 0成功,其他失败
  * @return 0成功,其他失败
@@ -149,6 +138,19 @@ void luat_camera_image_decode_deinit(void);
 int luat_camera_image_decode_get_result(uint8_t *buf);
 int luat_camera_image_decode_get_result(uint8_t *buf);
 
 
 /**********以下是luatos使用,csdk不要使用***********/
 /**********以下是luatos使用,csdk不要使用***********/
+/**
+ * @brief 开始接收camera数据
+ * @param id camera接收数据总线ID
+ * @return 0成功,其他失败
+ */
+int luat_camera_start(int id);
+/**
+ * @brief 停止接收camera数据
+ * @param id camera接收数据总线ID
+ * @return 0成功,其他失败
+ */
+int luat_camera_stop(int id);
+
 int luat_camera_preview(int id, uint8_t on_off);
 int luat_camera_preview(int id, uint8_t on_off);
 
 
 int luat_camera_work_mode(int id, int mode);
 int luat_camera_work_mode(int id, int mode);

+ 16 - 10
components/camera/luat_lib_camera.c

@@ -53,7 +53,7 @@ int l_camera_handler(lua_State *L, void* ptr) {
 
 
 /*
 /*
 初始化摄像头
 初始化摄像头
-@api    camera.init(InitReg_or_cspi_id, cspi_speed, mode, is_msb, rx_bit, seq_type, is_ddr, only_y, w, h)
+@api    camera.init(InitReg_or_cspi_id, cspi_speed, mode, is_msb, rx_bit, seq_type, is_ddr, only_y, scan_mode, w, h)
 @table/integer 如果是table,则是DVP摄像头的配置见demo/camera/AIR105,同时忽略后续参数;如果是数字,则是camera spi总线序号
 @table/integer 如果是table,则是DVP摄像头的配置见demo/camera/AIR105,同时忽略后续参数;如果是数字,则是camera spi总线序号
 @int camera spi总线速度
 @int camera spi总线速度
 @int camera spi模式,0~3
 @int camera spi模式,0~3
@@ -61,7 +61,8 @@ int l_camera_handler(lua_State *L, void* ptr) {
 @int 同时接收bit数,1,2,4
 @int 同时接收bit数,1,2,4
 @int byte序列,0~1
 @int byte序列,0~1
 @int 双边沿采样配置,0不启用,其他值根据实际SOC决定
 @int 双边沿采样配置,0不启用,其他值根据实际SOC决定
-@int 只接收Y分量,0不启用,1启用,扫码必须启用,不开启时扫码直接失败
+@int 只接收Y分量,0不启用,1启用,扫码必须启用,否则会失败
+@int 工作模式,camera.AUTO自动,camera.SCAN扫码
 @int 摄像头宽度
 @int 摄像头宽度
 @int 摄像头高度
 @int 摄像头高度
 @return int/false 成功返回camera_id,失败返回false
 @return int/false 成功返回camera_id,失败返回false
@@ -220,12 +221,15 @@ static int l_camera_init(lua_State *L){
     	result = lua_tointegerx(L, 7, &default_value);
     	result = lua_tointegerx(L, 7, &default_value);
     	memcpy(conf.plat_param, &result, 4);
     	memcpy(conf.plat_param, &result, 4);
     	conf.only_y = lua_tointegerx(L, 8, &default_value);
     	conf.only_y = lua_tointegerx(L, 8, &default_value);
+    	int mode = lua_tointegerx(L, 9, &default_value);
     	default_value = 240;
     	default_value = 240;
-    	conf.sensor_width = lua_tointegerx(L, 9, &default_value);
+    	conf.sensor_width = lua_tointegerx(L, 10, &default_value);
     	default_value = 320;
     	default_value = 320;
-    	conf.sensor_height = lua_tointegerx(L, 10, &default_value);
+    	conf.sensor_height = lua_tointegerx(L, 11, &default_value);
     	luat_camera_init(NULL);
     	luat_camera_init(NULL);
+    	luat_camera_work_mode(cspi_id, mode);
     	result = luat_camera_setup(cspi_id, &conf, NULL, 0);
     	result = luat_camera_setup(cspi_id, &conf, NULL, 0);
+
         if (result < 0) {
         if (result < 0) {
         	lua_pushboolean(L, 0);
         	lua_pushboolean(L, 0);
         } else {
         } else {
@@ -270,17 +274,14 @@ static int l_camera_on(lua_State *L) {
 
 
 /**
 /**
 开始指定的camera
 开始指定的camera
-@api camera.start(id,mode)
+@api camera.start(id)
 @int camera id,例如0
 @int camera id,例如0
-@int 工作模式,目前只有camera.AUTO自动,camera.SCAN连续扫码,默认是0
 @return boolean 成功返回true,否则返回false
 @return boolean 成功返回true,否则返回false
 @usage
 @usage
 camera.start(0)
 camera.start(0)
 */
 */
 static int l_camera_start(lua_State *L) {
 static int l_camera_start(lua_State *L) {
     int id = luaL_checkinteger(L, 1);
     int id = luaL_checkinteger(L, 1);
-    int mode = luaL_optinteger(L, 2, LUAT_CAMERA_MODE_AUTO);
-    luat_camera_work_mode(id, mode);
     lua_pushboolean(L, luat_camera_start(id) == 0 ? 1 : 0);
     lua_pushboolean(L, luat_camera_start(id) == 0 ? 1 : 0);
     return 1;
     return 1;
 }
 }
@@ -364,9 +365,14 @@ camera.capture(0)
 */
 */
 static int l_camera_capture(lua_State *L) {
 static int l_camera_capture(lua_State *L) {
     int id = luaL_checkinteger(L, 1);
     int id = luaL_checkinteger(L, 1);
-    const char* save_path = luaL_checkstring(L, 2);
     int quality = luaL_optinteger(L, 3, 1);
     int quality = luaL_optinteger(L, 3, 1);
-    lua_pushboolean(L, !luat_camera_capture(id, quality, save_path));
+    if (lua_isstring(L, 2)){
+    	const char* save_path = luaL_checkstring(L, 2);
+    	lua_pushboolean(L, !luat_camera_capture(id, quality, save_path));
+    } else {
+    	luat_zbuff_t *buff = luaL_checkudata(L, 2, LUAT_ZBUFF_TYPE);
+    	lua_pushboolean(L, !luat_camera_capture_in_ram(id, quality, buff));
+    }
     return 1;
     return 1;
 }
 }