add dora-joy node publishing gamepad axes and buttons
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
"""Prints every `joy` message, so `dataflow.yml` is self-contained.
|
||||
|
||||
It exists so the repo's own dataflow can be validated and run by CI with no
|
||||
gamepad and no consumer attached. It is not a test of anything: it prints what
|
||||
arrived and forgets it.
|
||||
"""
|
||||
|
||||
from dora import Node
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Print one line per reading."""
|
||||
node = Node("printer")
|
||||
count = 0
|
||||
|
||||
for event in node:
|
||||
if event["type"] != "INPUT" or event["id"] != "joy":
|
||||
continue
|
||||
row = event["value"][0].as_py()
|
||||
count += 1
|
||||
if not row["present"]:
|
||||
print(f"joy {count:5d} no gamepad", flush=True)
|
||||
continue
|
||||
axes = " ".join(f"{value:+6.3f}" for value in row["axes"])
|
||||
held = ",".join(str(index) for index, down in enumerate(row["buttons"]) if down) or "-"
|
||||
print(f"joy {count:5d} axes [{axes}] buttons [{held}]", flush=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user