-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay_manager.py
70 lines (56 loc) · 2.76 KB
/
display_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from waveshare_epd import epd2in13_V3
import time
from PIL import Image, ImageDraw, ImageFont
import os
class DisplayManager:
def __init__(self):
self.epd = epd2in13_V3.EPD()
self.width = 250
self.height = 122
self.font_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'fonts')
def init_display(self):
self.epd.init()
self.epd.Clear(0xFF)
def get_fonts(self):
try:
# Utiliser une police par défaut si la police personnalisée n'est pas disponible
default_font = '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf'
custom_font = os.path.join(self.font_dir, 'Font.ttc')
font_path = custom_font if os.path.exists(custom_font) else default_font
if not os.path.exists(font_path):
raise FileNotFoundError(f"Aucune police trouvée: ni personnalisée ni par défaut")
title_font = ImageFont.truetype(font_path, 16)
normal_font = ImageFont.truetype(font_path, 12)
return title_font, normal_font
except Exception as e:
print(f"Erreur de chargement des polices: {str(e)}")
# Utiliser une police par défaut intégrée à PIL comme solution de repli
return ImageFont.load_default(), ImageFont.load_default()
def create_display_image(self, stats_data):
image = Image.new('1', (self.width, self.height), 255)
draw = ImageDraw.Draw(image)
title_font, normal_font = self.get_fonts()
# Draw title with timestamp
draw.text((5, 5), f"NiceHash Stats", font=title_font, fill=0)
draw.text((5, 25), stats_data['timestamp'], font=normal_font, fill=0)
# Draw mining stats
draw.text((5, 45), f"Active Rigs: {stats_data['active_rigs']}", font=normal_font, fill=0)
draw.text((5, 60), f"Total Hashrate: {stats_data['total_hashrate']}", font=normal_font, fill=0)
# Draw wallet balances
y_pos = 80
for currency, balance in stats_data['balances'].items():
draw.text((5, y_pos), f"{currency}: {balance}", font=normal_font, fill=0)
y_pos += 15
# Draw EUR balance
if 'balance_eur' in stats_data:
draw.text((5, y_pos), f"EUR: {stats_data['balance_eur']}", font=normal_font, fill=0)
return image
def update_display(self, stats_data):
try:
self.init_display()
image = self.create_display_image(stats_data)
self.epd.display(self.epd.getbuffer(image))
except Exception as e:
print(f"Display Error: {str(e)}")
finally:
self.epd.sleep()