diff --git a/vinscant/main.py b/vinscant/main.py index 6af048a..7339072 100644 --- a/vinscant/main.py +++ b/vinscant/main.py @@ -8,7 +8,7 @@ def get_key(): with open("key.txt", "r") as file: return file.read().strip() - +LEDDY_ADDRESS = "http://10.0.2.3" def uidToString(uid): mystring = "" for i in uid: @@ -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: + leddy.setText(f"Welkom {name}!") self.gotoSleep() def error(self): @@ -70,12 +72,30 @@ def error(self): self.buzzer.start(250) self.gotoSleep() +class Leddy: + def __init__(self, address="http://10.0.2.3") -> None: + self.address = address + + def _post(self, command: str): + try: + req.post(self.address, data=command, timeout=2).close() + except Exception: + print("vinscant: leddy doesn't work :\x28") # indentation does weird + + def setText(self, text: str): + self._post(f"Option autoResetMs {5 * 1000}") + self._post(f"ScrollingText {text}") def do_read(): rdr = mfrc522.MFRC522(rst=16,cs=33,sck=34,mosi=35,miso=36) lastUid = '' lastTime = 0 + print("vinscant: watchdog starting in 2s, interupt now with Ctrl+C") + time.sleep(2) + watchdog = WDT(timeout=10 * 1000) + print("vinscant: watchdog started") + print("") print("Place card before reader to read from address 0x08") print("") @@ -94,10 +114,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,14 +133,11 @@ def do_read(): watchdog.feed() except KeyboardInterrupt: print("KeyboardInterrupt") - + watchdog = WDT(timeout=60 * 60 * 1000) return notifier = StatusNotifier(Buzzer(Pin(37, Pin.OUT)), Led()) notifier.idle() key = get_key() -print("vinscant: watchdog starting in 2s, interupt now with Ctrl+C") -time.sleep(2) -watchdog = WDT(timeout=10 * 1000) -print("vinscant: watchdog started") +leddy = Leddy() do_read() diff --git a/vinscant/music.py b/vinscant/music.py index 278f6be..8c88fbf 100644 --- a/vinscant/music.py +++ b/vinscant/music.py @@ -12,8 +12,7 @@ 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: