Compute emulated classic controller calibration data instead of having hardcoded values.

This commit is contained in:
Jordan Woyak 2018-12-15 10:12:04 -06:00
parent 6848812a31
commit a8a6bdcdd2
2 changed files with 48 additions and 33 deletions

View File

@ -21,26 +21,6 @@ namespace WiimoteEmu
{
constexpr std::array<u8, 6> classic_id{{0x00, 0x00, 0xa4, 0x20, 0x01, 0x01}};
// 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,
}};
constexpr std::array<u16, 9> classic_button_bitmasks{{
Classic::BUTTON_A,
Classic::BUTTON_B,
@ -124,9 +104,35 @@ Classic::Classic(ExtensionReg& reg) : Attachment(_trans("Classic"), reg)
new ControllerEmu::Input(ControllerEmu::Translate, named_direction));
}
// Set up register
m_calibration = classic_calibration;
m_id = classic_id;
// Build calibration data:
m_calibration = {{
// Left Stick X max,min,center:
CAL_STICK_CENTER + CAL_STICK_RANGE,
CAL_STICK_CENTER - CAL_STICK_RANGE,
CAL_STICK_CENTER,
// Left Stick Y max,min,center:
CAL_STICK_CENTER + CAL_STICK_RANGE,
CAL_STICK_CENTER - CAL_STICK_RANGE,
CAL_STICK_CENTER,
// Right Stick X max,min,center:
CAL_STICK_CENTER + CAL_STICK_RANGE,
CAL_STICK_CENTER - CAL_STICK_RANGE,
CAL_STICK_CENTER,
// Right Stick Y max,min,center:
CAL_STICK_CENTER + CAL_STICK_RANGE,
CAL_STICK_CENTER - CAL_STICK_RANGE,
CAL_STICK_CENTER,
// Left/Right trigger range: (assumed based on real calibration data values)
LEFT_TRIGGER_RANGE,
RIGHT_TRIGGER_RANGE,
// 2 checksum bytes calculated below:
0x00,
0x00,
}};
UpdateCalibrationDataChecksum(m_calibration);
}
void Classic::GetState(u8* const data)
@ -213,4 +219,4 @@ ControllerEmu::ControlGroup* Classic::GetGroup(ClassicGroup group)
return nullptr;
}
}
}
} // namespace WiimoteEmu

View File

@ -12,7 +12,7 @@ class AnalogStick;
class Buttons;
class ControlGroup;
class MixedTriggers;
}
} // namespace ControllerEmu
namespace WiimoteEmu
{
@ -48,16 +48,25 @@ public:
PAD_UP = 0x0100,
};
static const u8 LEFT_STICK_CENTER_X = 0x20;
static const u8 LEFT_STICK_CENTER_Y = 0x20;
static const u8 LEFT_STICK_RADIUS = 0x1F;
enum
{
CAL_STICK_CENTER = 0x80,
CAL_STICK_RANGE = 0x7f,
CAL_STICK_BITS = 8,
static const u8 RIGHT_STICK_CENTER_X = 0x10;
static const u8 RIGHT_STICK_CENTER_Y = 0x10;
static const u8 RIGHT_STICK_RADIUS = 0x0F;
LEFT_STICK_BITS = 6,
LEFT_STICK_CENTER_X = CAL_STICK_CENTER >> (CAL_STICK_BITS - LEFT_STICK_BITS),
LEFT_STICK_CENTER_Y = CAL_STICK_CENTER >> (CAL_STICK_BITS - LEFT_STICK_BITS),
LEFT_STICK_RADIUS = CAL_STICK_RANGE >> (CAL_STICK_BITS - LEFT_STICK_BITS),
static const u8 LEFT_TRIGGER_RANGE = 0x1F;
static const u8 RIGHT_TRIGGER_RANGE = 0x1F;
RIGHT_STICK_BITS = 5,
RIGHT_STICK_CENTER_X = CAL_STICK_CENTER >> (CAL_STICK_BITS - RIGHT_STICK_BITS),
RIGHT_STICK_CENTER_Y = CAL_STICK_CENTER >> (CAL_STICK_BITS - RIGHT_STICK_BITS),
RIGHT_STICK_RADIUS = CAL_STICK_RANGE >> (CAL_STICK_BITS - RIGHT_STICK_BITS),
LEFT_TRIGGER_RANGE = 0x1F,
RIGHT_TRIGGER_RANGE = 0x1F,
};
private:
ControllerEmu::Buttons* m_buttons;
@ -66,4 +75,4 @@ private:
ControllerEmu::AnalogStick* m_left_stick;
ControllerEmu::AnalogStick* m_right_stick;
};
}
} // namespace WiimoteEmu