19
19
20
20
LOG_CHANNEL (logitech_g27_log, " LOGIG27" );
21
21
22
+ // ref: https://github.com/libsdl-org/SDL/issues/7941, need to use SDL_HAPTIC_STEERING_AXIS for some windows drivers
23
+ static const SDL_HapticDirection STEERING_DIRECTION = {
24
+ .type = SDL_HAPTIC_STEERING_AXIS,
25
+ .dir = {0 , 0 , 0 }
26
+ };
27
+
22
28
usb_device_logitech_g27::usb_device_logitech_g27 (u32 controller_index, const std::array<u8, 7 >& location)
23
29
: usb_device_emulated(location), m_controller_index(controller_index)
24
30
{
@@ -36,11 +42,7 @@ usb_device_logitech_g27::usb_device_logitech_g27(u32 controller_index, const std
36
42
m_default_spring_effect.type = SDL_HAPTIC_SPRING;
37
43
38
44
// ref: https://github.com/libsdl-org/SDL/issues/7941, need to use SDL_HAPTIC_STEERING_AXIS for some windows drivers
39
- m_default_spring_effect.condition .direction = SDL_HapticDirection
40
- {
41
- .type = SDL_HAPTIC_STEERING_AXIS,
42
- .dir = {0 , 0 , 0 }
43
- };
45
+ m_default_spring_effect.condition .direction = STEERING_DIRECTION;
44
46
m_default_spring_effect.condition .length = SDL_HAPTIC_INFINITY;
45
47
for (int i = 0 ; i < 1 /* 3*/ ; i++)
46
48
{
@@ -790,12 +792,6 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
790
792
// logitech_g27_log.error("%02x %02x %02x %02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
791
793
// printf("%02x %02x %02x %02x %02x %02x %02x\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
792
794
793
- // ref: https://github.com/libsdl-org/SDL/issues/7941, need to use SDL_HAPTIC_STEERING_AXIS for some windows drivers
794
- SDL_HapticDirection direction = {
795
- .type = SDL_HAPTIC_STEERING_AXIS,
796
- .dir = {0 , 0 , 0 }
797
- };
798
-
799
795
// TODO maybe force clipping from cfg
800
796
801
797
// Process effects
@@ -908,7 +904,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
908
904
{
909
905
// Constant force
910
906
new_effect.type = SDL_HAPTIC_CONSTANT;
911
- new_effect.constant .direction = direction ;
907
+ new_effect.constant .direction = STEERING_DIRECTION ;
912
908
new_effect.constant .length = SDL_HAPTIC_INFINITY;
913
909
new_effect.constant .level = logitech_g27_force_to_level (buf[2 + i], m_reverse_effects);
914
910
break ;
@@ -918,7 +914,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
918
914
{
919
915
// Spring/High resolution spring
920
916
new_effect.type = SDL_HAPTIC_SPRING;
921
- new_effect.condition .direction = direction ;
917
+ new_effect.condition .direction = STEERING_DIRECTION ;
922
918
new_effect.condition .length = SDL_HAPTIC_INFINITY;
923
919
const u8 s1 = buf[5 ] & 1 ;
924
920
const u8 s2 = (buf[5 ] >> 4 ) & 1 ;
@@ -969,7 +965,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
969
965
{
970
966
// Damper/High resolution damper
971
967
new_effect.type = SDL_HAPTIC_DAMPER;
972
- new_effect.condition .direction = direction ;
968
+ new_effect.condition .direction = STEERING_DIRECTION ;
973
969
new_effect.condition .length = SDL_HAPTIC_INFINITY;
974
970
const u8 s1 = buf[3 ] & 1 ;
975
971
const u8 s2 = buf[5 ] & 1 ;
@@ -1009,7 +1005,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
1009
1005
{
1010
1006
// Friction
1011
1007
new_effect.type = SDL_HAPTIC_FRICTION;
1012
- new_effect.condition .direction = direction ;
1008
+ new_effect.condition .direction = STEERING_DIRECTION ;
1013
1009
new_effect.condition .length = SDL_HAPTIC_INFINITY;
1014
1010
const u8 k1 = buf[2 ];
1015
1011
const u8 k2 = buf[3 ];
@@ -1036,7 +1032,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
1036
1032
{
1037
1033
// Auto center spring/High resolution auto center spring
1038
1034
new_effect.type = SDL_HAPTIC_SPRING;
1039
- new_effect.condition .direction = direction ;
1035
+ new_effect.condition .direction = STEERING_DIRECTION ;
1040
1036
new_effect.condition .length = SDL_HAPTIC_INFINITY;
1041
1037
const u16 saturation = logitech_g27_clip_to_saturation (buf[4 ]);
1042
1038
const u16 deadband = 2 * 0xFFFF / 255 ;
@@ -1082,7 +1078,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
1082
1078
else
1083
1079
new_effect.type = m_reverse_effects ? SDL_HAPTIC_SAWTOOTHUP : SDL_HAPTIC_SAWTOOTHDOWN;
1084
1080
new_effect.type = buf[1 ] == 0x04 ? SDL_HAPTIC_SAWTOOTHUP : SDL_HAPTIC_SAWTOOTHDOWN;
1085
- new_effect.periodic .direction = direction ;
1081
+ new_effect.periodic .direction = STEERING_DIRECTION ;
1086
1082
new_effect.periodic .length = SDL_HAPTIC_INFINITY;
1087
1083
const u8 l1 = buf[2 ];
1088
1084
const u8 l2 = buf[3 ];
@@ -1106,7 +1102,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
1106
1102
{
1107
1103
// Trapezoid, convert to SDL_HAPTIC_SQUARE or SDL_HAPTIC_TRIANGLE
1108
1104
// TODO full accuracy will need some kind of rendering thread, cannot be represented with a single effect
1109
- new_effect.periodic .direction = direction ;
1105
+ new_effect.periodic .direction = STEERING_DIRECTION ;
1110
1106
new_effect.periodic .length = SDL_HAPTIC_INFINITY;
1111
1107
const u8 l1 = buf[2 ];
1112
1108
const u8 l2 = buf[3 ];
@@ -1135,7 +1131,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
1135
1131
// Rectangle, convert to SDL_HAPTIC_SQUARE
1136
1132
// TODO full accuracy will need some kind of rendering thread, cannot be represented with a single effect
1137
1133
new_effect.type = SDL_HAPTIC_SQUARE;
1138
- new_effect.periodic .direction = direction ;
1134
+ new_effect.periodic .direction = STEERING_DIRECTION ;
1139
1135
new_effect.periodic .length = SDL_HAPTIC_INFINITY;
1140
1136
const u8 l1 = buf[2 ];
1141
1137
const u8 l2 = buf[3 ];
@@ -1178,7 +1174,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
1178
1174
const u8 d = i == 0 ? d1 : d2;
1179
1175
const u8 l = i == 0 ? l1 : l2;
1180
1176
new_effect.constant .length = SDL_HAPTIC_INFINITY;
1181
- new_effect.constant .direction = direction ;
1177
+ new_effect.constant .direction = STEERING_DIRECTION ;
1182
1178
if (s == 0 || t == 0 )
1183
1179
{
1184
1180
// gran turismo 6 does this, gives a variable force with no step so it just behaves as constant force
@@ -1204,7 +1200,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
1204
1200
{
1205
1201
1206
1202
new_effect.type = SDL_HAPTIC_RAMP;
1207
- new_effect.ramp .direction = direction ;
1203
+ new_effect.ramp .direction = STEERING_DIRECTION ;
1208
1204
const s16 l1_converted = logitech_g27_force_to_level (l1, m_reverse_effects);
1209
1205
const s16 l2_converted = logitech_g27_force_to_level (l2, m_reverse_effects);
1210
1206
new_effect.ramp .start = d1 ? l1_converted : l2_converted;
@@ -1221,7 +1217,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
1221
1217
{
1222
1218
// Square
1223
1219
new_effect.type = SDL_HAPTIC_SQUARE;
1224
- new_effect.periodic .direction = direction ;
1220
+ new_effect.periodic .direction = STEERING_DIRECTION ;
1225
1221
const u8 a = buf[2 ];
1226
1222
const u8 tl = buf[3 ];
1227
1223
const u8 th = buf[4 ];
0 commit comments