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

Cleanup

parent c90dbecf
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,12 @@ from keycode import KEYCODE
APPLICATION_NAME = "stechuhr-client"
DEFAULT_CONFIG = """
[server]
address = "127.0.0.1"
port = 80
timeout = 5
verify_cert = true
[client]
location = "lerchenfeld/mensa"
entrance = "haupteingang"
......@@ -79,42 +85,34 @@ success_on_time = "[0.05]"
active = true
# Midi note numbers and lengths in seconds - played on startup
startup_notes = [69, 82, 72]
startup_note_lengths = [0.9, 0.25, 2.9]
startup_note_stop_lengths = [0.1, 0.25, 0.1]
startup_notes = [80, 92, 80, 81]
startup_note_lengths = [0.1, 0.05, 0.1, 0.6]
startup_note_stop_lengths = [0.1, 0.05, 0.3, 0.1]
# Midi note numbers and lengths in seconds - played on successful scan
success_notes = [69, 72, 69]
success_note_lengths = [0.9, 0.25, 0.9]
success_note_stop_lengths = [0.1, 0.25, 0.1]
success_notes = [60, 72]
success_note_lengths = [0.05, 0.05]
success_note_stop_lengths = [0.05, 0.05]
# Midi note numbers and lengths in seconds - played on successful scan
failure_notes = [63, 61, 60, 59]
failure_note_lengths = [0.9, 0.25, 0.9, 1.0]
failure_note_stop_lengths = [0.1, 0.25, 0.1, 0.1]
[server]
address = "127.0.0.1"
port = 80
timeout = 5
verify_cert = true
failure_notes = [72, 58, 56, 53]
failure_note_lengths = [0.05, 0.05, 0.05, 0.2]
failure_note_stop_lengths = [0.05, 0.05, 0.05, 0.1]
"""
# Setup LED
LEDS = neopixel_spi.NeoPixel_SPI(board.SPI(), 10)
# Setup Buzzer
buzzer_pin = 18
GPIO.setup(buzzer_pin, GPIO.OUT)
BUZZER = GPIO.PWM(buzzer_pin, 440) # Set frequency to 1 Khz
BUZZER = GPIO.PWM(buzzer_pin, 440)
# Setup Constants used fo binding to keypad
# from input-event-codes.h
# type can be EV_SYN, EV_KEY or EV_MSC
EV_KEY = 1
KEY_DOWN = 1
# also from input.h
EVENT_FORMAT = "llHHI"
EVENT_SIZE = struct.calcsize(EVENT_FORMAT)
......@@ -128,6 +126,7 @@ def repeat(l, index):
"""
return l[index%len(l)]
def dispatch_led(ledstate, config):
"""
Dispatch a LED thread with a given LED state
......@@ -136,6 +135,7 @@ def dispatch_led(ledstate, config):
led_thread.daemon = True
led_thread.start()
def set_led(ledstate, config):
"""
Toggle between differen LED colors
......@@ -167,6 +167,7 @@ def set_led(ledstate, config):
# Return to default standby LED color in the end
LEDS.fill(config["led"]["standby_color"][0])
def dispatch_buzzer(state, config):
"""
Dispatch a Buzzer thread with a given Buzzer state
......@@ -180,28 +181,32 @@ def dispatch_buzzer(state, config):
buzzer_thread.daemon = True
buzzer_thread.start()
def set_buzzer(state, config):
"""
Enable a buzzer and play a certain melody depending on the state
"""
global BUZZER
state = str(state).strip().lower()
if state in ["startup", "ready"]:
for i, note in enumerate(config["buzzer"]["startup_notes"]):
BUZZER.ChangeFrequency(midinumber_to_hertz(note)) # Set frequency to 1 Khz
BUZZER.start(50) # Set dutycycle to 10
BUZZER.ChangeFrequency(midinumber_to_hertz(note))
BUZZER.start(10) # Set dutycycle to 10
time.sleep(repeat(config["buzzer"]["startup_note_lengths"], i))
BUZZER.stop()
time.sleep(repeat(config["buzzer"]["startup_note_stop_lengths"], i))
elif state in ["success"]:
for i, note in enumerate(config["buzzer"]["success_notes"]):
BUZZER.ChangeFrequency(midinumber_to_hertz(note)) # Set frequency to 1 Khz
BUZZER.start(50) # Set dutycycle to 10
BUZZER.ChangeFrequency(midinumber_to_hertz(note))
BUZZER.start(10) # Set dutycycle to 10
time.sleep(repeat(config["buzzer"]["success_note_lengths"], i))
BUZZER.stop()
time.sleep(repeat(config["buzzer"]["success_note_stop_lengths"], i))
elif state in ["failure"]:
for i, note in enumerate(config["buzzer"]["failure_notes"]):
BUZZER.ChangeFrequency(midinumber_to_hertz(note)) # Set frequency to 1 Khz
BUZZER.start(50) # Set dutycycle to 10
BUZZER.ChangeFrequency(midinumber_to_hertz(note))
BUZZER.start(10) # Set dutycycle to 10
time.sleep(repeat(config["buzzer"]["failure_note_lengths"], i))
BUZZER.stop()
time.sleep(repeat(config["buzzer"]["failure_note_stop_lengths"], i))
......@@ -269,7 +274,6 @@ def send_request(verified_id, config, logger) -> bool:
return True
def id_pattern_check(visitor_id: str, config: dict) -> bool:
"""
Returns True if any of the patterns from the config matches.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment