Fix wiimote accel.
This commit is contained in:
parent
e0393be347
commit
b08d993b55
|
@ -112,16 +112,25 @@ void Nunchuk::GetState(u8* const data)
|
|||
// flip the button bits :/
|
||||
*(u8*)&ncdata->bt ^= 0x03;
|
||||
|
||||
wm_full_accel tmpAccel;
|
||||
accel_cal& calib = *(accel_cal*)®.calibration;
|
||||
|
||||
FillRawAccelFromGForceData(tmpAccel, *(accel_cal*)®.calibration, accel);
|
||||
u16 x = (u16)(accel.x * (calib.one_g.x - calib.zero_g.x) + calib.zero_g.x);
|
||||
u16 y = (u16)(accel.y * (calib.one_g.y - calib.zero_g.y) + calib.zero_g.y);
|
||||
u16 z = (u16)(accel.z * (calib.one_g.z - calib.zero_g.z) + calib.zero_g.z);
|
||||
|
||||
ncdata->ax = tmpAccel.x >> 2;
|
||||
ncdata->ay = tmpAccel.y >> 2;
|
||||
ncdata->az = tmpAccel.z >> 2;
|
||||
ncdata->passthrough_data.acc_x_lsb = tmpAccel.x & 0x3;
|
||||
ncdata->passthrough_data.acc_y_lsb = tmpAccel.y & 0x3;
|
||||
ncdata->passthrough_data.acc_z_lsb = tmpAccel.z & 0x3;
|
||||
if (x > 1024)
|
||||
x = 1024;
|
||||
if (y > 1024)
|
||||
y = 1024;
|
||||
if (z > 1024)
|
||||
z = 1024;
|
||||
|
||||
ncdata->ax = x & 0xFF;
|
||||
ncdata->ay = y & 0xFF;
|
||||
ncdata->az = z & 0xFF;
|
||||
ncdata->passthrough_data.acc_x_lsb = x >> 8 & 0x3;
|
||||
ncdata->passthrough_data.acc_y_lsb = y >> 8 & 0x3;
|
||||
ncdata->passthrough_data.acc_z_lsb = z >> 8 & 0x3;
|
||||
}
|
||||
|
||||
void Nunchuk::LoadDefaults(const ControllerInterface& ciface)
|
||||
|
|
|
@ -79,15 +79,6 @@ static const ReportFeatures reporting_mode_features[] =
|
|||
{ 0, 0, 0, 0, 23 },
|
||||
};
|
||||
|
||||
void FillRawAccelFromGForceData(wm_full_accel& raw_accel,
|
||||
const accel_cal& calib,
|
||||
const WiimoteEmu::AccelData& accel)
|
||||
{
|
||||
raw_accel.x = (u16)trim(accel.x * (calib.one_g.x - calib.zero_g.x) + calib.zero_g.x);
|
||||
raw_accel.y = (u16)trim(accel.y * (calib.one_g.y - calib.zero_g.y) + calib.zero_g.y);
|
||||
raw_accel.z = (u16)trim(accel.z * (calib.one_g.z - calib.zero_g.z) + calib.zero_g.z);
|
||||
}
|
||||
|
||||
void EmulateShake(AccelData* const accel
|
||||
, ControllerEmu::Buttons* const buttons_group
|
||||
, u8* const shake_step )
|
||||
|
@ -398,27 +389,32 @@ void Wiimote::GetAccelData(u8* const data, const ReportFeatures& rptf)
|
|||
const bool is_sideways = m_options->settings[1]->value != 0;
|
||||
const bool is_upright = m_options->settings[2]->value != 0;
|
||||
|
||||
// ----TILT----
|
||||
EmulateTilt(&m_accel, m_tilt, is_sideways, is_upright);
|
||||
|
||||
// ----SWING----
|
||||
// ----SHAKE----
|
||||
EmulateSwing(&m_accel, m_swing, is_sideways, is_upright);
|
||||
EmulateShake(&m_accel, m_shake, m_shake_step);
|
||||
|
||||
wm_full_accel tmpAccel;
|
||||
|
||||
FillRawAccelFromGForceData(tmpAccel, *(accel_cal*)&m_eeprom[0x16], m_accel);
|
||||
|
||||
wm_accel& accel = *(wm_accel*)(data + rptf.accel);
|
||||
wm_buttons& core = *(wm_buttons*)(data + rptf.core);
|
||||
accel_cal& calib = *(accel_cal*)&m_eeprom[0x16];
|
||||
|
||||
accel.x = tmpAccel.x >> 2;
|
||||
accel.y = tmpAccel.y >> 1;
|
||||
accel.z = tmpAccel.z >> 1;
|
||||
core.acc_x_lsb = tmpAccel.x & 0x3;
|
||||
core.acc_y_lsb = tmpAccel.y & 0x1;
|
||||
core.acc_z_lsb = tmpAccel.z & 0x1;
|
||||
u16 x = (u16)(m_accel.x * (calib.one_g.x - calib.zero_g.x) + calib.zero_g.x);
|
||||
u16 y = (u16)(m_accel.y * (calib.one_g.y - calib.zero_g.y) + calib.zero_g.y);
|
||||
u16 z = (u16)(m_accel.z * (calib.one_g.z - calib.zero_g.z) + calib.zero_g.z);
|
||||
|
||||
if (x > 1024)
|
||||
x = 1024;
|
||||
if (y > 1024)
|
||||
y = 1024;
|
||||
if (z > 1024)
|
||||
z = 1024;
|
||||
|
||||
accel.x = x & 0xFF;
|
||||
accel.y = y & 0xFF;
|
||||
accel.z = z & 0xFF;
|
||||
|
||||
core.acc_x_lsb = x >> 8 & 0x3;
|
||||
core.acc_y_lsb = y >> 8 & 0x1;
|
||||
core.acc_z_lsb = z >> 8 & 0x1;
|
||||
}
|
||||
#define kCutoffFreq 5.0
|
||||
inline void LowPassFilter(double & var, double newval, double period)
|
||||
|
|
|
@ -67,10 +67,6 @@ struct ExtensionReg
|
|||
u8 constant_id[6];
|
||||
};
|
||||
|
||||
void FillRawAccelFromGForceData(wm_full_accel& raw_accel,
|
||||
const accel_cal& calib,
|
||||
const WiimoteEmu::AccelData& accel);
|
||||
|
||||
void EmulateShake(AccelData* const accel_data
|
||||
, ControllerEmu::Buttons* const buttons_group
|
||||
, u8* const shake_step);
|
||||
|
|
|
@ -63,11 +63,6 @@ struct wm_accel
|
|||
u8 x, y, z;
|
||||
};
|
||||
|
||||
struct wm_full_accel
|
||||
{
|
||||
u16 x, y, z;
|
||||
};
|
||||
|
||||
// Four bytes for two objects. Filled with 0xFF if empty
|
||||
struct wm_ir_basic
|
||||
{
|
||||
|
|
|
@ -625,7 +625,8 @@ static void SetWiiInputDisplayString(int remoteID, u8* const data, const Wiimote
|
|||
if (accelData)
|
||||
{
|
||||
wm_accel* dt = (wm_accel*)accelData;
|
||||
std::string accel = StringFromFormat(" ACC:%d,%d,%d", dt->x, dt->y, dt->z);
|
||||
std::string accel = StringFromFormat(" ACC:%d,%d,%d",
|
||||
dt->x << 2 | ((wm_buttons*)coreData)->acc_x_lsb, dt->y << 2 | ((wm_buttons*)coreData)->acc_y_lsb << 1, dt->z << 2 | ((wm_buttons*)coreData)->acc_z_lsb << 1);
|
||||
s_InputDisplay[controllerID].append(accel);
|
||||
}
|
||||
|
||||
|
@ -645,7 +646,8 @@ static void SetWiiInputDisplayString(int remoteID, u8* const data, const Wiimote
|
|||
WiimoteDecrypt(&key, (u8*)&nunchuck, 0, sizeof(wm_nc));
|
||||
nunchuck.bt.hex = nunchuck.bt.hex ^ 0xFF;
|
||||
|
||||
std::string accel = StringFromFormat(" N-ACC:%d,%d,%d", nunchuck.ax, nunchuck.ay, nunchuck.az);
|
||||
std::string accel = StringFromFormat(" N-ACC:%d,%d,%d", nunchuck.ax << 2 | nunchuck.passthrough_data.acc_x_lsb,
|
||||
nunchuck.ay << 2 | nunchuck.passthrough_data.acc_y_lsb << 1, nunchuck.az << 2 | nunchuck.passthrough_data.acc_z_lsb << 1);
|
||||
|
||||
if (nunchuck.bt.c)
|
||||
s_InputDisplay[controllerID].append(" C");
|
||||
|
|
|
@ -112,10 +112,10 @@ void TASInputDlg::CreateWiiLayout()
|
|||
wxStaticBoxSizer* const yBox = new wxStaticBoxSizer(wxVERTICAL, this, _("Y"));
|
||||
wxStaticBoxSizer* const zBox = new wxStaticBoxSizer(wxVERTICAL, this, _("Z"));
|
||||
|
||||
m_x_cont = CreateControl(wxSL_VERTICAL, -1, 100);
|
||||
m_y_cont = CreateControl(wxSL_VERTICAL, -1, 100);
|
||||
m_z_cont = CreateControl(wxSL_VERTICAL, -1, 100);
|
||||
m_z_cont.default_value = 154;
|
||||
m_x_cont = CreateControl(wxSL_VERTICAL, -1, 100, 1023);
|
||||
m_y_cont = CreateControl(wxSL_VERTICAL, -1, 100, 1023);
|
||||
m_z_cont = CreateControl(wxSL_VERTICAL, -1, 100, 1023);
|
||||
m_z_cont.default_value = 616;
|
||||
xBox->Add(m_x_cont.slider, 0, wxALIGN_CENTER_VERTICAL);
|
||||
xBox->Add(m_x_cont.text, 0, wxALIGN_CENTER_VERTICAL);
|
||||
yBox->Add(m_y_cont.slider, 0, wxALIGN_CENTER_VERTICAL);
|
||||
|
@ -423,9 +423,9 @@ void TASInputDlg::GetKeyBoardInput(u8* data, WiimoteEmu::ReportFeatures rptf)
|
|||
{
|
||||
wm_accel* dt = (wm_accel*)accelData;
|
||||
|
||||
SetSliderValue(&m_x_cont, dt->x);
|
||||
SetSliderValue(&m_y_cont, dt->y);
|
||||
SetSliderValue(&m_z_cont, dt->z, 154);
|
||||
SetSliderValue(&m_x_cont, dt->x << 2 | ((wm_buttons*)coreData)->acc_x_lsb);
|
||||
SetSliderValue(&m_y_cont, dt->y << 2 | ((wm_buttons*)coreData)->acc_y_lsb);
|
||||
SetSliderValue(&m_z_cont, dt->z << 2 | ((wm_buttons*)coreData)->acc_z_lsb, 616);
|
||||
}
|
||||
|
||||
// I don't think this can be made to work in a sane manner.
|
||||
|
@ -455,10 +455,14 @@ void TASInputDlg::GetValues(u8* data, WiimoteEmu::ReportFeatures rptf)
|
|||
|
||||
if (accelData)
|
||||
{
|
||||
wm_accel* dt = (wm_accel*)accelData;
|
||||
dt->x = m_x_cont.value;
|
||||
dt->y = m_y_cont.value;
|
||||
dt->z = m_z_cont.value;
|
||||
wm_accel& dt = *(wm_accel*)accelData;
|
||||
wm_buttons& but = *(wm_buttons*)coreData;
|
||||
dt.x = m_x_cont.value >> 2;
|
||||
dt.y = m_y_cont.value >> 2;
|
||||
dt.z = m_z_cont.value >> 2;
|
||||
but.acc_x_lsb = m_x_cont.value & 0x3;
|
||||
but.acc_y_lsb = m_y_cont.value >> 1 & 0x1;
|
||||
but.acc_z_lsb = m_z_cont.value >> 1 & 0x1;
|
||||
}
|
||||
if (irData)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue