init
This commit is contained in:
commit
ce1095bb24
27 changed files with 621 additions and 0 deletions
17
app/utils/countdown.py
Normal file
17
app/utils/countdown.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import time
|
||||
import threading
|
||||
import pygame
|
||||
|
||||
def play_sound(path):
|
||||
pygame.mixer.init()
|
||||
sound = pygame.mixer.Sound(path)
|
||||
sound.play()
|
||||
time.sleep(sound.get_length())
|
||||
|
||||
def start():
|
||||
def countdown_thread():
|
||||
for i in range(3):
|
||||
play_sound("app/static/sounds/beep.wav")
|
||||
time.sleep(1)
|
||||
play_sound("app/static/sounds/go.wav")
|
||||
threading.Thread(target=countdown_thread).start()
|
||||
21
app/utils/gpio_handler.py
Normal file
21
app/utils/gpio_handler.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from gpiozero import Button
|
||||
from signal import pause
|
||||
import time
|
||||
|
||||
class Lichtschranke:
|
||||
def __init__(self, gpio_pin, callback, schutzzeit=3):
|
||||
self.pin = gpio_pin
|
||||
self.callback = callback
|
||||
self.last_trigger = 0
|
||||
self.button = Button(gpio_pin, pull_up=False, bounce_time=0.05)
|
||||
self.button.when_pressed = self._ausgeloest
|
||||
self.schutzzeit = schutzzeit
|
||||
|
||||
def _ausgeloest(self):
|
||||
jetzt = time.time()
|
||||
if jetzt - self.last_trigger > self.schutzzeit:
|
||||
self.last_trigger = jetzt
|
||||
self.callback()
|
||||
|
||||
def stop(self):
|
||||
self.button.close()
|
||||
1
app/utils/init.py
Normal file
1
app/utils/init.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
# leer
|
||||
14
app/utils/system_tools.py
Normal file
14
app/utils/system_tools.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import subprocess
|
||||
|
||||
def reboot():
|
||||
subprocess.run(["sudo", "reboot"])
|
||||
|
||||
def shutdown():
|
||||
subprocess.run(["sudo", "shutdown", "now"])
|
||||
|
||||
def restart_service():
|
||||
subprocess.run(["sudo", "systemctl", "restart", "rennstopuhr.service"])
|
||||
|
||||
def get_logs():
|
||||
result = subprocess.run(["journalctl", "-u", "rennstopuhr.service", "--no-pager"], capture_output=True, text=True)
|
||||
return result.stdout
|
||||
22
app/utils/zeitmessung.py
Normal file
22
app/utils/zeitmessung.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import time
|
||||
|
||||
class Zeitmesser:
|
||||
def __init__(self):
|
||||
self.startzeit = None
|
||||
self.runden = []
|
||||
|
||||
def start(self):
|
||||
self.startzeit = time.perf_counter()
|
||||
|
||||
def runde(self):
|
||||
if self.startzeit is None:
|
||||
return None
|
||||
jetzt = time.perf_counter()
|
||||
rundenzeit = jetzt - self.startzeit
|
||||
self.runden.append(rundenzeit)
|
||||
self.startzeit = jetzt
|
||||
return rundenzeit
|
||||
|
||||
def reset(self):
|
||||
self.startzeit = None
|
||||
self.runden = []
|
||||
Reference in a new issue