Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a message to leddy #20

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions vinscant/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -60,22 +60,42 @@ 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):
self.led.setColor(*StatusNotifier.colors[0])
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("")
Expand All @@ -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:
Expand All @@ -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()
5 changes: 2 additions & 3 deletions vinscant/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ 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)
if len(note) == 0:
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:
Expand Down