Added auto brightness adjustment
This commit is contained in:
parent
8537b30b49
commit
383cb15866
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.pyc
|
@ -10,7 +10,18 @@ from drawing import make_cpu_grid, draw_to_LEDs
|
||||
from monitors import CPUMonitorThread
|
||||
|
||||
# External Dependencies
|
||||
try:
|
||||
import serial # pyserial
|
||||
import numpy as np # This is used in a module and we import it here to fetch it if needed
|
||||
import screen_brightness_control as sbc
|
||||
except ImportError:
|
||||
import pip
|
||||
for dependency in ["numpy", "pyserial", "screen-brightness-control"]:
|
||||
pip.main(['install', '--user', dependency])
|
||||
import serial
|
||||
import screen_brightness_control as sbc
|
||||
|
||||
# print(sbc.get_brightness())
|
||||
|
||||
def get_ports():
|
||||
"""Returns a list of all available serial ports on the system.
|
||||
@ -47,18 +58,26 @@ if __name__ == "__main__":
|
||||
# print(get_ports())
|
||||
port = "COM3"
|
||||
|
||||
cpu_queue = queue.Queue()
|
||||
cpu_queue = queue.Queue(2)
|
||||
cpu_monitor = CPUMonitorThread(cpu_queue)
|
||||
cpu_monitor.start()
|
||||
|
||||
s = serial.Serial(port, 115200)
|
||||
|
||||
min_background_brightness = 10
|
||||
max_background_brightness = 30
|
||||
min_foreground_brightness = 30
|
||||
max_foreground_brightness = 120
|
||||
|
||||
while True:
|
||||
if not cpu_queue.empty():
|
||||
cpu_values = cpu_queue.get()
|
||||
grid = make_cpu_grid(cpu_values, 10, 30)
|
||||
screen_brightness = sbc.get_brightness()[0]
|
||||
background_value = int(screen_brightness / 100 * (max_background_brightness - min_background_brightness) + min_background_brightness)
|
||||
foreground_value = int(screen_brightness / 100 * (max_foreground_brightness - min_foreground_brightness) + min_foreground_brightness)
|
||||
grid = make_cpu_grid(cpu_values, background_value, foreground_value)
|
||||
draw_to_LEDs(s, grid)
|
||||
time.sleep(0.1)
|
||||
time.sleep(0.05)
|
||||
|
||||
|
||||
|
||||
|
@ -20,6 +20,7 @@ class DiskMonitorThread(threading.Thread):
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
if not self.output_queue.full():
|
||||
disk_io = psutil.disk_io_counters()
|
||||
read_usage = disk_io.read_bytes
|
||||
write_usage = disk_io.write_bytes
|
||||
@ -60,6 +61,7 @@ class NetworkMonitorThread(threading.Thread):
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
if not self.output_queue.full():
|
||||
net_io = psutil.net_io_counters()
|
||||
sent_usage = net_io.bytes_sent
|
||||
recv_usage = net_io.bytes_recv
|
||||
@ -98,6 +100,7 @@ class CPUMonitorThread(threading.Thread):
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
if not self.output_queue.full():
|
||||
cpu_usage = psutil.cpu_percent(percpu=True)
|
||||
for i in range(self.cpu_count):
|
||||
useage = 2 * max(cpu_usage[2*i], cpu_usage[2*i+1]) # Combine logical cores
|
||||
@ -126,6 +129,7 @@ class MemoryMonitorThread(threading.Thread):
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
if not self.output_queue.full():
|
||||
memory_usage = psutil.virtual_memory().percent / 100.0
|
||||
self.memory_usage_history.append(memory_usage)
|
||||
self.history_times.append(time.time())
|
||||
|
Loading…
Reference in New Issue
Block a user