-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcpu.py
executable file
·54 lines (40 loc) · 1.21 KB
/
cpu.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
#!/usr/bin/env python3
#
# Copyright 2020-2021 by Murray Altheim. All rights reserved. This file is part
# of the Robot Operating System project, released under the MIT License. Please
# see the LICENSE file included as part of this package.
#
# author: Murray Altheim
# created: 2021-02-22
# modified: 2021-02-22
#
import sys, time
from colorama import init, Fore, Style
init()
try:
import psutil
except ImportError:
sys.exit("This script requires the psutil module\nInstall with: pip3 install --user psutil")
from matrix11x7 import Matrix11x7
print(Fore.GREEN + Style.NORMAL + """
Matrix 11x7: CPU
Displays a graph with CPU values.
""" + Fore.RED + Style.NORMAL + """
Press Ctrl+C to exit.
""" + Style.RESET_ALL)
try:
matrix11x7 = Matrix11x7()
matrix11x7.set_brightness(0.5) # avoid retina-searage!
# uncomment if the display is upside down
# matrix11x7.rotate(degrees=180)
cpu_values = [0] * matrix11x7.width
while True:
cpu_values.pop(0)
cpu_values.append(psutil.cpu_percent())
matrix11x7.set_graph(cpu_values, low=0, high=25)
matrix11x7.show()
time.sleep(0.2)
except KeyboardInterrupt:
pass
finally:
matrix11x7.clear()