camCapture.lua 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. require "bf30a2"
  2. camera.on(0, "scanned", function(id, str)
  3. if type(str) == 'string' then
  4. log.info("扫码结果", str)
  5. elseif str == false then
  6. log.error("摄像头没有数据")
  7. else
  8. log.info("摄像头数据", str)
  9. sys.publish("capture done", true)
  10. end
  11. end)
  12. local function press_key()
  13. log.info("boot press")
  14. sys.publish("PRESS", true)
  15. end
  16. gpio.setup(0, press_key, gpio.PULLDOWN, gpio.RISING)
  17. gpio.debounce(0, 100, 1)
  18. local rawbuff, err = zbuff.create(60 * 1024, 0, zbuff.HEAP_AUTO)
  19. if rawbuff == nil then
  20. log.info(err)
  21. end
  22. sys.taskInit(function()
  23. log.info("摄像头启动")
  24. local cspiId, i2cId = 1, 0
  25. local camera_id
  26. i2c.setup(i2cId, i2c.FAST)
  27. gpio.setup(5, 0) -- PD拉低
  28. log.info("按下boot开始测试")
  29. log.info(rtos.meminfo("sys"))
  30. log.info(rtos.meminfo("psram"))
  31. while 1 do
  32. local result, data = sys.waitUntil("PRESS")
  33. if result == true and data == true then
  34. log.debug("摄像头拍照")
  35. camera_id = bf30a2Init(cspiId, i2cId, 25500000)
  36. camera.capture(camera_id, rawbuff, 1) -- 2和3需要非常多非常多的psram,尽量不要用
  37. result, data = sys.waitUntil("capture done", 30000)
  38. if result then
  39. log.info(rawbuff:used())
  40. end
  41. camera.close(camera_id) -- 完全关闭摄像头才用这个
  42. rawbuff:resize(60 * 1024)
  43. log.info(rtos.meminfo("sys"))
  44. log.info(rtos.meminfo("psram"))
  45. end
  46. end
  47. end)
  48. sys.publish("PRESS", true)
  49. sys.timerLoopStart(sys.publish, 60000, "PRESS", true)