raspberry pi zero based drum machine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

sWifi.py 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import FSM
  2. import utils as u
  3. import menus as m
  4. import os
  5. import socket
  6. #====================================
  7. State = type("State", (object,), {})
  8. #====================================
  9. class State(object):
  10. def __init__(self, FSM):
  11. self.FSM = FSM
  12. def Enter(self):
  13. pass
  14. def Execute(self):
  15. pass
  16. def Exit(self):
  17. pass
  18. class Wifi(State):
  19. def __init__(self,FSM):
  20. super(Wifi, self).__init__(FSM)
  21. def Enter(self):
  22. o = self.FSM.owner
  23. o.header_text = "Wifi"
  24. o.pub.register("beat", self)
  25. self.ipad = self.extract_ip()
  26. self.ssid = os.popen("sudo iwgetid -r").read()
  27. o.center_block(self.ipad, o.h2, [0, 0, o.width,o.height], o.light_grey)
  28. u.draw_header(o)
  29. self.draw_main(o)
  30. o.update_display(0)
  31. super(Wifi, self).Enter()
  32. def Execute(self):
  33. o = self.FSM.owner
  34. m.menu1_actions(self, o)
  35. if o.keyState[16] == 1:
  36. m.draw_menu1(o)
  37. o.update_display(0)
  38. elif o.keyState[16] == 4:
  39. u.draw_header(o)
  40. #self.draw_footer(o)
  41. self.draw_main(o)
  42. o.update_display(0)
  43. if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
  44. u.draw_header(o)
  45. #self.draw_footer(o)
  46. self.draw_main(o)
  47. o.update_display(0)
  48. def draw_main(self, o):
  49. o.center_block(self.ipad, o.h2, [0, 0, o.width, o.height], o.light_grey)
  50. o.center_block(self.ssid, o.h2, [0, 40, o.width, o.height+40], o.light_grey)
  51. def extract_ip(self):
  52. st = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  53. try:
  54. #st.connect(('10.255.255.255', 1))
  55. st.connect(("8.8.8.8", 80))
  56. IP = st.getsockname()[0]
  57. except Exception:
  58. IP = '127.0.0.1'
  59. finally:
  60. st.close()
  61. return IP
  62. #print(extract_ip())
  63. def ReceiveMessage(self, message):
  64. o = self.FSM.owner
  65. u.play_seq(o, message)
  66. def Exit(self):
  67. self.FSM.owner.pub.unregister("beat", self)
  68. #====================================