node.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. --gl.setup(800,600)
  2. gl.setup(1024,768)
  3. local json = require "json"
  4. local font = resource.load_font("silkscreen.ttf")
  5. local cur_image = resource.load_image("/home/pi/especificos-node/node/1.png")
  6. local state = "diapo"
  7. local cur_preg = ""
  8. local time = "0:0"
  9. local img_prog="0/0"
  10. node.alias("eba")
  11. function decode_command(line)
  12. local cmd = json.decode(line)
  13. print(line)
  14. print(cmd.type)
  15. if cmd.type == "diapo" then
  16. cur_image:dispose()
  17. cur_image = resource.load_image(cmd.value)
  18. img_prog= cmd.progress
  19. elseif cmd.type == "pregunta" then
  20. cur_preg = cmd.preg
  21. elseif cmd.type == "time" then
  22. time = cmd.time
  23. print(time)
  24. elseif cmd.type == "video" then
  25. -- ?
  26. elseif cmd.type == "switch" then
  27. state = cmd.new_state
  28. end
  29. end
  30. --node.event("input", decode_command) -- listen to TCP
  31. node.event("data", decode_command) -- listen to UDP
  32. function node.render()
  33. if state == "diapo" then
  34. --cur_image:draw(0,0,WIDTH,HEIGHT)
  35. util.draw_correct(image, 0, 0, WIDTH, HEIGHT)
  36. font:write(WIDTH-70,HEIGHT-20,time,20,1,1,1,1)
  37. font:write(10,HEIGHT-20,img_prog,20,1,1,1,1)
  38. elseif state == "pregunta" then
  39. preguntas:draw(0,0,WIDTH,HEIGHT)
  40. font:write(120,320,cur_preg,20,1,1,1,1)
  41. end
  42. end