main.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. PROJECT = "camerademo"
  2. VERSION = "1.0.0"
  3. sys = require("sys")
  4. httpplus = require "httpplus"
  5. local SCAN_MODE = 0 -- 写1演示扫码
  6. local scan_pause = true
  7. local getRawStart = false
  8. local RAW_MODE = 0 -- 写1演示获取原始图像
  9. local camera_id = camera.USB
  10. local usb_camera_table = {
  11. id = camera_id,
  12. sensor_width = 1280,
  13. sensor_height = 720,
  14. usb_port = 1
  15. }
  16. camera.on(camera_id, "scanned", function(id, str)
  17. if type(str) == 'string' then
  18. log.info("扫码结果", str)
  19. elseif str == false then
  20. log.error("摄像头没有数据")
  21. else
  22. log.info("摄像头数据", str)
  23. sys.publish("capture_done", true)
  24. end
  25. end)
  26. -- 按键触发拍照
  27. local function press_key()
  28. log.info("boot press")
  29. sys.publish("PRESS", true)
  30. end
  31. gpio.setup(14, press_key, gpio.PULLDOWN, gpio.RISING)
  32. gpio.debounce(14, 50)
  33. local rawbuff, err = zbuff.create(200 * 1024, 0, zbuff.HEAP_PSRAM)
  34. sys.taskInit(function()
  35. if rawbuff == nil then
  36. while true do
  37. sys.wait(1000)
  38. end
  39. log.info("zbuff创建失败", err)
  40. end
  41. wlan.init()
  42. wlan.connect("uiot", "12345678")
  43. sys.wait(3000)
  44. httpsrv.start(80, function() end) -- 联网且抓取成功之后, 可通过设备ip访问图片 http://192.168.1.19/abc.jpg
  45. log.info("摄像头初始化", camera.init(usb_camera_table))
  46. log.info(rtos.meminfo("sys"))
  47. log.info(rtos.meminfo("psram"))
  48. while 1 do
  49. local result, data = sys.waitUntil("PRESS", 5000)
  50. if true then
  51. -- camera.init(usb_camera_table)
  52. camera.start(camera_id)
  53. -- camera.capture(camera_id, rawbuff, 1)
  54. camera.capture(camera_id, "/abc.jpg", 1)
  55. result, data = sys.waitUntil("capture_done", 30000)
  56. -- log.info(rawbuff:used())
  57. camera.stop(camera_id)
  58. -- camera.close(camera_id) --完全关闭摄像头才用这个
  59. -- rawbuff:resize(60 * 1024)
  60. -- 上传到upload.air32.cn, 数据访问页面是 https://www.air32.cn/upload/data/
  61. -- local code, resp = httpplus.request({
  62. -- url = "http://upload.air32.cn/api/upload/jpg",
  63. -- method = "POST",
  64. -- body = rawbuff
  65. -- })
  66. -- log.info("http", code)
  67. -- 打印内存信息, 调试用
  68. -- log.info("sys", rtos.meminfo())
  69. -- log.info("sys", rtos.meminfo("sys"))
  70. -- log.info("psram", rtos.meminfo("psram"))
  71. end
  72. end
  73. end)
  74. -- sys.taskInit(
  75. -- function ()
  76. -- while 1 do
  77. -- sys.wait(1000)
  78. -- log.info("aaaaa")
  79. -- end
  80. -- end
  81. -- )
  82. -- 用户代码已结束---------------------------------------------
  83. -- 结尾总是这一句
  84. sys.run()
  85. -- sys.run()之后后面不要加任何语句!!!!!