Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

176 lines
5.6KB

  1. import time
  2. from thread import start_new_thread
  3. from modules import cbpi
  4. try:
  5. import RPi.GPIO as GPIO
  6. except Exception as e:
  7. pass
  8. class Buzzer(object):
  9. # custom beep sounds
  10. sound = ["H", 0.1, "L"]
  11. melodie1 = ["H", 0.1, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.1, "L"]
  12. melodie2 = ["H", 0.1, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.1, "L"]
  13. melodie3 = ["H", 0.4, "L", 0.1, "H", 0.4, "L", 0.1, "H", 0.4, "L"]
  14. melodie4 = ["H", 0.4, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.4, "L", 0.1, "H", 0.1, "L", 0.1, "H", 0.4, "L"]
  15. melodie5 = ["H", 0.6, "L", 0.3, "H", 0.6, "L", 0.3, "H", 0.6, "L"]
  16. melodie6 = ["H", 0.2, "L", 0.4, "H", 0.2, "L", 0.3, "H", 0.2, "L", 0.2, "H", 0.2, "L", 0.1, "H", 0.2, "L", 0.1, "H", 0.2, "L"]
  17. def __init__(self, gpio):
  18. try:
  19. cbpi.app.logger.info("INIT BUZZER NOW GPIO%s" % gpio)
  20. self.gpio = int(gpio)
  21. GPIO.setmode(GPIO.BCM)
  22. GPIO.setup(self.gpio, GPIO.OUT)
  23. self.state = True
  24. cbpi.app.logger.info("BUZZER SETUP OK")
  25. except Exception as e:
  26. cbpi.app.logger.info("BUZZER EXCEPTION %s" % str(e))
  27. self.state = False
  28. def beep(self): # beeps once when you boot up your Pi with CBPi -- beeps at Brewing finished
  29. if self.state is False:
  30. cbpi.app.logger.error("BUZZER not working")
  31. return
  32. def play(sound):
  33. try:
  34. for i in sound:
  35. if (isinstance(i, str)):
  36. if i == "H":
  37. GPIO.output(int(self.gpio), GPIO.HIGH)
  38. else:
  39. GPIO.output(int(self.gpio), GPIO.LOW)
  40. else:
  41. time.sleep(i)
  42. except Exception as e:
  43. pass
  44. start_new_thread(play, (self.melodie2,))
  45. def MashStepEndBeep(self): # beeps at end of step
  46. if self.state is False:
  47. cbpi.app.logger.error("BUZZER not working")
  48. return
  49. def play(sound):
  50. try:
  51. for i in sound:
  52. if (isinstance(i, str)):
  53. if i == "H":
  54. GPIO.output(int(self.gpio), GPIO.HIGH)
  55. else:
  56. GPIO.output(int(self.gpio), GPIO.LOW)
  57. else:
  58. time.sleep(i)
  59. except Exception as e:
  60. pass
  61. start_new_thread(play, (self.melodie1,))
  62. def MashInStepEndBeep(self): # beeps at end of step
  63. if self.state is False:
  64. cbpi.app.logger.error("BUZZER not working")
  65. return
  66. def play(sound):
  67. try:
  68. for i in sound:
  69. if (isinstance(i, str)):
  70. if i == "H":
  71. GPIO.output(int(self.gpio), GPIO.HIGH)
  72. else:
  73. GPIO.output(int(self.gpio), GPIO.LOW)
  74. else:
  75. time.sleep(i)
  76. except Exception as e:
  77. pass
  78. start_new_thread(play, (self.melodie3,))
  79. def ChilStepEndBeep(self): # beeps at end of step
  80. if self.state is False:
  81. cbpi.app.logger.error("BUZZER not working")
  82. return
  83. def play(sound):
  84. try:
  85. for i in sound:
  86. if (isinstance(i, str)):
  87. if i == "H":
  88. GPIO.output(int(self.gpio), GPIO.HIGH)
  89. else:
  90. GPIO.output(int(self.gpio), GPIO.LOW)
  91. else:
  92. time.sleep(i)
  93. except Exception as e:
  94. pass
  95. start_new_thread(play, (self.melodie4,))
  96. def PumpStepEndBeep(self): # beeps at end of step
  97. if self.state is False:
  98. cbpi.app.logger.error("BUZZER not working")
  99. return
  100. def play(sound):
  101. try:
  102. for i in sound:
  103. if (isinstance(i, str)):
  104. if i == "H":
  105. GPIO.output(int(self.gpio), GPIO.HIGH)
  106. else:
  107. GPIO.output(int(self.gpio), GPIO.LOW)
  108. else:
  109. time.sleep(i)
  110. except Exception as e:
  111. pass
  112. start_new_thread(play, (self.melodie5,))
  113. def BoilStepEndBeep(self): # beeps at end of step
  114. if self.state is False:
  115. cbpi.app.logger.error("BUZZER not working")
  116. return
  117. def play(sound):
  118. try:
  119. for i in sound:
  120. if (isinstance(i, str)):
  121. if i == "H":
  122. GPIO.output(int(self.gpio), GPIO.HIGH)
  123. else:
  124. GPIO.output(int(self.gpio), GPIO.LOW)
  125. else:
  126. time.sleep(i)
  127. except Exception as e:
  128. pass
  129. start_new_thread(play, (self.melodie6,))
  130. @cbpi.initalizer(order=1)
  131. def init(cbpi):
  132. gpio = cbpi.get_config_parameter("buzzer", 16)
  133. cbpi.buzzer = Buzzer(gpio)
  134. cbpi.beep()
  135. cbpi.MashStepEndBeep()
  136. cbpi.MashInStepEndBeep()
  137. cbpi.ChilStepEndBeep()
  138. cbpi.PumpStepEndBeep()
  139. cbpi.BoilStepEndBeep()
  140. cbpi.app.logger.info("INIT OK")