Skip to content

Commit 52aa475

Browse files
authored
Logitech G27 update shifter input (#17216)
Based on information provided by Florin9doi #17199 (comment)
1 parent 64a3e50 commit 52aa475

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

rpcs3/Emu/Io/LogitechG27.cpp

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ static inline logitech_g27_sdl_mapping get_runtime_mapping()
209209
convert_mapping(cfg.shifter_5, mapping.shifter_5);
210210
convert_mapping(cfg.shifter_6, mapping.shifter_6);
211211
convert_mapping(cfg.shifter_r, mapping.shifter_r);
212+
convert_mapping(cfg.shifter_press, mapping.shifter_press);
212213

213214
return mapping;
214215
}
@@ -711,6 +712,7 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
711712
const bool shifter_5 = sdl_to_logitech_g27_button(m_joysticks, m_mapping.shifter_5);
712713
const bool shifter_6 = sdl_to_logitech_g27_button(m_joysticks, m_mapping.shifter_6);
713714
const bool shifter_r = sdl_to_logitech_g27_button(m_joysticks, m_mapping.shifter_r);
715+
const bool shifter_press = sdl_to_logitech_g27_button(m_joysticks, m_mapping.shifter_press);
714716
m_sdl_handles_mutex.unlock();
715717

716718
// populate buffer
@@ -750,16 +752,64 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
750752
// shifter connected
751753
set_bit(buf, 83, true);
752754
// shifter stick down
753-
set_bit(buf, 86, shifter_1 || shifter_2 || shifter_3 || shifter_4 || shifter_5 || shifter_6 || shifter_r);
755+
set_bit(buf, 86, shifter_press);
754756

755757
buf[3] = (steering << 2) | buf[3];
756758
buf[4] = steering >> 6;
757759
buf[5] = throttle;
758760
buf[6] = brake;
759761
buf[7] = clutch;
760762

761-
buf[8] = 0x80; // shifter x, don't own one to test gear/coord mapping
762-
buf[9] = 0x80; // shifter y
763+
// rough analog values recorded in https://github.com/RPCS3/rpcs3/pull/17199#issuecomment-2883934412
764+
// buf[8] shifter x
765+
// buf[9] shifter y
766+
constexpr u8 shifter_coord_center = 0x80;
767+
constexpr u8 shifter_coord_top = 0xb7;
768+
constexpr u8 shifter_coord_bottom = 0x32;
769+
constexpr u8 shifter_coord_left = 0x30;
770+
constexpr u8 shifter_coord_right = 0xb3;
771+
constexpr u8 shifter_coord_right_reverse = 0xaa;
772+
if (shifter_1)
773+
{
774+
buf[8] = shifter_coord_left;
775+
buf[9] = shifter_coord_top;
776+
}
777+
else if (shifter_2)
778+
{
779+
buf[8] = shifter_coord_left;
780+
buf[9] = shifter_coord_bottom;
781+
}
782+
else if (shifter_3)
783+
{
784+
buf[8] = shifter_coord_center;
785+
buf[9] = shifter_coord_top;
786+
}
787+
else if (shifter_4)
788+
{
789+
buf[8] = shifter_coord_center;
790+
buf[9] = shifter_coord_bottom;
791+
}
792+
else if (shifter_5)
793+
{
794+
buf[8] = shifter_coord_right;
795+
buf[9] = shifter_coord_top;
796+
}
797+
else if (shifter_6)
798+
{
799+
buf[8] = shifter_coord_right;
800+
buf[9] = shifter_coord_bottom;
801+
}
802+
else if (shifter_r)
803+
{
804+
buf[8] = shifter_coord_right_reverse;
805+
buf[9] = shifter_coord_bottom;
806+
}
807+
else
808+
{
809+
buf[8] = shifter_coord_center;
810+
buf[9] = shifter_coord_center;
811+
}
812+
763813
buf[10] = buf[10] | (m_wheel_range > 360 ? 0x90 : 0x10);
764814

765815
// logitech_g27_log.error("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10]);

rpcs3/Emu/Io/LogitechG27.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct logitech_g27_sdl_mapping
9494
sdl_mapping shifter_5 {};
9595
sdl_mapping shifter_6 {};
9696
sdl_mapping shifter_r {};
97+
sdl_mapping shifter_press {};
9798
};
9899

99100
class usb_device_logitech_g27 : public usb_device_emulated

rpcs3/Emu/Io/LogitechG27Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ struct emulated_logitech_g27_config : cfg::node
107107
emulated_logitech_g27_mapping shifter_5{this, "shifter_5", 0, sdl_mapping_type::hat, 0, hat_component::up, false};
108108
emulated_logitech_g27_mapping shifter_6{this, "shifter_6", 0, sdl_mapping_type::hat, 0, hat_component::down, false};
109109
emulated_logitech_g27_mapping shifter_r{this, "shifter_r", 0, sdl_mapping_type::hat, 0, hat_component::left, false};
110+
emulated_logitech_g27_mapping shifter_press{this, "shifter_press", 0, sdl_mapping_type::hat, 0, hat_component::right, false};
110111

111112
cfg::_bool reverse_effects{this, "reverse_effects", false};
112113
cfg::uint<0, 0xFFFFFFFFFFFFFFFF> ffb_device_type_id{this, "ffb_device_type_id", 0};

rpcs3/rpcs3qt/emulated_logitech_g27_settings_dialog.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ enum class mapping_device
6868
SHIFTER_5,
6969
SHIFTER_6,
7070
SHIFTER_R,
71+
SHIFTER_PRESS,
7172

7273
// Enum count
7374
COUNT
@@ -109,6 +110,7 @@ QString device_name(mapping_device dev)
109110
case mapping_device::SHIFTER_5: return QObject::tr("Gear 5");
110111
case mapping_device::SHIFTER_6: return QObject::tr("Gear 6");
111112
case mapping_device::SHIFTER_R: return QObject::tr("Gear R");
113+
case mapping_device::SHIFTER_PRESS: return QObject::tr("Shifter press");
112114
case mapping_device::COUNT: return "";
113115
}
114116
return "";
@@ -151,6 +153,7 @@ emulated_logitech_g27_mapping& device_cfg(mapping_device dev)
151153
case mapping_device::SHIFTER_5: return cfg.shifter_5;
152154
case mapping_device::SHIFTER_6: return cfg.shifter_6;
153155
case mapping_device::SHIFTER_R: return cfg.shifter_r;
156+
case mapping_device::SHIFTER_PRESS: return cfg.shifter_press;
154157
default: fmt::throw_exception("Unexpected mapping_device %d", static_cast<int>(dev));
155158
}
156159
}

0 commit comments

Comments
 (0)