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.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import FSM
  2. import utils as u
  3. import menus as m
  4. import os
  5. #====================================
  6. State = type("State", (object,), {})
  7. #====================================
  8. class State(object):
  9. def __init__(self, FSM):
  10. self.FSM = FSM
  11. def Enter(self):
  12. pass
  13. def Execute(self):
  14. pass
  15. def Exit(self):
  16. pass
  17. class Ping(State):
  18. def __init__(self,FSM):
  19. super(Ping, self).__init__(FSM)
  20. def Enter(self):
  21. o = self.FSM.owner
  22. o.header_text = "Ping"
  23. o.pub.register("beat", self)
  24. self.pinging = self.check_ping()
  25. self.draw_main(o)
  26. u.draw_header(o)
  27. o.update_display(0)
  28. super(Ping, self).Enter()
  29. def Execute(self):
  30. o = self.FSM.owner
  31. m.menu1_actions(self, o)
  32. if o.keyState[16] == 1:
  33. m.draw_menu1(o)
  34. o.update_display(0)
  35. elif o.keyState[16] == 4:
  36. u.draw_header(o)
  37. self.draw_main(o)
  38. o.update_display(0)
  39. 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:
  40. u.draw_header(o)
  41. self.draw_main(o)
  42. o.update_display(0)
  43. def draw_main(self, o):
  44. o.center_block(self.pinging, o.h2, [0, 0, o.width, o.height], o.light_grey)
  45. def check_ping(self):
  46. hostname = "8.8.8.8"
  47. response = os.system("ping -c 1 " + hostname)
  48. if response == 0:
  49. pingstatus = "Network Active "
  50. else:
  51. pingstatus = "Network Error "
  52. return pingstatus
  53. def ReceiveMessage(self, message):
  54. o = self.FSM.owner
  55. u.play_seq(o, message)
  56. def Exit(self):
  57. self.FSM.owner.pub.unregister("beat", self)
  58. #====================================