Browse Source

different font, print samplerate, add readme.

Thomas Buck 10 months ago
parent
commit
9b69a062db
2 changed files with 34 additions and 6 deletions
  1. 7
    0
      README.md
  2. 27
    6
      osci-pi.py

+ 7
- 0
README.md View File

@@ -0,0 +1,7 @@
1
+# Osci Music Player
2
+
3
+Please see [my blog post for more details](https://www.xythobuz.de/osci_music_player.html).
4
+
5
+Quick start instructions can be found in the top comment of the Python script in this repo.
6
+
7
+    ssh osci-music "sudo systemctl disable --now osci.service" && scp osci-pi.py osci-music:~ && ssh osci-music "sudo systemctl enable --now osci.service"

+ 27
- 6
osci-pi.py View File

@@ -65,8 +65,14 @@ from luma.oled.device import ssd1306
65 65
 from luma.core.error import DeviceNotFoundError
66 66
 import psutil
67 67
 import RPi.GPIO as GPIO
68
+from PIL import ImageFont
68 69
 
69 70
 basevol = "70"
71
+debouncems = 200
72
+
73
+#fontfile = "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf"
74
+fontfile = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
75
+fontsize = 11
70 76
 
71 77
 LCD_REFRESH = 5.0
72 78
 
@@ -75,6 +81,7 @@ BTN_NEXT = 26
75 81
 
76 82
 currentplaying = None
77 83
 lcd = None
84
+font = None
78 85
 bat = None
79 86
 songlist = None
80 87
 currentfile = None
@@ -132,13 +139,23 @@ def status(filename):
132 139
             f = f.replace("/", "\n")
133 140
             f = f.replace("_", " ")
134 141
 
135
-            f += "\n"
136
-            f += "Batt: {:.0f}%  {:.2f}V  {:.2f}A".format(bat.get_battery_level(), bat.get_battery_voltage(), bat.get_battery_current())
142
+            f += "\n\n"
143
+            f += "Bat: {:.0f}% {:.2f}V {:.2f}A".format(bat.get_battery_level(), bat.get_battery_voltage(), bat.get_battery_current())
144
+
145
+            ip = get_ipv4_address()
146
+            if len(ip) > 0:
147
+                f += "\n"
148
+                f += "IP: %s" % (ip)
137 149
 
138
-            f += "\n"
139
-            f += "IP: %s" % (get_ipv4_address())
150
+            with open("/proc/asound/card0/pcm0p/sub0/hw_params", "r") as rf:
151
+                for line in rf:
152
+                    if line.startswith("rate:"):
153
+                        rate = int(line.split(" ")[1])
140 154
 
141
-            draw.multiline_text((0, 0), f, fill="white")
155
+                        f += "\n"
156
+                        f += "Rate: {:.0f}kHz".format(rate / 1000)
157
+
158
+            draw.multiline_text((0, 0), f, font=font, fill="white", spacing=-1)
142 159
     except Exception as e:
143 160
         raise e
144 161
 
@@ -234,6 +251,7 @@ def button(ch):
234 251
 
235 252
 def main():
236 253
     global lcd
254
+    global font
237 255
     global bat
238 256
     global currentfile
239 257
 
@@ -242,14 +260,17 @@ def main():
242 260
         print("\t" + sys.argv[0] + " PATH")
243 261
         sys.exit(1)
244 262
 
263
+    os.system("killall ffplay")
264
+
245 265
     GPIO.setmode(GPIO.BCM)
246 266
     for b in [ BTN_ARTIST, BTN_NEXT ]:
247 267
         GPIO.setup(b, GPIO.IN, pull_up_down=GPIO.PUD_UP)
248
-        GPIO.add_event_detect(b, GPIO.BOTH, callback=button, bouncetime=100)
268
+        GPIO.add_event_detect(b, GPIO.BOTH, callback=button, bouncetime=debouncems)
249 269
 
250 270
     try:
251 271
         bus = i2c(port=1, address=0x3C)
252 272
         lcd = ssd1306(bus)
273
+        font = ImageFont.truetype(fontfile, fontsize)
253 274
     except DeviceNotFoundError as E:
254 275
         print("No LCD connected")
255 276
         lcd = None

Loading…
Cancel
Save