raspberry pi zero based drum machine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sWifi.py 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_main(o)
  41. o.update_display(0)
  42. 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:
  43. u.draw_header(o)
  44. self.draw_main(o)
  45. o.update_display(0)
  46. def draw_main(self, o):
  47. o.center_block(self.ipad, o.h2, [0, 0, o.width, o.height], o.light_grey)
  48. o.center_block(self.ssid, o.h2, [0, 40, o.width, o.height+40], o.light_grey)
  49. def extract_ip(self):
  50. st = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  51. try:
  52. st.connect(("8.8.8.8", 80))
  53. IP = st.getsockname()[0]
  54. except Exception:
  55. IP = '127.0.0.1'
  56. finally:
  57. st.close()
  58. return IP
  59. def ReceiveMessage(self, message):
  60. o = self.FSM.owner
  61. u.play_seq(o, message)
  62. def Exit(self):
  63. self.FSM.owner.pub.unregister("beat", self)
  64. #====================================