From bae54e78a3312f71459171b85efd0adc70f4d110 Mon Sep 17 00:00:00 2001 From: Python1320 Date: Mon, 21 Feb 2022 22:14:43 +0200 Subject: [PATCH 1/2] Simple rumble (tested on knockoff joycons only without HD rumble) --- pyjoycon/joycon.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pyjoycon/joycon.py b/pyjoycon/joycon.py index 4e6fdee..5b45b58 100644 --- a/pyjoycon/joycon.py +++ b/pyjoycon/joycon.py @@ -432,7 +432,27 @@ def set_player_lamp(self, pattern: int): def disconnect_device(self): self._write_output_report(b'\x01', b'\x06', b'\x00') - + def _send_rumble(self,data=b'\x00\x00\x00\x00\x00\x00\x00\x00'): + self._RUMBLE_DATA = data + self._write_output_report(b'\x10', b'', b'') + + def enable_vibration(self,enable=True): + """Sends enable or disable command for vibration. Seems to do nothing.""" + self._write_output_report(b'\x01', b'\x48', b'\x01' if enable else b'\x00') + + def rumble_simple(self): + """Rumble for approximately 1.5 seconds (why?). Repeat sending to keep rumbling.""" + self._send_rumble(b'\x98\x1e\xc6\x47\x98\x1e\xc6\x47') + + def rumble_stop(self): + """Instantly stops the rumble""" + self._send_rumble() + + def connected(self): + """Are we still connected to the joycon?""" + return self._update_input_report_thread.is_alive() + + if __name__ == '__main__': import pyjoycon.device as d ids = d.get_L_id() if None not in d.get_L_id() else d.get_R_id() From 945b7feb8ff4803a846a10e81b5cf2ea74759f16 Mon Sep 17 00:00:00 2001 From: Python1320 Date: Mon, 21 Feb 2022 22:17:51 +0200 Subject: [PATCH 2/2] VRChat joycon helper --- joy360.py | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 joy360.py diff --git a/joy360.py b/joy360.py new file mode 100644 index 0000000..af021da --- /dev/null +++ b/joy360.py @@ -0,0 +1,148 @@ +#!/bin/env python + +# Only really useful for VRChat joycon with Driver4VR + +import time +import collections +import itertools + + +import openvr + +from pyjoycon import JoyCon, get_R_id, get_L_id, ButtonEventJoyCon +import logging + +import threading + +import time +import pprint + +import vgamepad as vg + +gamepad = vg.VX360Gamepad() + + + +class VibrationReceiver(object): + + def __init__(self): + pass + + def poll(self,cons): + new_event = openvr.VREvent_t() + while openvr.VRSystem().pollNextEvent(new_event): + self.checkHaptics(new_event,cons) + + def checkHaptics(self, event, cons): + if event.eventType == openvr.VREvent_HapticVibration_t: + print("VREvent_HapticVibration_t????") + return + if event.eventType != openvr.VREvent_Input_HapticVibration: + return + role = openvr.VRSystem().getControllerRoleForTrackedDeviceIndex(event.data.hapticVibration.containerHandle) + fDurationSeconds = event.data.hapticVibration.fDurationSeconds + con=False + if role == openvr.TrackedControllerRole_RightHand: + print(" right controller trigger") + con=cons[1] + elif role == openvr.TrackedControllerRole_LeftHand: + print(" left controller trigger ") + con=cons[0] + else: + print("getControllerRoleForTrackedDeviceIndex=",role,"???") + if con: + con[2].rumble_simple() + con[4]=time.time()+max(min(fDurationSeconds,3),0) + +class VibeStatus(): + pass #TODO Send vibrate cmd every 0.5 seconds + +def handleVibe(con): + if not con[4]: + return + if time.time()