Logitech G27 cleanup
Some checks are pending
Generate Translation Template / Generate Translation Template (push) Waiting to run
Build RPCS3 / RPCS3 Linux ubuntu-24.04 gcc (push) Waiting to run
Build RPCS3 / RPCS3 Linux ubuntu-24.04-arm clang (push) Waiting to run
Build RPCS3 / RPCS3 Linux ubuntu-24.04 clang (push) Waiting to run
Build RPCS3 / RPCS3 Windows (push) Waiting to run

This commit is contained in:
Megamouse 2025-05-03 10:42:08 +02:00
parent 6428088e46
commit 75b728be7e
6 changed files with 886 additions and 957 deletions

File diff suppressed because it is too large Load diff

View file

@ -16,72 +16,72 @@
#include <vector>
#include <thread>
enum logitech_g27_ffb_state
enum class logitech_g27_ffb_state
{
G27_FFB_INACTIVE,
G27_FFB_DOWNLOADED,
G27_FFB_PLAYING
inactive,
downloaded,
playing
};
struct logitech_g27_ffb_slot
{
logitech_g27_ffb_state state;
uint64_t last_update;
SDL_HapticEffect last_effect;
int effect_id;
logitech_g27_ffb_state state = logitech_g27_ffb_state::inactive;
u64 last_update = 0;
SDL_HapticEffect last_effect {};
s32 effect_id = -1;
};
struct sdl_mapping
{
uint32_t device_type_id; // (vendor_id << 16) | product_id
sdl_mapping_type type;
uint64_t id;
hat_component hat;
bool reverse;
bool positive_axis;
u32 device_type_id = 0; // (vendor_id << 16) | product_id
sdl_mapping_type type = sdl_mapping_type::button;
u64 id = 0;
hat_component hat = hat_component::none;
bool reverse = false;
bool positive_axis = false;
};
struct logitech_g27_sdl_mapping
{
sdl_mapping steering;
sdl_mapping throttle;
sdl_mapping brake;
sdl_mapping clutch;
sdl_mapping shift_up;
sdl_mapping shift_down;
sdl_mapping steering {};
sdl_mapping throttle {};
sdl_mapping brake {};
sdl_mapping clutch {};
sdl_mapping shift_up {};
sdl_mapping shift_down {};
sdl_mapping up;
sdl_mapping down;
sdl_mapping left;
sdl_mapping right;
sdl_mapping up {};
sdl_mapping down {};
sdl_mapping left {};
sdl_mapping right {};
sdl_mapping triangle;
sdl_mapping cross;
sdl_mapping square;
sdl_mapping circle;
sdl_mapping triangle {};
sdl_mapping cross {};
sdl_mapping square {};
sdl_mapping circle {};
// mappings based on g27 compat mode on g29
sdl_mapping l2;
sdl_mapping l3;
sdl_mapping r2;
sdl_mapping r3;
sdl_mapping l2 {};
sdl_mapping l3 {};
sdl_mapping r2 {};
sdl_mapping r3 {};
sdl_mapping plus;
sdl_mapping minus;
sdl_mapping plus {};
sdl_mapping minus {};
sdl_mapping dial_clockwise;
sdl_mapping dial_anticlockwise;
sdl_mapping dial_clockwise {};
sdl_mapping dial_anticlockwise {};
sdl_mapping select;
sdl_mapping pause;
sdl_mapping select {};
sdl_mapping pause {};
sdl_mapping shifter_1;
sdl_mapping shifter_2;
sdl_mapping shifter_3;
sdl_mapping shifter_4;
sdl_mapping shifter_5;
sdl_mapping shifter_6;
sdl_mapping shifter_r;
sdl_mapping shifter_1 {};
sdl_mapping shifter_2 {};
sdl_mapping shifter_3 {};
sdl_mapping shifter_4 {};
sdl_mapping shifter_5 {};
sdl_mapping shifter_6 {};
sdl_mapping shifter_r {};
};
class usb_device_logitech_g27 : public usb_device_emulated
@ -98,26 +98,25 @@ public:
bool open_device() override;
private:
u32 m_controller_index;
void sdl_refresh();
logitech_g27_sdl_mapping m_mapping;
bool m_reverse_effects;
u32 m_controller_index = 0;
logitech_g27_sdl_mapping m_mapping {};
bool m_reverse_effects = false;
std::mutex m_sdl_handles_mutex;
SDL_Joystick* m_led_joystick_handle = nullptr;
SDL_Haptic* m_haptic_handle = nullptr;
std::map<uint32_t, std::vector<SDL_Joystick*>> m_joysticks;
std::map<u32, std::vector<SDL_Joystick*>> m_joysticks;
bool m_fixed_loop = false;
uint16_t m_wheel_range = 200;
logitech_g27_ffb_slot m_effect_slots[4];
SDL_HapticEffect m_default_spring_effect = {0};
int m_default_spring_effect_id = -1;
u16 m_wheel_range = 200;
std::array<logitech_g27_ffb_slot, 4> m_effect_slots {};
SDL_HapticEffect m_default_spring_effect {};
s32 m_default_spring_effect_id = -1;
bool m_enabled = false;
std::thread m_house_keeping_thread;
std::mutex m_thread_control_mutex;
bool m_stop_thread;
void sdl_refresh();
atomic_t<bool> m_stop_thread { false };
};

