Skip to content

Commit

Permalink
Config: Port WiimoteEnableSpeaker setting to new config system.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiralCurtiss committed Jan 6, 2022
1 parent 8c554d2 commit 2354fb4
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 12 deletions.
1 change: 1 addition & 0 deletions Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp
Expand Up @@ -108,6 +108,7 @@ bool IsSettingSaveable(const Config::Location& config_location)
&Config::MAIN_WII_SD_CARD.GetLocation(),
&Config::MAIN_WII_KEYBOARD.GetLocation(),
&Config::MAIN_WIIMOTE_CONTINUOUS_SCANNING.GetLocation(),
&Config::MAIN_WIIMOTE_ENABLE_SPEAKER.GetLocation(),

// UI.General

Expand Down
2 changes: 0 additions & 2 deletions Source/Core/Core/ConfigManager.cpp
Expand Up @@ -111,7 +111,6 @@ void SConfig::SaveCoreSettings(IniFile& ini)
{
core->Set(fmt::format("SIDevice{}", i), m_SIDevice[i]);
}
core->Set("WiimoteEnableSpeaker", m_WiimoteEnableSpeaker);
core->Set("WiimoteControllerInterface", connect_wiimotes_for_ciface);
core->Set("MMU", bMMU);
}
Expand Down Expand Up @@ -140,7 +139,6 @@ void SConfig::LoadCoreSettings(IniFile& ini)
core->Get(fmt::format("SIDevice{}", i), &m_SIDevice[i],
(i == 0) ? SerialInterface::SIDEVICE_GC_CONTROLLER : SerialInterface::SIDEVICE_NONE);
}
core->Get("WiimoteEnableSpeaker", &m_WiimoteEnableSpeaker, false);
core->Get("WiimoteControllerInterface", &connect_wiimotes_for_ciface, false);
core->Get("MMU", &bMMU, bMMU);
core->Get("BBDumpPort", &iBBDumpPort, -1);
Expand Down
1 change: 0 additions & 1 deletion Source/Core/Core/ConfigManager.h
Expand Up @@ -50,7 +50,6 @@ struct BootParameters;
struct SConfig
{
// Wii Devices
bool m_WiimoteEnableSpeaker;
bool connect_wiimotes_for_ciface;

// Settings
Expand Down
7 changes: 6 additions & 1 deletion Source/Core/Core/HW/WiimoteEmu/Speaker.cpp
Expand Up @@ -73,7 +73,7 @@ void stopdamnwav()
void SpeakerLogic::SpeakerData(const u8* data, int length, float speaker_pan)
{
// TODO: should we still process samples for the decoder state?
if (!SConfig::GetInstance().m_WiimoteEnableSpeaker)
if (!m_speaker_enabled)
return;

if (reg_data.sample_rate == 0 || length == 0)
Expand Down Expand Up @@ -186,6 +186,11 @@ void SpeakerLogic::DoState(PointerWrap& p)
p.Do(reg_data);
}

void SpeakerLogic::SetSpeakerEnabled(bool enabled)
{
m_speaker_enabled = enabled;
}

int SpeakerLogic::BusRead(u8 slave_addr, u8 addr, int count, u8* data_out)
{
if (I2C_ADDR != slave_addr)
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/Speaker.h
Expand Up @@ -29,6 +29,8 @@ class SpeakerLogic : public I2CSlave
void Reset();
void DoState(PointerWrap& p);

void SetSpeakerEnabled(bool enabled);

private:
// Pan is -1.0 to +1.0
void SpeakerData(const u8* data, int length, float speaker_pan);
Expand Down Expand Up @@ -71,6 +73,8 @@ class SpeakerLogic : public I2CSlave
ADPCMState adpcm_state{};

ControllerEmu::SettingValue<double> m_speaker_pan_setting;

bool m_speaker_enabled = false;
};

} // namespace WiimoteEmu
16 changes: 14 additions & 2 deletions Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp
Expand Up @@ -17,8 +17,7 @@
#include "Common/MathUtil.h"
#include "Common/MsgHandler.h"

#include "Core/Config/SYSCONFSettings.h"
#include "Core/ConfigManager.h"
#include "Core/Config/MainSettings.h"
#include "Core/Core.h"
#include "Core/HW/Wiimote.h"
#include "Core/Movie.h"
Expand Down Expand Up @@ -297,6 +296,14 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index)
m_hotkeys->AddInput(_trans("Upright Hold"), false);

Reset();

m_config_changed_callback_id = Config::AddConfigChangedCallback([this] { RefreshConfig(); });
RefreshConfig();
}

Wiimote::~Wiimote()
{
Config::RemoveConfigChangedCallback(m_config_changed_callback_id);
}

std::string Wiimote::GetName() const
Expand Down Expand Up @@ -726,6 +733,11 @@ void Wiimote::SetRumble(bool on)
m_rumble->controls.front()->control_ref->State(on);
}

void Wiimote::RefreshConfig()
{
m_speaker_logic.SetSpeakerEnabled(Config::Get(Config::MAIN_WIIMOTE_ENABLE_SPEAKER));
}

void Wiimote::StepDynamics()
{
EmulateSwing(&m_swing_state, m_swing, 1.f / ::Wiimote::UPDATE_FREQ);
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h
Expand Up @@ -109,6 +109,7 @@ class Wiimote : public ControllerEmu::EmulatedController, public WiimoteCommon::
static constexpr u16 BUTTON_HOME = 0x8000;

explicit Wiimote(unsigned int index);
~Wiimote();

std::string GetName() const override;
void LoadDefaults(const ControllerInterface& ciface) override;
Expand Down Expand Up @@ -144,6 +145,8 @@ class Wiimote : public ControllerEmu::EmulatedController, public WiimoteCommon::
// This is the region exposed over bluetooth:
static constexpr int EEPROM_FREE_SIZE = 0x1700;

void RefreshConfig();

void StepDynamics();
void UpdateButtonsStatus();

Expand Down Expand Up @@ -297,5 +300,7 @@ class Wiimote : public ControllerEmu::EmulatedController, public WiimoteCommon::
PositionalState m_shake_state;

IMUCursorState m_imu_cursor_state;

size_t m_config_changed_callback_id;
};
} // namespace WiimoteEmu
18 changes: 16 additions & 2 deletions Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp
Expand Up @@ -142,7 +142,16 @@ void AddWiimoteToPool(std::unique_ptr<Wiimote> wiimote)
s_wiimote_pool.emplace_back(WiimotePoolEntry{std::move(wiimote)});
}

Wiimote::Wiimote() = default;
Wiimote::Wiimote()
{
m_config_changed_callback_id = Config::AddConfigChangedCallback([this] { RefreshConfig(); });
RefreshConfig();
}

Wiimote::~Wiimote()
{
Config::RemoveConfigChangedCallback(m_config_changed_callback_id);
}

void Wiimote::Shutdown()
{
Expand Down Expand Up @@ -263,7 +272,7 @@ void Wiimote::InterruptDataOutput(const u8* data, const u32 size)
}
}
else if (rpt[1] == u8(OutputReportID::SpeakerData) &&
(!SConfig::GetInstance().m_WiimoteEnableSpeaker || !m_speaker_enable || m_speaker_mute))
(!m_speaker_enabled_in_dolphin_config || !m_speaker_enable || m_speaker_mute))
{
rpt.resize(3);
// Translate undesired speaker data reports into rumble reports.
Expand Down Expand Up @@ -804,6 +813,11 @@ void Wiimote::ThreadFunc()
DisconnectInternal();
}

void Wiimote::RefreshConfig()
{
m_speaker_enabled_in_dolphin_config = Config::Get(Config::MAIN_WIIMOTE_ENABLE_SPEAKER);
}

int Wiimote::GetIndex() const
{
return m_index;
Expand Down
9 changes: 7 additions & 2 deletions Source/Core/Core/HW/WiimoteReal/WiimoteReal.h
Expand Up @@ -51,7 +51,7 @@ class Wiimote : public WiimoteCommon::HIDWiimote
Wiimote(Wiimote&&) = delete;
Wiimote& operator=(Wiimote&&) = delete;

virtual ~Wiimote() {}
~Wiimote() override;
// This needs to be called in derived destructors!
void Shutdown();

Expand Down Expand Up @@ -125,6 +125,8 @@ class Wiimote : public WiimoteCommon::HIDWiimote

void ThreadFunc();

void RefreshConfig();

bool m_is_linked = false;

// We track the speaker state to convert unnecessary speaker data into rumble reports.
Expand All @@ -144,6 +146,10 @@ class Wiimote : public WiimoteCommon::HIDWiimote

Common::SPSCQueue<Report> m_read_reports;
Common::SPSCQueue<Report> m_write_reports;

bool m_speaker_enabled_in_dolphin_config = false;

size_t m_config_changed_callback_id;
};

class WiimoteScannerBackend
Expand Down Expand Up @@ -209,5 +215,4 @@ void InitAdapterClass();
void HandleWiimotesInControllerInterfaceSettingChange();
void PopulateDevices();
void ProcessWiimotePool();

} // namespace WiimoteReal
5 changes: 3 additions & 2 deletions Source/Core/DolphinQt/Config/WiimoteControllersWidget.cpp
Expand Up @@ -305,7 +305,7 @@ void WiimoteControllersWidget::LoadSettings()
}
m_wiimote_real_balance_board->setChecked(WiimoteCommon::GetSource(WIIMOTE_BALANCE_BOARD) ==
WiimoteSource::Real);
m_wiimote_speaker_data->setChecked(SConfig::GetInstance().m_WiimoteEnableSpeaker);
m_wiimote_speaker_data->setChecked(Config::Get(Config::MAIN_WIIMOTE_ENABLE_SPEAKER));
m_wiimote_ciface->setChecked(SConfig::GetInstance().connect_wiimotes_for_ciface);
m_wiimote_continuous_scanning->setChecked(Config::Get(Config::MAIN_WIIMOTE_CONTINUOUS_SCANNING));

Expand All @@ -319,7 +319,8 @@ void WiimoteControllersWidget::LoadSettings()

void WiimoteControllersWidget::SaveSettings()
{
SConfig::GetInstance().m_WiimoteEnableSpeaker = m_wiimote_speaker_data->isChecked();
Config::SetBaseOrCurrent(Config::MAIN_WIIMOTE_ENABLE_SPEAKER,
m_wiimote_speaker_data->isChecked());
SConfig::GetInstance().connect_wiimotes_for_ciface = m_wiimote_ciface->isChecked();
Config::SetBaseOrCurrent(Config::MAIN_WIIMOTE_CONTINUOUS_SCANNING,
m_wiimote_continuous_scanning->isChecked());
Expand Down

0 comments on commit 2354fb4

Please sign in to comment.