big changes
This commit is contained in:
@@ -22,9 +22,7 @@ class ClockBackend:
|
||||
|
||||
|
||||
|
||||
def clock_loop(self):
|
||||
print("looping")
|
||||
|
||||
def clock_loop(self):
|
||||
t = int(datetime.datetime.now().strftime("%H%M"))
|
||||
|
||||
if t % 5 == 0:
|
||||
|
@@ -13,7 +13,7 @@ class SensorReadout:
|
||||
self.sensor_modules = { # we already call them, they are objects and not classes anymore
|
||||
"temperature" : hardware.sensors.TemperatureModule(),
|
||||
"humidity" : hardware.sensors.HumidityModule(),
|
||||
"brightness" : hardware.sensors.BrightnessModule(),
|
||||
"luminosity" : hardware.sensors.BrightnessModule(),
|
||||
# more to come?
|
||||
}
|
||||
|
||||
@@ -21,23 +21,36 @@ class SensorReadout:
|
||||
helpers.timer.RepeatedTimer(300, self.spread_measure)
|
||||
|
||||
def spread_measure(self):
|
||||
results = dict((el,[]) for el in self.sensor_modules.keys()) # create an empty dict with a list for each readout-type
|
||||
measurements = dict((el,[]) for el in self.sensor_modules.keys())
|
||||
# create an empty dict with a list for each readout-type
|
||||
|
||||
for _ in range(5): # number of measures to average out
|
||||
for name in self.sensor_modules.keys():
|
||||
measure = self.sensor_modules[name].readout()
|
||||
results[name].append(measure)
|
||||
measurements[name].append(measure)
|
||||
time.sleep(3)
|
||||
|
||||
results = {}
|
||||
for e in measurements.keys():
|
||||
lst = measurements[e]
|
||||
results[e] = int(sum(lst) / len(lst))
|
||||
|
||||
self.save_results(**results)
|
||||
|
||||
|
||||
# def save_results(self, results):
|
||||
# current_minute = int(datetime.datetime.now().timestamp() // 60)
|
||||
|
||||
self.save_results(results)
|
||||
# self.persistence["clock"]["sensors"]["time"] += [current_minute]
|
||||
|
||||
|
||||
def save_results(self, results):
|
||||
current_minute = int(datetime.datetime.now().timestamp() // 60)
|
||||
|
||||
self.persistence["clock"]["sensors"]["time"] += [current_minute]
|
||||
|
||||
for name in results.keys():
|
||||
keep_value = sum(results[name]) / len(results[name])
|
||||
self.persistence["clock"]["sensors"][name] += [keep_value]
|
||||
# for name in results.keys():
|
||||
# keep_value = sum(results[name]) / len(results[name])
|
||||
# self.persistence["clock"]["sensors"][name] += [keep_value]
|
||||
|
||||
|
||||
def save_results(self, **results):
|
||||
data = self.db.sensors(
|
||||
time=datetime.datetime.now(),
|
||||
**results,
|
||||
)
|
||||
data.save()
|
||||
|
@@ -13,21 +13,17 @@ class ClockFace:
|
||||
""""""
|
||||
# added by the launcher, we have self.modules (dict)
|
||||
|
||||
|
||||
|
||||
self.IO = hardware.led.get_handler()
|
||||
self.shape = self.IO.shape # (16,32) for now
|
||||
# TODO handle differently!
|
||||
self.MOP = helpers.computations.MatrixOperations()
|
||||
|
||||
|
||||
self.kill_output = False
|
||||
|
||||
def start(self):
|
||||
helpers.timer.RepeatedTimer(60, self.clock_loop)
|
||||
# schedule for in 60 seconds
|
||||
self.clock_loop()
|
||||
# run once now
|
||||
# TODO start as a thread
|
||||
# helpers.timer.RepeatedTimer(60, self.clock_loop)
|
||||
# # schedule for in 60 seconds
|
||||
Thread(target = self.clock_loop).start()
|
||||
|
||||
|
||||
# TODO Turn off when button pressed?
|
||||
@@ -38,13 +34,18 @@ class ClockFace:
|
||||
t_minutes = int(datetime.datetime.now().strftime("%H%M"))
|
||||
|
||||
has_queue, data = self.modules["receive"].fetch_data()
|
||||
self.set_brightness()
|
||||
|
||||
if data == {}:
|
||||
matrices = self.MOP.get_fallback()
|
||||
else:
|
||||
matrices = [np.asarray(d).astype(int) for d in data["matrices"]]
|
||||
|
||||
self.IO.put(matrices)
|
||||
|
||||
if not self.kill_output:
|
||||
self.IO.put(matrices)
|
||||
else:
|
||||
z = np.zeros((16,16,3))
|
||||
self.IO.put([z,z,z])
|
||||
|
||||
if has_queue:
|
||||
tnext = 1
|
||||
@@ -59,3 +60,14 @@ class ClockFace:
|
||||
time.sleep(max(delta.total_seconds(), 0))
|
||||
self.clock_loop()
|
||||
|
||||
|
||||
def set_brightness(self):
|
||||
"""Kill the brightness at night"""
|
||||
|
||||
is_WE = datetime.datetime.now().weekday() > 4
|
||||
now = int(datetime.datetime.now().strftime("%H%M"))
|
||||
if (is_WE and (now > 1000 and now < 2200)) or ((not is_WE) and (now > 830 and now < 2130)):
|
||||
self.kill_output = False
|
||||
else:
|
||||
self.kill_output = True
|
||||
|
||||
|
@@ -5,17 +5,23 @@ logger = logging.getLogger(__name__)
|
||||
class TempSim:
|
||||
"""Simulates a temperature for running on windows"""
|
||||
temperature = 23 # return a celsius value
|
||||
humidity = 0.3
|
||||
humidity = 30
|
||||
|
||||
|
||||
class LightSim:
|
||||
def input(self, *args):
|
||||
return 1
|
||||
|
||||
|
||||
|
||||
|
||||
class SensorModule:
|
||||
def __init__(self):
|
||||
logger.info("Using module " + self.__class__.__name__)
|
||||
|
||||
class LightSim:
|
||||
def input(self, *args):
|
||||
return 1
|
||||
|
||||
|
||||
|
||||
## Real sensors!
|
||||
try:
|
||||
import board
|
||||
import adafruit_dht
|
||||
|
Reference in New Issue
Block a user