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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. # and then check the response...
  49. if response == 0:
  50. pingstatus = "Network Active "
  51. else:
  52. pingstatus = "Network Error "
  53. return pingstatus
  54. def ReceiveMessage(self, message):
  55. o = self.FSM.owner
  56. u.play_seq(o, message)
  57. def Exit(self):
  58. self.FSM.owner.pub.unregister("beat", self)
  59. #====================================