Skip to content

Commit 868e53c

Browse files
committed
Add files for Pi SSD server
Add files for Pi SSD server
1 parent 7a9a1e2 commit 868e53c

File tree

11 files changed

+45894
-0
lines changed

11 files changed

+45894
-0
lines changed

Pi_SSD_Media_Server/display-info.py

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

0 commit comments

Comments
 (0)