camera_test.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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输出
  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,
  13. sensor_height = 480,
  14. color_bit = 16,
  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. camera.on(0, "scanned", function(id, str)
  21. if type(str) == 'string' then
  22. log.info("扫码结果", str)
  23. log.info(rtos.meminfo("sys"))
  24. -- air105每次扫码仅需200ms, 当目标一维码或二维码持续被识别, 本函数会反复触发
  25. -- 鉴于某些场景需要间隔时间输出, 下列代码就是演示间隔输出
  26. -- if mcu.ticks() - tick < 1000 then
  27. -- return
  28. -- end
  29. -- tick_scan = mcu.ticks()
  30. -- 输出内容可以经过加工后输出, 例如带上换行(回车键)
  31. usbapp.vhid_upload(0, str.."\r\n")
  32. elseif str == true then
  33. log.info("拍照完成")
  34. elseif str == false then
  35. log.error("摄像头没有数据")
  36. end
  37. end)
  38. sys.taskInit(function()
  39. camera_rst(0)
  40. uart.setup(
  41. uart.VUART_0,--串口id
  42. 115200,--波特率
  43. 8,--数据位
  44. 1--停止位
  45. )
  46. -- 拍照, 自然就是RGB输出了
  47. local camera_id = camera.init(GC032A_InitReg)--屏幕输出rgb图像
  48. log.info("摄像头启动")
  49. camera.video(camera_id, 320, 240, uart.VUART_0)
  50. log.info("摄像头启动完成")
  51. while 1 do
  52. sys.wait(10000)
  53. end
  54. end)