예제 #1
0
void Wiimote::GetAccelData(u8* const data, const ReportFeatures& rptf)
{
  const bool sideways_modifier_toggle = m_hotkeys->getSettingsModifier()[0];
  const bool upright_modifier_toggle = m_hotkeys->getSettingsModifier()[1];
  const bool sideways_modifier_switch = m_hotkeys->getSettingsModifier()[2];
  const bool upright_modifier_switch = m_hotkeys->getSettingsModifier()[3];
  const bool is_sideways =
    m_sideways_setting->GetValue() ^ sideways_modifier_toggle ^ sideways_modifier_switch;
  const bool is_upright =
    m_upright_setting->GetValue() ^ upright_modifier_toggle ^ upright_modifier_switch;

  EmulateTilt(&m_accel, m_tilt, is_sideways, is_upright);
  EmulateSwing(&m_accel, m_swing, is_sideways, is_upright);
  EmulateShake(&m_accel, m_shake, m_shake_step);

  wm_accel& accel = *reinterpret_cast<wm_accel*>(data + rptf.accel);
  wm_buttons& core = *reinterpret_cast<wm_buttons*>(data + rptf.core);

  // We now use 2 bits more precision, so multiply by 4 before converting to int
  s16 x = (s16)(4 * (m_accel.x * ACCEL_RANGE + ACCEL_ZERO_G));
  s16 y = (s16)(4 * (m_accel.y * ACCEL_RANGE + ACCEL_ZERO_G));
  s16 z = (s16)(4 * (m_accel.z * ACCEL_RANGE + ACCEL_ZERO_G));

  x = MathUtil::Clamp<s16>(x, 0, 1024);
  y = MathUtil::Clamp<s16>(y, 0, 1024);
  z = MathUtil::Clamp<s16>(z, 0, 1024);

  accel.x = (x >> 2) & 0xFF;
  accel.y = (y >> 2) & 0xFF;
  accel.z = (z >> 2) & 0xFF;

  core.acc_x_lsb = x & 0x3;
  core.acc_y_lsb = (y >> 1) & 0x1;
  core.acc_z_lsb = (z >> 1) & 0x1;
}
예제 #2
0
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;

	EmulateTilt(&m_accel, m_tilt, is_sideways, is_upright);
	EmulateSwing(&m_accel, m_swing, is_sideways, is_upright);
	EmulateShake(&m_accel, m_shake, m_shake_step);

	wm_accel& accel = *(wm_accel*)(data + rptf.accel);
	wm_buttons& core = *(wm_buttons*)(data + rptf.core);

	// We now use 2 bits more precision, so multiply by 4 before converting to int
	s16 x = (s16)(4 * (m_accel.x * ACCEL_RANGE + ACCEL_ZERO_G));
	s16 y = (s16)(4 * (m_accel.y * ACCEL_RANGE + ACCEL_ZERO_G));
	s16 z = (s16)(4 * (m_accel.z * ACCEL_RANGE + ACCEL_ZERO_G));

	x = MathUtil::Clamp<s16>(x, 0, 1024);
	y = MathUtil::Clamp<s16>(y, 0, 1024);
	z = MathUtil::Clamp<s16>(z, 0, 1024);

	accel.x = (x >> 2) & 0xFF;
	accel.y = (y >> 2) & 0xFF;
	accel.z = (z >> 2) & 0xFF;

	core.acc_x_lsb = x & 0x3;
	core.acc_y_lsb = (y >> 1) & 0x1;
	core.acc_z_lsb = (z >> 1) & 0x1;
}
예제 #3
0
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);

	// ----SWING----
	// ----SHAKE----
	if (has_focus)
	{
		EmulateSwing(&m_accel, m_swing, is_sideways, is_upright);
		EmulateShake(&m_accel, calib, m_shake, m_shake_step);
		UDPTLayer::GetAcceleration(m_udp, &m_accel);
	}
	wm_accel* dt = (wm_accel*)data;
	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);
	cz=trim(m_accel.z*(calib->one_g.z-calib->zero_g.z)+calib->zero_g.z);
	dt->x=u8(cx);
	dt->y=u8(cy);
	dt->z=u8(cz);
	if (buttons)
	{
		buttons[0]|=(u8(cx*4)&3)<<5;
		buttons[1]|=((u8(cy*2)&1)<<5)|((u8(cz*2)&1)<<6);
	}
}
예제 #4
0
void Wiimote::GetAccelData(u8* const data)
{
	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;

	// ----TILT----
	EmulateTilt(&m_accel, m_tilt, has_focus, is_sideways, is_upright);

	// ----SWING----
	// ----SHAKE----
	if (has_focus)
	{
		EmulateSwing(&m_accel, m_swing, is_sideways, is_upright);
		EmulateShake(&m_accel, m_shake, m_shake_step);
		UDPTLayer::GetAcceleration(m_udp, &m_accel);
	}

	FillRawAccelFromGForceData(*(wm_accel*)data, *(accel_cal*)&m_eeprom[0x16], m_accel);
}
예제 #5
0
void Nunchuk::GetState(u8* const data, const bool focus)
{
	wm_extension* const ncdata = (wm_extension*)data;
	ncdata->bt = 0;

	// stick / not using calibration data for stick, o well
	m_stick->GetState(&ncdata->jx, &ncdata->jy, 0x80, focus ? 127 : 0);
	
	AccelData accel;

	// tilt
	EmulateTilt(&accel, m_tilt, focus);

	if (focus)
	{
		// swing
		EmulateSwing(&accel, m_swing);
		// shake
		EmulateShake(&accel, m_shake, m_shake_step);
		// buttons
		m_buttons->GetState(&ncdata->bt, nunchuk_button_bitmasks);
	}
	
	// flip the button bits :/
	ncdata->bt ^= 0x03;
	
	if (m_udpWrap->inst)
	{
		if (m_udpWrap->updNun)
		{
			u8 mask;
			float x, y;
			m_udpWrap->inst->getNunchuck(x, y, mask);
			// buttons
			if (mask & UDPWM_NC)
				ncdata->bt &= ~WiimoteEmu::Nunchuk::BUTTON_C;
			if (mask & UDPWM_NZ)
				ncdata->bt &= ~WiimoteEmu::Nunchuk::BUTTON_Z;
			// stick
			if (ncdata->jx == 0x80 && ncdata->jy == 0x80)
			{
				ncdata->jx = u8(0x80 + x*127);
				ncdata->jy = u8(0x80 + y*127);
			}
		}
		if (m_udpWrap->updNunAccel)
		{
			float x, y, z;
			m_udpWrap->inst->getNunchuckAccel(x, y, z);
			accel.x = x;
			accel.y = y;
			accel.z = z;
		}	
	}

	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));
}
예제 #6
0
파일: Nunchuk.cpp 프로젝트: Chiri23/dolphin
void Nunchuk::GetState(u8* const data, const bool focus)
{
	wm_extension* const ncdata = (wm_extension*)data;
	ncdata->bt = 0;

	// stick
	ControlState state[2];
	m_stick->GetState(&state[0], &state[1], 0, 1);

	nu_cal &cal = *(nu_cal*)&reg.calibration;
	nu_js cal_js[2];
	cal_js[0] = *&cal.jx;
	cal_js[1] = *&cal.jy;

	for (int i = 0; i < 2; i++) {
		ControlState &s = *&state[i];
		nu_js c = *&cal_js[i];
		if (s < 0)
			s = s * abs(c.min - c.center) + c.center;
		else if (s > 0)
			s = s * abs(c.max - c.center) + c.center;
		else
			s = c.center;
	}

	ncdata->jx = u8(trim(state[0]));
	ncdata->jy = u8(trim(state[1]));

	if (ncdata->jx != cal.jx.center || ncdata->jy != cal.jy.center)
	{
		if (ncdata->jy == cal.jy.center)
			ncdata->jy = cal.jy.center + 1;
		if (ncdata->jx == cal.jx.center)
			ncdata->jx = cal.jx.center + 1;
	}

	if (!focus)
	{
		ncdata->jx = cal.jx.center;
		ncdata->jy = cal.jy.center;
	}

	AccelData accel;

	// tilt
	EmulateTilt(&accel, m_tilt, focus);

	if (focus)
	{
		// swing
		EmulateSwing(&accel, m_swing);
		// shake
		EmulateShake(&accel, m_shake, m_shake_step);
		// buttons
		m_buttons->GetState(&ncdata->bt, nunchuk_button_bitmasks);
	}

	// flip the button bits :/
	ncdata->bt ^= 0x03;

	if (m_udpWrap->inst)
	{
		if (m_udpWrap->updNun)
		{
			u8 mask;
			float x, y;
			m_udpWrap->inst->getNunchuck(&x, &y, &mask);
			// buttons
			if (mask & UDPWM_NC)
				ncdata->bt &= ~WiimoteEmu::Nunchuk::BUTTON_C;
			if (mask & UDPWM_NZ)
				ncdata->bt &= ~WiimoteEmu::Nunchuk::BUTTON_Z;
			// stick
			if (ncdata->jx == 0x80 && ncdata->jy == 0x80)
			{
				ncdata->jx = u8(0x80 + x*127);
				ncdata->jy = u8(0x80 + y*127);
			}
		}
		if (m_udpWrap->updNunAccel)
		{
			float x, y, z;
			m_udpWrap->inst->getNunchuckAccel(&x, &y, &z);
			accel.x = x;
			accel.y = y;
			accel.z = z;
		}
	}

	FillRawAccelFromGForceData(*(wm_accel*)&ncdata->ax, *(accel_cal*)&reg.calibration, accel);
}