Skip to content

Commit

Permalink
Merge pull request #1 from FlameSoulis/pov_target
Browse files Browse the repository at this point in the history
Add Hat/POV Support
  • Loading branch information
FlameSoulis authored Jul 6, 2023
2 parents b77b4a2 + 5fe5c13 commit ce66441
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ You will need [pygame](https://github.com/pygame/pygame) and [websocket-server](
pip install pygame websocket-server
```

This was originally created for pygame 2.2.0 and websocket-server 0.6.4 with [Python](https://www.python.org/) 3.10.9. It has been tested on Windows 10 and SteamOS 3.4.6, but should play safely on most Linux distributions.
This was originally created for pygame 2.2.0 and websocket-server 0.6.4 with [Python](https://www.python.org/) 3.10.9. It has been tested on Windows 10 and SteamOS 3.4.6, but should play safely on most Linux distributions.

## NeosVR Shared Folder

This folder contains a demonstration core system for reading the GamePad Reader's output. To view the folder's content, copy and paste the below link into the NeosVR client.
```
neosrec:///U-Flame-Soulis/R-d4dbd71a-7aed-4ea7-9629-e9ec2c068b19
```
13 changes: 13 additions & 0 deletions gamepad_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
JOYSTICK_TO_USE = None
JOYSTICK_AXES = []
JOYSTICK_BUTTONS = []
JOYSTICK_HATS = []

# Some globals for websockets
WEBSOCKET_SERVER = None
Expand Down Expand Up @@ -75,8 +76,10 @@ def new_user_notice(_client, _server):
# Setup the arrays
JOYSTICK_AXES = list(range(JOYSTICK_HANDLE.get_numaxes()))
JOYSTICK_BUTTONS = list(range(JOYSTICK_HANDLE.get_numbuttons()))
JOYSTICK_HATS = list(range(JOYSTICK_HANDLE.get_numhats() * 2))
TEMP_JOYSTICK_AXES = []
TEMP_JOYSTICK_BUTTONS = []
TEMP_JOYSTICK_HATS = []

# Get the websocket server going
print(f"Starting Websocket Server on port {WEBSOCKET_PORT}...")
Expand All @@ -101,17 +104,27 @@ def new_user_notice(_client, _server):
for _button in range(JOYSTICK_HANDLE.get_numbuttons()):
JOYSTICK_BUTTONS[_button] = JOYSTICK_HANDLE.get_button(_button)

# Grab the hat data
for _hat in range(JOYSTICK_HANDLE.get_numhats()):
# Convert to handle like Axis
JOYSTICK_HATS[_hat*2] = JOYSTICK_HANDLE.get_hat(_hat)[0]
JOYSTICK_HATS[(_hat*2)+1] = JOYSTICK_HANDLE.get_hat(_hat)[1]

# Do we have any updates?
if not compareInputs(TEMP_JOYSTICK_AXES, JOYSTICK_AXES):
print(f"Axes:{JOYSTICK_AXES}")
WEBSOCKET_SERVER.send_message_to_all(arrayDump(["axes"]+JOYSTICK_AXES))
if not compareInputs(TEMP_JOYSTICK_BUTTONS, JOYSTICK_BUTTONS):
print(f"Btns:{JOYSTICK_BUTTONS}")
WEBSOCKET_SERVER.send_message_to_all(arrayDump(["btns"]+JOYSTICK_BUTTONS))
if not compareInputs(TEMP_JOYSTICK_HATS, JOYSTICK_HATS):
print(f"Hats:{JOYSTICK_HATS}")
WEBSOCKET_SERVER.send_message_to_all(arrayDump(["hats"]+JOYSTICK_HATS))

# Update our temporary values
TEMP_JOYSTICK_AXES = JOYSTICK_AXES.copy()
TEMP_JOYSTICK_BUTTONS = JOYSTICK_BUTTONS.copy()
TEMP_JOYSTICK_HATS = JOYSTICK_HATS.copy()

except KeyboardInterrupt:
print("Keyboard Interrupt Detected - Closing")
Expand Down

0 comments on commit ce66441

Please sign in to comment.