kopia lustrzana https://github.com/cyoung/stratux
Daemonize stratux-screen.py and fancontrol.py.
rodzic
333bb6c3ce
commit
0588f8b0e7
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
/usr/bin/stratux-screen.py
|
/usr/bin/stratux-screen.py start
|
||||||
/usr/bin/fancontrol.py
|
/usr/bin/fancontrol.py start
|
||||||
|
|
|
@ -9,26 +9,37 @@ import RPi.GPIO as GPIO
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# Return CPU temperature as float
|
from daemon import runner
|
||||||
def getCPUtemp():
|
|
||||||
cTemp = os.popen('vcgencmd measure_temp').readline()
|
|
||||||
return float(cTemp.replace("temp=","").replace("'C\n",""))
|
|
||||||
|
|
||||||
GPIO.setmode(GPIO.BOARD)
|
class FanControl():
|
||||||
GPIO.setup(11,GPIO.OUT)
|
# Return CPU temperature as float
|
||||||
GPIO.setwarnings(False)
|
def getCPUtemp(self):
|
||||||
p=GPIO.PWM(11,1000)
|
cTemp = os.popen('vcgencmd measure_temp').readline()
|
||||||
PWM = 50
|
return float(cTemp.replace("temp=","").replace("'C\n",""))
|
||||||
|
|
||||||
while True:
|
def __init__(self):
|
||||||
|
self.stdin_path = '/dev/null'
|
||||||
|
self.stdout_path = '/dev/tty'
|
||||||
|
self.stderr_path = '/dev/tty'
|
||||||
|
self.pidfile_path = '/var/run/fancontrol.pid'
|
||||||
|
self.pidfile_timeout = 5
|
||||||
|
def run(self):
|
||||||
|
GPIO.setmode(GPIO.BOARD)
|
||||||
|
GPIO.setup(11,GPIO.OUT)
|
||||||
|
GPIO.setwarnings(False)
|
||||||
|
p=GPIO.PWM(11,1000)
|
||||||
|
PWM = 50
|
||||||
|
while True:
|
||||||
|
CPU_temp = self.getCPUtemp()
|
||||||
|
if CPU_temp > 40.5:
|
||||||
|
PWM = min(max(PWM + 1, 0), 100)
|
||||||
|
p.start(PWM)
|
||||||
|
elif CPU_temp < 39.5:
|
||||||
|
PWM = min(max(PWM - 1, 0), 100)
|
||||||
|
p.start(PWM)
|
||||||
|
time.sleep(5)
|
||||||
|
GPIO.cleanup()
|
||||||
|
|
||||||
CPU_temp = getCPUtemp()
|
fancontrol = FanControl()
|
||||||
if CPU_temp > 40.5:
|
daemon_runner = runner.DaemonRunner(fancontrol)
|
||||||
PWM = min(max(PWM + 1, 0), 100)
|
daemon_runner.do_action()
|
||||||
p.start(PWM)
|
|
||||||
elif CPU_temp < 39.5:
|
|
||||||
PWM = min(max(PWM - 1, 0), 100)
|
|
||||||
p.start(PWM)
|
|
||||||
time.sleep(5)
|
|
||||||
|
|
||||||
GPIO.cleanup()
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ sed -i /etc/default/keyboard -e "/^XKBLAYOUT/s/\".*\"/\"us\"/"
|
||||||
cp -f config.txt mnt/boot/
|
cp -f config.txt mnt/boot/
|
||||||
|
|
||||||
#external OLED screen
|
#external OLED screen
|
||||||
apt-get install -y libjpeg-dev i2c-tools python-smbus python-pip python-dev python-pil screen
|
apt-get install -y libjpeg-dev i2c-tools python-smbus python-pip python-dev python-pil python-daemon screen
|
||||||
git clone https://github.com/rm-hull/ssd1306
|
git clone https://github.com/rm-hull/ssd1306
|
||||||
cd ssd1306 && python setup.py install
|
cd ssd1306 && python setup.py install
|
||||||
cp /root/stratux/test/screen/screen.py /usr/bin/stratux-screen.py
|
cp /root/stratux/test/screen/screen.py /usr/bin/stratux-screen.py
|
||||||
|
|
|
@ -9,69 +9,80 @@ import urllib2
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
font2 = ImageFont.truetype('/etc/stratux-screen/CnC_Red_Alert.ttf', 12)
|
from daemon import runner
|
||||||
oled = ssd1306(port=1, address=0x3C)
|
|
||||||
|
|
||||||
with canvas(oled) as draw:
|
class StratuxScreen():
|
||||||
logo = Image.open('/etc/stratux-screen/stratux-logo-64x64.bmp')
|
def __init__(self):
|
||||||
draw.bitmap((32, 0), logo, fill=1)
|
self.stdin_path = '/dev/null'
|
||||||
|
self.stdout_path = '/dev/tty'
|
||||||
|
self.stderr_path = '/dev/tty'
|
||||||
|
self.pidfile_path = '/var/run/fancontrol.pid'
|
||||||
|
self.pidfile_timeout = 5
|
||||||
|
def run(self):
|
||||||
|
font2 = ImageFont.truetype('/etc/stratux-screen/CnC_Red_Alert.ttf', 12)
|
||||||
|
oled = ssd1306(port=1, address=0x3C)
|
||||||
|
|
||||||
time.sleep(10)
|
with canvas(oled) as draw:
|
||||||
|
logo = Image.open('/etc/stratux-screen/stratux-logo-64x64.bmp')
|
||||||
|
draw.bitmap((32, 0), logo, fill=1)
|
||||||
|
|
||||||
n = 0
|
time.sleep(10)
|
||||||
|
n = 0
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
response = urllib2.urlopen('http://localhost/getStatus')
|
response = urllib2.urlopen('http://localhost/getStatus')
|
||||||
getStatusHTML = response.read()
|
getStatusHTML = response.read()
|
||||||
getStatusData = json.loads(getStatusHTML)
|
getStatusData = json.loads(getStatusHTML)
|
||||||
CPUTemp = getStatusData["CPUTemp"]
|
CPUTemp = getStatusData["CPUTemp"]
|
||||||
uat_current = getStatusData["UAT_messages_last_minute"]
|
uat_current = getStatusData["UAT_messages_last_minute"]
|
||||||
uat_max = getStatusData["UAT_messages_max"]
|
uat_max = getStatusData["UAT_messages_max"]
|
||||||
es_current = getStatusData["ES_messages_last_minute"]
|
es_current = getStatusData["ES_messages_last_minute"]
|
||||||
es_max = getStatusData["ES_messages_max"]
|
es_max = getStatusData["ES_messages_max"]
|
||||||
|
|
||||||
response = urllib2.urlopen('http://localhost/getTowers')
|
response = urllib2.urlopen('http://localhost/getTowers')
|
||||||
getTowersHTML = response.read()
|
getTowersHTML = response.read()
|
||||||
getTowersData = json.loads(getTowersHTML)
|
getTowersData = json.loads(getTowersHTML)
|
||||||
NumTowers = len(getTowersData)
|
NumTowers = len(getTowersData)
|
||||||
|
|
||||||
|
with canvas(oled) as draw:
|
||||||
|
pad = 2 # Two pixels on the left and right.
|
||||||
|
text_margin = 25
|
||||||
with canvas(oled) as draw:
|
# UAT status.
|
||||||
pad = 2 # Two pixels on the left and right.
|
draw.text((50, 0), "UAT", font=font2, fill=255)
|
||||||
text_margin = 25
|
# "Status bar", 2 pixels high.
|
||||||
# UAT status.
|
status_bar_width_max = oled.width - (2 * pad) - (2 * text_margin)
|
||||||
draw.text((50, 0), "UAT", font=font2, fill=255)
|
status_bar_width = 0
|
||||||
# "Status bar", 2 pixels high.
|
if uat_max > 0:
|
||||||
status_bar_width_max = oled.width - (2 * pad) - (2 * text_margin)
|
status_bar_width = int((float(uat_current) / uat_max) * status_bar_width_max)
|
||||||
status_bar_width = 0
|
draw.rectangle((pad + text_margin, 14, pad + text_margin + status_bar_width, 20), outline=255, fill=255) # Top left, bottom right.
|
||||||
if uat_max > 0:
|
# Draw the current (left) and max (right) numbers.
|
||||||
status_bar_width = int((float(uat_current) / uat_max) * status_bar_width_max)
|
draw.text((pad, 14), str(uat_current), font=font2, fill=255)
|
||||||
draw.rectangle((pad + text_margin, 14, pad + text_margin + status_bar_width, 20), outline=255, fill=255) # Top left, bottom right.
|
draw.text(((2*pad) + text_margin + status_bar_width_max, 14), str(uat_max), font=font2, fill=255)
|
||||||
# Draw the current (left) and max (right) numbers.
|
# ES status.
|
||||||
draw.text((pad, 14), str(uat_current), font=font2, fill=255)
|
draw.text((44, 24), "1090ES", font=font2, fill=255)
|
||||||
draw.text(((2*pad) + text_margin + status_bar_width_max, 14), str(uat_max), font=font2, fill=255)
|
status_bar_width = 0
|
||||||
# ES status.
|
if es_max > 0:
|
||||||
draw.text((44, 24), "1090ES", font=font2, fill=255)
|
status_bar_width = int((float(es_current) / es_max) * status_bar_width_max)
|
||||||
status_bar_width = 0
|
draw.rectangle((pad + text_margin, 34, pad + text_margin + status_bar_width, 40), outline=255, fill=255) # Top left, bottom right.
|
||||||
if es_max > 0:
|
# Draw the current (left) and max (right) numbers.
|
||||||
status_bar_width = int((float(es_current) / es_max) * status_bar_width_max)
|
draw.text((pad, 34), str(es_current), font=font2, fill=255)
|
||||||
draw.rectangle((pad + text_margin, 34, pad + text_margin + status_bar_width, 40), outline=255, fill=255) # Top left, bottom right.
|
draw.text(((2*pad) + text_margin + status_bar_width_max, 34), str(es_max), font=font2, fill=255)
|
||||||
# Draw the current (left) and max (right) numbers.
|
# Other stats.
|
||||||
draw.text((pad, 34), str(es_current), font=font2, fill=255)
|
seq = (n / 5) % 2
|
||||||
draw.text(((2*pad) + text_margin + status_bar_width_max, 34), str(es_max), font=font2, fill=255)
|
t = ""
|
||||||
# Other stats.
|
if seq == 0:
|
||||||
seq = (n / 5) % 2
|
t = "CPU: %0.1fC, Towers: %d" % (CPUTemp, NumTowers)
|
||||||
t = ""
|
if seq == 1:
|
||||||
if seq == 0:
|
t = "GPS Sat: %d/%d/%d" % (getStatusData["GPS_satellites_locked"], getStatusData["GPS_satellites_seen"], getStatusData["GPS_satellites_tracked"])
|
||||||
t = "CPU: %0.1fC, Towers: %d" % (CPUTemp, NumTowers)
|
if getStatusData["GPS_solution"] == "GPS + SBAS (WAAS / EGNOS)":
|
||||||
if seq == 1:
|
t = t + " (WAAS)"
|
||||||
t = "GPS Sat: %d/%d/%d" % (getStatusData["GPS_satellites_locked"], getStatusData["GPS_satellites_seen"], getStatusData["GPS_satellites_tracked"])
|
#print t
|
||||||
if getStatusData["GPS_solution"] == "GPS + SBAS (WAAS / EGNOS)":
|
draw.text((pad, 45), t, font=font2, fill=255)
|
||||||
t = t + " (WAAS)"
|
|
||||||
print t
|
n = n+1
|
||||||
draw.text((pad, 45), t, font=font2, fill=255)
|
|
||||||
|
|
||||||
n = n+1
|
stratuxscreen = StratuxScreen()
|
||||||
|
daemon_runner = runner.DaemonRunner(stratuxscreen)
|
||||||
|
daemon_runner.do_action()
|
||||||
|
|
Ładowanie…
Reference in New Issue