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.

sPing.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 Ping(State):
  19. def __init__(self,FSM):
  20. super(Ping, self).__init__(FSM)
  21. def Enter(self):
  22. o = self.FSM.owner
  23. o.header_text = "Ping"
  24. o.pub.register("beat", self)
  25. self.pinging = self.check_ping()
  26. self.draw_main(o)
  27. u.draw_header(o)
  28. o.update_display(0)
  29. super(Ping, self).Enter()
  30. def Execute(self):
  31. o = self.FSM.owner
  32. m.menu1_actions(self, o)
  33. if o.keyState[16] == 1:
  34. m.draw_menu1(o)
  35. o.update_display(0)
  36. elif o.keyState[16] == 4:
  37. u.draw_header(o)
  38. #self.draw_footer(o)
  39. self.draw_main(o)
  40. o.update_display(0)
  41. 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:
  42. u.draw_header(o)
  43. #self.draw_footer(o)
  44. self.draw_main(o)
  45. o.update_display(0)
  46. def draw_main(self, o):
  47. o.center_block(self.pinging, o.h2, [0, 0, o.width, o.height], o.light_grey)
  48. def check_ping(self):
  49. hostname = "8.8.8.8"
  50. response = os.system("ping -c 1 " + hostname)
  51. # and then check the response...
  52. if response == 0:
  53. pingstatus = "Network Active "
  54. else:
  55. pingstatus = "Network Error "
  56. return pingstatus
  57. def ReceiveMessage(self, message):
  58. o = self.FSM.owner
  59. u.play_seq(o, message)
  60. def Exit(self):
  61. self.FSM.owner.pub.unregister("beat", self)
  62. #====================================