You've already forked Argon-One-Daemon
Inital Commit
All checks were successful
Argon One Daemon / Argon One Daemon [arm64] (push) Successful in 33s
All checks were successful
Argon One Daemon / Argon One Daemon [arm64] (push) Successful in 33s
This commit is contained in:
1
root/DEBIAN/conffiles
Normal file
1
root/DEBIAN/conffiles
Normal file
@@ -0,0 +1 @@
|
||||
/etc/argon-one.conf
|
||||
10
root/DEBIAN/control
Normal file
10
root/DEBIAN/control
Normal file
@@ -0,0 +1,10 @@
|
||||
Package: argon-one
|
||||
Version: 1.0.0
|
||||
Architecture:
|
||||
Installed-Size:
|
||||
Depends: python3, python3-rpi-lgpio, python3-smbus, raspi-gpio
|
||||
Priority: optional
|
||||
Section: misc
|
||||
Homepage: http://www.privlab.it
|
||||
Maintainer: PrivLab <hostmaster@privlab.it>
|
||||
Description: Argon One Case Daemon
|
||||
25
root/DEBIAN/postinst
Normal file
25
root/DEBIAN/postinst
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/sh
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
if [ -d '/run/systemd/system' ]; then
|
||||
/usr/bin/systemctl --system daemon-reload > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
fi
|
||||
|
||||
case "${1}" in
|
||||
configure)
|
||||
if [ -x '/usr/bin/deb-systemd-helper' ]; then
|
||||
/usr/bin/deb-systemd-helper unmask 'argon-one.service' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
fi
|
||||
if /usr/bin/deb-systemd-helper --quiet was-enabled 'argon-one.service'; then
|
||||
/usr/bin/deb-systemd-helper enable 'argon-one.service' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
else
|
||||
/usr/bin/deb-systemd-helper update-state 'argon-one.service' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
23
root/DEBIAN/postrm
Normal file
23
root/DEBIAN/postrm
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
if [ -d '/run/systemd/system' ]; then
|
||||
/usr/bin/systemctl --system daemon-reload > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
fi
|
||||
|
||||
case "${1}" in
|
||||
remove|purge)
|
||||
if [ -x '/usr/bin/deb-systemd-helper' ]; then
|
||||
/usr/bin/deb-systemd-helper purge 'argon-one.service' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
/usr/bin/deb-systemd-helper unmask 'argon-one.service' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
fi
|
||||
BOOT=$(/usr/bin/grep '/boot' '/etc/fstab' | /usr/bin/mawk '$1 !~ /^#/ && $2 ~ /^[/]/ {print $2}')
|
||||
/usr/bin/sed --in-place 's/dtparam=i2c_arm=on/dtparam=i2c_arm=off/' "${BOOT}/config.txt"
|
||||
/usr/bin/sed --in-place 's/console=tty0/console=tty0 console=ttyS1,115200/' "${BOOT}/cmdline.txt"
|
||||
;;
|
||||
esac
|
||||
17
root/DEBIAN/preinst
Normal file
17
root/DEBIAN/preinst
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/sh
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
case "${1}" in
|
||||
install)
|
||||
BOOT=$(/usr/bin/grep '/boot' '/etc/fstab' | /usr/bin/mawk '$1 !~ /^#/ && $2 ~ /^[/]/ {print $2}')
|
||||
/usr/bin/sed --in-place 's/dtparam=i2c_arm=off/dtparam=i2c_arm=on/' "${BOOT}/config.txt"
|
||||
/usr/bin/sed --in-place 's/ console=ttyS1,115200//' "${BOOT}/cmdline.txt"
|
||||
/usr/bin/echo '##'
|
||||
/usr/bin/echo '##'
|
||||
/usr/bin/echo '## Restart the device to load the necessary drivers.'
|
||||
/usr/bin/echo '##'
|
||||
/usr/bin/echo '##'
|
||||
;;
|
||||
esac
|
||||
15
root/DEBIAN/prerm
Normal file
15
root/DEBIAN/prerm
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/sh
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
case "${1}" in
|
||||
remove)
|
||||
if [ -x '/usr/bin/deb-systemd-invoke' ]; then
|
||||
/usr/bin/deb-systemd-invoke stop 'argon-one.service' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
/usr/bin/deb-systemd-invoke disable 'argon-one.service' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
10
root/etc/argon-one.conf
Normal file
10
root/etc/argon-one.conf
Normal file
@@ -0,0 +1,10 @@
|
||||
# Argon One Case Fan Configuration
|
||||
#
|
||||
# List below the temperature (Celsius) and fan speed (in percent) pairs
|
||||
# Use the following form:
|
||||
# min.temperature=speed
|
||||
#
|
||||
55=25
|
||||
60=50
|
||||
66=75
|
||||
70=100
|
||||
18
root/lib/systemd/system-shutdown/argon-one_poweroff.py
Normal file
18
root/lib/systemd/system-shutdown/argon-one_poweroff.py
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import sys
|
||||
import smbus
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
rev = GPIO.RPI_REVISION
|
||||
if rev == 2 or rev == 3:
|
||||
bus = smbus.SMBus(1)
|
||||
else:
|
||||
bus = smbus.SMBus(0)
|
||||
if len(sys.argv) > 1:
|
||||
bus.write_byte(0x1A, 0)
|
||||
if sys.argv[1] == "poweroff" or sys.argv[1] == "halt":
|
||||
try:
|
||||
bus.write_byte(0x1A, 0xFF)
|
||||
except:
|
||||
rev = 0
|
||||
15
root/lib/systemd/system/argon-one.service
Normal file
15
root/lib/systemd/system/argon-one.service
Normal file
@@ -0,0 +1,15 @@
|
||||
[Unit]
|
||||
Description=Argon One Case Daemon
|
||||
After=multi-user.target
|
||||
|
||||
[Service]
|
||||
Type=idle
|
||||
ExecStart=/usr/lib/argon-one/daemon
|
||||
ProtectSystem=full
|
||||
Restart=always
|
||||
RestartSec=15
|
||||
RestartPreventExitStatus=0
|
||||
TimeoutStopSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
117
root/usr/lib/argon-one/daemon
Normal file
117
root/usr/lib/argon-one/daemon
Normal file
@@ -0,0 +1,117 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import smbus
|
||||
import RPi.GPIO as GPIO
|
||||
import os
|
||||
import time
|
||||
from threading import Thread
|
||||
|
||||
rev = GPIO.RPI_REVISION
|
||||
if rev == 2 or rev == 3:
|
||||
bus = smbus.SMBus(1)
|
||||
else:
|
||||
bus = smbus.SMBus(0)
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
shutdown_pin = 4
|
||||
GPIO.setup(shutdown_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
|
||||
def shutdown_check():
|
||||
while True:
|
||||
pulsetime = 1
|
||||
GPIO.wait_for_edge(shutdown_pin, GPIO.RISING)
|
||||
time.sleep(0.01)
|
||||
while GPIO.input(shutdown_pin) == GPIO.HIGH:
|
||||
time.sleep(0.01)
|
||||
pulsetime += 1
|
||||
if pulsetime >= 2 and pulsetime <= 3:
|
||||
os.system("reboot")
|
||||
elif pulsetime >= 4 and pulsetime <= 5:
|
||||
os.system("poweroff")
|
||||
|
||||
def get_fanspeed(tempval, configlist):
|
||||
for curconfig in configlist:
|
||||
curpair = curconfig.split("=")
|
||||
tempcfg = float(curpair[0])
|
||||
fancfg = int(float(curpair[1]))
|
||||
if tempval >= tempcfg:
|
||||
if fancfg < 1:
|
||||
return 0
|
||||
elif fancfg < 25:
|
||||
return 25
|
||||
return fancfg
|
||||
return 0
|
||||
|
||||
def load_config(fname):
|
||||
newconfig = []
|
||||
try:
|
||||
with open(fname, "r") as fp:
|
||||
for curline in fp:
|
||||
if not curline:
|
||||
continue
|
||||
tmpline = curline.strip()
|
||||
if not tmpline:
|
||||
continue
|
||||
if tmpline[0] == "#":
|
||||
continue
|
||||
tmppair = tmpline.split("=")
|
||||
if len(tmppair) != 2:
|
||||
continue
|
||||
tempval = 0
|
||||
fanval = 0
|
||||
try:
|
||||
tempval = float(tmppair[0])
|
||||
if tempval < 0 or tempval > 100:
|
||||
continue
|
||||
except:
|
||||
continue
|
||||
try:
|
||||
fanval = int(float(tmppair[1]))
|
||||
if fanval < 0 or fanval > 100:
|
||||
continue
|
||||
except:
|
||||
continue
|
||||
newconfig.append("{:5.1f}={}".format(tempval, fanval))
|
||||
if len(newconfig) > 0:
|
||||
newconfig.sort(reverse=True)
|
||||
except:
|
||||
return []
|
||||
return newconfig
|
||||
|
||||
def temp_check():
|
||||
fanconfig = ["70=100", "65=75", "50=50", "55=25"]
|
||||
tmpconfig = load_config("/etc/argon-one.conf")
|
||||
if len(tmpconfig) > 0:
|
||||
fanconfig = tmpconfig
|
||||
address = 0x1A
|
||||
prevblock = 0
|
||||
while True:
|
||||
try:
|
||||
tempfp = open("/sys/class/thermal/thermal_zone0/temp", "r")
|
||||
temp = tempfp.readline()
|
||||
tempfp.close()
|
||||
val = float(int(temp) / 1000)
|
||||
except IOError:
|
||||
val = 0
|
||||
block = get_fanspeed(val, fanconfig)
|
||||
if block < prevblock:
|
||||
time.sleep(30)
|
||||
prevblock = block
|
||||
try:
|
||||
if block > 0:
|
||||
bus.write_byte(address, 100)
|
||||
time.sleep(1)
|
||||
bus.write_byte(address, block)
|
||||
except IOError:
|
||||
temp = ""
|
||||
time.sleep(30)
|
||||
|
||||
try:
|
||||
t1 = Thread(target=shutdown_check)
|
||||
t2 = Thread(target=temp_check)
|
||||
t1.start()
|
||||
t2.start()
|
||||
except:
|
||||
t1.stop()
|
||||
t2.stop()
|
||||
GPIO.cleanup()
|
||||
Reference in New Issue
Block a user