diff options
| author | Léo Lam <leo@leolam.fr> | 2020-10-23 19:59:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-23 19:59:22 +0200 |
| commit | ce6eda7c717c1dad7d79b91ec421c196ac969357 (patch) | |
| tree | 873d58f4d200391135106b5e459b8d45cf47332c /Source/Core/InputCommon/ControllerInterface/Wiimote | |
| parent | 87e4a0785addc5c0e4eb04cb7cf8d93c551d34fc (diff) | |
| parent | a5e1415e74ce5b6b2a339256aa3e97748a3a2484 (diff) | |
Merge pull request #9184 from lioncash/inputlog
InputCommon: Migrate logging over to fmt
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/Wiimote')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/Wiimote/Wiimote.cpp | 136 |
1 files changed, 77 insertions, 59 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/Wiimote/Wiimote.cpp b/Source/Core/InputCommon/ControllerInterface/Wiimote/Wiimote.cpp index 2a95fc0a57..2a11904550 100644 --- a/Source/Core/InputCommon/ControllerInterface/Wiimote/Wiimote.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Wiimote/Wiimote.cpp @@ -112,7 +112,7 @@ void AddDevice(std::unique_ptr<WiimoteReal::Wiimote> wiimote) if (!wiimote->Connect(CIFACE_WIIMOTE_INDEX)) { - WARN_LOG(WIIMOTE, "WiiRemote: Failed to connect."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Failed to connect."); return; } @@ -303,7 +303,7 @@ Device::~Device() m_wiimote->EmuStop(); - INFO_LOG(WIIMOTE, "WiiRemote: Returning remote to pool."); + INFO_LOG_FMT(WIIMOTE, "WiiRemote: Returning remote to pool."); WiimoteReal::AddWiimoteToPool(std::move(m_wiimote)); } @@ -329,7 +329,7 @@ void Device::RunTasks() AddReportHandler(std::function<void(const InputReportStatus& status)>( [this](const InputReportStatus& status) { - DEBUG_LOG(WIIMOTE, "WiiRemote: Received requested status."); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Received requested status."); ProcessStatusReport(status); })); @@ -346,11 +346,11 @@ void Device::RunTasks() QueueReport(rpt, [this, desired_leds](ErrorCode result) { if (result != ErrorCode::Success) { - WARN_LOG(WIIMOTE, "WiiRemote: Failed to set LEDs."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Failed to set LEDs."); return; } - DEBUG_LOG(WIIMOTE, "WiiRemote: Set LEDs."); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Set LEDs."); m_leds = desired_leds; }); @@ -368,13 +368,13 @@ void Device::RunTasks() QueueReport(mode, [this](ErrorCode error) { if (error != ErrorCode::Success) { - WARN_LOG(WIIMOTE, "WiiRemote: Failed to set reporting mode."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Failed to set reporting mode."); return; } m_reporting_mode = desired_reporting_mode; - DEBUG_LOG(WIIMOTE, "WiiRemote: Set reporting mode."); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Set reporting mode."); }); return; @@ -389,11 +389,11 @@ void Device::RunTasks() [this](ReadResponse response) { if (!response) { - WARN_LOG(WIIMOTE, "WiiRemote: Failed to read accelerometer calibration."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Failed to read accelerometer calibration."); return; } - DEBUG_LOG(WIIMOTE, "WiiRemote: Read accelerometer calibration."); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Read accelerometer calibration."); auto& calibration_data = *response; @@ -405,7 +405,7 @@ void Device::RunTasks() // We could potentially try the second block at 0x26 if the checksum is bad. if (accel_calibration.checksum != calibration_data.back()) - WARN_LOG(WIIMOTE, "WiiRemote: Bad accelerometer calibration checksum."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Bad accelerometer calibration checksum."); }); return; @@ -460,8 +460,7 @@ void Device::RunTasks() // Note that this signal also DE-activates a M+. WriteData(AddressSpace::I2CBus, WiimoteEmu::ExtensionPort::REPORT_I2C_SLAVE, INIT_ADDR, {INIT_VALUE}, [this](ErrorCode result) { - DEBUG_LOG(WIIMOTE, "WiiRemote: Initialized extension: %d.", int(result)); - + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Initialized extension: {}.", int(result)); m_extension_id = std::nullopt; }); @@ -489,14 +488,14 @@ void Device::RunTasks() [this](ReadResponse response) { if (!response) { - DEBUG_LOG(WIIMOTE, "WiiRemote: M+ poll failed."); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: M+ poll failed."); HandleMotionPlusNonResponse(); return; } WriteData(AddressSpace::I2CBus, WiimoteEmu::MotionPlus::INACTIVE_DEVICE_ADDR, INIT_ADDR, {INIT_VALUE}, [this](ErrorCode result) { - DEBUG_LOG(WIIMOTE, "WiiRemote: M+ initialization: %d.", int(result)); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: M+ initialization: {}.", int(result)); if (result != ErrorCode::Success) { HandleMotionPlusNonResponse(); @@ -563,7 +562,7 @@ void Device::RunTasks() if (!response) return; - DEBUG_LOG(WIIMOTE, "WiiRemote: Read M+ calibration."); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Read M+ calibration."); WiimoteEmu::MotionPlus::CalibrationData calibration = Common::BitCastPtr<WiimoteEmu::MotionPlus::CalibrationData>(response->data()); @@ -577,7 +576,7 @@ void Device::RunTasks() if (read_checksum != std::pair(calibration.crc32_lsb, calibration.crc32_msb)) { // We could potentially try another read or call the M+ unusable. - WARN_LOG(WIIMOTE, "WiiRemote: Bad M+ calibration checksum."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Bad M+ calibration checksum."); } }); @@ -601,7 +600,7 @@ void Device::RunTasks() if (!response) return; - DEBUG_LOG(WIIMOTE, "WiiRemote: Read extension calibration."); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Read extension calibration."); auto& calibration_data = *response; @@ -616,7 +615,7 @@ void Device::RunTasks() calibration_data[CALIBRATION_SIZE - 1])) { // We could potentially try another block or call the extension unusable. - WARN_LOG(WIIMOTE, "WiiRemote: Bad extension calibration checksum."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Bad extension calibration checksum."); checksum = Checksum::Bad; } @@ -704,14 +703,14 @@ void Device::ProcessExtensionID(u8 id_0, u8 id_4, u8 id_5) { if (id_4 == 0x00 && id_5 == 0x00) { - INFO_LOG(WIIMOTE, "WiiRemote: Nunchuk is attached."); + INFO_LOG_FMT(WIIMOTE, "WiiRemote: Nunchuk is attached."); m_extension_id = ExtensionID::Nunchuk; m_mplus_desired_mode = MotionPlusState::PassthroughMode::Nunchuk; } else if (id_4 == 0x01 && id_5 == 0x01) { - INFO_LOG(WIIMOTE, "WiiRemote: Classic Controller is attached."); + INFO_LOG_FMT(WIIMOTE, "WiiRemote: Classic Controller is attached."); m_extension_id = ExtensionID::Classic; m_mplus_desired_mode = MotionPlusState::PassthroughMode::Classic; @@ -719,7 +718,7 @@ void Device::ProcessExtensionID(u8 id_0, u8 id_4, u8 id_5) else { // This is a normal occurance before extension initialization. - DEBUG_LOG(WIIMOTE, "WiiRemote: Unknown extension: %d %d %d.", id_0, id_4, id_5); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Unknown extension: {} {} {}.", id_0, id_4, id_5); m_extension_id = ExtensionID::Unsupported; } } @@ -727,7 +726,7 @@ void Device::ProcessExtensionID(u8 id_0, u8 id_4, u8 id_5) void Device::MotionPlusState::SetCalibrationData( const WiimoteEmu::MotionPlus::CalibrationData& data) { - DEBUG_LOG(WIIMOTE, "WiiRemote: Set M+ calibration."); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Set M+ calibration."); calibration.emplace(); @@ -748,7 +747,7 @@ Device::NunchukState::Calibration::Calibration() : accel{}, stick{} void Device::NunchukState::SetCalibrationData(const WiimoteEmu::Nunchuk::CalibrationData& data, Checksum checksum) { - DEBUG_LOG(WIIMOTE, "WiiRemote: Set Nunchuk calibration."); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Set Nunchuk calibration."); calibration.emplace(); @@ -759,16 +758,26 @@ void Device::NunchukState::SetCalibrationData(const WiimoteEmu::Nunchuk::Calibra // We catch that here and fall back to "full range" calibration. const auto stick_calibration = data.GetStick(); if (stick_calibration.IsSane()) + { calibration->stick = stick_calibration; + } else - WARN_LOG(WIIMOTE, "WiiRemote: Nunchuk stick calibration is not sane. Using fallback values."); + { + WARN_LOG_FMT(WIIMOTE, + "WiiRemote: Nunchuk stick calibration is not sane. Using fallback values."); + } // No known reports of bad accelerometer calibration but we'll handle it just in case. const auto accel_calibration = data.GetAccel(); if (accel_calibration.IsSane()) + { calibration->accel = accel_calibration; + } else - WARN_LOG(WIIMOTE, "WiiRemote: Nunchuk accel calibration is not sane. Using fallback values."); + { + WARN_LOG_FMT(WIIMOTE, + "WiiRemote: Nunchuk accel calibration is not sane. Using fallback values."); + } } Device::ClassicState::Calibration::Calibration() @@ -787,7 +796,7 @@ Device::ClassicState::Calibration::Calibration() void Device::ClassicState::SetCalibrationData(const WiimoteEmu::Classic::CalibrationData& data, Checksum checksum) { - DEBUG_LOG(WIIMOTE, "WiiRemote: Set Classic Controller calibration."); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Set Classic Controller calibration."); calibration.emplace(); @@ -796,16 +805,25 @@ void Device::ClassicState::SetCalibrationData(const WiimoteEmu::Classic::Calibra const auto left_stick_calibration = data.GetLeftStick(); if (left_stick_calibration.IsSane()) + { calibration->left_stick = left_stick_calibration; + } else - WARN_LOG(WIIMOTE, "WiiRemote: CC left stick calibration is not sane. Using fallback values."); + { + WARN_LOG_FMT(WIIMOTE, + "WiiRemote: CC left stick calibration is not sane. Using fallback values."); + } const auto right_stick_calibration = data.GetRightStick(); if (right_stick_calibration.IsSane()) + { calibration->right_stick = right_stick_calibration; + } else - WARN_LOG(WIIMOTE, "WiiRemote: CC right stick calibration is not sane. Using fallback values."); - + { + WARN_LOG_FMT(WIIMOTE, + "WiiRemote: CC right stick calibration is not sane. Using fallback values."); + } calibration->left_trigger = data.GetLeftTrigger(); calibration->right_trigger = data.GetRightTrigger(); } @@ -829,7 +847,7 @@ void Device::ReadActiveExtensionID() m_mplus_state.current_mode = passthrough_mode; - INFO_LOG(WIIMOTE, "WiiRemote: M+ is active in mode: %d.", int(passthrough_mode)); + INFO_LOG_FMT(WIIMOTE, "WiiRemote: M+ is active in mode: {}.", int(passthrough_mode)); } else { @@ -878,7 +896,7 @@ void Device::SetIRSensitivity(u32 level) static constexpr u16 BLOCK1_ADDR = 0x00; static constexpr u16 BLOCK2_ADDR = 0x1a; - DEBUG_LOG(WIIMOTE, "WiiRemote: Setting IR sensitivity: %d.", level + 1); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Setting IR sensitivity: {}.", level + 1); const auto& sensitivity_config = sensitivity_configs[level]; @@ -886,7 +904,7 @@ void Device::SetIRSensitivity(u32 level) sensitivity_config.block1, [&sensitivity_config, level, this](ErrorCode block_result) { if (block_result != ErrorCode::Success) { - WARN_LOG(WIIMOTE, "WiiRemote: Failed to write IR block 1."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Failed to write IR block 1."); return; } @@ -894,11 +912,11 @@ void Device::SetIRSensitivity(u32 level) sensitivity_config.block2, [&, level, this](ErrorCode block2_result) { if (block2_result != ErrorCode::Success) { - WARN_LOG(WIIMOTE, "WiiRemote: Failed to write IR block 2."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Failed to write IR block 2."); return; } - DEBUG_LOG(WIIMOTE, "WiiRemote: IR sensitivity set."); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: IR sensitivity set."); m_ir_state.current_sensitivity = level; }); @@ -915,7 +933,7 @@ void Device::ConfigureIRCamera() QueueReport(ir_logic2, [this](ErrorCode result) { if (result != ErrorCode::Success) { - WARN_LOG(WIIMOTE, "WiiRemote: Failed to enable IR."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Failed to enable IR."); return; } @@ -925,11 +943,11 @@ void Device::ConfigureIRCamera() QueueReport(ir_logic, [this](ErrorCode ir_result) { if (ir_result != ErrorCode::Success) { - WARN_LOG(WIIMOTE, "WiiRemote: Failed to enable IR."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Failed to enable IR."); return; } - DEBUG_LOG(WIIMOTE, "WiiRemote: IR enabled."); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: IR enabled."); m_ir_state.enabled = true; }); @@ -955,7 +973,7 @@ void Device::ConfigureIRCamera() {WiimoteEmu::CameraLogic::IR_MODE_BASIC}, [this](ErrorCode mode_result) { if (mode_result != ErrorCode::Success) { - WARN_LOG(WIIMOTE, "WiiRemote: Failed to set IR mode."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Failed to set IR mode."); return; } @@ -967,11 +985,11 @@ void Device::ConfigureIRCamera() {ENABLE_VALUE}, [this](ErrorCode result) { if (result != ErrorCode::Success) { - WARN_LOG(WIIMOTE, "WiiRemote: Failed to enable object tracking."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Failed to enable object tracking."); return; } - DEBUG_LOG(WIIMOTE, "WiiRemote: IR mode set."); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: IR mode set."); m_ir_state.mode_set = true; }); @@ -987,7 +1005,7 @@ void Device::ConfigureSpeaker() QueueReport(mute, [this](ErrorCode mute_result) { if (mute_result != ErrorCode::Success) { - WARN_LOG(WIIMOTE, "WiiRemote: Failed to mute speaker."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Failed to mute speaker."); return; } @@ -997,11 +1015,11 @@ void Device::ConfigureSpeaker() QueueReport(spkr, [this](ErrorCode enable_result) { if (enable_result != ErrorCode::Success) { - WARN_LOG(WIIMOTE, "WiiRemote: Failed to disable speaker."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Failed to disable speaker."); return; } - DEBUG_LOG(WIIMOTE, "WiiRemote: Speaker muted and disabled."); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Speaker muted and disabled."); m_speaker_configured = true; }); @@ -1020,7 +1038,7 @@ void Device::TriggerMotionPlusModeChange() WriteData(AddressSpace::I2CBus, device_addr, WiimoteEmu::MotionPlus::PASSTHROUGH_MODE_OFFSET, {passthrough_mode}, [this](ErrorCode activation_result) { - DEBUG_LOG(WIIMOTE, "WiiRemote: M+ activation: %d.", int(activation_result)); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: M+ activation: {}.", int(activation_result)); WaitForMotionPlus(); @@ -1041,7 +1059,7 @@ void Device::TriggerMotionPlusCalibration() // It seems we're better off just manually determining "zero". WriteData(AddressSpace::I2CBus, WiimoteEmu::MotionPlus::ACTIVE_DEVICE_ADDR, CALIBRATION_TRIGGER_ADDR, {CALIBRATION_TRIGGER_VALUE}, [](ErrorCode result) { - DEBUG_LOG(WIIMOTE, "WiiRemote: M+ calibration trigger done: %d.", int(result)); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: M+ calibration trigger done: {}.", int(result)); }); } @@ -1065,7 +1083,7 @@ void Device::ProcessInputReport(WiimoteReal::Report& report) { if (report.size() < WiimoteReal::REPORT_HID_HEADER_SIZE) { - WARN_LOG(WIIMOTE, "WiiRemote: Bad report size."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Bad report size."); return; } @@ -1080,7 +1098,7 @@ void Device::ProcessInputReport(WiimoteReal::Report& report) if (report.size() - WiimoteReal::REPORT_HID_HEADER_SIZE < sizeof(TypedInputData<InputReportStatus>)) { - WARN_LOG(WIIMOTE, "WiiRemote: Bad report size."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Bad report size."); } else { @@ -1089,8 +1107,8 @@ void Device::ProcessInputReport(WiimoteReal::Report& report) } else if (report_id < InputReportID::ReportCore) { - WARN_LOG(WIIMOTE, "WiiRemote: Unhandled input report: %s.", - ArrayToString(report.data(), u32(report.size())).c_str()); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Unhandled input report: {}.", + ArrayToString(report.data(), u32(report.size()))); } break; @@ -1098,7 +1116,7 @@ void Device::ProcessInputReport(WiimoteReal::Report& report) if (it->IsExpired()) { - WARN_LOG(WIIMOTE, "WiiRemote: Removing expired handler."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Removing expired handler."); it = m_report_handlers.erase(it); continue; } @@ -1130,7 +1148,7 @@ void Device::ProcessInputReport(WiimoteReal::Report& report) if (manipulator->GetDataSize() + WiimoteReal::REPORT_HID_HEADER_SIZE > report.size()) { - WARN_LOG(WIIMOTE, "WiiRemote: Bad report size."); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Bad report size."); return; } @@ -1291,7 +1309,7 @@ void Device::ProcessMotionPlusExtensionData(const u8* ext_data, u32 ext_size) { m_mplus_state.passthrough_port = is_ext_connected; - DEBUG_LOG(WIIMOTE, "WiiRemote: M+ passthrough port event: %d.", is_ext_connected); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: M+ passthrough port event: {}.", is_ext_connected); // With no passthrough extension we'll be happy with the current mode. if (!is_ext_connected) @@ -1308,7 +1326,7 @@ void Device::ProcessMotionPlusExtensionData(const u8* ext_data, u32 ext_size) if (!IsMotionPlusInDesiredMode()) { - DEBUG_LOG(WIIMOTE, "WiiRemote: Ignoring unwanted passthrough data."); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Ignoring unwanted passthrough data."); return; } @@ -1403,7 +1421,7 @@ bool Device::IsWaitingForMotionPlus() const void Device::WaitForMotionPlus() { - DEBUG_LOG(WIIMOTE, "WiiRemote: Wait for M+."); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Wait for M+."); m_mplus_wait_time = Clock::now() + std::chrono::seconds{2}; } @@ -1455,7 +1473,7 @@ void Device::AddReadDataReplyHandler(AddressSpace space, u8 slave, u16 address, { // Data read may return a busy ack. auto ack_handler = MakeAckHandler(OutputReportID::ReadData, [callback](ErrorCode result) { - DEBUG_LOG(WIIMOTE, "WiiRemote: Read ack error: %d.", int(result)); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Read ack error: {}.", int(result)); callback(ReadResponse{}); }); @@ -1468,7 +1486,7 @@ void Device::AddReadDataReplyHandler(AddressSpace space, u8 slave, u16 address, if (reply.error != u8(ErrorCode::Success)) { - DEBUG_LOG(WIIMOTE, "WiiRemote: Read reply error: %d.", int(reply.error)); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Read reply error: {}.", int(reply.error)); callback(ReadResponse{}); return ReportHandler::HandlerResult::Handled; @@ -1557,8 +1575,8 @@ void Device::ReportHandler::AddHandler(std::function<R(const T&)> handler) if (report.size() < sizeof(T) + WiimoteReal::REPORT_HID_HEADER_SIZE + 1) { // Off-brand "NEW 2in1" Wii Remote likes to shorten read data replies. - WARN_LOG(WIIMOTE, "WiiRemote: Bad report size (%d) for report 0x%x. Zero-filling.", - int(report.size()), int(T::REPORT_ID)); + WARN_LOG_FMT(WIIMOTE, "WiiRemote: Bad report size ({}) for report {:#x}. Zero-filling.", + report.size(), int(T::REPORT_ID)); data = {}; std::memcpy(&data, report.data() + WiimoteReal::REPORT_HID_HEADER_SIZE + 1, @@ -1631,7 +1649,7 @@ void Device::ProcessStatusReport(const InputReportStatus& status) // Handle extension port state change. if (is_ext_connected != m_extension_port) { - DEBUG_LOG(WIIMOTE, "WiiRemote: Extension port event: %d.", is_ext_connected); + DEBUG_LOG_FMT(WIIMOTE, "WiiRemote: Extension port event: {}.", is_ext_connected); m_extension_port = is_ext_connected; |
