diff --git a/spotiplayer_pi/main.py b/spotiplayer_pi/main.py index e679920..e05ef8f 100644 --- a/spotiplayer_pi/main.py +++ b/spotiplayer_pi/main.py @@ -7,11 +7,28 @@ import warnings from datetime import datetime import yaml from typing import Dict +import subprocess from spotiplayer_pi.lib import LCD_2inch from spotiplayer_pi.api import Api +def get_cpu_temp(): + try: + result = subprocess.run( + ["vcgencmd", "measure_temp"], capture_output=True, text=True, check=True + ) + temp_str = result.stdout.strip() + temp_value = temp_str.split("=")[1].replace("'C", "") + return float(temp_value) + except subprocess.CalledProcessError as e: + warnings.warn(f"Error executing vcgencmd: {e}") + return "None" + except (IndexError, ValueError) as e: + warnings.warn(f"Error parsing temperature: {e}") + return "None" + + def parse_config(path="spotiplayer_pi/config.yaml"): with open(path, "r") as file: data = yaml.safe_load(file) @@ -78,7 +95,7 @@ def display_loop(api: Api, cfg: Dict): elif data == "not-playing": draw = ImageDraw.Draw(not_playing_img) current_time = datetime.now().time() - draw.rectangle([(00, 120), (119, 170)], fill=(0, 0, 0)) + draw.rectangle([(00, 120), (119, 190)], fill=(0, 0, 0)) offset = 10 if current_time.hour < 9 else 0 draw.text( (10 + offset, 120), @@ -87,11 +104,17 @@ def display_loop(api: Api, cfg: Dict): fill=(255, 255, 255), ) draw.text( - (20, 152), + (25, 152), current_time.strftime("%a %d"), font=Font2, fill=(255, 255, 255), ) + draw.text( + (20, 175), + f"CPU: {get_cpu_temp():.2f}°", + font=Font0, + fill=(255, 255, 255), + ) if current_mode != 0: current_mode = 0 print("Standby mode")