introduced service class
This commit is contained in:
parent
70e2b0dc72
commit
6ae519f78e
40
config.json
40
config.json
|
@ -1,12 +1,14 @@
|
|||
{
|
||||
"sensors": {
|
||||
"0":{
|
||||
"name": "inside",
|
||||
"BCM": 20,
|
||||
"GPIO": 20,
|
||||
"header-pin": 38,
|
||||
"pre-resistance": 9770.0
|
||||
},
|
||||
"1":{
|
||||
"name": "outside",
|
||||
"BCM": 26,
|
||||
"GPIO": 26,
|
||||
"header-pin": 37,
|
||||
|
@ -82,5 +84,43 @@
|
|||
},
|
||||
"pwm-defaults":{
|
||||
"frequency": 25000
|
||||
},
|
||||
"activated-channels": [ 0, 1],
|
||||
"interval": 1.0,
|
||||
"use_difference": false,
|
||||
"thresholds-for": "inside",
|
||||
"thresholds": {
|
||||
"off":{
|
||||
"temp": 25,
|
||||
"diff": 5,
|
||||
"fan-up": false,
|
||||
"fan-low": false,
|
||||
"pwm-up": 0.0,
|
||||
"pwm-low": 0.0
|
||||
},
|
||||
"33%": {
|
||||
"temp": 35,
|
||||
"diff": 15,
|
||||
"fan-up": false,
|
||||
"fan-low": true,
|
||||
"pwm-up": 33.0,
|
||||
"pwm-low": 33.0
|
||||
},
|
||||
"66%": {
|
||||
"temp": 45,
|
||||
"diff": 25,
|
||||
"fan-up": true,
|
||||
"fan-low": true,
|
||||
"pwm-up": 100.0,
|
||||
"pwm-low": 66.0
|
||||
},
|
||||
"100%": {
|
||||
"temp": 100,
|
||||
"diff": 50,
|
||||
"fan-up": true,
|
||||
"fan-low": true,
|
||||
"pwm-up": 100.0,
|
||||
"pwm-low": 100.0
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
from config import Config
|
||||
import time
|
||||
from threading import Thread
|
||||
from temperature import Temperature
|
||||
import graphitesend
|
||||
from lowlevel import LowLevel
|
||||
|
||||
|
||||
class Service(object):
|
||||
def __init__(self):
|
||||
self.__cfg = Config()
|
||||
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
interval = self.__cfg.get_data()["interval"]
|
||||
t = time.time()
|
||||
while True:
|
||||
t = time.time()
|
||||
time.sleep(t + interval - time.time())
|
||||
thread = Thread(self.work)
|
||||
thread.start()
|
||||
pass
|
||||
|
||||
def work(self):
|
||||
# get sensor data
|
||||
channels = self.__cfg.get_data()["activated-channels"]
|
||||
results = []
|
||||
for c in channels:
|
||||
results.append(Temperature(c).read())
|
||||
|
||||
# check thresholds
|
||||
thresholds = self.__cfg.get_data()["thresholds"]
|
||||
sensors = self.__cfg.get_sensors_dict()
|
||||
channel = -1
|
||||
for k in sensors:
|
||||
if sensors[k]["name"] == self.__cfg.get_data()["thresholds-for"]:
|
||||
channel = int(k)
|
||||
if k < 0:
|
||||
raise RuntimeError("fuck.")
|
||||
for threshold in thresholds:
|
||||
if results[channel] < threshold["temp"]:
|
||||
LowLevel().lower_fan(threshold["fan-low"])
|
||||
LowLevel().lower_fan_pwm(threshold["pwm-low"])
|
||||
LowLevel().upper_fan(threshold["fan-up"])
|
||||
LowLevel().upper_fan_pwm(threshold["pwm-up"])
|
||||
break
|
||||
pass
|
||||
|
|
@ -4,7 +4,8 @@ from decimal import *
|
|||
from lowlevel import LowLevel
|
||||
from config import Config
|
||||
|
||||
class Temperature:
|
||||
|
||||
class Temperature(object):
|
||||
def __init__(self, channel):
|
||||
self.__channel = channel
|
||||
self.__cfg = Config()
|
||||
|
|
Loading…
Reference in New Issue