camera_test.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. --上位机源码: https://gitee.com/openLuat/luatos-soc-air105 C#写的, 就能用, 勿生产
  2. --编译好的工具:https://gitee.com/openLuat/luatos-soc-air105/attach_files
  3. local GC032A_InitReg =
  4. {
  5. zbar_scan = 0,--是否为扫码, 扫码模式会显示灰度图像!!!
  6. draw_lcd = 0,--是否向lcd输出, 若没有接lcd显示屏就不用设置为1
  7. i2c_id = 0,
  8. i2c_addr = 0x21,
  9. pwm_id = 5;
  10. pwm_period = 24*1000*1000, -- 摄像头的时钟线的波特率
  11. pwm_pulse = 0,
  12. sensor_width = 640, -- GC032A摄像头的实际分辨率是30w,但内存不足,实际显示居中的1/4图像
  13. sensor_height = 480,
  14. color_bit = 16, -- 颜色空间是 RGB565
  15. init_cmd = "/luadb/GC032A_InitReg.txt"--此方法将初始化指令写在外部文件,支持使用 # 进行注释
  16. }
  17. local camera_pwdn = gpio.setup(pin.PD06, 1, gpio.PULLUP) -- PD06 camera_pwdn引脚
  18. local camera_rst = gpio.setup(pin.PD07, 1, gpio.PULLUP) -- PD07 camera_rst引脚
  19. usbapp.start(0)
  20. sys.taskInit(function()
  21. camera_rst(0)
  22. uart.setup(
  23. uart.VUART_0,-- USB虚拟串口id
  24. 115200,--波特率
  25. 8,--数据位
  26. 1--停止位
  27. )
  28. -- 拍照, 自然就是RGB输出了
  29. local camera_id = camera.init(GC032A_InitReg)--屏幕输出rgb图像
  30. log.info("摄像头启动")
  31. camera.video(camera_id, 320, 240, uart.VUART_0)
  32. log.info("摄像头启动完成")
  33. end)
  34. -- 以下是扫码的回调, 仅当zbar_scan=1时会有回调
  35. camera.on(0, "scanned", function(id, str)
  36. if type(str) == 'string' then
  37. log.info("扫码结果", str)
  38. log.info(rtos.meminfo("sys"))
  39. -- air105每次扫码仅需200ms, 当目标一维码或二维码持续被识别, 本函数会反复触发
  40. -- 鉴于某些场景需要间隔时间输出, 下列代码就是演示间隔输出
  41. -- if mcu.ticks() - tick < 1000 then
  42. -- return
  43. -- end
  44. -- tick_scan = mcu.ticks()
  45. -- 输出内容可以经过加工后输出, 例如带上换行(回车键)
  46. usbapp.vhid_upload(0, str.."\r\n")
  47. elseif str == true then
  48. log.info("拍照完成")
  49. elseif str == false then
  50. log.error("摄像头没有数据")
  51. end
  52. end)