fix asyncio calling, accept changes before mutating

This commit is contained in:
2021-04-02 21:27:58 +02:00
parent e6e63efb3f
commit 7556deede0
4 changed files with 58 additions and 41 deletions

View File

@@ -6,7 +6,7 @@ from artnet import buildPacket
from effects import *
import state
AVAILABLE_EFFECTS = [rainbow_whole, rainbow_whole_offset_stat, rainbow_whole_offset_dyn, two_colors_red_blue, two_colors_red_red, two_colors_cyan_blue, two_colors_cyan_orange ]
AVAILABLE_EFFECTS = [ black, rainbow_whole, rainbow_whole_offset_stat, rainbow_whole_offset_dyn, two_colors_red_blue, two_colors_red_red, two_colors_cyan_blue, two_colors_cyan_orange]
current_effect = rainbow_whole
framecount = 0
@@ -21,6 +21,12 @@ def get_options():
}
}
def serialize_internal_state():
global current_effect
return {
"current_effect": function_str(current_effect)
}
def set_immidiate(framecount, channels, update):
for inx, (current, target) in enumerate(zip(channels["current"], channels["target"])):
update(framecount, inx, target)
@@ -35,6 +41,7 @@ async def handle_state_change(old, new):
new_effect = [ x for x in AVAILABLE_EFFECTS if function_str(x) == new["current_effect"] ][0]
current_effect = new_effect if new_effect != None else current_effect
framecount = 0
await state.mutate(serialize_internal_state())
async def main(target_ips):
global current_effect
@@ -47,9 +54,9 @@ async def main(target_ips):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
debug = False
current_state = await state.get_data()
state.register_callback(handle_state_change)
await state.mutate({ "current_effect": function_str(current_effect) })
current_state = state.get_data()
state.register_on_input_callback(handle_state_change)
await state.mutate(serialize_internal_state())
await state.inc_initialized()
while True: