fixing recursion issues
This commit is contained in:
@@ -12,15 +12,11 @@ class ClockBackend:
|
||||
self.weather_raw = {}
|
||||
self.weather_face_swap = False
|
||||
|
||||
self.brightness = 1
|
||||
self.brightness_overwrite = {"value" : 1, "duration" : 0}
|
||||
|
||||
|
||||
def start(self):
|
||||
self.out = self.modules["broadcast"]
|
||||
helpers.timer.RepeatedTimer(15, self.clock_loop)
|
||||
|
||||
|
||||
|
||||
def clock_loop(self):
|
||||
t = int(datetime.datetime.now().strftime("%H%M"))
|
||||
@@ -40,7 +36,7 @@ class ClockBackend:
|
||||
self.weather["weather"] = "error"
|
||||
self.weather["high"] = "error"
|
||||
self.weather["low"] = "error"
|
||||
# if weather == self.weather.raw do nothing
|
||||
|
||||
self.weather_face_swap = not self.weather_face_swap
|
||||
|
||||
self.send_face()
|
||||
@@ -54,23 +50,10 @@ class ClockBackend:
|
||||
if self.weather_face_swap:
|
||||
matrices = [matrices[0], matrices[2], matrices[1]]
|
||||
|
||||
# apply brightness
|
||||
b = self.get_brightness()
|
||||
matrices = [(b * m).tolist() for m in matrices]
|
||||
matrices = [m.tolist() for m in matrices]
|
||||
self.out.queue.append({"matrices" : matrices})
|
||||
|
||||
|
||||
def get_brightness(self):
|
||||
"""Checks, what brightness rules to apply"""
|
||||
|
||||
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 > 800 and now < 2130)):
|
||||
brightness = 0.8
|
||||
else:
|
||||
brightness = 0.01
|
||||
|
||||
return brightness
|
||||
|
||||
|
||||
# def text_scroll(self, text, color=[[200,200,200]]):
|
||||
|
@@ -21,44 +21,38 @@ class ClockFace:
|
||||
self.kill_output = False
|
||||
|
||||
def start(self):
|
||||
# helpers.timer.RepeatedTimer(60, self.clock_loop)
|
||||
# # schedule for in 60 seconds
|
||||
Thread(target = self.clock_loop).start()
|
||||
|
||||
|
||||
# TODO Turn off when button pressed?
|
||||
|
||||
def clock_loop(self):
|
||||
t_start = datetime.datetime.now()
|
||||
|
||||
t_minutes = int(datetime.datetime.now().strftime("%H%M"))
|
||||
while True: # TODO: allow this to be exited gracefully
|
||||
|
||||
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"]]
|
||||
|
||||
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
|
||||
else:
|
||||
tnext = 30
|
||||
t_start = datetime.datetime.now()
|
||||
|
||||
self.set_brightness()
|
||||
|
||||
t_end = datetime.datetime.now()
|
||||
delta_planned = datetime.timedelta(seconds = tnext)
|
||||
delta = delta_planned - (t_end - t_start)
|
||||
|
||||
time.sleep(max(delta.total_seconds(), 0))
|
||||
self.clock_loop()
|
||||
has_queue, data = self.modules["receive"].fetch_data()
|
||||
tnext = 1 if has_queue else 30
|
||||
|
||||
if data == {}:
|
||||
matrices = self.MOP.get_fallback()
|
||||
matrices[0][0,0] = [255, 0, 0] # red dot on the top left
|
||||
else:
|
||||
matrices = [np.asarray(d).astype(int) for d in data["matrices"]]
|
||||
matrices[0][0,0] = [0, 255, 0] # green dot on the top left
|
||||
|
||||
if not self.kill_output:
|
||||
self.IO.put(matrices)
|
||||
else:
|
||||
z = np.zeros((16,16,3))
|
||||
self.IO.put([z,z,z])
|
||||
|
||||
|
||||
t_end = datetime.datetime.now()
|
||||
delta_planned = datetime.timedelta(seconds = tnext)
|
||||
delta = delta_planned - (t_end - t_start)
|
||||
|
||||
time.sleep(max(delta.total_seconds(), 0))
|
||||
|
||||
|
||||
def set_brightness(self):
|
||||
@@ -66,8 +60,6 @@ class ClockFace:
|
||||
|
||||
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
|
||||
|
||||
self.kill_output = (now < 1000 or now > 2200) if is_WE else (now < 830 or now > 2130)
|
||||
|
||||
|
@@ -26,7 +26,6 @@ class ClockOut:
|
||||
self.screen.fill((0, 0, 0))
|
||||
for event in pygame.event.get(): # User did something
|
||||
if event.type == pygame.QUIT:
|
||||
print("Exiting...")
|
||||
pygame.quit()
|
||||
sys.exit()
|
||||
|
||||
|
Reference in New Issue
Block a user