Add RockPro64 Fan Controller
This commit is contained in:
parent
58ce699b75
commit
17d734df53
20
rootfs/rockpro64/etc/systemd/system/fan_control.service
Normal file
20
rootfs/rockpro64/etc/systemd/system/fan_control.service
Normal file
|
@ -0,0 +1,20 @@
|
|||
# myNode Fan Control (RockPro64)
|
||||
# /etc/systemd/system/fan_control.service
|
||||
|
||||
[Unit]
|
||||
Description=myNode Fan Control
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
KillMode=control-group
|
||||
ExecStart=/usr/bin/fan_control.py
|
||||
User=root
|
||||
Group=root
|
||||
StandardOutput=syslog
|
||||
StandardError=syslog
|
||||
SyslogIdentifier=mynode_fan
|
||||
Restart=always
|
||||
RestartSec=30
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
55
rootfs/standard/usr/bin/fan_control.py
Executable file
55
rootfs/standard/usr/bin/fan_control.py
Executable file
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/python3
|
||||
from time import sleep
|
||||
|
||||
current_fan_speed=0
|
||||
|
||||
def get_temp():
|
||||
with open('/sys/class/thermal/thermal_zone0/temp') as f:
|
||||
results = f.read()
|
||||
device_temp = int(int(results) / 1000)
|
||||
print("Current temp: {}C".format(device_temp))
|
||||
return device_temp
|
||||
|
||||
def set_fan_speed(percent):
|
||||
global current_fan_speed
|
||||
|
||||
if percent != current_fan_speed:
|
||||
print("Setting fan speed: {}%".format(percent))
|
||||
fan_speed=int(float(percent) * 2.55)
|
||||
current_fan_speed = percent
|
||||
with open('/sys/class/hwmon/hwmon0/pwm1', 'w') as f:
|
||||
f.write("{}".format(fan_speed))
|
||||
|
||||
|
||||
def calculate_fan_setting(temp):
|
||||
if temp <= 50:
|
||||
set_fan_speed(0)
|
||||
elif temp >= 65 and temp < 70:
|
||||
set_fan_speed(30)
|
||||
elif temp >= 70 and temp < 75:
|
||||
set_fan_speed(60)
|
||||
elif temp >= 75:
|
||||
set_fan_speed(100)
|
||||
|
||||
def main_loop():
|
||||
# On start run fan for a bit
|
||||
try:
|
||||
set_fan_speed(60)
|
||||
sleep(20)
|
||||
set_fan_speed(0)
|
||||
except:
|
||||
pass
|
||||
|
||||
while True:
|
||||
try:
|
||||
temp = get_temp()
|
||||
calculate_fan_setting(temp)
|
||||
except Exception as e:
|
||||
print("Exception: {}".format(str(e)))
|
||||
set_fan_speed(80)
|
||||
finally:
|
||||
sleep(10)
|
||||
|
||||
# This is the main entry point for the program
|
||||
if __name__ == "__main__":
|
||||
main_loop()
|
|
@ -418,6 +418,12 @@ apt-get remove -y tor
|
|||
apt-get install -y tor
|
||||
|
||||
|
||||
# Enable fan control
|
||||
if [ $IS_ROCKPRO64 = 1 ]; then
|
||||
systemctl enable fan_control
|
||||
fi
|
||||
|
||||
|
||||
# Enable any new/required services
|
||||
systemctl enable firewall
|
||||
systemctl enable invalid_block_check
|
||||
|
|
|
@ -25,14 +25,6 @@ sudo apt-get -y upgrade
|
|||
sudo apt-get -y install network-manager tmux
|
||||
sudo apt-get -y install lua5.3 lua5.3-dev gcc make git
|
||||
|
||||
# Install fan controller
|
||||
git clone https://github.com/tuxd3v/ats.git
|
||||
cd ats
|
||||
make
|
||||
sudo make install
|
||||
cd ../
|
||||
rm -rf ats
|
||||
|
||||
# Regenerate MAC Address for RockPro64
|
||||
. /usr/lib/armbian/armbian-common
|
||||
CONNECTION="$(nmcli -f UUID,ACTIVE,DEVICE,TYPE connection show --active | tail -n1)"
|
||||
|
|
|
@ -525,6 +525,12 @@ sync
|
|||
sleep 1
|
||||
|
||||
|
||||
# Enable fan control
|
||||
if [ $IS_ROCKPRO64 = 1 ]; then
|
||||
systemctl enable fan_control
|
||||
fi
|
||||
|
||||
|
||||
# Setup myNode Startup Script
|
||||
systemctl daemon-reload
|
||||
systemctl enable mynode
|
||||
|
|
Loading…
Reference in New Issue
Block a user