-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTempLED.py
75 lines (60 loc) · 1.65 KB
/
TempLED.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
71
72
73
74
75
# -*- coding: utf-8 -*-
import SystemInfo
import serial
import serial.tools.list_ports
from time import sleep
# You must change this for your Arduino VID:PID!!
ARDUINO_ID = "1A86:7523"
NORMAL = "0"
THEATER_CHASE = "1"
RAINBOW = "2"
RAINBOW_CYCLE = "3"
BREATHING = "4"
RED = "125 0 0"
ELECTRIC_BLUE = "0 125 125"
def select_mode(load):
if(load > 30):
return THEATER_CHASE
else:
return BREATHING
def select_color(temp):
if(temp > 50):
return RED
else:
return ELECTRIC_BLUE
# Get the GPU's temperature sensor
system = SystemInfo.SystemInfo()
graphic_temp_sensor = None
graphic_load_sensor = None
for sensor in system.GPU.Sensors:
if sensor.SensorType == "Temperature":
graphic_temp_sensor = sensor
if sensor.SensorType == "Load" and sensor.Name == "GPU Core":
graphic_load_sensor = sensor
# Get the Arduino port
arduino_list = serial.tools.list_ports.grep(ARDUINO_ID)
for device in arduino_list:
arduino_port = device.device
ser = serial.Serial(arduino_port, 9600)
try:
n = 0
m_load = 0
m_temp = 0
command = "0 0 0 0"
ser.write(command.encode('UTF-8'))
sleep(2)
while True:
load = graphic_load_sensor.getValue()
m_load += load
temp = graphic_temp_sensor.getValue()
m_temp += temp
n += 1
print("Load:", load, "%", "Temp:", temp, "Cº")
command = select_mode(load) + ' ' + select_color(temp)
ser.write(command.encode('UTF-8'))
ser.read()
except KeyboardInterrupt:
print("Medium Load:", m_load/n, "%", "Medium Temp:", m_temp/n, "Cº")
ser.write("0".encode('UTF-8'))
print("Exit!")
ser.close()