Browse Source

different font, print samplerate, add readme.

master
Thomas Buck 1 year ago
parent
commit
9b69a062db
  1. 7
      README.md
  2. 33
      osci-pi.py

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

33
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

Loading…
Cancel
Save