From ef777c4186778272a6afc0d1c8909d7f75eaa703 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Mon, 24 Feb 2020 19:04:48 -0600 Subject: [PATCH] HW/WiimoteEmu: Fill IR data with 0xFF on failed bus read. --- Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index a9d564d116..cd05f70426 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -516,8 +516,15 @@ void Wiimote::SendDataReport() const u8 camera_data_offset = CameraLogic::REPORT_DATA_OFFSET + rpt_builder.GetIRDataFormatOffset(); - m_i2c_bus.BusRead(CameraLogic::I2C_ADDR, camera_data_offset, rpt_builder.GetIRDataSize(), - rpt_builder.GetIRDataPtr()); + u8* ir_data = rpt_builder.GetIRDataPtr(); + const u8 ir_size = rpt_builder.GetIRDataSize(); + + if (ir_size != m_i2c_bus.BusRead(CameraLogic::I2C_ADDR, camera_data_offset, ir_size, ir_data)) + { + // This happens when IR reporting is enabled but the camera hardware is disabled. + // It commonly occurs when changing IR sensitivity. + std::fill_n(ir_data, ir_size, u8(0xff)); + } } // Extension port: @@ -541,7 +548,7 @@ void Wiimote::SendDataReport() ExtensionPort::REPORT_I2C_ADDR, ext_size, ext_data)) { // Real wiimote seems to fill with 0xff on failed bus read - std::fill_n(ext_data, ext_size, 0xff); + std::fill_n(ext_data, ext_size, u8(0xff)); } }