From 06e9cc7972249895319dcce50a08b060a6261409 Mon Sep 17 00:00:00 2001 From: Flame Soulis Date: Wed, 5 Jul 2023 21:00:04 -0400 Subject: [PATCH 1/3] Adds Hat/POV support for gamepads. --- gamepad_reader.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gamepad_reader.py b/gamepad_reader.py index 76cbcd0..ba98ec7 100644 --- a/gamepad_reader.py +++ b/gamepad_reader.py @@ -12,6 +12,7 @@ JOYSTICK_TO_USE = None JOYSTICK_AXES = [] JOYSTICK_BUTTONS = [] +JOYSTICK_HATS = [] # Some globals for websockets WEBSOCKET_SERVER = None @@ -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())) TEMP_JOYSTICK_AXES = [] TEMP_JOYSTICK_BUTTONS = [] +TEMP_JOYSTICK_HATS = [] # Get the websocket server going print(f"Starting Websocket Server on port {WEBSOCKET_PORT}...") @@ -101,6 +104,10 @@ 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()): + JOYSTICK_HATS[_hat] = JOYSTICK_HANDLE.get_hat(_hat) + # Do we have any updates? if not compareInputs(TEMP_JOYSTICK_AXES, JOYSTICK_AXES): print(f"Axes:{JOYSTICK_AXES}") @@ -108,10 +115,14 @@ def new_user_notice(_client, _server): 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") From 57f6a7d75cd5082e83c8a6f8174cc30619c3564c Mon Sep 17 00:00:00 2001 From: Flame Soulis Date: Wed, 5 Jul 2023 21:01:02 -0400 Subject: [PATCH 2/3] Adjusted Hat reading to act like Axis --- gamepad_reader.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gamepad_reader.py b/gamepad_reader.py index ba98ec7..e8530db 100644 --- a/gamepad_reader.py +++ b/gamepad_reader.py @@ -76,7 +76,7 @@ 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())) +JOYSTICK_HATS = list(range(JOYSTICK_HANDLE.get_numhats() * 2)) TEMP_JOYSTICK_AXES = [] TEMP_JOYSTICK_BUTTONS = [] TEMP_JOYSTICK_HATS = [] @@ -106,7 +106,9 @@ def new_user_notice(_client, _server): # Grab the hat data for _hat in range(JOYSTICK_HANDLE.get_numhats()): - JOYSTICK_HATS[_hat] = JOYSTICK_HANDLE.get_hat(_hat) + # 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): From 5fe5c13aaf64d6a5af029501bbac08dacd40e5df Mon Sep 17 00:00:00 2001 From: Flame Soulis Date: Wed, 5 Jul 2023 23:47:48 -0400 Subject: [PATCH 3/3] AddddNsosVR folder irl --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b5f753a..4b71b19 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file +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 +``` \ No newline at end of file