From 9b69a062db7631fb6bd9b1419a2e445c06cc551a Mon Sep 17 00:00:00 2001 From: Thomas Buck Date: Tue, 13 Feb 2024 21:10:17 +0100 Subject: [PATCH] different font, print samplerate, add readme. --- README.md | 7 +++++++ osci-pi.py | 33 +++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..ce30116 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Osci Music Player + +Please see [my blog post for more details](https://www.xythobuz.de/osci_music_player.html). + +Quick start instructions can be found in the top comment of the Python script in this repo. + + ssh osci-music "sudo systemctl disable --now osci.service" && scp osci-pi.py osci-music:~ && ssh osci-music "sudo systemctl enable --now osci.service" diff --git a/osci-pi.py b/osci-pi.py index 0bed2d1..11ef388 100755 --- a/osci-pi.py +++ b/osci-pi.py @@ -65,8 +65,14 @@ from luma.oled.device import ssd1306 from luma.core.error import DeviceNotFoundError import psutil import RPi.GPIO as GPIO +from PIL import ImageFont basevol = "70" +debouncems = 200 + +#fontfile = "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf" +fontfile = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf" +fontsize = 11 LCD_REFRESH = 5.0 @@ -75,6 +81,7 @@ BTN_NEXT = 26 currentplaying = None lcd = None +font = None bat = None songlist = None currentfile = None @@ -132,13 +139,23 @@ def status(filename): f = f.replace("/", "\n") f = f.replace("_", " ") - f += "\n" - f += "Batt: {:.0f}% {:.2f}V {:.2f}A".format(bat.get_battery_level(), bat.get_battery_voltage(), bat.get_battery_current()) + f += "\n\n" + f += "Bat: {:.0f}% {:.2f}V {:.2f}A".format(bat.get_battery_level(), bat.get_battery_voltage(), bat.get_battery_current()) + + ip = get_ipv4_address() + if len(ip) > 0: + f += "\n" + f += "IP: %s" % (ip) - f += "\n" - f += "IP: %s" % (get_ipv4_address()) + with open("/proc/asound/card0/pcm0p/sub0/hw_params", "r") as rf: + for line in rf: + if line.startswith("rate:"): + rate = int(line.split(" ")[1]) - draw.multiline_text((0, 0), f, fill="white") + f += "\n" + f += "Rate: {:.0f}kHz".format(rate / 1000) + + draw.multiline_text((0, 0), f, font=font, fill="white", spacing=-1) except Exception as e: raise e @@ -234,6 +251,7 @@ def button(ch): def main(): global lcd + global font global bat global currentfile @@ -242,14 +260,17 @@ def main(): print("\t" + sys.argv[0] + " PATH") sys.exit(1) + os.system("killall ffplay") + GPIO.setmode(GPIO.BCM) for b in [ BTN_ARTIST, BTN_NEXT ]: GPIO.setup(b, GPIO.IN, pull_up_down=GPIO.PUD_UP) - GPIO.add_event_detect(b, GPIO.BOTH, callback=button, bouncetime=100) + GPIO.add_event_detect(b, GPIO.BOTH, callback=button, bouncetime=debouncems) try: bus = i2c(port=1, address=0x3C) lcd = ssd1306(bus) + font = ImageFont.truetype(fontfile, fontsize) except DeviceNotFoundError as E: print("No LCD connected") lcd = None