remove old config compat, do not save config on reset

This commit is contained in:
Katharine Chui 2025-05-13 20:57:20 +02:00
parent 861b46bf83
commit d77a48c88c
4 changed files with 43 additions and 144 deletions

View file

@ -159,20 +159,6 @@ static bool sdl_joysticks_equal(std::map<u64, std::vector<SDL_Joystick*>>& left,
return true; return true;
} }
static std::map<u64, std::vector<SDL_Joystick*>> get_sdl_joysticks_v1(std::map<u64, std::vector<SDL_Joystick*>>& v2)
{
std::map<u64, std::vector<SDL_Joystick*>> v1;
for (const auto& [v2_key, joysticks] : v2)
{
const u64 v1_key = v2_key & 0xFFFFFFFF;
// this only works with wheels that worked with v1, and that's okay, Fanatec users need to re-map anyway
v1[v1_key] = joysticks;
}
return v1;
}
static inline logitech_g27_sdl_mapping get_runtime_mapping() static inline logitech_g27_sdl_mapping get_runtime_mapping()
{ {
logitech_g27_sdl_mapping mapping {}; logitech_g27_sdl_mapping mapping {};
@ -280,11 +266,7 @@ void usb_device_logitech_g27::sdl_refresh()
joysticks_of_type->second.push_back(cur_joystick); joysticks_of_type->second.push_back(cur_joystick);
} }
u64 joystick_type_id_for_ffb = joystick_type_id; if (joystick_type_id == ffb_device_type_id && new_haptic_handle == nullptr)
if (emulated_g27_device_type_id::is_v1(ffb_device_type_id))
joystick_type_id_for_ffb = joystick_type_id & 0xFFFFFFFF;
if (joystick_type_id_for_ffb == ffb_device_type_id && new_haptic_handle == nullptr)
{ {
SDL_Haptic* cur_haptic = SDL_OpenHapticFromJoystick(cur_joystick); SDL_Haptic* cur_haptic = SDL_OpenHapticFromJoystick(cur_joystick);
if (cur_haptic == nullptr) if (cur_haptic == nullptr)
@ -297,11 +279,7 @@ void usb_device_logitech_g27::sdl_refresh()
} }
} }
u64 joystick_type_id_for_led = joystick_type_id; if (joystick_type_id == led_device_type_id && new_led_joystick_handle == nullptr)
if (emulated_g27_device_type_id::is_v1(led_device_type_id))
joystick_type_id_for_led = joystick_type_id & 0xFFFFFFFF;
if (joystick_type_id_for_led == led_device_type_id && new_led_joystick_handle == nullptr)
{ {
new_led_joystick_handle = cur_joystick; new_led_joystick_handle = cur_joystick;
} }
@ -346,7 +324,6 @@ void usb_device_logitech_g27::sdl_refresh()
// finally clear out previous joystick handles // finally clear out previous joystick handles
clear_sdl_joysticks(m_joysticks); clear_sdl_joysticks(m_joysticks);
m_joysticks = new_joysticks; m_joysticks = new_joysticks;
m_joysticks_v1 = get_sdl_joysticks_v1(new_joysticks);
} }
} }
@ -604,7 +581,7 @@ static s16 fetch_sdl_as_axis(SDL_Joystick* joystick, const sdl_mapping& mapping)
return 0; return 0;
} }
static s16 fetch_sdl_axis_avg(std::map<u64, std::vector<SDL_Joystick*>>& joysticks, std::map<u64, std::vector<SDL_Joystick*>>& joysticks_v1, const sdl_mapping& mapping) static s16 fetch_sdl_axis_avg(std::map<u64, std::vector<SDL_Joystick*>>& joysticks, const sdl_mapping& mapping)
{ {
constexpr s16 MAX = 0x7FFF; constexpr s16 MAX = 0x7FFF;
constexpr s16 MIN = -0x8000; constexpr s16 MIN = -0x8000;
@ -612,9 +589,7 @@ static s16 fetch_sdl_axis_avg(std::map<u64, std::vector<SDL_Joystick*>>& joystic
auto joysticks_of_type = joysticks.find(mapping.device_type_id); auto joysticks_of_type = joysticks.find(mapping.device_type_id);
if (joysticks_of_type == joysticks.end()) if (joysticks_of_type == joysticks.end())
{ {
joysticks_of_type = joysticks_v1.find(mapping.device_type_id); return mapping.reverse ? MAX : MIN;
if (joysticks_of_type == joysticks_v1.end())
return mapping.reverse ? MAX : MIN;
} }
if (joysticks_of_type->second.empty()) if (joysticks_of_type->second.empty())
@ -632,14 +607,12 @@ static s16 fetch_sdl_axis_avg(std::map<u64, std::vector<SDL_Joystick*>>& joystic
return std::clamp<s16>(sdl_joysticks_total_value / static_cast<s32>(joysticks_of_type->second.size()), MIN, MAX); return std::clamp<s16>(sdl_joysticks_total_value / static_cast<s32>(joysticks_of_type->second.size()), MIN, MAX);
} }
static bool sdl_to_logitech_g27_button(std::map<u64, std::vector<SDL_Joystick*>>& joysticks, std::map<u64, std::vector<SDL_Joystick*>>& joysticks_v1, const sdl_mapping& mapping) static bool sdl_to_logitech_g27_button(std::map<u64, std::vector<SDL_Joystick*>>& joysticks, const sdl_mapping& mapping)
{ {
auto joysticks_of_type = joysticks.find(mapping.device_type_id); auto joysticks_of_type = joysticks.find(mapping.device_type_id);
if (joysticks_of_type == joysticks.end()) if (joysticks_of_type == joysticks.end())
{ {
joysticks_of_type = joysticks_v1.find(mapping.device_type_id); return mapping.reverse;
if (joysticks_of_type == joysticks_v1.end())
return mapping.reverse;
} }
if (joysticks_of_type->second.empty()) if (joysticks_of_type->second.empty())
@ -655,16 +628,16 @@ static bool sdl_to_logitech_g27_button(std::map<u64, std::vector<SDL_Joystick*>>
return pressed; return pressed;
} }
static u16 sdl_to_logitech_g27_steering(std::map<u64, std::vector<SDL_Joystick*>>& joysticks, std::map<u64, std::vector<SDL_Joystick*>>& joysticks_v1, const sdl_mapping& mapping) static u16 sdl_to_logitech_g27_steering(std::map<u64, std::vector<SDL_Joystick*>>& joysticks, const sdl_mapping& mapping)
{ {
const s16 avg = fetch_sdl_axis_avg(joysticks, joysticks_v1, mapping); const s16 avg = fetch_sdl_axis_avg(joysticks, mapping);
const u16 unsigned_avg = avg + 0x8000; const u16 unsigned_avg = avg + 0x8000;
return unsigned_avg * (0xFFFF >> 2) / 0xFFFF; return unsigned_avg * (0xFFFF >> 2) / 0xFFFF;
} }
static u8 sdl_to_logitech_g27_pedal(std::map<u64, std::vector<SDL_Joystick*>>& joysticks, std::map<u64, std::vector<SDL_Joystick*>>& joysticks_v1, const sdl_mapping& mapping) static u8 sdl_to_logitech_g27_pedal(std::map<u64, std::vector<SDL_Joystick*>>& joysticks, const sdl_mapping& mapping)
{ {
const s16 avg = fetch_sdl_axis_avg(joysticks, joysticks_v1, mapping); const s16 avg = fetch_sdl_axis_avg(joysticks, mapping);
const u16 unsigned_avg = avg + 0x8000; const u16 unsigned_avg = avg + 0x8000;
return unsigned_avg * 0xFF / 0xFFFF; return unsigned_avg * 0xFF / 0xFFFF;
} }
@ -704,44 +677,44 @@ void usb_device_logitech_g27::interrupt_transfer(u32 buf_size, u8* buf, u32 endp
// Fetch input states from SDL // Fetch input states from SDL
m_sdl_handles_mutex.lock(); m_sdl_handles_mutex.lock();
const u16 steering = sdl_to_logitech_g27_steering(m_joysticks, m_joysticks_v1, m_mapping.steering); const u16 steering = sdl_to_logitech_g27_steering(m_joysticks, m_mapping.steering);
const u8 throttle = sdl_to_logitech_g27_pedal(m_joysticks, m_joysticks_v1, m_mapping.throttle); const u8 throttle = sdl_to_logitech_g27_pedal(m_joysticks, m_mapping.throttle);
const u8 brake = sdl_to_logitech_g27_pedal(m_joysticks, m_joysticks_v1, m_mapping.brake); const u8 brake = sdl_to_logitech_g27_pedal(m_joysticks, m_mapping.brake);
const u8 clutch = sdl_to_logitech_g27_pedal(m_joysticks, m_joysticks_v1, m_mapping.clutch); const u8 clutch = sdl_to_logitech_g27_pedal(m_joysticks, m_mapping.clutch);
const bool shift_up = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.shift_up); const bool shift_up = sdl_to_logitech_g27_button(m_joysticks, m_mapping.shift_up);
const bool shift_down = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.shift_down); const bool shift_down = sdl_to_logitech_g27_button(m_joysticks, m_mapping.shift_down);
const bool up = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.up); const bool up = sdl_to_logitech_g27_button(m_joysticks, m_mapping.up);
const bool down = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.down); const bool down = sdl_to_logitech_g27_button(m_joysticks, m_mapping.down);
const bool left = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.left); const bool left = sdl_to_logitech_g27_button(m_joysticks, m_mapping.left);
const bool right = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.right); const bool right = sdl_to_logitech_g27_button(m_joysticks, m_mapping.right);
const bool triangle = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.triangle); const bool triangle = sdl_to_logitech_g27_button(m_joysticks, m_mapping.triangle);
const bool cross = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.cross); const bool cross = sdl_to_logitech_g27_button(m_joysticks, m_mapping.cross);
const bool square = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.square); const bool square = sdl_to_logitech_g27_button(m_joysticks, m_mapping.square);
const bool circle = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.circle); const bool circle = sdl_to_logitech_g27_button(m_joysticks, m_mapping.circle);
const bool l2 = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.l2); const bool l2 = sdl_to_logitech_g27_button(m_joysticks, m_mapping.l2);
const bool l3 = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.l3); const bool l3 = sdl_to_logitech_g27_button(m_joysticks, m_mapping.l3);
const bool r2 = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.r2); const bool r2 = sdl_to_logitech_g27_button(m_joysticks, m_mapping.r2);
const bool r3 = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.r3); const bool r3 = sdl_to_logitech_g27_button(m_joysticks, m_mapping.r3);
const bool plus = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.plus); const bool plus = sdl_to_logitech_g27_button(m_joysticks, m_mapping.plus);
const bool minus = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.minus); const bool minus = sdl_to_logitech_g27_button(m_joysticks, m_mapping.minus);
const bool dial_clockwise = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.dial_clockwise); const bool dial_clockwise = sdl_to_logitech_g27_button(m_joysticks, m_mapping.dial_clockwise);
const bool dial_anticlockwise = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.dial_anticlockwise); const bool dial_anticlockwise = sdl_to_logitech_g27_button(m_joysticks, m_mapping.dial_anticlockwise);
const bool select = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.select); const bool select = sdl_to_logitech_g27_button(m_joysticks, m_mapping.select);
const bool pause = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.pause); const bool pause = sdl_to_logitech_g27_button(m_joysticks, m_mapping.pause);
const bool shifter_1 = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.shifter_1); const bool shifter_1 = sdl_to_logitech_g27_button(m_joysticks, m_mapping.shifter_1);
const bool shifter_2 = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.shifter_2); const bool shifter_2 = sdl_to_logitech_g27_button(m_joysticks, m_mapping.shifter_2);
const bool shifter_3 = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.shifter_3); const bool shifter_3 = sdl_to_logitech_g27_button(m_joysticks, m_mapping.shifter_3);
const bool shifter_4 = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.shifter_4); const bool shifter_4 = sdl_to_logitech_g27_button(m_joysticks, m_mapping.shifter_4);
const bool shifter_5 = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.shifter_5); const bool shifter_5 = sdl_to_logitech_g27_button(m_joysticks, m_mapping.shifter_5);
const bool shifter_6 = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.shifter_6); const bool shifter_6 = sdl_to_logitech_g27_button(m_joysticks, m_mapping.shifter_6);
const bool shifter_r = sdl_to_logitech_g27_button(m_joysticks, m_joysticks_v1, m_mapping.shifter_r); const bool shifter_r = sdl_to_logitech_g27_button(m_joysticks, m_mapping.shifter_r);
m_sdl_handles_mutex.unlock(); m_sdl_handles_mutex.unlock();
// populate buffer // populate buffer

View file

@ -121,7 +121,6 @@ private:
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<u64, std::vector<SDL_Joystick*>> m_joysticks; std::map<u64, std::vector<SDL_Joystick*>> m_joysticks;
std::map<u64, std::vector<SDL_Joystick*>> m_joysticks_v1;
bool m_fixed_loop = false; bool m_fixed_loop = false;
u16 m_wheel_range = 200; u16 m_wheel_range = 200;
std::array<logitech_g27_ffb_slot, 4> m_effect_slots {}; std::array<logitech_g27_ffb_slot, 4> m_effect_slots {};

View file

@ -40,30 +40,6 @@ struct emulated_g27_device_type_id
value |= (num_buttons & ((1 << 10) - 1)) << 52; value |= (num_buttons & ((1 << 10) - 1)) << 52;
return value; return value;
} }
bool is_v1()
{
return !num_axes && !num_hats && !num_buttons;
}
static emulated_g27_device_type_id from_u64(u64 data)
{
const emulated_g27_device_type_id id =
{
.product_id = static_cast<u64>(data & 0xFFFF),
.vendor_id = static_cast<u64>((data >> 16) & 0xFFFF),
.num_axes = static_cast<u64>((data >> 32) & ((1 << 10) - 1)),
.num_hats = static_cast<u64>((data >> 42) & ((1 << 10) - 1)),
.num_buttons = static_cast<u64>((data >> 52) & ((1 << 10) - 1))
};
return id;
}
static bool is_v1(u64 data)
{
emulated_g27_device_type_id id = from_u64(data);
return id.is_v1();
}
}; };
struct emulated_logitech_g27_mapping : cfg::node struct emulated_logitech_g27_mapping : cfg::node

View file

@ -525,46 +525,6 @@ void emulated_logitech_g27_settings_dialog::save_ui_state_to_config()
} }
} }
static void migrate_device_type_id(emulated_g27_device_type_id& device_type_id_struct)
{
if (!device_type_id_struct.is_v1())
return;
sdl_instance::get_instance().pump_events();
int joystick_count = 0;
SDL_JoystickID* joystick_ids = SDL_GetJoysticks(&joystick_count);
if (!joystick_ids)
return;
for (int i = 0; i < joystick_count; i++)
{
SDL_Joystick* cur_joystick = SDL_OpenJoystick(joystick_ids[i]);
if (!cur_joystick)
continue;
const u16 vendor_id = SDL_GetJoystickVendor(cur_joystick);
const u16 product_id = SDL_GetJoystickProduct(cur_joystick);
if (vendor_id == device_type_id_struct.vendor_id && product_id == device_type_id_struct.product_id)
{
device_type_id_struct.num_axes = SDL_GetNumJoystickAxes(cur_joystick);
device_type_id_struct.num_hats = SDL_GetNumJoystickHats(cur_joystick);
device_type_id_struct.num_buttons = SDL_GetNumJoystickButtons(cur_joystick);
SDL_CloseJoystick(cur_joystick);
break;
}
SDL_CloseJoystick(cur_joystick);
}
SDL_free(joystick_ids);
}
static u64 migrate_device_type_id(u64 old_id)
{
emulated_g27_device_type_id old_id_struct = emulated_g27_device_type_id::from_u64(old_id);
migrate_device_type_id(old_id_struct);
return old_id_struct.as_u64();
}
void emulated_logitech_g27_settings_dialog::load_ui_state_from_config() void emulated_logitech_g27_settings_dialog::load_ui_state_from_config()
{ {
const auto load_mapping = [this](const emulated_logitech_g27_mapping& mapping, Mapping* ui_mapping, mapping_device_choice device_choice) const auto load_mapping = [this](const emulated_logitech_g27_mapping& mapping, Mapping* ui_mapping, mapping_device_choice device_choice)
@ -579,18 +539,10 @@ void emulated_logitech_g27_settings_dialog::load_ui_state_from_config()
.positive_axis = false .positive_axis = false
}; };
if (m_sdl_initialized)
m.device_type_id = migrate_device_type_id(m.device_type_id);
ui_mapping->set_mapping(m); ui_mapping->set_mapping(m);
u64 ffb_device_type_id = g_cfg_logitech_g27.ffb_device_type_id.get(); const u64 ffb_device_type_id = g_cfg_logitech_g27.ffb_device_type_id.get();
u64 led_device_type_id = g_cfg_logitech_g27.led_device_type_id.get(); const u64 led_device_type_id = g_cfg_logitech_g27.led_device_type_id.get();
if (m_sdl_initialized)
{
ffb_device_type_id = migrate_device_type_id(ffb_device_type_id);
led_device_type_id = migrate_device_type_id(led_device_type_id);
}
if (ffb_device_type_id == m.device_type_id && m_ffb_device->get_device_choice() == mapping_device_choice::NONE) if (ffb_device_type_id == m.device_type_id && m_ffb_device->get_device_choice() == mapping_device_choice::NONE)
{ {
@ -682,7 +634,6 @@ emulated_logitech_g27_settings_dialog::emulated_logitech_g27_settings_dialog(QWi
if (QMessageBox::question(this, tr("Confirm Reset"), tr("Reset all?")) != QMessageBox::Yes) if (QMessageBox::question(this, tr("Confirm Reset"), tr("Reset all?")) != QMessageBox::Yes)
return; return;
g_cfg_logitech_g27.reset(); g_cfg_logitech_g27.reset();
g_cfg_logitech_g27.save();
load_ui_state_from_config(); load_ui_state_from_config();
} }
else if (button == buttons->button(QDialogButtonBox::Cancel)) else if (button == buttons->button(QDialogButtonBox::Cancel))