add siwatlib

This commit is contained in:
Siwat Sirichai 2022-04-09 01:10:31 +07:00
parent b242d5cb6e
commit 99432ea074
2 changed files with 39 additions and 0 deletions

12
siwatlib/debounce.py Normal file
View File

@ -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

27
siwatlib/sound.py Normal file
View File

@ -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()