|
@@ -7,11 +7,37 @@
|
|
|
*/
|
|
*/
|
|
|
#include "luat_base.h"
|
|
#include "luat_base.h"
|
|
|
#include "luat_camera.h"
|
|
#include "luat_camera.h"
|
|
|
|
|
+#include "luat_msgbus.h"
|
|
|
|
|
|
|
|
#define LUAT_LOG_TAG "camera"
|
|
#define LUAT_LOG_TAG "camera"
|
|
|
|
|
+#include "luat_log.h"
|
|
|
|
|
+
|
|
|
|
|
+#define MAX_DEVICE_COUNT 2
|
|
|
|
|
+
|
|
|
|
|
+typedef struct luat_camera_cb {
|
|
|
|
|
+ int scanned;
|
|
|
|
|
+} luat_camera_cb_t;
|
|
|
|
|
+static luat_camera_cb_t camera_cbs[MAX_DEVICE_COUNT];
|
|
|
|
|
+
|
|
|
|
|
+int l_camera_handler(lua_State *L, void* ptr) {
|
|
|
|
|
+ rtos_msg_t* msg = (rtos_msg_t*)lua_topointer(L, -1);
|
|
|
|
|
+ lua_pop(L, 1);
|
|
|
|
|
+ int camera_id = msg->arg1;
|
|
|
|
|
+ if (camera_cbs[camera_id].scanned) {
|
|
|
|
|
+ lua_geti(L, LUA_REGISTRYINDEX, camera_cbs[camera_id].scanned);
|
|
|
|
|
+ if (lua_isfunction(L, -1)) {
|
|
|
|
|
+ lua_pushinteger(L, camera_id);
|
|
|
|
|
+ lua_pushlstring(L, (char *)msg->ptr,msg->arg2);
|
|
|
|
|
+ lua_call(L, 2, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ lua_pushinteger(L, 0);
|
|
|
|
|
+ return 1;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
static int l_camera_init(lua_State *L){
|
|
static int l_camera_init(lua_State *L){
|
|
|
luat_camera_conf_t conf = {0};
|
|
luat_camera_conf_t conf = {0};
|
|
|
|
|
+ conf.lcd_conf = luat_lcd_get_default();
|
|
|
if (lua_istable(L, 1)) {
|
|
if (lua_istable(L, 1)) {
|
|
|
lua_pushliteral(L, "zbar_scan");
|
|
lua_pushliteral(L, "zbar_scan");
|
|
|
lua_gettable(L, 1);
|
|
lua_gettable(L, 1);
|
|
@@ -19,6 +45,12 @@ static int l_camera_init(lua_State *L){
|
|
|
conf.zbar_scan = luaL_checkinteger(L, -1);
|
|
conf.zbar_scan = luaL_checkinteger(L, -1);
|
|
|
}
|
|
}
|
|
|
lua_pop(L, 1);
|
|
lua_pop(L, 1);
|
|
|
|
|
+ lua_pushliteral(L, "i2c_id");
|
|
|
|
|
+ lua_gettable(L, 1);
|
|
|
|
|
+ if (lua_isinteger(L, -1)) {
|
|
|
|
|
+ conf.i2c_id = luaL_checkinteger(L, -1);
|
|
|
|
|
+ }
|
|
|
|
|
+ lua_pop(L, 1);
|
|
|
lua_pushliteral(L, "i2c_addr");
|
|
lua_pushliteral(L, "i2c_addr");
|
|
|
lua_gettable(L, 1);
|
|
lua_gettable(L, 1);
|
|
|
if (lua_isinteger(L, -1)) {
|
|
if (lua_isinteger(L, -1)) {
|
|
@@ -37,6 +69,12 @@ static int l_camera_init(lua_State *L){
|
|
|
conf.sensor_height = luaL_checkinteger(L, -1);
|
|
conf.sensor_height = luaL_checkinteger(L, -1);
|
|
|
}
|
|
}
|
|
|
lua_pop(L, 1);
|
|
lua_pop(L, 1);
|
|
|
|
|
+ lua_pushliteral(L, "color_bit");
|
|
|
|
|
+ lua_gettable(L, 1);
|
|
|
|
|
+ if (lua_isinteger(L, -1)) {
|
|
|
|
|
+ conf.color_bit = luaL_checkinteger(L, -1);
|
|
|
|
|
+ }
|
|
|
|
|
+ lua_pop(L, 1);
|
|
|
lua_pushliteral(L, "id_reg");
|
|
lua_pushliteral(L, "id_reg");
|
|
|
lua_gettable(L, 1);
|
|
lua_gettable(L, 1);
|
|
|
if (lua_isinteger(L, -1)) {
|
|
if (lua_isinteger(L, -1)) {
|
|
@@ -52,9 +90,9 @@ static int l_camera_init(lua_State *L){
|
|
|
lua_pushliteral(L, "init_cmd");
|
|
lua_pushliteral(L, "init_cmd");
|
|
|
lua_gettable(L, 1);
|
|
lua_gettable(L, 1);
|
|
|
if (lua_istable(L, -1)) {
|
|
if (lua_istable(L, -1)) {
|
|
|
- size_t init_cmd_size = lua_rawlen(L, -1);
|
|
|
|
|
- conf.init_cmd = luat_heap_malloc(init_cmd_size * sizeof(uint8_t));
|
|
|
|
|
- for (size_t i = 1; i <= init_cmd_size; i++){
|
|
|
|
|
|
|
+ conf.init_cmd_size = lua_rawlen(L, -1);
|
|
|
|
|
+ conf.init_cmd = luat_heap_malloc(conf.init_cmd_size * sizeof(uint8_t));
|
|
|
|
|
+ for (size_t i = 1; i <= conf.init_cmd_size; i++){
|
|
|
lua_geti(L, -1, i);
|
|
lua_geti(L, -1, i);
|
|
|
conf.init_cmd[i-1] = luaL_checkinteger(L, -1);
|
|
conf.init_cmd[i-1] = luaL_checkinteger(L, -1);
|
|
|
lua_pop(L, 1);
|
|
lua_pop(L, 1);
|
|
@@ -66,12 +104,41 @@ static int l_camera_init(lua_State *L){
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/*
|
|
|
|
|
+注册摄像头事件回调
|
|
|
|
|
+@api camera.on(id, event, func)
|
|
|
|
|
+@int camera id, camera 0写0, camera 1写1
|
|
|
|
|
+@string 事件名称
|
|
|
|
|
+@function 回调方法
|
|
|
|
|
+@return nil 无返回值
|
|
|
|
|
+@usage
|
|
|
|
|
+camera.on(0, "scanned", function(id, str)
|
|
|
|
|
+ print(id, str)
|
|
|
|
|
+end)
|
|
|
|
|
+*/
|
|
|
|
|
+static int l_camera_on(lua_State *L) {
|
|
|
|
|
+ int camera_id = luaL_checkinteger(L, 1);
|
|
|
|
|
+ const char* event = luaL_checkstring(L, 2);
|
|
|
|
|
+ if (!strcmp("scanned", event)) {
|
|
|
|
|
+ if (camera_cbs[camera_id].scanned != 0) {
|
|
|
|
|
+ luaL_unref(L, LUA_REGISTRYINDEX, camera_cbs[camera_id].scanned);
|
|
|
|
|
+ camera_cbs[camera_id].scanned = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (lua_isfunction(L, 3)) {
|
|
|
|
|
+ lua_pushvalue(L, 3);
|
|
|
|
|
+ camera_cbs[camera_id].scanned = luaL_ref(L, LUA_REGISTRYINDEX);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
#include "rotable.h"
|
|
#include "rotable.h"
|
|
|
static const rotable_Reg reg_camera[] =
|
|
static const rotable_Reg reg_camera[] =
|
|
|
{
|
|
{
|
|
|
{ "init" , l_camera_init , 0},
|
|
{ "init" , l_camera_init , 0},
|
|
|
// { "open" , l_camera_open , 0},
|
|
// { "open" , l_camera_open , 0},
|
|
|
// { "close" , l_camera_close, 0},
|
|
// { "close" , l_camera_close, 0},
|
|
|
|
|
+ { "on", l_camera_on, 0},
|
|
|
{ NULL, NULL , 0}
|
|
{ NULL, NULL , 0}
|
|
|
};
|
|
};
|
|
|
|
|
|