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

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
 from luma.core.error import DeviceNotFoundError
65
 from luma.core.error import DeviceNotFoundError
66
 import psutil
66
 import psutil
67
 import RPi.GPIO as GPIO
67
 import RPi.GPIO as GPIO
68
+from PIL import ImageFont
68
 
69
 
69
 basevol = "70"
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
 LCD_REFRESH = 5.0
77
 LCD_REFRESH = 5.0
72
 
78
 
75
 
81
 
76
 currentplaying = None
82
 currentplaying = None
77
 lcd = None
83
 lcd = None
84
+font = None
78
 bat = None
85
 bat = None
79
 songlist = None
86
 songlist = None
80
 currentfile = None
87
 currentfile = None
132
             f = f.replace("/", "\n")
139
             f = f.replace("/", "\n")
133
             f = f.replace("_", " ")
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
     except Exception as e:
159
     except Exception as e:
143
         raise e
160
         raise e
144
 
161
 
234
 
251
 
235
 def main():
252
 def main():
236
     global lcd
253
     global lcd
254
+    global font
237
     global bat
255
     global bat
238
     global currentfile
256
     global currentfile
239
 
257
 
242
         print("\t" + sys.argv[0] + " PATH")
260
         print("\t" + sys.argv[0] + " PATH")
243
         sys.exit(1)
261
         sys.exit(1)
244
 
262
 
263
+    os.system("killall ffplay")
264
+
245
     GPIO.setmode(GPIO.BCM)
265
     GPIO.setmode(GPIO.BCM)
246
     for b in [ BTN_ARTIST, BTN_NEXT ]:
266
     for b in [ BTN_ARTIST, BTN_NEXT ]:
247
         GPIO.setup(b, GPIO.IN, pull_up_down=GPIO.PUD_UP)
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
     try:
270
     try:
251
         bus = i2c(port=1, address=0x3C)
271
         bus = i2c(port=1, address=0x3C)
252
         lcd = ssd1306(bus)
272
         lcd = ssd1306(bus)
273
+        font = ImageFont.truetype(fontfile, fontsize)
253
     except DeviceNotFoundError as E:
274
     except DeviceNotFoundError as E:
254
         print("No LCD connected")
275
         print("No LCD connected")
255
         lcd = None
276
         lcd = None

Loading…
Cancel
Save