Reading shake force from calibration rather than a constant

because that allow maximum force regardless of calibration
This commit is contained in:
John Peterson 2013-05-28 02:03:06 +02:00
parent 388ddee685
commit 4dad640d5f
3 changed files with 10 additions and 5 deletions

View File

@ -72,6 +72,7 @@ void Nunchuk::GetState(u8* const data, const bool focus)
m_stick->GetState(&ncdata->jx, &ncdata->jy, 0x80, focus ? 127 : 0);
AccelData accel;
accel_cal* calib = (accel_cal*)&reg[0x20];
// tilt
EmulateTilt(&accel, m_tilt, focus);
@ -81,7 +82,7 @@ void Nunchuk::GetState(u8* const data, const bool focus)
// swing
EmulateSwing(&accel, m_swing);
// shake
EmulateShake(&accel, m_shake, m_shake_step);
EmulateShake(&accel, calib, m_shake, m_shake_step);
// buttons
m_buttons->GetState(&ncdata->bt, nunchuk_button_bitmasks);
}
@ -119,7 +120,6 @@ void Nunchuk::GetState(u8* const data, const bool focus)
}
wm_accel* dt = (wm_accel*)&ncdata->ax;
accel_cal* calib = (accel_cal*)&reg[0x20];
dt->x = u8(trim(accel.x * (calib->one_g.x - calib->zero_g.x) + calib->zero_g.x));
dt->y = u8(trim(accel.y * (calib->one_g.y - calib->zero_g.y) + calib->zero_g.y));
dt->z = u8(trim(accel.z * (calib->one_g.z - calib->zero_g.z) + calib->zero_g.z));

View File

@ -86,6 +86,7 @@ const ReportFeatures reporting_mode_features[] =
};
void EmulateShake(AccelData* const accel
, accel_cal* const calib
, ControllerEmu::Buttons* const buttons_group
, u8* const shake_step )
{
@ -94,7 +95,7 @@ void EmulateShake(AccelData* const accel
auto const shake_step_max = 15;
// peak G-force
auto const shake_intensity = 3.f;
double shake_intensity;
// shake is a bitfield of X,Y,Z shake button states
static const unsigned int btns[] = { 0x01, 0x02, 0x04 };
@ -105,6 +106,9 @@ void EmulateShake(AccelData* const accel
{
if (shake & (1 << i))
{
double zero = double((&(calib->zero_g.x))[i]);
double one = double((&(calib->one_g.x))[i]);
shake_intensity = max(zero / (one - zero), (255.f - zero) / (one - zero));
(&(accel->x))[i] = std::sin(TAU * shake_step[i] / shake_step_max) * shake_intensity;
shake_step[i] = (shake_step[i] + 1) % shake_step_max;
}
@ -406,6 +410,7 @@ void Wiimote::GetAccelData(u8* const data, u8* const buttons)
const bool has_focus = HAS_FOCUS;
const bool is_sideways = m_options->settings[1]->value != 0;
const bool is_upright = m_options->settings[2]->value != 0;
accel_cal* calib = (accel_cal*)&m_eeprom[0x16];
// ----TILT----
EmulateTilt(&m_accel, m_tilt, has_focus, is_sideways, is_upright);
@ -415,11 +420,10 @@ void Wiimote::GetAccelData(u8* const data, u8* const buttons)
if (has_focus)
{
EmulateSwing(&m_accel, m_swing, is_sideways, is_upright);
EmulateShake(&m_accel, m_shake, m_shake_step);
EmulateShake(&m_accel, calib, m_shake, m_shake_step);
UDPTLayer::GetAcceleration(m_udp, &m_accel);
}
wm_accel* dt = (wm_accel*)data;
accel_cal* calib = (accel_cal*)&m_eeprom[0x16];
double cx,cy,cz;
cx=trim(m_accel.x*(calib->one_g.x-calib->zero_g.x)+calib->zero_g.x);
cy=trim(m_accel.y*(calib->one_g.y-calib->zero_g.y)+calib->zero_g.y);

View File

@ -45,6 +45,7 @@ struct ADPCMState
extern const ReportFeatures reporting_mode_features[];
void EmulateShake(AccelData* const accel_data
, accel_cal* const calib
, ControllerEmu::Buttons* const buttons_group
, u8* const shake_step);