Skip to content

Commit

Permalink
Merge pull request #53 from xszym/fix_dmx_values_reset
Browse files Browse the repository at this point in the history
Fix DMXvalues reset to properly serialize zeros
  • Loading branch information
mMosiur committed May 11, 2021
2 parents 88ccaf3 + 2db6de1 commit 314fbcd
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions emulate/emulate_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class UserCodeException(BaseException):


class NoCodeInDatabaseException(BaseException):
"""Exception when there is no code in databae"""
"""Exception when there is no code in database"""


def check_process(process) -> None:
Expand Down Expand Up @@ -120,13 +120,15 @@ def retrieve_next_animation() -> Code:
random_pk = random.choice(pk_list)
return Code.objects.get(pk=random_pk)


def is_time_between(begin_time, end_time, check_time=None) -> bool:
check_time = check_time or datetime.now().time()
if begin_time < end_time:
return check_time >= begin_time and check_time <= end_time
return begin_time <= check_time <= end_time
else: # crosses midnight
return check_time >= begin_time or check_time <= end_time


def should_animate() -> bool:
cfg = Config.objects.first()
if cfg is None:
Expand All @@ -139,13 +141,12 @@ def should_animate() -> bool:
return True
return is_time_between(cfg.animation_start_time, cfg.animation_end_time)


def reset_dmx_values():
dmx_values_zeros = list()
for i in range(5):
dmx_values_zeros.append(list())
for j in range(28):
dmx_values_zeros[i].append([0, 0, 0])
redis_db.set('DMXvalues', str(dmx_values_zeros))
number_of_values = 5 * 28 * 3 # 5 rows, 28 columns, 3 color values
serialized = ",".join("0" * number_of_values)
redis_db.set('DMXvalues', serialized)


def main():
while True:
Expand Down

0 comments on commit 314fbcd

Please # to comment.