-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhydra_to_vjoy_chatgpt.py
More file actions
185 lines (155 loc) · 8.72 KB
/
hydra_to_vjoy_chatgpt.py
File metadata and controls
185 lines (155 loc) · 8.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# Script created by VerdeMsk using ChatGPT. Version 0.7
# UPDATE NOTES - dinput triggers fixed. motion from both hydras
if starting:
# Settings
# Swap controllers
aiming_hydra_switch = 2 # Change this value to 1 or 2 to switch between Hydra - left and Hydra - right.
#This one will be your main Hydra. And the other one will work as stick.
left_hydra_behaviour = 1 # 1 - left stick, no motion from hydra; 2 - stick and hydra combined; 3 - no stick, hydra only.
# Define the switch: 1 for hydra yaw, 2 for hydra roll
translation_switch = 2 # Change this value to 1 or 2 to switch between yaw and roll (right controller)
# Define the switch: 1 for hydra yaw, 2 for hydra roll
translation_switch_left = 1 # Change this value to 1 or 2 to switch between yaw and roll (left controller)
# Invert the direction of the pitch
left_pitch_invert = -1 # -1 or 1
# Invert the direction of the pitch
right_pitch_invert = -1 # -1 or 1
invert_trigger = False # Set to True for inverted triggers, False for non-inverted triggers
# Settings end
v = vJoy[0]
v.x, v.y, v.z, v.rx, v.ry, v.rz, v.slider, v.dial = (0,) * 8 # Reset vJoy axes to 0 initially
global yaw_sensitivity, roll_sensitivity, pitch_sensitivity, left_stick_sensitivity
global left_trigger_sensitivity, right_trigger_sensitivity
global lefthydra
global righthydra
yaw_sensitivity = 1 # Adjust the sensitivity for yaw as needed
roll_sensitivity = 1 # Adjust the sensitivity for the roll axis as needed
pitch_sensitivity = 1 # Adjust the sensitivity for pitch as needed
left_stick_sensitivity = 1 # Adjust the sensitivity for the left stick as needed
left_trigger_sensitivity = 1 # Adjust the sensitivity for left trigger as needed
right_trigger_sensitivity = 1 # Adjust the sensitivity for right trigger as needed
# Define vJoy X, Y, Z, Rx, Ry, Rz, Slider, and Dial axis maximum and minimum range
vjoy_x_max = 16383
vjoy_x_min = -16383
vjoy_y_max = 16383
vjoy_y_min = -16383
vjoy_z_max = 16383
vjoy_z_min = -16383
vjoy_rx_max = 16383
vjoy_rx_min = -16383
vjoy_ry_max = 16383
vjoy_ry_min = -16383
vjoy_rz_max = 16383
vjoy_rz_min = -16383
vjoy_slider_max = 16383
vjoy_slider_min = -16383
vjoy_dial_max = 16383
vjoy_dial_min = -16383
# Calculate the ratio to map Hydra yaw, pitch, left stick, triggers, and second stick to vJoy axes range
yaw_to_vjoy_x_ratio = vjoy_x_max / 1.0 # Maximum Hydra yaw (adjust this value if needed)
roll_to_vjoy_x_ratio = vjoy_x_max / 1.0 # Maximum Hydra roll (adjust this value if needed)
pitch_to_vjoy_y_ratio = vjoy_y_max / 1.0 # Maximum Hydra pitch (adjust this value if needed)
left_stick_to_vjoy_rx_ratio = vjoy_rx_max / 1.0 # Maximum Hydra left stick axis (adjust this value if needed)
left_stick_to_vjoy_ry_ratio = vjoy_ry_max / 1.0 # Maximum Hydra left stick axis (adjust this value if needed)
#trigger_to_vjoy_z_ratio = vjoy_z_max / 1.0 # Maximum Hydra trigger (adjust this value if needed)
#trigger_to_vjoy_rz_ratio = vjoy_rz_max / 1.0 # Maximum Hydra trigger (adjust this value if needed)
joy_to_vjoy_slider_ratio = vjoy_slider_max / 1.0 # Maximum Hydra joyx (adjust this value if needed)
joy_to_vjoy_dial_ratio = vjoy_dial_max / 1.0 # Maximum Hydra joyy (adjust this value if needed)
# Calculate the offset for mapping Hydra triggers to vJoy sliders
if invert_trigger:
trigger_offset = vjoy_slider_max # Inverted: triggers at maximum when not pressed
else:
trigger_offset = vjoy_slider_min # Non-inverted: triggers at minimum when not pressed
if hydra[0].yaw or hydra[0].roll or hydra[0].pitch or hydra[0].joyx or hydra[0].joyy or hydra[0].trigger or hydra[1].trigger or hydra[1].joyx or hydra[1].joyy:
# Update Hydra values using Razer Hydra controller data
if aiming_hydra_switch == 1:
lefthydra = hydra[1]
righthydra = hydra[0]
elif aiming_hydra_switch == 2:
lefthydra = hydra[0]
righthydra = hydra[1]
right_yaw = righthydra.yaw * yaw_sensitivity
right_roll = righthydra.roll * roll_sensitivity
right_pitch = righthydra.pitch * pitch_sensitivity
#Buttons
vJoy[0].setButton(0,int(lefthydra.one))
vJoy[0].setButton(1,int(lefthydra.two))
vJoy[0].setButton(2,int(lefthydra.three))
vJoy[0].setButton(3,int(lefthydra.four))
vJoy[0].setButton(4,int(righthydra.one))
vJoy[0].setButton(5,int(righthydra.two))
vJoy[0].setButton(6,int(righthydra.three))
vJoy[0].setButton(7,int(righthydra.four))
vJoy[0].setButton(8,int(lefthydra.start))
vJoy[0].setButton(9,int(righthydra.start))
vJoy[0].setButton(10,int(lefthydra.bumper))
vJoy[0].setButton(11,int(righthydra.bumper))
vJoy[0].setButton(12,int(lefthydra.joybutton))
vJoy[0].setButton(13,int(righthydra.joybutton))
# Use the switch to determine what to map to vJoy x-axis
if translation_switch == 1:
v.x = max(vjoy_x_min, min(vjoy_x_max, int(round(right_yaw * yaw_to_vjoy_x_ratio))))
elif translation_switch == 2:
v.x = max(vjoy_x_min, min(vjoy_x_max, int(round(right_roll * roll_to_vjoy_x_ratio))))
left_stick_x = lefthydra.joyx * left_stick_sensitivity
left_stick_y = lefthydra.joyy * left_stick_sensitivity
left_trigger = lefthydra.trigger * left_trigger_sensitivity
right_trigger = righthydra.trigger * right_trigger_sensitivity
right_stick_x = righthydra.joyx * left_stick_sensitivity
right_stick_y = righthydra.joyy * left_stick_sensitivity
leftpitch_scaled = lefthydra.pitch * pitch_to_vjoy_y_ratio
leftjoyy_scaled = -left_stick_y * joy_to_vjoy_dial_ratio
leftyaw_scaled = lefthydra.yaw * yaw_to_vjoy_x_ratio
leftroll_scaled = lefthydra.roll * roll_to_vjoy_x_ratio
leftjoyx_scaled = left_stick_x * left_stick_to_vjoy_rx_ratio
# Calculate the combined value for vJoy Y-axis, X-axis
combined_y_value = ((leftpitch_scaled * left_pitch_invert) + leftjoyy_scaled) / 1
if translation_switch_left == 1:
combined_x_value = (leftyaw_scaled + leftjoyx_scaled) / 1
elif translation_switch_left == 2:
combined_x_value = (leftroll_scaled + leftjoyx_scaled) / 1
# Map Hydra pitch to vJoy Y-axis range centered around 0
v.y = max(vjoy_y_min, min(vjoy_y_max, int(round(right_pitch * pitch_to_vjoy_y_ratio * right_pitch_invert))))
# Map Hydra left stick x-axis to vJoy Rx-axis
if left_hydra_behaviour == 1:
v.rx = max(vjoy_rx_min, min(vjoy_rx_max, int(round(left_stick_x * left_stick_to_vjoy_rx_ratio))))
elif left_hydra_behaviour == 2:
v.rx = max(vjoy_rx_min, min(vjoy_rx_max, int(round(combined_x_value))))
else:
if translation_switch_left == 1:
v.rx = max(vjoy_rx_min, min(vjoy_rx_max, int(round(lefthydra.yaw * yaw_to_vjoy_x_ratio))))
elif translation_switch_left == 2:
v.rx = max(vjoy_rx_min, min(vjoy_rx_max, int(round(lefthydra.roll * roll_to_vjoy_x_ratio))))
# Map Hydra left stick y-axis to vJoy Ry-axis
if left_hydra_behaviour == 1:
v.ry = max(vjoy_ry_min, min(vjoy_ry_max, int(round(-left_stick_y * left_stick_to_vjoy_ry_ratio))))
elif left_hydra_behaviour == 2:
v.ry = max(vjoy_ry_min, min(vjoy_ry_max, int(round(combined_y_value))))
else:
v.ry = max(vjoy_ry_min, min(vjoy_ry_max, int(round(lefthydra.pitch * pitch_to_vjoy_y_ratio * left_pitch_invert))))
# Map Hydra left trigger to vJoy Slider axis
v.z = max(vjoy_z_min, min(vjoy_z_max, int(round(right_stick_x * joy_to_vjoy_slider_ratio))))
# Map Hydra right stick y-axis to vJoy Z-axis
v.rz = max(vjoy_rz_min, min(vjoy_rz_max, int(round(-right_stick_y * joy_to_vjoy_dial_ratio))))
# Map Hydra joyx to vJoy Z-axis
if invert_trigger:
v.slider = max(vjoy_slider_min, min(vjoy_slider_max, int(round((1 - left_trigger) * (vjoy_slider_max - vjoy_slider_min) + vjoy_slider_min))))
else:
v.slider = max(vjoy_slider_min, min(vjoy_slider_max, int(round(left_trigger * (vjoy_slider_max - vjoy_slider_min) + vjoy_slider_min))))
# Map Hydra joyy to vJoy Dial axis
if invert_trigger:
v.dial = max(vjoy_dial_min, min(vjoy_dial_max, int(round((1 - right_trigger) * (vjoy_dial_max - vjoy_dial_min) + vjoy_dial_min))))
else:
v.dial = max(vjoy_dial_min, min(vjoy_dial_max, int(round(right_trigger * (vjoy_dial_max - vjoy_dial_min) + vjoy_dial_min))))
diagnostics.watch(hydra[0].yaw)
#diagnostics.watch(hydra[0].roll)
#diagnostics.watch(hydra[0].pitch)
diagnostics.watch(hydra[1].yaw)
#diagnostics.watch(hydra[1].roll)
#diagnostics.watch(hydra[1].pitch)
#diagnostics.watch(vJoy[0].x)
#diagnostics.watch(v.x)
#diagnostics.watch(hydra[0].trigger)
#diagnostics.watch(hydra[1].trigger)
#diagnostics.watch(vJoy[0].z)
#diagnostics.watch(v.z)