View file

@ -5,18 +5,52 @@
#include "Utilities/File.h"
#include "LogitechG27Config.h"
template <>
void fmt_class_string<sdl_mapping_type>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](sdl_mapping_type value)
{
switch (value)
{
case sdl_mapping_type::button: return "button";
case sdl_mapping_type::hat: return "hat";
case sdl_mapping_type::axis: return "axis";
}
return unknown;
});
}
template <>
void fmt_class_string<hat_component>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](hat_component value)
{
switch (value)
{
case hat_component::up: return "up";
case hat_component::down: return "down";
case hat_component::left: return "left";
case hat_component::right: return "right";
case hat_component::none: return "";
}
return unknown;
});
}
emulated_logitech_g27_config g_cfg_logitech_g27;
LOG_CHANNEL(cfg_log, "CFG");
emulated_logitech_g27_config::emulated_logitech_g27_config()
: m_path(fmt::format("%s%s.yml", fs::get_config_dir(true), "LogitechG27"))
: m_path(fs::get_config_dir(true) + "LogitechG27.yml")
{
}
void emulated_logitech_g27_config::reset()
{
const std::lock_guard<std::mutex> lock(m_mutex);
const std::lock_guard lock(m_mutex);
cfg::node::from_default();
}

View file

@ -4,31 +4,31 @@
#include <mutex>
enum sdl_mapping_type
enum class sdl_mapping_type
{
MAPPING_BUTTON = 0,
MAPPING_HAT,
MAPPING_AXIS,
button = 0,
hat,
axis,
};
enum hat_component
enum class hat_component
{
HAT_NONE = 0,
HAT_UP,
HAT_DOWN,
HAT_LEFT,
HAT_RIGHT
none = 0,
up,
down,
left,
right
};
struct emulated_logitech_g27_mapping : cfg::node
{
cfg::uint<0, 0xFFFFFFFF> device_type_id;
cfg::uint<0, 0xFFFFFFFF> type;
cfg::_enum<sdl_mapping_type> type;
cfg::uint<0, 0xFFFFFFFFFFFFFFFF> id;
cfg::uint<0, 0xFFFFFFFF> hat;
cfg::_enum<hat_component> hat;
cfg::_bool reverse;
emulated_logitech_g27_mapping(cfg::node* owner, std::string name, uint32_t device_type_id_def, sdl_mapping_type type_def, uint64_t id_def, hat_component hat_def, bool reverse_def)
emulated_logitech_g27_mapping(cfg::node* owner, std::string name, u32 device_type_id_def, sdl_mapping_type type_def, uint64_t id_def, hat_component hat_def, bool reverse_def)
: cfg::node(owner, std::move(name)),
device_type_id(this, "device_type_id", device_type_id_def),
type(this, "type", type_def),
@ -46,44 +46,44 @@ public:
// TODO these defaults are for a shifter-less G29 + a xbox controller for shifter testing, perhaps find a new default
emulated_logitech_g27_mapping steering{this, "steering", 0x046dc24f, MAPPING_AXIS, 0, HAT_NONE, false};
emulated_logitech_g27_mapping throttle{this, "throttle", 0x046dc24f, MAPPING_AXIS, 2, HAT_NONE, false};
emulated_logitech_g27_mapping brake{this, "brake", 0x046dc24f, MAPPING_AXIS, 3, HAT_NONE, false};
emulated_logitech_g27_mapping clutch{this, "clutch", 0x046dc24f, MAPPING_AXIS, 1, HAT_NONE, false};
emulated_logitech_g27_mapping shift_up{this, "shift_up", 0x046dc24f, MAPPING_BUTTON, 4, HAT_NONE, false};
emulated_logitech_g27_mapping shift_down{this, "shift_down", 0x046dc24f, MAPPING_BUTTON, 5, HAT_NONE, false};
emulated_logitech_g27_mapping steering{this, "steering", 0x046dc24f, sdl_mapping_type::axis, 0, hat_component::none, false};
emulated_logitech_g27_mapping throttle{this, "throttle", 0x046dc24f, sdl_mapping_type::axis, 2, hat_component::none, false};
emulated_logitech_g27_mapping brake{this, "brake", 0x046dc24f, sdl_mapping_type::axis, 3, hat_component::none, false};
emulated_logitech_g27_mapping clutch{this, "clutch", 0x046dc24f, sdl_mapping_type::axis, 1, hat_component::none, false};
emulated_logitech_g27_mapping shift_up{this, "shift_up", 0x046dc24f, sdl_mapping_type::button, 4, hat_component::none, false};
emulated_logitech_g27_mapping shift_down{this, "shift_down", 0x046dc24f, sdl_mapping_type::button, 5, hat_component::none, false};
emulated_logitech_g27_mapping up{this, "up", 0x046dc24f, MAPPING_HAT, 0, HAT_UP, false};
emulated_logitech_g27_mapping down{this, "down", 0x046dc24f, MAPPING_HAT, 0, HAT_DOWN, false};
emulated_logitech_g27_mapping left{this, "left", 0x046dc24f, MAPPING_HAT, 0, HAT_LEFT, false};
emulated_logitech_g27_mapping right{this, "right", 0x046dc24f, MAPPING_HAT, 0, HAT_RIGHT, false};
emulated_logitech_g27_mapping up{this, "up", 0x046dc24f, sdl_mapping_type::hat, 0, hat_component::up, false};
emulated_logitech_g27_mapping down{this, "down", 0x046dc24f, sdl_mapping_type::hat, 0, hat_component::down, false};
emulated_logitech_g27_mapping left{this, "left", 0x046dc24f, sdl_mapping_type::hat, 0, hat_component::left, false};
emulated_logitech_g27_mapping right{this, "right", 0x046dc24f, sdl_mapping_type::hat, 0, hat_component::right, false};
emulated_logitech_g27_mapping triangle{this, "triangle", 0x046dc24f, MAPPING_BUTTON, 3, HAT_NONE, false};
emulated_logitech_g27_mapping cross{this, "cross", 0x046dc24f, MAPPING_BUTTON, 0, HAT_NONE, false};
emulated_logitech_g27_mapping square{this, "square", 0x046dc24f, MAPPING_BUTTON, 1, HAT_NONE, false};
emulated_logitech_g27_mapping circle{this, "circle", 0x046dc24f, MAPPING_BUTTON, 2, HAT_NONE, false};
emulated_logitech_g27_mapping triangle{this, "triangle", 0x046dc24f, sdl_mapping_type::button, 3, hat_component::none, false};
emulated_logitech_g27_mapping cross{this, "cross", 0x046dc24f, sdl_mapping_type::button, 0, hat_component::none, false};
emulated_logitech_g27_mapping square{this, "square", 0x046dc24f, sdl_mapping_type::button, 1, hat_component::none, false};
emulated_logitech_g27_mapping circle{this, "circle", 0x046dc24f, sdl_mapping_type::button, 2, hat_component::none, false};
emulated_logitech_g27_mapping l2{this, "l2", 0x046dc24f, MAPPING_BUTTON, 7, HAT_NONE, false};
emulated_logitech_g27_mapping l3{this, "l3", 0x046dc24f, MAPPING_BUTTON, 11, HAT_NONE, false};
emulated_logitech_g27_mapping r2{this, "r2", 0x046dc24f, MAPPING_BUTTON, 6, HAT_NONE, false};
emulated_logitech_g27_mapping r3{this, "r3", 0x046dc24f, MAPPING_BUTTON, 10, HAT_NONE, false};
emulated_logitech_g27_mapping l2{this, "l2", 0x046dc24f, sdl_mapping_type::button, 7, hat_component::none, false};
emulated_logitech_g27_mapping l3{this, "l3", 0x046dc24f, sdl_mapping_type::button, 11, hat_component::none, false};
emulated_logitech_g27_mapping r2{this, "r2", 0x046dc24f, sdl_mapping_type::button, 6, hat_component::none, false};
emulated_logitech_g27_mapping r3{this, "r3", 0x046dc24f, sdl_mapping_type::button, 10, hat_component::none, false};
emulated_logitech_g27_mapping plus{this, "plus", 0x046dc24f, MAPPING_BUTTON, 19, HAT_NONE, false};
emulated_logitech_g27_mapping minus{this, "minus", 0x046dc24f, MAPPING_BUTTON, 20, HAT_NONE, false};
emulated_logitech_g27_mapping plus{this, "plus", 0x046dc24f, sdl_mapping_type::button, 19, hat_component::none, false};
emulated_logitech_g27_mapping minus{this, "minus", 0x046dc24f, sdl_mapping_type::button, 20, hat_component::none, false};
emulated_logitech_g27_mapping dial_clockwise{this, "dial_clockwise", 0x046dc24f, MAPPING_BUTTON, 21, HAT_NONE, false};
emulated_logitech_g27_mapping dial_anticlockwise{this, "dial_anticlockwise", 0x046dc24f, MAPPING_BUTTON, 22, HAT_NONE, false};
emulated_logitech_g27_mapping dial_clockwise{this, "dial_clockwise", 0x046dc24f, sdl_mapping_type::button, 21, hat_component::none, false};
emulated_logitech_g27_mapping dial_anticlockwise{this, "dial_anticlockwise", 0x046dc24f, sdl_mapping_type::button, 22, hat_component::none, false};
emulated_logitech_g27_mapping select{this, "select", 0x046dc24f, MAPPING_BUTTON, 8, HAT_NONE, false};
emulated_logitech_g27_mapping pause{this, "pause", 0x046dc24f, MAPPING_BUTTON, 9, HAT_NONE, false};
emulated_logitech_g27_mapping select{this, "select", 0x046dc24f, sdl_mapping_type::button, 8, hat_component::none, false};
emulated_logitech_g27_mapping pause{this, "pause", 0x046dc24f, sdl_mapping_type::button, 9, hat_component::none, false};
emulated_logitech_g27_mapping shifter_1{this, "shifter_1", 0x045e028e, MAPPING_BUTTON, 3, HAT_NONE, false};
emulated_logitech_g27_mapping shifter_2{this, "shifter_2", 0x045e028e, MAPPING_BUTTON, 0, HAT_NONE, false};
emulated_logitech_g27_mapping shifter_3{this, "shifter_3", 0x045e028e, MAPPING_BUTTON, 2, HAT_NONE, false};
emulated_logitech_g27_mapping shifter_4{this, "shifter_4", 0x045e028e, MAPPING_BUTTON, 1, HAT_NONE, false};
emulated_logitech_g27_mapping shifter_5{this, "shifter_5", 0x045e028e, MAPPING_HAT, 0, HAT_UP, false};
emulated_logitech_g27_mapping shifter_6{this, "shifter_6", 0x045e028e, MAPPING_HAT, 0, HAT_DOWN, false};
emulated_logitech_g27_mapping shifter_r{this, "shifter_r", 0x045e028e, MAPPING_HAT, 0, HAT_LEFT, false};
emulated_logitech_g27_mapping shifter_1{this, "shifter_1", 0x045e028e, sdl_mapping_type::button, 3, hat_component::none, false};
emulated_logitech_g27_mapping shifter_2{this, "shifter_2", 0x045e028e, sdl_mapping_type::button, 0, hat_component::none, false};
emulated_logitech_g27_mapping shifter_3{this, "shifter_3", 0x045e028e, sdl_mapping_type::button, 2, hat_component::none, false};
emulated_logitech_g27_mapping shifter_4{this, "shifter_4", 0x045e028e, sdl_mapping_type::button, 1, hat_component::none, false};
emulated_logitech_g27_mapping shifter_5{this, "shifter_5", 0x045e028e, sdl_mapping_type::hat, 0, hat_component::up, false};
emulated_logitech_g27_mapping shifter_6{this, "shifter_6", 0x045e028e, sdl_mapping_type::hat, 0, hat_component::down, false};
emulated_logitech_g27_mapping shifter_r{this, "shifter_r", 0x045e028e, sdl_mapping_type::hat, 0, hat_component::left, false};
cfg::_bool reverse_effects{this, "reverse_effects", true};
cfg::uint<0, 0xFFFFFFFF> ffb_device_type_id{this, "ffb_device_type_id", 0x046dc24f};

File diff suppressed because it is too large Load diff

View file

@ -1,11 +1,12 @@
#pragma once
#ifdef HAVE_SDL3
#include <QDialog>
#include <QLabel>
#include <QCheckBox>
#include <QScrollArea>
#ifdef HAVE_SDL3
#ifndef _MSC_VER
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
@ -14,7 +15,6 @@
#ifndef _MSC_VER
#pragma GCC diagnostic pop
#endif
#endif
#include <map>
#include <vector>
@ -22,7 +22,7 @@
struct joystick_state
{
std::vector<int16_t> axes;
std::vector<s16> axes;
std::vector<bool> buttons;
std::vector<hat_component> hats;
};
@ -36,15 +36,17 @@ class emulated_logitech_g27_settings_dialog : public QDialog
public:
emulated_logitech_g27_settings_dialog(QWidget* parent = nullptr);
~emulated_logitech_g27_settings_dialog();
void set_state_text(const char*);
const std::map<uint32_t, joystick_state>& get_joystick_states();
virtual ~emulated_logitech_g27_settings_dialog();
void set_state_text(const QString& text);
const std::map<u32, joystick_state>& get_joystick_states();
void set_enable(bool enable);
private:
std::map<uint32_t, joystick_state> m_last_joystick_states;
// hack: need a completed dummy class when linking automoc generated with sdl-less build
std::vector<void*> m_joystick_handles;
void load_ui_state_from_config();
void save_ui_state_to_config();
std::map<u32, joystick_state> m_last_joystick_states;
std::vector<SDL_Joystick*> m_joystick_handles;
uint64_t m_last_joystick_states_update = 0;
bool m_sdl_initialized = false;
@ -97,7 +99,6 @@ private:
DeviceChoice* m_led_device = nullptr;
QScrollArea* m_mapping_scroll_area = nullptr;
void load_ui_state_from_config();
void save_ui_state_to_config();
};
#endif