Produce emulated nunchuk calibration data.

This commit is contained in:
Jordan Woyak 2018-12-15 09:43:45 -06:00
parent 3fa81f39fb
commit 6848812a31
3 changed files with 46 additions and 5 deletions

View File

@ -69,6 +69,35 @@ Nunchuk::Nunchuk(ExtensionReg& reg) : Attachment(_trans("Nunchuk"), reg)
m_shake_hard->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "Z"));
m_id = nunchuk_id;
// Build calibration data:
m_calibration = {{
// Accel Zero X,Y,Z:
ACCEL_ZERO_G,
ACCEL_ZERO_G,
ACCEL_ZERO_G,
// Possibly LSBs of zero values:
0x00,
// Accel 1G X,Y,Z:
ACCEL_ONE_G,
ACCEL_ONE_G,
ACCEL_ONE_G,
// Possibly LSBs of 1G values:
0x00,
// Stick X max,min,center:
STICK_CENTER + STICK_RADIUS,
STICK_CENTER - STICK_RADIUS,
STICK_CENTER,
// Stick Y max,min,center:
STICK_CENTER + STICK_RADIUS,
STICK_CENTER - STICK_RADIUS,
STICK_CENTER,
// 2 checksum bytes calculated below:
0x00,
0x00,
}};
UpdateCalibrationDataChecksum(m_calibration);
}
void Nunchuk::GetState(u8* const data)
@ -186,4 +215,4 @@ void Nunchuk::LoadDefaults(const ControllerInterface& ciface)
m_buttons->SetControlExpression(1, "Shift_L"); // Z
#endif
}
}
} // namespace WiimoteEmu

View File

@ -11,6 +11,7 @@
#include <cstddef>
#include <cstring>
#include <mutex>
#include <numeric>
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
@ -101,6 +102,15 @@ static const ReportFeatures reporting_mode_features[] = {
{0, 0, 0, 0, 23},
};
// Used for extension calibration data:
// Last two bytes are the sum of the previous bytes plus 0x55 and 0xaa
void UpdateCalibrationDataChecksum(std::array<u8, 0x10>& data)
{
const u8 ck1 = std::accumulate(std::begin(data), std::end(data) - 2, (u8)0x55);
data[0xe] = ck1;
data[0xf] = ck1 + 0x55;
}
void EmulateShake(AccelData* const accel, ControllerEmu::Buttons* const buttons_group,
const double intensity, u8* const shake_step)
{
@ -1028,8 +1038,8 @@ void Wiimote::LoadDefaults(const ControllerInterface& ciface)
m_buttons->SetControlExpression(0, "Click 1"); // A
m_buttons->SetControlExpression(1, "Click 3"); // B
#else
m_buttons->SetControlExpression(0, "Click 0"); // A
m_buttons->SetControlExpression(1, "Click 1"); // B
m_buttons->SetControlExpression(0, "Click 0"); // A
m_buttons->SetControlExpression(1, "Click 1"); // B
#endif
m_buttons->SetControlExpression(2, "1"); // 1
m_buttons->SetControlExpression(3, "2"); // 2

View File

@ -34,7 +34,7 @@ class ModifySettingsButton;
class NumericSetting;
class Output;
class Tilt;
}
} // namespace ControllerEmu
namespace WiimoteReal
{
@ -181,6 +181,8 @@ struct ExtensionReg
};
#pragma pack(pop)
void UpdateCalibrationDataChecksum(std::array<u8, 0x10>& data);
void EmulateShake(AccelData* accel, ControllerEmu::Buttons* buttons_group, double intensity,
u8* shake_step);
@ -377,4 +379,4 @@ private:
#pragma pack(pop)
};
}
} // namespace WiimoteEmu