From d39d89594dd802593ab00b482306a14d8cc5ad8b Mon Sep 17 00:00:00 2001 From: Rachel Bryk Date: Sat, 28 Mar 2015 06:28:37 -0400 Subject: [PATCH] Limit Wiimote battery usage for Dolphin-lite users. Wiimote batteries drain over time. The user must upgrade to Dolphin Pro for $19.95 to recharge them. --- Source/Core/Core/ConfigManager.cpp | 6 ++++++ Source/Core/Core/ConfigManager.h | 2 ++ Source/Core/Core/HW/Wiimote.cpp | 2 ++ Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp | 20 +++++++++++++++++++ Source/Core/DolphinWX/InputConfigDiag.cpp | 9 ++++++++- Source/Core/InputCommon/ControllerEmu.cpp | 1 - 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index 1afa82d1aa45..aa7de0ab9c72 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -354,6 +354,7 @@ void SConfig::SaveCoreSettings(IniFile& ini) core->Set("GFXBackend", m_LocalCoreStartupParameter.m_strVideoBackend); core->Set("GPUDeterminismMode", m_LocalCoreStartupParameter.m_strGPUDeterminismMode); core->Set("GameCubeAdapter", m_GameCubeAdapter); + core->Set("DolphinPro", m_DolphinPro); } void SConfig::SaveMovieSettings(IniFile& ini) @@ -621,6 +622,11 @@ void SConfig::LoadCoreSettings(IniFile& ini) core->Get("GFXBackend", &m_LocalCoreStartupParameter.m_strVideoBackend, ""); core->Get("GPUDeterminismMode", &m_LocalCoreStartupParameter.m_strGPUDeterminismMode, "auto"); core->Get("GameCubeAdapter", &m_GameCubeAdapter, true); +#ifdef DOLPHINPRO + m_DolphinPro = true; +#else + core->Get("DolphinPro", &m_DolphinPro, false); +#endif } void SConfig::LoadMovieSettings(IniFile& ini) diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index cac39cbb3154..2554519186a3 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -119,6 +119,8 @@ struct SConfig : NonCopyable SysConf* m_SYSCONF; + bool m_DolphinPro; + // Save settings void SaveSettings(); diff --git a/Source/Core/Core/HW/Wiimote.cpp b/Source/Core/Core/HW/Wiimote.cpp index 13797a118095..28e086e50f1b 100644 --- a/Source/Core/Core/HW/Wiimote.cpp +++ b/Source/Core/Core/HW/Wiimote.cpp @@ -25,6 +25,8 @@ InputConfig* GetConfig() void Shutdown() { + s_config.SaveConfig(); + for (const ControllerEmu* i : s_config.controllers) { delete i; diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index b16dbce96380..c39aa9f18f2d 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -21,6 +21,8 @@ #include "Core/HW/WiimoteEmu/Attachment/Nunchuk.h" #include "Core/HW/WiimoteEmu/Attachment/Turntable.h" #include "Core/HW/WiimoteReal/WiimoteReal.h" +#include "Core/IPC_HLE/WII_IPC_HLE_Device_usb.h" +#include "Core/IPC_HLE/WII_IPC_HLE_WiiMote.h" namespace { @@ -302,6 +304,7 @@ Wiimote::Wiimote( const unsigned int index ) m_options->settings.emplace_back(new ControlGroup::Setting(_trans("Upright Wiimote"), false)); m_options->settings.emplace_back(new ControlGroup::IterateUI(_trans("Iterative Input"))); m_options->settings.emplace_back(new ControlGroup::Setting(_trans("Speaker Pan"), 0, -127, 127)); + m_options->settings.emplace_back(new ControlGroup::Setting(_trans("Battery"), 95, 0, 255)); // TODO: This value should probably be re-read if SYSCONF gets changed m_sensor_bar_on_top = SConfig::GetInstance().m_SYSCONF->GetData("BT.BAR") != 0; @@ -636,6 +639,23 @@ void Wiimote::Update() if (Step()) return; + m_status.battery = (u8)(m_options->settings[5]->GetValue() * 100); + if (!m_status.battery) + { + GetUsbPointer()->AccessWiiMote(m_index | 0x100)->Activate(false); + return; + } + + static u32 batteryCounter = 0; + // drop battery by 1 every 144000 times input is polled. At 200 hz polling, this is once per 12 mins. Gives 19 hours + // of battery life from the default of 95, or 51 hours at the max of 255. + if (++batteryCounter > 144000) + { + m_status.battery--; + m_options->settings[5]->SetValue(((ControlState)m_status.battery) / 100); + batteryCounter = 0; + } + u8 data[MAX_PAYLOAD]; memset(data, 0, sizeof(data)); diff --git a/Source/Core/DolphinWX/InputConfigDiag.cpp b/Source/Core/DolphinWX/InputConfigDiag.cpp index 4997ca318e1b..1369752fa8c1 100644 --- a/Source/Core/DolphinWX/InputConfigDiag.cpp +++ b/Source/Core/DolphinWX/InputConfigDiag.cpp @@ -946,7 +946,14 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin setting->wxcontrol->Bind(wxEVT_SPINCTRL, &GamepadPage::AdjustSetting, eventsink); options.push_back(setting); wxBoxSizer* const szr = new wxBoxSizer(wxHORIZONTAL); - szr->Add(new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(groupSetting->name))), 0, wxCENTER | wxRIGHT, 3); + wxStaticText* nameBox = new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(groupSetting->name))); + if (groupSetting->name == "Battery" && !SConfig::GetInstance().m_DolphinPro) + { + setting->wxcontrol->Disable(); + nameBox->SetToolTip(wxGetTranslation("Upgrade to Dolphin Pro™ to recharge batteries.")); + } + + szr->Add(nameBox, 0, wxCENTER | wxRIGHT, 3); szr->Add(setting->wxcontrol, 0, wxRIGHT, 3); Add(szr, 0, wxALL | wxCENTER, 3); } diff --git a/Source/Core/InputCommon/ControllerEmu.cpp b/Source/Core/InputCommon/ControllerEmu.cpp index df82bc09708a..17e7a6d7cc6b 100644 --- a/Source/Core/InputCommon/ControllerEmu.cpp +++ b/Source/Core/InputCommon/ControllerEmu.cpp @@ -219,7 +219,6 @@ ControllerEmu::Cursor::Cursor(const std::string& _name) settings.emplace_back(new Setting(_trans("Center"), 0.5)); settings.emplace_back(new Setting(_trans("Width"), 0.5)); settings.emplace_back(new Setting(_trans("Height"), 0.5)); - } void ControllerEmu::LoadDefaults(const ControllerInterface &ciface)