luat_lib_camera.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. @module camera
  3. @summary 摄像头
  4. @version 1.0
  5. @date 2022.01.11
  6. */
  7. #include "luat_base.h"
  8. #include "luat_camera.h"
  9. #define LUAT_LOG_TAG "camera"
  10. static int l_camera_init(lua_State *L){
  11. luat_camera_conf_t conf = {0};
  12. if (lua_istable(L, 1)) {
  13. lua_pushliteral(L, "zbar_scan");
  14. lua_gettable(L, 1);
  15. if (lua_isinteger(L, -1)) {
  16. conf.zbar_scan = luaL_checkinteger(L, -1);
  17. }
  18. lua_pop(L, 1);
  19. lua_pushliteral(L, "i2c_addr");
  20. lua_gettable(L, 1);
  21. if (lua_isinteger(L, -1)) {
  22. conf.i2c_addr = luaL_checkinteger(L, -1);
  23. }
  24. lua_pop(L, 1);
  25. lua_pushliteral(L, "sensor_width");
  26. lua_gettable(L, 1);
  27. if (lua_isinteger(L, -1)) {
  28. conf.sensor_width = luaL_checkinteger(L, -1);
  29. }
  30. lua_pop(L, 1);
  31. lua_pushliteral(L, "sensor_height");
  32. lua_gettable(L, 1);
  33. if (lua_isinteger(L, -1)) {
  34. conf.sensor_height = luaL_checkinteger(L, -1);
  35. }
  36. lua_pop(L, 1);
  37. lua_pushliteral(L, "id_reg");
  38. lua_gettable(L, 1);
  39. if (lua_isinteger(L, -1)) {
  40. conf.id_reg = luaL_checkinteger(L, -1);
  41. }
  42. lua_pop(L, 1);
  43. lua_pushliteral(L, "id_value");
  44. lua_gettable(L, 1);
  45. if (lua_isinteger(L, -1)) {
  46. conf.id_value = luaL_checkinteger(L, -1);
  47. }
  48. lua_pop(L, 1);
  49. lua_pushliteral(L, "init_cmd");
  50. lua_gettable(L, 1);
  51. if (lua_istable(L, -1)) {
  52. size_t init_cmd_size = lua_rawlen(L, -1);
  53. conf.init_cmd = luat_heap_malloc(init_cmd_size * sizeof(uint8_t));
  54. for (size_t i = 1; i <= init_cmd_size; i++){
  55. lua_geti(L, -1, i);
  56. conf.init_cmd[i-1] = luaL_checkinteger(L, -1);
  57. lua_pop(L, 1);
  58. }
  59. }
  60. lua_pop(L, 1);
  61. }
  62. luat_camera_init(&conf);
  63. return 0;
  64. }
  65. #include "rotable.h"
  66. static const rotable_Reg reg_camera[] =
  67. {
  68. { "init" , l_camera_init , 0},
  69. // { "open" , l_camera_open , 0},
  70. // { "close" , l_camera_close, 0},
  71. { NULL, NULL , 0}
  72. };
  73. LUAMOD_API int luaopen_camera( lua_State *L ) {
  74. luat_newlib(L, reg_camera);
  75. return 1;
  76. }