main.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. -- LuaTools需要PROJECT和VERSION这两个信息
  2. PROJECT = "air8000_gpio_ext"
  3. VERSION = "1.0.5"
  4. -- sys库是标配
  5. _G.sys = require("sys")
  6. --[[特别注意, 使用http库需要下列语句]]
  7. PWR8000S = function(level)
  8. gpio.set(23, level)
  9. end
  10. gpio.debounce(0, 1000)
  11. gpio.setup(0, function()
  12. sys.taskInit(function()
  13. log.info("复位Air8000S")
  14. PWR8000S(0)
  15. sys.wait(20)
  16. PWR8000S(1)
  17. end)
  18. end, gpio.PULLDOWN)
  19. local uartid = 11
  20. local buff = zbuff.create(1024)
  21. function uart_on()
  22. local result = uart.on(uartid, "receive", function(id, len)
  23. local s = ""
  24. log.info("uart", "recv", id, len)
  25. repeat
  26. -- s = uart.read(id, 128)
  27. uart.rx(id, buff)
  28. s = buff:query()
  29. if s and #s > 0 then -- #s 是取字符串的长度
  30. -- 如果传输二进制/十六进制数据, 部分字符不可见, 不代表没收到
  31. -- 关于收发hex值,请查阅 https://doc.openluat.com/article/583
  32. log.info("uart", "receive", id, #s, s)
  33. -- log.info("uart", "receive", id, #s, s:toHex())
  34. buff:del()
  35. else
  36. break
  37. end
  38. until s == ""
  39. end)
  40. log.info("uart.on", "receive", result)
  41. uart.on(uartid, "sent", function(id)
  42. log.info("uart", id, "sent")
  43. end)
  44. end
  45. sys.taskInit(function()
  46. sys.wait(1000)
  47. airlink.debug(1)
  48. local ret = uart.setup(uartid, 115200)
  49. log.info("执行初始化", ret);
  50. uart_on()
  51. while 1 do
  52. uart.write(uartid, "1234123412341234")
  53. -- gpio.setup(164, 0, gpio.PULLDOWN)
  54. sys.wait(1000)
  55. -- break
  56. -- airlink.statistics()
  57. end
  58. -- while 1 do
  59. -- uart.write(11, "ABC\r\n")
  60. -- sys.wait(1000)
  61. -- end
  62. end)
  63. -- 用户代码已结束---------------------------------------------
  64. -- 结尾总是这一句
  65. sys.run()
  66. -- sys.run()之后后面不要加任何语句!!!!!