Skip to content

Commit

Permalink
Adding a keyboard listener and __init__ files
Browse files Browse the repository at this point in the history
  • Loading branch information
haixuanTao committed Aug 13, 2024
1 parent aea441b commit 69e1178
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
3 changes: 3 additions & 0 deletions node-hub/keyboard-listener/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Dora Node for sending arrow data.

This node send DATA that is specified within the environemnt variable or from `--data` argument.

Check warning on line 3 in node-hub/keyboard-listener/README.md

View workflow job for this annotation

GitHub Actions / Typos

"environemnt" should be "environment".
11 changes: 11 additions & 0 deletions node-hub/keyboard-listener/keyboard_listener/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

# Define the path to the README file relative to the package directory
readme_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "README.md")

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."
41 changes: 41 additions & 0 deletions node-hub/keyboard-listener/keyboard_listener/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from pynput import keyboard
from pynput.keyboard import Key, Events
import pyarrow as pa
from dora import Node


node = Node()


with keyboard.Events() as events:
while True:
event = events.get(1.0)
if event is not None and isinstance(event, Events.Press):
if hasattr(event.key, "char"):
if event.key.char == "w":
node.send_output("move", pa.array([-0.02, 0, 0, 0, 0, 0]))
elif event.key.char == "s":
node.send_output("move", pa.array([0.02, 0, 0, 0, 0, 0]))
elif event.key.char == "d":
node.send_output("move", pa.array([0, 0.02, 0, 0, 0, 0]))
elif event.key.char == "a":
node.send_output("move", pa.array([0, -0.02, 0, 0, 0, 0]))
elif event.key.char == "e":
node.send_output("move", pa.array([0, 0, 0.02, 0, 0, 0]))
elif event.key.char == "q":
node.send_output("move", pa.array([0, 0, -0.02, 0, 0, 0]))
elif event.key.char == "t":
node.send_output("claw", pa.array([0]))
elif event.key.char == "r":
node.send_output("claw", pa.array([100]))
elif event.key == Key.up:
node.send_output("move", pa.array([0, 0, 0, 0, 0.2, 0]))
elif event.key == Key.down:
node.send_output("move", pa.array([0, 0, 0, 0, -0.2, 0]))
elif event.key == Key.left:
node.send_output("move", pa.array([0, 0, 0, 0.2, 0, 0]))
elif event.key == Key.right:
node.send_output("move", pa.array([0, 0, 0, -0.2, 0, 0]))

# if event is not None and isinstance(event, Events.Release):
# node.send_output("move", pa.array([0.0, 0, 0, 0, 0, 0]))
29 changes: 29 additions & 0 deletions node-hub/keyboard-listener/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[tool.poetry]
name = "keyboard-listener"
version = "0.3.5"
authors = [
"Haixuan Xavier Tao <[email protected]>",
"Enzo Le Van <[email protected]>",
]
description = "Dora keyboard-listener"
license = "MIT License"
homepage = "https://github.com/dora-rs/dora.git"
documentation = "https://github.com/dora-rs/dora/blob/main/node-hub/keyboard-listener/README.md"
readme = "README.md"
packages = [{ include = "keyboard_listener" }]

[tool.poetry.dependencies]
dora-rs = "0.3.5"
numpy = "< 2.0.0"
pyarrow = ">= 5.0.0"
pynput = "^1.7.6"

[tool.poetry.scripts]
keyboard-listener = "keyboard_listener.main:main"

[build-system]
requires = ["poetry-core>=1.8.0"]
build-backend = "poetry.core.masonry.api"

[project]
readme = "README.md"
11 changes: 11 additions & 0 deletions node-hub/opencv-plot/opencv_plot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

# Define the path to the README file relative to the package directory
readme_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "README.md")

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."
11 changes: 11 additions & 0 deletions node-hub/ultralytics-yolo/ultralytics_yolo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

# Define the path to the README file relative to the package directory
readme_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "README.md")

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."

0 comments on commit 69e1178

Please sign in to comment.