Skip to content

Commit 05baa9d

Browse files
authored
Merge pull request #2256 from adafruit/pi_ssd_server
Add files for Pi SSD server
2 parents 7a9a1e2 + 6317bbe commit 05baa9d

File tree

11 files changed

+45891
-0
lines changed

11 files changed

+45891
-0
lines changed

Pi_SSD_Media_Server/display-info.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
import subprocess
5+
import board
6+
import displayio
7+
from adafruit_display_text import label
8+
from adafruit_bitmap_font import bitmap_font
9+
from adafruit_st7789 import ST7789
10+
11+
BORDER_WIDTH = 4
12+
TEXT_SCALE = 1
13+
14+
font = bitmap_font.load_font("/home/pi/fonts/Arial-18.bdf")
15+
font_small = bitmap_font.load_font("/home/pi/fonts/Arial-14.bdf")
16+
font_bold = bitmap_font.load_font("/home/pi/fonts/Arial-Bold-24.bdf")
17+
18+
# Release any resources currently in use for the displays
19+
displayio.release_displays()
20+
21+
spi = board.SPI()
22+
tft_cs = board.CE0
23+
tft_dc = board.D25
24+
tft_rst = board.D24
25+
26+
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=tft_rst)
27+
28+
display = ST7789(display_bus, width=320, height=170, colstart=35, rotation=270)
29+
30+
# Make the display context
31+
splash = displayio.Group()
32+
display.show(splash)
33+
34+
color_bitmap = displayio.Bitmap(display.width, display.height, 1)
35+
color_palette = displayio.Palette(1)
36+
color_palette[0] = 0xAA0088 # Purple
37+
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
38+
splash.append(bg_sprite)
39+
40+
# Draw a smaller inner rectangle
41+
inner_bitmap = displayio.Bitmap(
42+
display.width - (BORDER_WIDTH * 2), display.height - (BORDER_WIDTH * 2), 1
43+
)
44+
inner_palette = displayio.Palette(1)
45+
inner_palette[0] = 0x222222 # Dark Gray
46+
inner_sprite = displayio.TileGrid(
47+
inner_bitmap, pixel_shader=inner_palette, x=BORDER_WIDTH, y=BORDER_WIDTH
48+
)
49+
splash.append(inner_sprite)
50+
51+
# display ip, cpu and memory usage
52+
cmd = "hostname -I | cut -d' ' -f1"
53+
IP = subprocess.check_output(cmd, shell=True).decode("utf-8")
54+
cmd = 'cut -f 1 -d " " /proc/loadavg'
55+
CPU = subprocess.check_output(cmd, shell=True).decode("utf-8")
56+
cmd = "free -m | awk 'NR==2{printf \"Mem: %s/%s MB %.2f%%\", $3,$2,$3*100/$2 }'"
57+
MemUsage = subprocess.check_output(cmd, shell=True).decode("utf-8")
58+
cmd = "vcgencmd measure_temp | grep -o -E '[[:digit:]].*'"
59+
cpu_temp = subprocess.check_output(cmd, shell=True).decode("utf-8")
60+
61+
# Draw a label
62+
text_ip = label.Label(
63+
font_bold,
64+
text="IP: " + IP,
65+
color=0x1BF702,
66+
scale=TEXT_SCALE,
67+
)
68+
text_cpu = label.Label(
69+
font,
70+
text="CPU: " + cpu_temp,
71+
color=0xFFFFFF,
72+
scale=TEXT_SCALE,
73+
)
74+
text_mem = label.Label(
75+
font_small,
76+
text=MemUsage,
77+
color=0xCCCCCC,
78+
scale=TEXT_SCALE,
79+
)
80+
text_ip.x = 12
81+
text_cpu.x = 12
82+
text_mem.x = 12
83+
84+
text_ip.y = 30
85+
text_cpu.y = 70
86+
text_mem.y = 150
87+
88+
splash.append(text_ip)
89+
splash.append(text_cpu)
90+
splash.append(text_mem)
91+
92+
while True:
93+
text_ip.text = "IP: " + IP
94+
text_cpu.text = "CPU:" + cpu_temp
95+
text_mem.text = MemUsage
96+
display.refresh()

0 commit comments

Comments
 (0)