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

View file

@ -5,18 +5,52 @@
#include "Utilities/File.h" #include "Utilities/File.h"
#include "LogitechG27Config.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; emulated_logitech_g27_config g_cfg_logitech_g27;
LOG_CHANNEL(cfg_log, "CFG"); LOG_CHANNEL(cfg_log, "CFG");
emulated_logitech_g27_config::emulated_logitech_g27_config() 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() 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(); cfg::node::from_default();
} }

View file

@ -4,31 +4,31 @@
#include <mutex> #include <mutex>
enum sdl_mapping_type enum class sdl_mapping_type
{ {
MAPPING_BUTTON = 0, button = 0,
MAPPING_HAT, hat,
MAPPING_AXIS, axis,
}; };
enum hat_component enum class hat_component
{ {
HAT_NONE = 0, none = 0,
HAT_UP, up,
HAT_DOWN, down,
HAT_LEFT, left,
HAT_RIGHT right
}; };
struct emulated_logitech_g27_mapping : cfg::node struct emulated_logitech_g27_mapping : cfg::node
{ {
cfg::uint<0, 0xFFFFFFFF> device_type_id; 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, 0xFFFFFFFFFFFFFFFF> id;
cfg::uint<0, 0xFFFFFFFF> hat; cfg::_enum<hat_component> hat;
cfg::_bool reverse; 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)), : cfg::node(owner, std::move(name)),
device_type_id(this, "device_type_id", device_type_id_def), device_type_id(this, "device_type_id", device_type_id_def),
type(this, "type", type_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 // 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 steering{this, "steering", 0x046dc24f, sdl_mapping_type::axis, 0, hat_component::none, false};
emulated_logitech_g27_mapping throttle{this, "throttle", 0x046dc24f, MAPPING_AXIS, 2, HAT_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, MAPPING_AXIS, 3, HAT_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, MAPPING_AXIS, 1, HAT_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, MAPPING_BUTTON, 4, HAT_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, MAPPING_BUTTON, 5, HAT_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 up{this, "up", 0x046dc24f, sdl_mapping_type::hat, 0, hat_component::up, false};
emulated_logitech_g27_mapping down{this, "down", 0x046dc24f, MAPPING_HAT, 0, HAT_DOWN, 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, MAPPING_HAT, 0, HAT_LEFT, 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, MAPPING_HAT, 0, HAT_RIGHT, 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 triangle{this, "triangle", 0x046dc24f, sdl_mapping_type::button, 3, hat_component::none, false};
emulated_logitech_g27_mapping cross{this, "cross", 0x046dc24f, MAPPING_BUTTON, 0, HAT_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, MAPPING_BUTTON, 1, HAT_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, MAPPING_BUTTON, 2, HAT_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 l2{this, "l2", 0x046dc24f, sdl_mapping_type::button, 7, hat_component::none, false};
emulated_logitech_g27_mapping l3{this, "l3", 0x046dc24f, MAPPING_BUTTON, 11, HAT_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, MAPPING_BUTTON, 6, HAT_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, MAPPING_BUTTON, 10, HAT_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 plus{this, "plus", 0x046dc24f, sdl_mapping_type::button, 19, hat_component::none, false};
emulated_logitech_g27_mapping minus{this, "minus", 0x046dc24f, MAPPING_BUTTON, 20, HAT_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_clockwise{this, "dial_clockwise", 0x046dc24f, sdl_mapping_type::button, 21, hat_component::none, false};
emulated_logitech_g27_mapping dial_anticlockwise{this, "dial_anticlockwise", 0x046dc24f, MAPPING_BUTTON, 22, HAT_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 select{this, "select", 0x046dc24f, sdl_mapping_type::button, 8, hat_component::none, false};
emulated_logitech_g27_mapping pause{this, "pause", 0x046dc24f, MAPPING_BUTTON, 9, HAT_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_1{this, "shifter_1", 0x045e028e, sdl_mapping_type::button, 3, hat_component::none, false};
emulated_logitech_g27_mapping shifter_2{this, "shifter_2", 0x045e028e, MAPPING_BUTTON, 0, HAT_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, MAPPING_BUTTON, 2, HAT_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, MAPPING_BUTTON, 1, HAT_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, MAPPING_HAT, 0, HAT_UP, 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, MAPPING_HAT, 0, HAT_DOWN, 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, MAPPING_HAT, 0, HAT_LEFT, 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::_bool reverse_effects{this, "reverse_effects", true};
cfg::uint<0, 0xFFFFFFFF> ffb_device_type_id{this, "ffb_device_type_id", 0x046dc24f}; 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 #pragma once
#ifdef HAVE_SDL3
#include <QDialog> #include <QDialog>
#include <QLabel> #include <QLabel>
#include <QCheckBox> #include <QCheckBox>
#include <QScrollArea> #include <QScrollArea>
#ifdef HAVE_SDL3
#ifndef _MSC_VER #ifndef _MSC_VER
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wold-style-cast"
@ -14,7 +15,6 @@
#ifndef _MSC_VER #ifndef _MSC_VER
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif
#endif
#include <map> #include <map>
#include <vector> #include <vector>
@ -22,7 +22,7 @@
struct joystick_state struct joystick_state
{ {
std::vector<int16_t> axes; std::vector<s16> axes;
std::vector<bool> buttons; std::vector<bool> buttons;
std::vector<hat_component> hats; std::vector<hat_component> hats;
}; };
@ -36,15 +36,17 @@ class emulated_logitech_g27_settings_dialog : public QDialog
public: public:
emulated_logitech_g27_settings_dialog(QWidget* parent = nullptr); emulated_logitech_g27_settings_dialog(QWidget* parent = nullptr);
~emulated_logitech_g27_settings_dialog(); virtual ~emulated_logitech_g27_settings_dialog();
void set_state_text(const char*); void set_state_text(const QString& text);
const std::map<uint32_t, joystick_state>& get_joystick_states(); const std::map<u32, joystick_state>& get_joystick_states();
void set_enable(bool enable); void set_enable(bool enable);
private: private:
std::map<uint32_t, joystick_state> m_last_joystick_states; void load_ui_state_from_config();
// hack: need a completed dummy class when linking automoc generated with sdl-less build void save_ui_state_to_config();
std::vector<void*> m_joystick_handles;
std::map<u32, joystick_state> m_last_joystick_states;
std::vector<SDL_Joystick*> m_joystick_handles;
uint64_t m_last_joystick_states_update = 0; uint64_t m_last_joystick_states_update = 0;
bool m_sdl_initialized = false; bool m_sdl_initialized = false;
@ -97,7 +99,6 @@ private:
DeviceChoice* m_led_device = nullptr; DeviceChoice* m_led_device = nullptr;
QScrollArea* m_mapping_scroll_area = nullptr; QScrollArea* m_mapping_scroll_area = nullptr;
void load_ui_state_from_config();
void save_ui_state_to_config();
}; };
#endif