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

Add states

parent f2e656ba
No related branches found
No related tags found
No related merge requests found
......@@ -75,6 +75,10 @@ success_off_time = "[0.05]"
success_on_time = "[0.05]"
[buzzer]
active = true
[server]
address = "127.0.0.1"
port = 80
......@@ -112,6 +116,7 @@ def dispatch_led(ledstate, config):
Dispatch a LED thread with a given LED state
"""
led_thread = threading.Thread(target=set_led, args=(ledstate, config, ))
led_thread.daemon = True
led_thread.start()
def set_led(ledstate, config):
......@@ -149,23 +154,58 @@ def dispatch_buzzer(state, config):
"""
Dispatch a Buzzer thread with a given Buzzer state
"""
# If the buzzer is not active, return before starting a thread
if not config["buzzer"]["active"]:
return
# Start a daemonized buzzer thread
buzzer_thread = threading.Thread(target=set_buzzer, args=(state, config, ))
buzzer_thread.daemon = True
buzzer_thread.start()
def set_buzzer(state, config):
global buzzer_pin
f = 220
state = str(state).strip().lower()
if state in ["startup", "ready"]:
f = 1000
buzzer = GPIO.PWM(buzzer_pin, f) # Set frequency to 1 Khz
buzzer.start(50) # Set dutycycle to 10
time.sleep(0.1)
buzzer.stop()
time.sleep(0.1)
for i in [1, 3, 1, 2, 3, 4, 5, 6, 1]:
buzzer.ChangeFrequency((1+i)*0.083333333*f) # Set frequency to 1 Khz
buzzer.start(50) # Set dutycycle to 10
time.sleep(0.1)
buzzer.stop()
time.sleep(0.1)
elif state in ["success"]:
f = 1000
buzzer = GPIO.PWM(buzzer_pin, f) # Set frequency to 1 Khz
buzzer.start(50) # Set dutycycle to 10
time.sleep(0.5)
time.sleep(0.1)
buzzer.stop()
time.sleep(0.5)
for i in range(1, 10):
buzzer.ChangeFrequency(i*f) # Set frequency to 1 Khz
time.sleep(0.1)
for i in [12, 1]:
buzzer.ChangeFrequency((1+i)*0.083333333*f) # Set frequency to 1 Khz
buzzer.start(50) # Set dutycycle to 10
time.sleep(0.5)
time.sleep(0.1)
buzzer.stop()
time.sleep(0.5)
time.sleep(0.1)
elif state in ["failure"]:
f = 1000
buzzer = GPIO.PWM(buzzer_pin, f) # Set frequency to 1 Khz
buzzer.start(50) # Set dutycycle to 10
time.sleep(0.1)
buzzer.stop()
time.sleep(0.1)
for i in [5,3,2]:
buzzer.ChangeFrequency((1+i)*0.083333333*f) # Set frequency to 1 Khz
buzzer.start(50) # Set dutycycle to 10
time.sleep(0.1)
buzzer.stop()
time.sleep(0.1)
def process_request(output_queue, config=None, logger=None):
......@@ -182,9 +222,11 @@ def process_request(output_queue, config=None, logger=None):
if success:
logger.info("Server Response: Success")
dispatch_led("success", config)
dispatch_buzzer("success", config)
else:
logger.info("Server Response: Failed")
dispatch_led("failure", config)
dispatch_buzzer("failure", config)
else:
time.sleep(0.01)
......@@ -356,8 +398,8 @@ def main():
outputThread = threading.Thread(target=process_request, args=(output_queue, config, logger), daemon=True)
outputThread.start()
# Dispatch a startup sound to signal readyness
dispatch_buzzer("startup", config)
exit()
# Set the LED to display readyness
dispatch_led("startup", config)
......@@ -374,6 +416,7 @@ def main():
else:
logger.warning("Didn't register as a valid ID: {}".format(potential_id[:1024]))
dispatch_led("failure", config)
dispatch_buzzer("failure", config)
else:
time.sleep(0.01)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment