main.lua 670 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. DEBUG = true
  2. function debug_message(message)
  3. if DEBUG then
  4. print(message)
  5. end
  6. --TODO: rolling last 10
  7. end
  8. local yo = require('yo')
  9. local server = require('server')
  10. local read = require('read')
  11. function wifi_setup(func, ...)
  12. wifi.setmode(wifi.STATIONAP)
  13. wifi.ap.config({
  14. ssid = "YoButton-" .. node.chipid(),
  15. pwd = "yobutton",
  16. max = 1,
  17. auth = wifi.AUTH_OPEN
  18. })
  19. wifi.ap.dhcp.start()
  20. func(...)
  21. end
  22. function wifi_default(func, ...)
  23. server.stop()
  24. wifi.setmode(wifi.STATION)
  25. func(...)
  26. end
  27. function short_press()
  28. wifi_default(yo.yo, read.yo_recipient(), read.api_key())
  29. end
  30. function long_press()
  31. wifi_setup(server.start)
  32. end