From dda060d8a00aaa93bb904dc07051b15bdcc52e5a Mon Sep 17 00:00:00 2001 From: draxaris1010 Date: Tue, 11 Jun 2024 13:38:48 +0200 Subject: [PATCH] vinscant: beep beep beep & welkom message --- vinscant/main.py | 11 ++++++++--- vinscant/music.py | 7 +++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/vinscant/main.py b/vinscant/main.py index 6af048a..47587d5 100644 --- a/vinscant/main.py +++ b/vinscant/main.py @@ -60,9 +60,11 @@ def gotoSleep(self): self.idle() - def good(self): + def good(self, name=None): self.led.setColor(*StatusNotifier.colors[2]) self.buzzer.start(500) + if name: + req.post("http://10.0.2.3", data=f"ScrollingText Welkom {name}!").close() self.gotoSleep() def error(self): @@ -70,6 +72,7 @@ def error(self): self.buzzer.start(250) self.gotoSleep() +watchdog = None def do_read(): rdr = mfrc522.MFRC522(rst=16,cs=33,sck=34,mosi=35,miso=36) @@ -94,10 +97,11 @@ def do_read(): if uid != lastUid or currentTime - lastTime > 5: res = req.post("https://zess.zeus.gent/scans", data=f"{uid};{key}") print("vingo: " + res.text) + name = res.text res.close() # beep beep if 200 <= res.status_code < 300: - notifier.good() + notifier.good(name) else: notifier.error() else: @@ -112,7 +116,7 @@ def do_read(): watchdog.feed() except KeyboardInterrupt: print("KeyboardInterrupt") - + watchdog = WDT(timeout=60 * 60 * 1000) return notifier = StatusNotifier(Buzzer(Pin(37, Pin.OUT)), Led()) @@ -122,4 +126,5 @@ def do_read(): time.sleep(2) watchdog = WDT(timeout=10 * 1000) print("vinscant: watchdog started") +req.post("http://10.0.2.3", data=f"Option autoResetMs {5 * 1000}").close() do_read() diff --git a/vinscant/music.py b/vinscant/music.py index 278f6be..77505d3 100644 --- a/vinscant/music.py +++ b/vinscant/music.py @@ -5,15 +5,14 @@ def __init__(self, melody: io.IOBase, pin: Pin) -> None: self.melody = melody self.pin = pin self.pwm: PWM = PWM(pin, freq=1, duty_u16=0) - self.timer = Timer(0) + self.timer = Timer(1) @staticmethod def midi_to_freq(note: int): return 440 * 2**((float(note) - 69) / 12) def start(self): - self.timer.init(mode=Timer.PERIODIC, freq=10, callback=self.playNote) - self.pwm = PWM() + self.timer.init(mode=Timer.PERIODIC, freq=1, callback=self.playNote) def playNote(self, ignored: Timer): note = self.melody.read(1) @@ -21,7 +20,7 @@ def playNote(self, ignored: Timer): self.close() return note = note[0] - self.pwm.freq(MusicPlayer.midi_to_freq(note)) + self.pwm.freq(int(MusicPlayer.midi_to_freq(note))) if note == 0: self.pwm.duty_u16(0) else: