Skip to content
Permalink
Browse files

WiimoteEmu: Emulated motion plus is detected by game now.

  • Loading branch information...
jordan-woyak committed Nov 24, 2018
1 parent ba93692 commit 372b12c67fe2afbe749d6c6c8de3629a1b942c62
@@ -33,6 +33,7 @@
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h"
#include "InputCommon/ControllerEmu/ControlGroup/Extension.h"
#include "InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h"

namespace WiimoteEmu
{
@@ -146,9 +147,6 @@ void Wiimote::HidOutputReport(const wm_report* const sr, const bool send_ack)
break;

case RT_IR_LOGIC: // 0x1a
// comment from old plugin:
// This enables or disables the IR lights, we update the global variable g_IR
// so that WmRequestStatus() knows about it
m_status.ir = sr->enable;
if (false == sr->ack)
return;
@@ -206,10 +204,18 @@ void Wiimote::HandleExtensionSwap()

void Wiimote::RequestStatus(const wm_request_status* const rs)
{
HandleExtensionSwap();
INFO_LOG(WIIMOTE, "Wiimote::RequestStatus");

// update status struct
m_status.extension = m_extension->active_extension ? 1 : 0;
m_status.extension = m_extension_port.IsDeviceConnected();
// Battery levels in voltage
// 0x00 - 0x32: level 1
// 0x33 - 0x43: level 2
// 0x33 - 0x54: level 3
// 0x55 - 0xff: level 4
m_status.battery = (u8)(m_battery_setting->GetValue() * 0xff);
// TODO: this right?
m_status.battery_low = m_status.battery < 0x33;

// set up report
u8 data[8];
@@ -228,7 +234,13 @@ void Wiimote::WriteData(const wm_write_data* const wd)
{
u16 address = Common::swap16(wd->address);

INFO_LOG(WIIMOTE, "Wiimote::WriteData: 0x%02x @ 0x%02x (%d)", wd->space, address, wd->size);
if (0 == wd->size)
{
// Ignore requests of zero size
return;
}

INFO_LOG(WIIMOTE, "Wiimote::WriteData: 0x%02x @ 0x%02x @ 0x%02x (%d)", wd->space, wd->slave_address, address, wd->size);

if (wd->size > 16)
{
@@ -277,18 +289,6 @@ void Wiimote::WriteData(const wm_write_data* const wd)
// A real wiimote gives error 7 for failed write to i2c bus (mainly a non-existant slave)
error_code = 0x07;
}

// else if (&m_reg_motion_plus == region_ptr)
//{
// // activate/deactivate motion plus
// if (0x55 == m_reg_motion_plus.activated)
// {
// // maybe hacky
// m_reg_motion_plus.activated = 0;

// RequestStatus();
// }
//}
}
break;

@@ -308,16 +308,13 @@ static const char* const named_buttons[] = {
void Wiimote::Reset()
{
m_reporting_mode = RT_REPORT_CORE;
// i think these two are good
m_reporting_channel = 0;
m_reporting_auto = false;

m_rumble_on = false;
m_speaker_mute = false;

// will make the first Update() call send a status request
// the first call to RequestStatus() will then set up the status struct extension bit
m_extension->active_extension = -1;
m_extension->active_extension = 0;

// eeprom
memset(m_eeprom, 0, sizeof(m_eeprom));
@@ -338,12 +335,6 @@ void Wiimote::Reset()

// status
memset(&m_status, 0, sizeof(m_status));
// Battery levels in voltage
// 0x00 - 0x32: level 1
// 0x33 - 0x43: level 2
// 0x33 - 0x54: level 3
// 0x55 - 0xff: level 4
m_status.battery = (u8)(m_battery_setting->GetValue() * 100);

m_shake_step = {};
m_shake_soft_step = {};
@@ -358,22 +349,22 @@ void Wiimote::Reset()
m_speaker_logic.adpcm_state.step = 127;

// Initialize i2c bus
// TODO: kill magic numbers
m_i2c_bus.Reset();
// Address 0x51
m_i2c_bus.AddSlave(&m_speaker_logic);
// Address 0x58
m_i2c_bus.AddSlave(&m_camera_logic);

// TODO: only add to bus when enabled
// This also adds the motion plus to the i2c bus
// Address 0x53 (or 0x52 when activated)
m_i2c_bus.AddSlave(&m_motion_plus_logic);
// Address 0x58
m_i2c_bus.AddSlave(&m_camera_logic);
m_extension_port.SetAttachment(&m_motion_plus_logic);

// TODO: add directly to wiimote bus when mplus is disabled
// TODO: only add to bus when connected:
// Address 0x52 (when motion plus is not activated)
// Connected to motion plus i2c_bus (with passthrough by default)
m_motion_plus_logic.i2c_bus.AddSlave(&m_ext_logic);
m_motion_plus_logic.extension_port.SetAttachment(&m_ext_logic);
}

Wiimote::Wiimote(const unsigned int index) : m_index(index), ir_sin(0), ir_cos(1)
@@ -564,19 +555,22 @@ bool Wiimote::Step()
return true;
}

// If an extension change is requested in the GUI it will first be disconnected here.
// causing IsDeviceConnected() to return false below:
HandleExtensionSwap();

// check if a status report needs to be sent
// this happens on Wii Remote sync and when extensions are switched
if (m_extension->active_extension != m_extension->switch_extension)
// this happens when extensions are switched
if (m_status.extension != m_extension_port.IsDeviceConnected())
{
RequestStatus();

// WiiBrew: Following a connection or disconnection event on the Extension Port,
// data reporting is disabled and the Data Reporting Mode must be reset before new data can
// arrive.
// after a game receives an unrequested status report,
// it expects data reports to stop until it sets the reporting mode again
m_reporting_mode = RT_REPORT_CORE;
m_reporting_auto = false;

RequestStatus();

return true;
}

@@ -859,9 +853,6 @@ void Wiimote::Update()

Movie::SetPolledDevice();

// TODO: Is max battery really 100 and not 0xff?
m_status.battery = (u8)(m_battery_setting->GetValue() * 100);

const ReportFeatures& rptf = reporting_mode_features[m_reporting_mode - RT_REPORT_CORE];
s8 rptf_size = rptf.total_size;
if (Movie::IsPlayingInput() &&
@@ -1113,13 +1104,9 @@ int Wiimote::CurrentExtension() const
return m_extension->active_extension;
}

bool Wiimote::HaveExtension() const
bool Wiimote::ExtensionLogic::ReadDeviceDetectPin()
{
return m_extension->active_extension > 0;
return extension->active_extension ? true : false;
}

bool Wiimote::WantExtension() const
{
return m_extension->switch_extension != 0;
}
} // namespace WiimoteEmu

0 comments on commit 372b12c

Please sign in to comment.
You can’t perform that action at this time.