|
|
@ -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\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 += "Batt: {:.0f}% {:.2f}V {:.2f}A".format(bat.get_battery_level(), bat.get_battery_voltage(), bat.get_battery_current()) |
|
|
|
f += "IP: %s" % (ip) |
|
|
|
|
|
|
|
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]) |
|
|
|
|
|
|
|
f += "\n" |
|
|
|
f += "IP: %s" % (get_ipv4_address()) |
|
|
|
f += "Rate: {:.0f}kHz".format(rate / 1000) |
|
|
|
|
|
|
|
draw.multiline_text((0, 0), f, fill="white") |
|
|
|
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 |
|
|
|