Skip to content

Commit

Permalink
Merge pull request #2774 from AdmiralCurtiss/wiimote-extension-reconn…
Browse files Browse the repository at this point in the history
…ect-on-button-press

Wiimote: Extend emulated Wiimote reconnect-on-button-press to attachments.
  • Loading branch information
Tilka committed Sep 1, 2015
2 parents 0ba7a65 + 244e522 commit 3b13449
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,15 @@ void ControllerEmu::Extension::GetState(u8* const data)
{
((WiimoteEmu::Attachment*)attachments[active_extension].get())->GetState(data);
}

bool ControllerEmu::Extension::IsButtonPressed() const
{
// Extension == 0 means no Extension, > 0 means one is connected
// Since we want to use this to know if disconnected Wiimotes want to be connected, and disconnected
// Wiimotes (can? always?) have their active_extension set to -1, we also have to check the switch_extension
if (active_extension > 0)
return ((WiimoteEmu::Attachment*)attachments[active_extension].get())->IsButtonPressed();
if (switch_extension > 0)
return ((WiimoteEmu::Attachment*)attachments[switch_extension].get())->IsButtonPressed();
return false;
}
1 change: 1 addition & 0 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Attachment : public ControllerEmu
Attachment(const char* const _name, WiimoteEmu::ExtensionReg& _reg);

virtual void GetState(u8* const data) {}
virtual bool IsButtonPressed() const { return false; }
void Reset();
std::string GetName() const override;

Expand Down
9 changes: 9 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,14 @@ void Classic::GetState(u8* const data)
ccdata->bt.hex ^= 0xFFFF;
}

bool Classic::IsButtonPressed() const
{
u16 buttons = 0;
ControlState trigs[2] = { 0, 0 };
m_buttons->GetState(&buttons, classic_button_bitmasks);
m_dpad->GetState(&buttons, classic_dpad_bitmasks);
m_triggers->GetState(&buttons, classic_trigger_bitmasks, trigs);
return buttons != 0;
}

}
1 change: 1 addition & 0 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Classic : public Attachment
public:
Classic(WiimoteEmu::ExtensionReg& _reg);
void GetState(u8* const data) override;
bool IsButtonPressed() const override;

enum
{
Expand Down
8 changes: 8 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,12 @@ void Drums::GetState(u8* const data)
ddata->bt ^= 0xFFFF;
}

bool Drums::IsButtonPressed() const
{
u16 buttons = 0;
m_buttons->GetState(&buttons, drum_button_bitmasks);
m_pads->GetState(&buttons, drum_pad_bitmasks);
return buttons != 0;
}

}
1 change: 1 addition & 0 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Drums : public Attachment
public:
Drums(WiimoteEmu::ExtensionReg& _reg);
void GetState(u8* const data) override;
bool IsButtonPressed() const override;

enum
{
Expand Down
9 changes: 9 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,13 @@ void Guitar::GetState(u8* const data)
gdata->bt ^= 0xFFFF;
}

bool Guitar::IsButtonPressed() const
{
u16 buttons = 0;
m_buttons->GetState(&buttons, guitar_button_bitmasks);
m_frets->GetState(&buttons, guitar_fret_bitmasks);
m_strum->GetState(&buttons, guitar_strum_bitmasks);
return buttons != 0;
}

}
1 change: 1 addition & 0 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Guitar : public Attachment
public:
Guitar(WiimoteEmu::ExtensionReg& _reg);
void GetState(u8* const data) override;
bool IsButtonPressed() const override;

enum
{
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ void Nunchuk::GetState(u8* const data)
ncdata->bt.acc_z_lsb = accel_z & 0x3;
}

bool Nunchuk::IsButtonPressed() const
{
u8 buttons = 0;
m_buttons->GetState(&buttons, nunchuk_button_bitmasks);
return buttons != 0;
}

void Nunchuk::LoadDefaults(const ControllerInterface& ciface)
{
// ugly macroooo
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Nunchuk : public Attachment
Nunchuk(WiimoteEmu::ExtensionReg& _reg);

void GetState(u8* const data) override;
bool IsButtonPressed() const override;

enum
{
Expand Down
6 changes: 6 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,11 @@ void Turntable::GetState(u8* const data)
);
}

bool Turntable::IsButtonPressed() const
{
u16 buttons = 0;
m_buttons->GetState(&buttons, turntable_button_bitmasks);
return buttons != 0;
}

}
1 change: 1 addition & 0 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Turntable.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Turntable : public Attachment
public:
Turntable(WiimoteEmu::ExtensionReg& _reg);
void GetState(u8* const data) override;
bool IsButtonPressed() const override;

enum
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ void Wiimote::ConnectOnInput()
m_buttons->GetState(&buttons, button_bitmasks);
m_dpad->GetState(&buttons, dpad_bitmasks);

if (buttons != 0)
if (buttons != 0 || m_extension->IsButtonPressed())
{
Host_ConnectWiimote(m_index, true);
// arbitrary value so it doesn't try to send multiple requests before Dolphin can react
Expand Down
1 change: 1 addition & 0 deletions Source/Core/InputCommon/ControllerEmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ class ControllerEmu
~Extension() {}

void GetState(u8* const data);
bool IsButtonPressed() const;

std::vector<std::unique_ptr<ControllerEmu>> attachments;

Expand Down

0 comments on commit 3b13449

Please sign in to comment.