Skip to content

Commit

Permalink
Implement StringAwait node
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippThoelke committed Jul 12, 2024
1 parent 3ed0545 commit 98ccb45
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/goofi/nodes/misc/stringawait.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from goofi.data import Data, DataType
from goofi.node import Node
from goofi.params import BoolParam


class StringAwait(Node):
def config_input_slots():
return {"message": DataType.STRING, "trigger": DataType.ARRAY}

def config_output_slots():
return {"out": DataType.STRING}

def config_params():
return {
"string_await": {
"require_change": BoolParam(True, doc="Only output when the message changes, and we have an unconsumed trigger")
}
}

def setup(self):
self.last_message = None

def process(self, message: Data, trigger: Data):
if trigger is None or message is None:
return

if self.params.string_await.require_change.value and self.last_message == message.data:
return

self.input_slots["trigger"].clear()

self.last_message = message.data
return {"out": (message.data, message.meta)}

0 comments on commit 98ccb45

Please sign in to comment.