Skip to content
Snippets Groups Projects
Commit f2e656ba authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Seperate out buzzer thread

parent dda0fd94
No related branches found
No related tags found
No related merge requests found
...@@ -114,9 +114,6 @@ def dispatch_led(ledstate, config): ...@@ -114,9 +114,6 @@ def dispatch_led(ledstate, config):
led_thread = threading.Thread(target=set_led, args=(ledstate, config, )) led_thread = threading.Thread(target=set_led, args=(ledstate, config, ))
led_thread.start() led_thread.start()
buzzer_thread = threading.Thread(target = set_buzzer, args = (ledstate, config, ))
buzzer_thread.start()
def set_led(ledstate, config): def set_led(ledstate, config):
""" """
Toggle between differen LED colors Toggle between differen LED colors
...@@ -148,8 +145,14 @@ def set_led(ledstate, config): ...@@ -148,8 +145,14 @@ def set_led(ledstate, config):
# Return to default standby LED color in the end # Return to default standby LED color in the end
LEDS.fill(config["led"]["standby_color"][0]) LEDS.fill(config["led"]["standby_color"][0])
def dispatch_buzzer(state, config):
"""
Dispatch a Buzzer thread with a given Buzzer state
"""
buzzer_thread = threading.Thread(target=set_buzzer, args=(state, config, ))
buzzer_thread.start()
def set_buzzer(ledstate, config): def set_buzzer(state, config):
global buzzer_pin global buzzer_pin
f = 220 f = 220
buzzer = GPIO.PWM(buzzer_pin, f) # Set frequency to 1 Khz buzzer = GPIO.PWM(buzzer_pin, f) # Set frequency to 1 Khz
...@@ -157,11 +160,12 @@ def set_buzzer(ledstate, config): ...@@ -157,11 +160,12 @@ def set_buzzer(ledstate, config):
time.sleep(0.5) time.sleep(0.5)
buzzer.stop() buzzer.stop()
time.sleep(0.5) time.sleep(0.5)
for i in range(10): for i in range(1, 10):
buzzer.ChangeFrequency(i*f) # Set frequency to 1 Khz buzzer.ChangeFrequency(i*f) # Set frequency to 1 Khz
buzzer.ChangeDutyCycle(50) # Set dutycycle to 10 buzzer.start(50) # Set dutycycle to 10
time.sleep(0.5) time.sleep(0.5)
buzzer.stop() buzzer.stop()
time.sleep(0.5)
def process_request(output_queue, config=None, logger=None): def process_request(output_queue, config=None, logger=None):
...@@ -352,6 +356,9 @@ def main(): ...@@ -352,6 +356,9 @@ def main():
outputThread = threading.Thread(target=process_request, args=(output_queue, config, logger), daemon=True) outputThread = threading.Thread(target=process_request, args=(output_queue, config, logger), daemon=True)
outputThread.start() outputThread.start()
dispatch_buzzer("startup", config)
exit()
# Set the LED to display readyness # Set the LED to display readyness
dispatch_led("startup", config) dispatch_led("startup", config)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment