Merge pull request #4725 from lioncash/attachments
Attachments: Minor cleanup
This commit is contained in:
commit
4436011c50
|
@ -2,47 +2,56 @@
|
|||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Core/HW/WiimoteEmu/Attachment/Attachment.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
|
||||
#include "Common/Common.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Core/HW/WiimoteEmu/Attachment/Attachment.h"
|
||||
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
||||
|
||||
namespace WiimoteEmu
|
||||
{
|
||||
// Extension device IDs to be written to the last bytes of the extension reg
|
||||
// The id for nothing inserted
|
||||
static const u8 nothing_id[] = {0x00, 0x00, 0x00, 0x00, 0x2e, 0x2e};
|
||||
constexpr std::array<u8, 6> nothing_id{{0x00, 0x00, 0x00, 0x00, 0x2e, 0x2e}};
|
||||
// The id for a partially inserted extension (currently unused)
|
||||
UNUSED static const u8 partially_id[] = {0x00, 0x00, 0x00, 0x00, 0xff, 0xff};
|
||||
UNUSED constexpr std::array<u8, 6> partially_id{{0x00, 0x00, 0x00, 0x00, 0xff, 0xff}};
|
||||
|
||||
Attachment::Attachment(const char* const _name, WiimoteEmu::ExtensionReg& _reg)
|
||||
: name(_name), reg(_reg)
|
||||
Attachment::Attachment(const char* const name, ExtensionReg& reg) : m_name(name), m_reg(reg)
|
||||
{
|
||||
memset(id, 0, sizeof(id));
|
||||
memset(calibration, 0, sizeof(calibration));
|
||||
}
|
||||
|
||||
None::None(WiimoteEmu::ExtensionReg& _reg) : Attachment("None", _reg)
|
||||
None::None(ExtensionReg& reg) : Attachment("None", reg)
|
||||
{
|
||||
// set up register
|
||||
memcpy(&id, nothing_id, sizeof(nothing_id));
|
||||
m_id = nothing_id;
|
||||
}
|
||||
|
||||
void Attachment::GetState(u8* const data)
|
||||
{
|
||||
}
|
||||
|
||||
bool Attachment::IsButtonPressed() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string Attachment::GetName() const
|
||||
{
|
||||
return name;
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void Attachment::Reset()
|
||||
{
|
||||
// set up register
|
||||
memset(®, 0, WIIMOTE_REG_EXT_SIZE);
|
||||
memcpy(®.constant_id, id, sizeof(id));
|
||||
memcpy(®.calibration, calibration, sizeof(calibration));
|
||||
}
|
||||
m_reg = {};
|
||||
std::copy(m_id.cbegin(), m_id.cend(), m_reg.constant_id);
|
||||
std::copy(m_calibration.cbegin(), m_calibration.cend(), m_reg.calibration);
|
||||
}
|
||||
} // namespace WiimoteEmu
|
||||
|
||||
void ControllerEmu::Extension::GetState(u8* const data)
|
||||
{
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "InputCommon/ControllerEmu.h"
|
||||
|
||||
namespace WiimoteEmu
|
||||
|
@ -13,27 +16,29 @@ struct ExtensionReg;
|
|||
class Attachment : public ControllerEmu
|
||||
{
|
||||
public:
|
||||
Attachment(const char* const _name, WiimoteEmu::ExtensionReg& _reg);
|
||||
Attachment(const char* const name, ExtensionReg& reg);
|
||||
|
||||
virtual void GetState(u8* const data);
|
||||
virtual bool IsButtonPressed() const;
|
||||
|
||||
virtual void GetState(u8* const data) {}
|
||||
virtual bool IsButtonPressed() const { return false; }
|
||||
void Reset();
|
||||
std::string GetName() const override;
|
||||
|
||||
const char* const name;
|
||||
WiimoteEmu::ExtensionReg& reg;
|
||||
|
||||
u8 id[6];
|
||||
u8 calibration[0x10];
|
||||
|
||||
protected:
|
||||
// Default radius for attachment analog sticks.
|
||||
static constexpr ControlState DEFAULT_ATTACHMENT_STICK_RADIUS = 1.0;
|
||||
|
||||
std::array<u8, 6> m_id{};
|
||||
std::array<u8, 0x10> m_calibration{};
|
||||
|
||||
private:
|
||||
const char* const m_name;
|
||||
ExtensionReg& m_reg;
|
||||
};
|
||||
|
||||
class None : public Attachment
|
||||
{
|
||||
public:
|
||||
None(WiimoteEmu::ExtensionReg& _reg);
|
||||
explicit None(ExtensionReg& reg);
|
||||
};
|
||||
}
|
||||
} // namespace WiimoteEmu
|
||||
|
|
|
@ -2,45 +2,51 @@
|
|||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Core/HW/WiimoteEmu/Attachment/Classic.h"
|
||||
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include "Common/Common.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Core/HW/WiimoteEmu/Attachment/Classic.h"
|
||||
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
||||
|
||||
namespace WiimoteEmu
|
||||
{
|
||||
static const u8 classic_id[] = {0x00, 0x00, 0xa4, 0x20, 0x01, 0x01};
|
||||
/* Classic Controller calibration */
|
||||
static const u8 classic_calibration[] = {0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00,
|
||||
0x80, 0xff, 0x00, 0x80, 0x00, 0x00, 0x51, 0xa6};
|
||||
constexpr std::array<u8, 6> classic_id{{0x00, 0x00, 0xa4, 0x20, 0x01, 0x01}};
|
||||
|
||||
static const u16 classic_button_bitmasks[] = {
|
||||
Classic::BUTTON_A, Classic::BUTTON_B, Classic::BUTTON_X, Classic::BUTTON_Y,
|
||||
// Classic Controller calibration
|
||||
constexpr std::array<u8, 0x10> classic_calibration{{
|
||||
0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x00, 0x00, 0x51, 0xa6,
|
||||
}};
|
||||
|
||||
Classic::BUTTON_ZL, Classic::BUTTON_ZR,
|
||||
constexpr std::array<u16, 9> classic_button_bitmasks{{
|
||||
Classic::BUTTON_A, Classic::BUTTON_B, Classic::BUTTON_X, Classic::BUTTON_Y,
|
||||
|
||||
Classic::BUTTON_ZL, Classic::BUTTON_ZR,
|
||||
|
||||
Classic::BUTTON_MINUS, Classic::BUTTON_PLUS,
|
||||
|
||||
Classic::BUTTON_HOME,
|
||||
};
|
||||
}};
|
||||
|
||||
static const char* const classic_button_names[] = {
|
||||
constexpr std::array<const char*, 9> classic_button_names{{
|
||||
"A", "B", "X", "Y", "ZL", "ZR", "-", "+", "Home",
|
||||
};
|
||||
}};
|
||||
|
||||
static const u16 classic_trigger_bitmasks[] = {
|
||||
constexpr std::array<u16, 2> classic_trigger_bitmasks{{
|
||||
Classic::TRIGGER_L, Classic::TRIGGER_R,
|
||||
};
|
||||
}};
|
||||
|
||||
static const char* const classic_trigger_names[] = {"L", "R", "L-Analog", "R-Analog"};
|
||||
constexpr std::array<const char*, 4> classic_trigger_names{{
|
||||
"L", "R", "L-Analog", "R-Analog",
|
||||
}};
|
||||
|
||||
static const u16 classic_dpad_bitmasks[] = {Classic::PAD_UP, Classic::PAD_DOWN, Classic::PAD_LEFT,
|
||||
Classic::PAD_RIGHT};
|
||||
constexpr std::array<u16, 4> classic_dpad_bitmasks{{
|
||||
Classic::PAD_UP, Classic::PAD_DOWN, Classic::PAD_LEFT, Classic::PAD_RIGHT,
|
||||
}};
|
||||
|
||||
Classic::Classic(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Classic"), _reg)
|
||||
Classic::Classic(ExtensionReg& reg) : Attachment(_trans("Classic"), reg)
|
||||
{
|
||||
// buttons
|
||||
groups.emplace_back(m_buttons = new Buttons("Buttons"));
|
||||
|
@ -63,11 +69,9 @@ Classic::Classic(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Classic"),
|
|||
for (auto& named_direction : named_directions)
|
||||
m_dpad->controls.emplace_back(new ControlGroup::Input(named_direction));
|
||||
|
||||
// set up register
|
||||
// calibration
|
||||
memcpy(&calibration, classic_calibration, sizeof(classic_calibration));
|
||||
// id
|
||||
memcpy(&id, classic_id, sizeof(classic_id));
|
||||
// Set up register
|
||||
m_calibration = classic_calibration;
|
||||
m_id = classic_id;
|
||||
}
|
||||
|
||||
void Classic::GetState(u8* const data)
|
||||
|
@ -107,7 +111,7 @@ void Classic::GetState(u8* const data)
|
|||
{
|
||||
ControlState trigs[2] = {0, 0};
|
||||
u8 lt, rt;
|
||||
m_triggers->GetState(&ccdata->bt.hex, classic_trigger_bitmasks, trigs);
|
||||
m_triggers->GetState(&ccdata->bt.hex, classic_trigger_bitmasks.data(), trigs);
|
||||
|
||||
lt = static_cast<u8>(trigs[0] * Classic::LEFT_TRIGGER_RANGE);
|
||||
rt = static_cast<u8>(trigs[1] * Classic::RIGHT_TRIGGER_RANGE);
|
||||
|
@ -118,9 +122,9 @@ void Classic::GetState(u8* const data)
|
|||
}
|
||||
|
||||
// buttons
|
||||
m_buttons->GetState(&ccdata->bt.hex, classic_button_bitmasks);
|
||||
m_buttons->GetState(&ccdata->bt.hex, classic_button_bitmasks.data());
|
||||
// dpad
|
||||
m_dpad->GetState(&ccdata->bt.hex, classic_dpad_bitmasks);
|
||||
m_dpad->GetState(&ccdata->bt.hex, classic_dpad_bitmasks.data());
|
||||
|
||||
// flip button bits
|
||||
ccdata->bt.hex ^= 0xFFFF;
|
||||
|
@ -129,10 +133,10 @@ void Classic::GetState(u8* const data)
|
|||
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);
|
||||
std::array<ControlState, 2> trigs{};
|
||||
m_buttons->GetState(&buttons, classic_button_bitmasks.data());
|
||||
m_dpad->GetState(&buttons, classic_dpad_bitmasks.data());
|
||||
m_triggers->GetState(&buttons, classic_trigger_bitmasks.data(), trigs.data());
|
||||
return buttons != 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ struct ExtensionReg;
|
|||
class Classic : public Attachment
|
||||
{
|
||||
public:
|
||||
Classic(WiimoteEmu::ExtensionReg& _reg);
|
||||
explicit Classic(ExtensionReg& reg);
|
||||
void GetState(u8* const data) override;
|
||||
bool IsButtonPressed() const override;
|
||||
|
||||
|
|
|
@ -2,31 +2,34 @@
|
|||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Core/HW/WiimoteEmu/Attachment/Drums.h"
|
||||
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include "Common/Common.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Core/HW/WiimoteEmu/Attachment/Drums.h"
|
||||
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
||||
|
||||
namespace WiimoteEmu
|
||||
{
|
||||
static const u8 drums_id[] = {0x01, 0x00, 0xa4, 0x20, 0x01, 0x03};
|
||||
constexpr std::array<u8, 6> drums_id{{0x01, 0x00, 0xa4, 0x20, 0x01, 0x03}};
|
||||
|
||||
static const u16 drum_pad_bitmasks[] = {
|
||||
Drums::PAD_RED, Drums::PAD_YELLOW, Drums::PAD_BLUE,
|
||||
Drums::PAD_GREEN, Drums::PAD_ORANGE, Drums::PAD_BASS,
|
||||
};
|
||||
constexpr std::array<u16, 6> drum_pad_bitmasks{{
|
||||
Drums::PAD_RED, Drums::PAD_YELLOW, Drums::PAD_BLUE, Drums::PAD_GREEN, Drums::PAD_ORANGE,
|
||||
Drums::PAD_BASS,
|
||||
}};
|
||||
|
||||
static const char* const drum_pad_names[] = {_trans("Red"), _trans("Yellow"), _trans("Blue"),
|
||||
_trans("Green"), _trans("Orange"), _trans("Bass")};
|
||||
constexpr std::array<const char*, 6> drum_pad_names{{
|
||||
_trans("Red"), _trans("Yellow"), _trans("Blue"), _trans("Green"), _trans("Orange"),
|
||||
_trans("Bass"),
|
||||
}};
|
||||
|
||||
static const u16 drum_button_bitmasks[] = {
|
||||
constexpr std::array<u16, 2> drum_button_bitmasks{{
|
||||
Drums::BUTTON_MINUS, Drums::BUTTON_PLUS,
|
||||
};
|
||||
}};
|
||||
|
||||
Drums::Drums(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Drums"), _reg)
|
||||
Drums::Drums(ExtensionReg& reg) : Attachment(_trans("Drums"), reg)
|
||||
{
|
||||
// pads
|
||||
groups.emplace_back(m_pads = new Buttons(_trans("Pads")));
|
||||
|
@ -42,8 +45,7 @@ Drums::Drums(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Drums"), _reg)
|
|||
m_buttons->controls.emplace_back(new ControlGroup::Input("+"));
|
||||
|
||||
// set up register
|
||||
// id
|
||||
memcpy(&id, drums_id, sizeof(drums_id));
|
||||
m_id = drums_id;
|
||||
}
|
||||
|
||||
void Drums::GetState(u8* const data)
|
||||
|
@ -67,9 +69,9 @@ void Drums::GetState(u8* const data)
|
|||
data[3] = 0xFF;
|
||||
|
||||
// buttons
|
||||
m_buttons->GetState(&ddata->bt, drum_button_bitmasks);
|
||||
m_buttons->GetState(&ddata->bt, drum_button_bitmasks.data());
|
||||
// pads
|
||||
m_pads->GetState(&ddata->bt, drum_pad_bitmasks);
|
||||
m_pads->GetState(&ddata->bt, drum_pad_bitmasks.data());
|
||||
|
||||
// flip button bits
|
||||
ddata->bt ^= 0xFFFF;
|
||||
|
@ -78,8 +80,8 @@ void Drums::GetState(u8* const data)
|
|||
bool Drums::IsButtonPressed() const
|
||||
{
|
||||
u16 buttons = 0;
|
||||
m_buttons->GetState(&buttons, drum_button_bitmasks);
|
||||
m_pads->GetState(&buttons, drum_pad_bitmasks);
|
||||
m_buttons->GetState(&buttons, drum_button_bitmasks.data());
|
||||
m_pads->GetState(&buttons, drum_pad_bitmasks.data());
|
||||
return buttons != 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ struct ExtensionReg;
|
|||
class Drums : public Attachment
|
||||
{
|
||||
public:
|
||||
Drums(WiimoteEmu::ExtensionReg& _reg);
|
||||
explicit Drums(ExtensionReg& reg);
|
||||
void GetState(u8* const data) override;
|
||||
bool IsButtonPressed() const override;
|
||||
|
||||
|
|
|
@ -2,36 +2,37 @@
|
|||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Core/HW/WiimoteEmu/Attachment/Guitar.h"
|
||||
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include "Common/Common.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Core/HW/WiimoteEmu/Attachment/Guitar.h"
|
||||
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
||||
|
||||
namespace WiimoteEmu
|
||||
{
|
||||
static const u8 guitar_id[] = {0x00, 0x00, 0xa4, 0x20, 0x01, 0x03};
|
||||
constexpr std::array<u8, 6> guitar_id{{0x00, 0x00, 0xa4, 0x20, 0x01, 0x03}};
|
||||
|
||||
static const u16 guitar_fret_bitmasks[] = {
|
||||
Guitar::FRET_GREEN, Guitar::FRET_RED, Guitar::FRET_YELLOW,
|
||||
Guitar::FRET_BLUE, Guitar::FRET_ORANGE,
|
||||
};
|
||||
constexpr std::array<u16, 5> guitar_fret_bitmasks{{
|
||||
Guitar::FRET_GREEN, Guitar::FRET_RED, Guitar::FRET_YELLOW, Guitar::FRET_BLUE,
|
||||
Guitar::FRET_ORANGE,
|
||||
}};
|
||||
|
||||
static const char* const guitar_fret_names[] = {
|
||||
constexpr std::array<const char*, 5> guitar_fret_names{{
|
||||
"Green", "Red", "Yellow", "Blue", "Orange",
|
||||
};
|
||||
}};
|
||||
|
||||
static const u16 guitar_button_bitmasks[] = {
|
||||
constexpr std::array<u16, 2> guitar_button_bitmasks{{
|
||||
Guitar::BUTTON_MINUS, Guitar::BUTTON_PLUS,
|
||||
};
|
||||
}};
|
||||
|
||||
static const u16 guitar_strum_bitmasks[] = {
|
||||
constexpr std::array<u16, 2> guitar_strum_bitmasks{{
|
||||
Guitar::BAR_UP, Guitar::BAR_DOWN,
|
||||
};
|
||||
}};
|
||||
|
||||
Guitar::Guitar(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Guitar"), _reg)
|
||||
Guitar::Guitar(ExtensionReg& reg) : Attachment(_trans("Guitar"), reg)
|
||||
{
|
||||
// frets
|
||||
groups.emplace_back(m_frets = new Buttons(_trans("Frets")));
|
||||
|
@ -56,8 +57,7 @@ Guitar::Guitar(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Guitar"), _r
|
|||
m_whammy->controls.emplace_back(new ControlGroup::Input(_trans("Bar")));
|
||||
|
||||
// set up register
|
||||
// id
|
||||
memcpy(&id, guitar_id, sizeof(guitar_id));
|
||||
m_id = guitar_id;
|
||||
}
|
||||
|
||||
void Guitar::GetState(u8* const data)
|
||||
|
@ -85,11 +85,11 @@ void Guitar::GetState(u8* const data)
|
|||
gdata->whammy = static_cast<u8>(whammy * 0x1F);
|
||||
|
||||
// buttons
|
||||
m_buttons->GetState(&gdata->bt, guitar_button_bitmasks);
|
||||
m_buttons->GetState(&gdata->bt, guitar_button_bitmasks.data());
|
||||
// frets
|
||||
m_frets->GetState(&gdata->bt, guitar_fret_bitmasks);
|
||||
m_frets->GetState(&gdata->bt, guitar_fret_bitmasks.data());
|
||||
// strum
|
||||
m_strum->GetState(&gdata->bt, guitar_strum_bitmasks);
|
||||
m_strum->GetState(&gdata->bt, guitar_strum_bitmasks.data());
|
||||
|
||||
// flip button bits
|
||||
gdata->bt ^= 0xFFFF;
|
||||
|
@ -98,9 +98,9 @@ void Guitar::GetState(u8* const data)
|
|||
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);
|
||||
m_buttons->GetState(&buttons, guitar_button_bitmasks.data());
|
||||
m_frets->GetState(&buttons, guitar_fret_bitmasks.data());
|
||||
m_strum->GetState(&buttons, guitar_strum_bitmasks.data());
|
||||
return buttons != 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ struct ExtensionReg;
|
|||
class Guitar : public Attachment
|
||||
{
|
||||
public:
|
||||
Guitar(WiimoteEmu::ExtensionReg& _reg);
|
||||
explicit Guitar(ExtensionReg& reg);
|
||||
void GetState(u8* const data) override;
|
||||
bool IsButtonPressed() const override;
|
||||
|
||||
|
|
|
@ -2,24 +2,25 @@
|
|||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Core/HW/WiimoteEmu/Attachment/Nunchuk.h"
|
||||
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include "Common/Common.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/MathUtil.h"
|
||||
#include "Core/HW/WiimoteEmu/Attachment/Nunchuk.h"
|
||||
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
||||
|
||||
namespace WiimoteEmu
|
||||
{
|
||||
static const u8 nunchuk_id[] = {0x00, 0x00, 0xa4, 0x20, 0x00, 0x00};
|
||||
constexpr std::array<u8, 6> nunchuk_id{{0x00, 0x00, 0xa4, 0x20, 0x00, 0x00}};
|
||||
|
||||
static const u8 nunchuk_button_bitmasks[] = {
|
||||
constexpr std::array<u8, 2> nunchuk_button_bitmasks{{
|
||||
Nunchuk::BUTTON_C, Nunchuk::BUTTON_Z,
|
||||
};
|
||||
}};
|
||||
|
||||
Nunchuk::Nunchuk(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Nunchuk"), _reg)
|
||||
Nunchuk::Nunchuk(ExtensionReg& reg) : Attachment(_trans("Nunchuk"), reg)
|
||||
{
|
||||
// buttons
|
||||
groups.emplace_back(m_buttons = new Buttons("Buttons"));
|
||||
|
@ -41,11 +42,7 @@ Nunchuk::Nunchuk(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Nunchuk"),
|
|||
m_shake->controls.emplace_back(new ControlGroup::Input("Y"));
|
||||
m_shake->controls.emplace_back(new ControlGroup::Input("Z"));
|
||||
|
||||
// id
|
||||
memcpy(&id, nunchuk_id, sizeof(nunchuk_id));
|
||||
|
||||
// this should get set to 0 on disconnect, but it isn't, o well
|
||||
memset(m_shake_step, 0, sizeof(m_shake_step));
|
||||
m_id = nunchuk_id;
|
||||
}
|
||||
|
||||
void Nunchuk::GetState(u8* const data)
|
||||
|
@ -84,9 +81,9 @@ void Nunchuk::GetState(u8* const data)
|
|||
// swing
|
||||
EmulateSwing(&accel, m_swing);
|
||||
// shake
|
||||
EmulateShake(&accel, m_shake, m_shake_step);
|
||||
EmulateShake(&accel, m_shake, m_shake_step.data());
|
||||
// buttons
|
||||
m_buttons->GetState(&ncdata->bt.hex, nunchuk_button_bitmasks);
|
||||
m_buttons->GetState(&ncdata->bt.hex, nunchuk_button_bitmasks.data());
|
||||
|
||||
// flip the button bits :/
|
||||
ncdata->bt.hex ^= 0x03;
|
||||
|
@ -111,7 +108,7 @@ void Nunchuk::GetState(u8* const data)
|
|||
bool Nunchuk::IsButtonPressed() const
|
||||
{
|
||||
u8 buttons = 0;
|
||||
m_buttons->GetState(&buttons, nunchuk_button_bitmasks);
|
||||
m_buttons->GetState(&buttons, nunchuk_button_bitmasks.data());
|
||||
return buttons != 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include "Core/HW/WiimoteEmu/Attachment/Attachment.h"
|
||||
|
||||
namespace WiimoteEmu
|
||||
|
@ -14,7 +15,7 @@ struct ExtensionReg;
|
|||
class Nunchuk : public Attachment
|
||||
{
|
||||
public:
|
||||
Nunchuk(WiimoteEmu::ExtensionReg& _reg);
|
||||
explicit Nunchuk(ExtensionReg& reg);
|
||||
|
||||
void GetState(u8* const data) override;
|
||||
bool IsButtonPressed() const override;
|
||||
|
@ -51,6 +52,6 @@ private:
|
|||
Buttons* m_buttons;
|
||||
AnalogStick* m_stick;
|
||||
|
||||
u8 m_shake_step[3];
|
||||
std::array<u8, 3> m_shake_step{};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2,37 +2,31 @@
|
|||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Core/HW/WiimoteEmu/Attachment/Turntable.h"
|
||||
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include "Common/Common.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Core/HW/WiimoteEmu/Attachment/Turntable.h"
|
||||
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
||||
|
||||
namespace WiimoteEmu
|
||||
{
|
||||
static const u8 turntable_id[] = {0x03, 0x00, 0xa4, 0x20, 0x01, 0x03};
|
||||
constexpr std::array<u8, 6> turntable_id{{0x03, 0x00, 0xa4, 0x20, 0x01, 0x03}};
|
||||
|
||||
static const u16 turntable_button_bitmasks[] = {
|
||||
constexpr std::array<u16, 9> turntable_button_bitmasks{{
|
||||
Turntable::BUTTON_L_GREEN, Turntable::BUTTON_L_RED, Turntable::BUTTON_L_BLUE,
|
||||
Turntable::BUTTON_R_GREEN, Turntable::BUTTON_R_RED, Turntable::BUTTON_R_BLUE,
|
||||
Turntable::BUTTON_MINUS, Turntable::BUTTON_PLUS, Turntable::BUTTON_EUPHORIA,
|
||||
};
|
||||
Turntable::BUTTON_MINUS, Turntable::BUTTON_PLUS, Turntable::BUTTON_EUPHORIA,
|
||||
}};
|
||||
|
||||
static const char* const turntable_button_names[] = {
|
||||
_trans("Green Left"),
|
||||
_trans("Red Left"),
|
||||
_trans("Blue Left"),
|
||||
_trans("Green Right"),
|
||||
_trans("Red Right"),
|
||||
_trans("Blue Right"),
|
||||
"-",
|
||||
"+",
|
||||
_trans("Euphoria"),
|
||||
};
|
||||
constexpr std::array<const char*, 9> turntable_button_names{{
|
||||
_trans("Green Left"), _trans("Red Left"), _trans("Blue Left"), _trans("Green Right"),
|
||||
_trans("Red Right"), _trans("Blue Right"), "-", "+", _trans("Euphoria"),
|
||||
}};
|
||||
|
||||
Turntable::Turntable(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Turntable"), _reg)
|
||||
Turntable::Turntable(ExtensionReg& reg) : Attachment(_trans("Turntable"), reg)
|
||||
{
|
||||
// buttons
|
||||
groups.emplace_back(m_buttons = new Buttons("Buttons"));
|
||||
|
@ -54,8 +48,7 @@ Turntable::Turntable(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Turnta
|
|||
groups.emplace_back(m_crossfade = new Slider(_trans("Crossfade")));
|
||||
|
||||
// set up register
|
||||
// id
|
||||
memcpy(&id, turntable_id, sizeof(turntable_id));
|
||||
m_id = turntable_id;
|
||||
}
|
||||
|
||||
void Turntable::GetState(u8* const data)
|
||||
|
@ -119,7 +112,7 @@ void Turntable::GetState(u8* const data)
|
|||
}
|
||||
|
||||
// buttons
|
||||
m_buttons->GetState(&ttdata->bt, turntable_button_bitmasks);
|
||||
m_buttons->GetState(&ttdata->bt, turntable_button_bitmasks.data());
|
||||
|
||||
// flip button bits :/
|
||||
ttdata->bt ^= (BUTTON_L_GREEN | BUTTON_L_RED | BUTTON_L_BLUE | BUTTON_R_GREEN | BUTTON_R_RED |
|
||||
|
@ -129,7 +122,7 @@ void Turntable::GetState(u8* const data)
|
|||
bool Turntable::IsButtonPressed() const
|
||||
{
|
||||
u16 buttons = 0;
|
||||
m_buttons->GetState(&buttons, turntable_button_bitmasks);
|
||||
m_buttons->GetState(&buttons, turntable_button_bitmasks.data());
|
||||
return buttons != 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ struct ExtensionReg;
|
|||
class Turntable : public Attachment
|
||||
{
|
||||
public:
|
||||
Turntable(WiimoteEmu::ExtensionReg& _reg);
|
||||
explicit Turntable(ExtensionReg& reg);
|
||||
void GetState(u8* const data) override;
|
||||
bool IsButtonPressed() const override;
|
||||
|
||||
|
|
Loading…
Reference in New Issue