diff --git a/siwatlib/debounce.py b/siwatlib/debounce.py new file mode 100644 index 0000000..e614803 --- /dev/null +++ b/siwatlib/debounce.py @@ -0,0 +1,12 @@ +from time import perf_counter as seconds +class debounce: + def __init__(self,state: bool, debounce_time: float) -> None: + self.last_pressed = seconds() + self.debounce_time = debounce_time + self.state = state + def set_state(self, state: bool) -> bool: + if seconds()-self.last_pressed > self.debounce_time: + self.state = state + return self.state + else: + return self.state \ No newline at end of file diff --git a/siwatlib/sound.py b/siwatlib/sound.py new file mode 100644 index 0000000..71ae48a --- /dev/null +++ b/siwatlib/sound.py @@ -0,0 +1,27 @@ +from pysine import pysine +import winsound +import threading + +MODE = 'pysine' + +global __beeper__ + +def __beeper_therad__(frequency: float, duration: float): + if MODE == 'winsound': + winsound.Beep(frequency=int(frequency), duration=int(duration*1000)) + elif MODE == 'pysine': + pysine.sine(frequency=frequency,duration=duration) + +__beeper__ = threading.Thread(target=__beeper_therad__, + kwargs={'frequency': 0, 'duration': 0} + ) + +def beep(frequency: float, duration: float): + global __beeper__ + if not __beeper__.is_alive(): + __beeper__ = threading.Thread(target=__beeper_therad__, + kwargs={'frequency': frequency, 'duration': duration} + ) + __beeper__.start() + +