Commit cad649a9 authored by Aljaž Srebrnič's avatar Aljaž Srebrnič

Deluxe auto-map stage names

This patch calculates the stages of the current vehicle and arranges the stages
into "pre-launch", "liftoff", "stage_*_separation" in the correct order.
parent a93a3427
......@@ -16,7 +16,7 @@ def main():
1: "liftoff",
2: "stage_1_separation",
3: "stage_2_separation"}
stage_map = dict([(i,i) for i in range(10)])
stage_map = dict(zip(range(10), range(10, 0, -1)))
context = zmq.Context()
socket = context.socket(zmq.PUB)
......@@ -38,8 +38,10 @@ def main():
def stage_changed(new_stage):
try:
socket.send_string(f"{topic} {stage_map[new_stage]}")
print(f"Sending event {topic} {new_stage}")
stage_mapped = stage_map.get(new_stage, new_stage)
stage_name = states.get(stage_mapped, "Unknown")
socket.send_string(f"{topic} {stage_name}")
print(f"Sending event {stage_name} ({stage_mapped})")
except Exception as e:
pass
......@@ -52,6 +54,9 @@ def main():
running.clear()
vessel = conn.space_center.active_vessel
control = vessel.control
vehicle_stages = max([p.stage for p in vessel.parts.all]) + 1
stage_map = dict(zip(range(vehicle_stages + 1),
range(vehicle_stages, -1, -1)))
stage = conn.add_stream(getattr, control, 'current_stage', scene)
stage.add_callback(stage_changed)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment