main.lua 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. -- LuaTools需要PROJECT和VERSION这两个信息
  2. PROJECT = "air302_fs_demo"
  3. VERSION = "1.0.0"
  4. -- sys库是标配
  5. _G.sys = require("sys")
  6. -- 日志TAG, 非必须
  7. local NETLED = gpio.setup(19, 0)
  8. function fs_test()
  9. local f = io.open("boot_time", "rb")
  10. local c = 0
  11. if f then
  12. local data = f:read("*a")
  13. log.info("fs", "data", data, data:toHex())
  14. c = tonumber(data)
  15. f:close()
  16. end
  17. log.info("fs", "boot count", c)
  18. c = c + 1
  19. f = io.open("boot_time", "wb")
  20. --if f ~= nil then
  21. log.info("fs", "write c to file", c, tostring(c))
  22. f:write(tostring(c))
  23. f:close()
  24. --end
  25. end
  26. fs_test() -- 每次开机,把记录的数值+1
  27. sys.taskInit(function()
  28. while 1 do
  29. if socket.isReady() then
  30. NETLED(1)
  31. sys.wait(100)
  32. NETLED(0)
  33. sys.wait(1900)
  34. else
  35. NETLED(1)
  36. sys.wait(500)
  37. NETLED(0)
  38. sys.wait(500)
  39. end
  40. end
  41. end)
  42. -- 用户代码已结束---------------------------------------------
  43. -- 结尾总是这一句
  44. sys.run()
  45. -- sys.run()之后后面不要加任何语句!!!!!