Merge pull request #1477 from magcius/nunchuk-cleanup

Nunchuk cleanup
This commit is contained in:
Ryan Houdek 2014-12-07 01:29:59 -06:00
commit 81cc177c44
7 changed files with 55 additions and 797 deletions

View File

@ -8,19 +8,6 @@ namespace WiimoteEmu
{
static const u8 nunchuk_id[] = { 0x00, 0x00, 0xa4, 0x20, 0x00, 0x00 };
/* Default calibration for the nunchuk. It should be written to 0x20 - 0x3f of the
extension register. 0x80 is the neutral x and y accelerators and 0xb3 is the
neutral z accelerometer that is adjusted for gravity. */
static const u8 nunchuk_calibration[] =
{
0x80, 0x80, 0x80, 0x00, // accelerometer x, y, z neutral
0xb3, 0xb3, 0xb3, 0x00, // x, y, z g-force values
// 0x80 = analog stick x and y axis center
0xff, 0x00, 0x80,
0xff, 0x00, 0x80,
0xec, 0x41 // checksum on the last two bytes
};
static const u8 nunchuk_button_bitmasks[] =
{
@ -50,9 +37,6 @@ Nunchuk::Nunchuk(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Nunchuk"),
m_shake->controls.emplace_back(new ControlGroup::Input("Y"));
m_shake->controls.emplace_back(new ControlGroup::Input("Z"));
// set up register
// calibration
memcpy(&calibration, nunchuk_calibration, sizeof(nunchuk_calibration));
// id
memcpy(&id, nunchuk_id, sizeof(nunchuk_id));
@ -66,35 +50,26 @@ void Nunchuk::GetState(u8* const data)
ncdata->bt.hex = 0;
// stick
double state[2];
m_stick->GetState(&state[0], &state[1]);
double jx, jy;
m_stick->GetState(&jx, &jy);
nu_cal &cal = *(nu_cal*)&reg.calibration;
nu_js cal_js[2];
cal_js[0] = cal.jx;
cal_js[1] = cal.jy;
ncdata->jx = u8(STICK_CENTER + jx * STICK_RADIUS);
ncdata->jy = u8(STICK_CENTER + jy * STICK_RADIUS);
for (int i = 0; i < 2; i++)
// Some terribly coded games check whether to move with a check like
//
// if (x != 0 && y != 0)
// do_movement(x, y);
//
// With keyboard controls, these games break if you simply hit
// of the axes. Adjust this if you're hitting one of the axes so that
// we slightly tweak the other axis.
if (ncdata->jx != STICK_CENTER || ncdata->jy != STICK_CENTER)
{
double &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 (ncdata->jx == STICK_CENTER)
++ncdata->jx;
if (ncdata->jy == STICK_CENTER)
++ncdata->jy;
}
AccelData accel;
@ -112,25 +87,23 @@ void Nunchuk::GetState(u8* const data)
// flip the button bits :/
ncdata->bt.hex ^= 0x03;
accel_cal& calib = *(accel_cal*)&reg.calibration;
u16 accel_x = (u16)(accel.x * ACCEL_RANGE + ACCEL_ZERO_G);
u16 accel_y = (u16)(accel.y * ACCEL_RANGE + ACCEL_ZERO_G);
u16 accel_z = (u16)(accel.z * ACCEL_RANGE + ACCEL_ZERO_G);
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);
if (accel_x > 1024)
accel_x = 1024;
if (accel_y > 1024)
accel_y = 1024;
if (accel_z > 1024)
accel_z = 1024;
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;
ncdata->ax = accel_x & 0xFF;
ncdata->ay = accel_y & 0xFF;
ncdata->az = accel_z & 0xFF;
ncdata->passthrough_data.acc_x_lsb = accel_x >> 8 & 0x3;
ncdata->passthrough_data.acc_y_lsb = accel_y >> 8 & 0x3;
ncdata->passthrough_data.acc_z_lsb = accel_z >> 8 & 0x3;
}
void Nunchuk::LoadDefaults(const ControllerInterface& ciface)

View File

@ -22,6 +22,19 @@ public:
BUTTON_Z = 0x01,
};
enum
{
ACCEL_ZERO_G = 0x80,
ACCEL_ONE_G = 0xB3,
ACCEL_RANGE = (ACCEL_ONE_G - ACCEL_ZERO_G),
};
enum
{
STICK_CENTER = 0x80,
STICK_RADIUS = 0x7F,
};
void LoadDefaults(const ControllerInterface& ciface) override;
private:

View File

@ -31,668 +31,6 @@
namespace WiimoteEmu
{
void Spy(Wiimote* wm_, const void* data_, size_t size_)
{
// Enable for logging and debugging purposes.
#if 0
// enable log
bool logCom = true;
bool logData = true;
bool logMP = false;
bool logAudio = false;
std::string Name, TmpData;
static int c;
int size;
u16 SampleValue;
bool AudioData = false;
bool DataReport = false;
static std::queue<u32> dataRep;
static u8 dataReply[3] = {0};
bool emu = wm_;
static Wiimote* wm = 0;
// a container for f.e. the extension encryption key
if (!wm_ && !wm)
wm = new Wiimote(0);
else
wm = wm_;
// ignore emulated Wiimote data
if (emu) return;
const hid_packet* const hidp = (hid_packet*)data_;
const wm_report* const sr = (wm_report*)hidp->data;
// use a non-pointer array because that makes read syntax shorter
u8 data[32] = {};
memcpy(data, data_, size_);
switch (data[1])
{
case WM_RUMBLE:
size = 1;
if (logCom) Name.append("WM_RUMBLE");
break;
case WM_LEDS:
size = sizeof(wm_leds);
if (logCom) Name.append("WM_LEDS");
break;
case WM_REPORT_MODE:
size = sizeof(wm_report_mode);
if (logCom) Name.append("WM_REPORT_MODE");
ERROR_LOG(CONSOLE, "WM_REPORT_MODE: 0x%02x", data[3]);
break;
case WM_IR_PIXEL_CLOCK:
if (logCom) Name.append("WM_IR_PIXEL_CLOCK");
break;
case WM_SPEAKER_ENABLE:
if (logCom) Name.append("WM_SPEAKER_ENABLE");
NOTICE_LOG(CONSOLE, "Speaker on: %d", sr->enable);
break;
case WM_REQUEST_STATUS:
size = sizeof(wm_request_status);
if (logCom) Name.append("WM_REQUEST_STATUS");
NOTICE_LOG(CONSOLE, "WM_REQUEST_STATUS: %s", ArrayToString(data, size+2, 0).c_str());
break;
case WM_WRITE_DATA:
{
if (logCom) Name.append("W 0x16");
size = sizeof(wm_write_data);
wm_write_data* wd = (wm_write_data*)sr->data;
u32 address = Common::swap24(wd->address);
address &= ~0x010000;
switch (data[2] >> 0x01)
{
case WM_SPACE_EEPROM:
if (logCom) Name.append(" REG_EEPROM"); break;
case WM_SPACE_REGS1:
case WM_SPACE_REGS2:
{
const u8 region_offset = (u8)address;
void *region_ptr = nullptr;
int region_size = 0;
switch (data[3])
{
case 0xa2:
if (logCom)
{
Name.append(" REG_SPEAKER");
if (data[6] == 7)
{
//INFO_LOG(CONSOLE, "Sound configuration:");
if (data[8] == 0x00)
{
//memcpy(&SampleValue, &data[9], 2);
//NOTICE_LOG(CONSOLE, " Data format: 4-bit ADPCM (%i Hz)", 6000000 / SampleValue);
//NOTICE_LOG(CONSOLE, " Volume: %02i%%", (data[11] / 0x40) * 100);
}
else if (data[8] == 0x40)
{
//memcpy(&SampleValue, &data[9], 2);
//NOTICE_LOG(CONSOLE, " Data format: 8-bit PCM (%i Hz)", 12000000 / SampleValue);
//NOTICE_LOG(CONSOLE, " Volume: %02i%%", (data[11] / 0xff) * 100);
}
}
}
break;
case 0xa4:
if (logCom) Name.append(" REG_EXT");
// Update the encryption mode
if (data[5] == 0xf0)
{
if (!emu)
wm->m_reg_ext.encryption = wd->data[0];
//NOTICE_LOG(CONSOLE, "Extension encryption: %u", wm->m_reg_ext.encryption);
}
region_ptr = &wm->m_reg_ext;
break;
case 0xa6 :
if (logCom) Name.append(" REG_M+");
// update the encryption mode
if (data[5] == 0xf0)
{
if (!emu)
wm->m_reg_motion_plus.activated = wd->data[0];
//NOTICE_LOG(CONSOLE, "Extension enryption: %u", wm->m_reg_ext.encryption);
}
region_ptr = &wm->m_reg_motion_plus;
break;
case 0xb0:
if (logCom) Name.append(" REG_IR"); break;
}
// save register
if (!emu && region_ptr)
memcpy((u8*)region_ptr + region_offset, wd->data, wd->size);
// save key
if (region_offset >= 0x40 && region_offset <= 0x4c)
{
if (!emu)
WiimoteGenerateKey(&wm->m_ext_key, wm->m_reg_ext.encryption_key);
INFO_LOG(CONSOLE, "Writing key: %s", ArrayToString((u8*)&wm->m_ext_key, sizeof(wm->m_ext_key), 0, 30).c_str());
}
if (data[3] == 0xa4 || data[3] == 0xa6)
{
//DEBUG_LOG(CONSOLE, "M+: %s", ArrayToString((u8*)&wm->m_reg_motion_plus, sizeof(wm->m_reg_motion_plus), 0, 30).c_str());
//DEBUG_LOG(CONSOLE, "M+: %s", ArrayToString((u8*)&wm->m_reg_motion_plus.ext_identifier, sizeof(wm->m_reg_motion_plus.ext_identifier), 0, 30).c_str());
NOTICE_LOG(CONSOLE, "W[0x%02x 0x%02x|%d]: %s", data[3], region_offset, wd->size, ArrayToString(wd->data, wd->size, 0).c_str());
}
break;
}
}
break;
}
case WM_READ_DATA:
{
if (logCom) Name.append("R");
size = sizeof(wm_read_data);
wm_read_data* rd = (wm_read_data*)sr->data;
u32 address = Common::swap24(rd->address);
u8 addressLO = address & 0xFFFF;
address &= 0xFEFFFF;
u16 size = Common::swap16(rd->size);
u8 *const block = new u8[size];
void *region_ptr = nullptr;
dataRep.push(((data[2]>>1)<<16) + ((data[3])<<8) + addressLO);
switch (data[2]>>1)
{
case WM_SPACE_EEPROM:
if (logCom) Name.append(" REG_EEPROM");
if (!emu)
memcpy(block, wm->m_eeprom + address, size);
break;
case WM_SPACE_REGS1:
case WM_SPACE_REGS2:
// ignore second byte for extension area
if (address>>16 == 0xA4) address &= 0xFF00FF;
const u8 region_offset = (u8)address;
switch (data[3])
{
case 0xa2:
if (logCom) Name.append(" REG_SPEAKER");
region_ptr = &wm->m_reg_speaker;
break;
case 0xa4:
if (logCom) Name.append(" REG_EXT");
region_ptr = &wm->m_reg_motion_plus;
break;
case 0xa6:
if (logCom) Name.append(" REG_M+");
region_ptr = &wm->m_reg_motion_plus;
break;
case 0xb0:
if (logCom) Name.append(" REG_IR");
region_ptr = &wm->m_reg_ir;
break;
}
//if (!emu && region_ptr)
//memcpy(block, (u8*)region_ptr + region_offset, size);
//WARN_LOG(CONSOLE, "READING[0x%02x 0x%02x|%d]: %s", data[3], region_offset, size, ArrayToString(block, size, 0, 30).c_str());
break;
}
break;
}
case WM_WRITE_SPEAKER_DATA:
if (logCom) Name.append("WM_SPEAKER_DATA");
size = 21;
break;
case WM_SPEAKER_MUTE:
if (logCom) Name.append("WM_SPEAKER");
size = 1;
NOTICE_LOG(CONSOLE, "Speaker mute: %d", sr->enable);
break;
case WM_IR_LOGIC:
if (logCom) Name.append("WM_IR");
size = 1;
break;
case WM_STATUS_REPORT:
size = sizeof(wm_status_report);
Name = "WM_STATUS_REPORT";
//INFO_LOG(CONSOLE, "WM_STATUS_REPORT: %s", ArrayToString(data, size+2, 0).c_str());
{
wm_status_report* pStatus = (wm_status_report*)(data + 2);
ERROR_LOG(CONSOLE, ""
"Statusreport extension: %i",
//"Speaker enabled: %i"
//"IR camera enabled: %i"
//"LED 1: %i\n"
//"LED 2: %i\n"
//"LED 3: %i\n"
//"LED 4: %i\n"
//"Battery low: %i\n"
//"Battery level: %i",
pStatus->extension
//pStatus->speaker,
//pStatus->ir,
//(pStatus->leds >> 0),
//(pStatus->leds >> 1),
//(pStatus->leds >> 2),
//(pStatus->leds >> 3),
//pStatus->battery_low,
//pStatus->battery
);
}
break;
case WM_READ_DATA_REPLY:
{
size = sizeof(wm_read_data_reply);
Name = "R_REPLY";
u8 data2[32];
memset(data2, 0, sizeof(data2));
memcpy(data2, data, size_);
wm_read_data_reply* const rdr = (wm_read_data_reply*)(data2 + 2);
bool decrypted = false;
if (!dataRep.empty())
{
dataReply[0] = (dataRep.front()>>16)&0x00FF;
dataReply[1] = (dataRep.front()>>8)&0x00FF;
dataReply[2] = dataRep.front()&0x00FF;
dataRep.pop();
}
switch (dataReply[0])
{
case WM_SPACE_EEPROM:
if (logCom)
Name.append(" REG_EEPROM");
// Wiimote calibration
if (data[4] == 0xf0 && data[5] == 0x00 && data[6] == 0x10)
{
if (data[6] == 0x10)
{
accel_cal* calib = (accel_cal*)&rdr->data[6];
ERROR_LOG(CONSOLE, "Wiimote calibration:");
//SERROR_LOG(CONSOLE, "%s", ArrayToString(rdr->data, rdr->size).c_str());
ERROR_LOG(CONSOLE, "Cal_zero.x: %i", calib->zero_g.x);
ERROR_LOG(CONSOLE, "Cal_zero.y: %i", calib->zero_g.y);
ERROR_LOG(CONSOLE, "Cal_zero.z: %i", calib->zero_g.z);
ERROR_LOG(CONSOLE, "Cal_g.x: %i", calib->one_g.x);
ERROR_LOG(CONSOLE, "Cal_g.y: %i", calib->one_g.y);
ERROR_LOG(CONSOLE, "Cal_g.z: %i", calib->one_g.z);
// save
if (!emu)
memcpy(wm->m_eeprom + 0x16, rdr->data + 6, rdr->size);
}
}
break;
case WM_SPACE_REGS1:
case WM_SPACE_REGS2:
switch (dataReply[1])
{
case 0xa2: if (logCom) Name.append(" REG_SPEAKER"); break;
case 0xa4: if (logCom) Name.append(" REG_EXT"); break;
case 0xa6: if (logCom) Name.append(" REG_M+"); break;
case 0xb0: if (logCom) Name.append(" REG_IR"); break;
}
}
// save key
if (!emu && rdr->address>>8 == 0x40)
{
memcpy(((u8*)&wm->m_reg_ext.encryption_key), rdr->data, rdr->size+1);
WiimoteGenerateKey(&wm->m_ext_key, wm->m_reg_ext.encryption_key);
NOTICE_LOG(CONSOLE, "Reading key: %s", ArrayToString(((u8*)&wm->m_ext_key), sizeof(wm->m_ext_key), 0, 30).c_str());
}
// select decryption
//if(((!wm->GetMotionPlusActive() && ((u8*)&wm->m_reg_ext)[0xf0] == 0xaa) || (wm->GetMotionPlusActive() && ((u8*)&wm->m_reg_motion_plus)[0xf0] == 0xaa)) && rdr->address>>8 < 0xf0) {
//if(((((u8*)&wm->m_reg_ext)[0xf0] == 0xaa) || ((u8*)&wm->m_reg_motion_plus)[0xf0] == 0xaa) && rdr->address>>8 < 0xf0) {
//if(!wm->GetMotionPlusActive() && ((u8*)&wm->m_reg_ext)[0xf0] == 0xaa && rdr->address>>8 < 0xf0) {
//if(!wm->GetMotionPlusActive() && ((u8*)&wm->m_reg_ext)[0xf0] == 0xaa) {
// SWARN_LOG(CONSOLE, "key %s", ArrayToString(((u8*)&wm->m_ext_key), sizeof(wm->m_ext_key), 0, 30).c_str());
// SWARN_LOG(CONSOLE, "decrypt %s", ArrayToString(rdr->data, rdr->size+1, 0, 30).c_str());
// WiimoteDecrypt(&wm->m_ext_key, rdr->data, dataReply[2]&0xffff, rdr->size+1);
// SWARN_LOG(CONSOLE, "decrypt %s", ArrayToString(rdr->data, rdr->size+1, 0, 30).c_str());
// decrypted = true;
//}
// save data
if (!emu && !rdr->error)
{
//if (dataReply[1] == 0xa4 && wm->GetMotionPlusActive())
// memcpy(&((u8*)&wm->m_reg_motion_plus)[rdr->address>>8], rdr->data, rdr->size+1);
//if (dataReply[1] == 0xa4 && !wm->GetMotionPlusActive())
//if (dataReply[1] == 0xa4)
// memcpy(&((u8*)&wm->m_reg_ext)[rdr->address>>8], rdr->data, rdr->size+1);
//if (!wm->GetMotionPlusActive() && wm->GetMotionPlusAttached())
//if (dataReply[1] == 0xa6)
// memcpy(&((u8*)&wm->m_reg_motion_plus)[rdr->address>>8], rdr->data, rdr->size+1);
//INFO_LOG(CONSOLE, "Saving[0x%2x:0x%2x]: %s", dataReply[1], rdr->address>>8, ArrayToString(rdr->data, rdr->size+1).c_str());
}
if (!rdr->error && rdr->address>>8 >= 0xf0 && rdr->address>>8 <= 0xff)
{
//INFO_LOG(CONSOLE, "Extension ID: %s", ArrayToString(rdr->data, rdr->size+1).c_str());
}
// Nunchuk calibration
if (data[4] == 0xf0 && data[5] == 0x00 && (data[6] == 0x20 || data[6] == 0x30))
{
// log
//TmpData = StringFromFormat("Read[%s] (enc): %s", (Emu ? "Emu" : "Real"), ArrayToString(data, size + 2).c_str());
// decrypt
//if(((u8*)&wm->m_reg_ext)[0xf0] == 0xaa) {
// WiimoteDecrypt(&wm->m_ext_key, &data[0x07], 0x00, (data[4] >> 0x04) + 1);
//if (wm->m_extension->name == "NUNCHUK")
//{
// INFO_LOG(CONSOLE, "\nGame got the Nunchuk calibration:\n");
// INFO_LOG(CONSOLE, "Cal_zero.x: %i\n", data[7 + 0]);
// INFO_LOG(CONSOLE, "Cal_zero.y: %i\n", data[7 + 1]);
// INFO_LOG(CONSOLE, "Cal_zero.z: %i\n", data[7 + 2]);
// INFO_LOG(CONSOLE, "Cal_g.x: %i\n", data[7 + 4]);
// INFO_LOG(CONSOLE, "Cal_g.y: %i\n", data[7 + 5]);
// INFO_LOG(CONSOLE, "Cal_g.z: %i\n", data[7 + 6]);
// INFO_LOG(CONSOLE, "Js.Max.x: %i\n", data[7 + 8]);
// INFO_LOG(CONSOLE, "Js.Min.x: %i\n", data[7 + 9]);
// INFO_LOG(CONSOLE, "Js.Center.x: %i\n", data[7 + 10]);
// INFO_LOG(CONSOLE, "Js.Max.y: %i\n", data[7 + 11]);
// INFO_LOG(CONSOLE, "Js.Min.y: %i\n", data[7 + 12]);
// INFO_LOG(CONSOLE, "JS.Center.y: %i\n\n", data[7 + 13]);
//}
//else // g_Config.bClassicControllerConnected
//{
// INFO_LOG(CONSOLE, "\nGame got the Classic Controller calibration:\n");
// INFO_LOG(CONSOLE, "Lx.Max: %i\n", data[7 + 0]);
// INFO_LOG(CONSOLE, "Lx.Min: %i\n", data[7 + 1]);
// INFO_LOG(CONSOLE, "Lx.Center: %i\n", data[7 + 2]);
// INFO_LOG(CONSOLE, "Ly.Max: %i\n", data[7 + 3]);
// INFO_LOG(CONSOLE, "Ly.Min: %i\n", data[7 + 4]);
// INFO_LOG(CONSOLE, "Ly.Center: %i\n", data[7 + 5]);
// INFO_LOG(CONSOLE, "Rx.Max.x: %i\n", data[7 + 6]);
// INFO_LOG(CONSOLE, "Rx.Min.x: %i\n", data[7 + 7]);
// INFO_LOG(CONSOLE, "Rx.Center.x: %i\n", data[7 + 8]);
// INFO_LOG(CONSOLE, "Ry.Max.y: %i\n", data[7 + 9]);
// INFO_LOG(CONSOLE, "Ry.Min: %i\n", data[7 + 10]);
// INFO_LOG(CONSOLE, "Ry.Center: %i\n\n", data[7 + 11]);
// INFO_LOG(CONSOLE, "Lt.Neutral: %i\n", data[7 + 12]);
// INFO_LOG(CONSOLE, "Rt.Neutral %i\n\n", data[7 + 13]);
//}
// save values
if (!emu)
{
// Save to registry
if (data[7 + 0] != 0xff)
{
//memcpy((u8*)&wm->m_reg_ext.calibration, &data[7], 0x10);
//memcpy((u8*)&wm->m_reg_ext.unknown3, &data[7], 0x10);
}
// Save the default values that should work with Wireless Nunchuks
else
{
//WiimoteEmu::SetDefaultExtensionRegistry();
}
//WiimoteEmu::UpdateEeprom();
}
// third party Nunchuk
else if (data[7] == 0xff)
{
//memcpy(wm->m_reg_ext + 0x20, WiimoteEmu::wireless_nunchuk_calibration, sizeof(WiimoteEmu::wireless_nunchuk_calibration));
//memcpy(wm->m_reg_ext + 0x30, WiimoteEmu::wireless_nunchuk_calibration, sizeof(WiimoteEmu::wireless_nunchuk_calibration));
}
// print encrypted data
//INFO_LOG(CONSOLE, "WM_READ_DATA_REPLY: Extension calibration: %s", TmpData.c_str());
}
if (dataReply[1] == 0xa4 || dataReply[1] == 0xa6)
{
if (rdr->error == 7 || rdr->error == 8)
{
WARN_LOG(CONSOLE, "R%s[0x%02x 0x%02x]: e-%d", decrypted?"*":"", dataReply[1], rdr->address>>8, rdr->error);
}
else
{
WARN_LOG(CONSOLE, "R%s[0x%02x 0x%02x|%d]: %s", decrypted?"*":"", dataReply[1], rdr->address>>8, rdr->size+1, ArrayToString(rdr->data, rdr->size+1, 0).c_str());
}
}
break;
}
case WM_ACK_DATA:
size = sizeof(wm_acknowledge);
Name = "WM_ACK_DATA";
//INFO_LOG(CONSOLE, "ACK 0x%02x", data[4]);
break;
case WM_REPORT_CORE:
size = sizeof(wm_report_core);
DataReport = true;
break;
case WM_REPORT_CORE_ACCEL:
size = sizeof(wm_report_core_accel);
DataReport = true;
break;
case WM_REPORT_CORE_EXT8:
size = sizeof(wm_report_core_accel_ir12);
DataReport = true;
break;
case WM_REPORT_CORE_ACCEL_IR12:
size = sizeof(wm_report_core_accel_ir12);
DataReport = true;
break;
case WM_REPORT_CORE_EXT19:
size = sizeof(wm_report_core_accel_ext16);
DataReport = true;
break;
case WM_REPORT_CORE_ACCEL_EXT16:
size = sizeof(wm_report_core_accel_ext16);
DataReport = true;
break;
case WM_REPORT_CORE_IR10_EXT9:
size = sizeof(wm_report_core_accel_ir10_ext6);
DataReport = true;
break;
case WM_REPORT_CORE_ACCEL_IR10_EXT6:
size = sizeof(wm_report_core_accel_ir10_ext6);
DataReport = true;
break;
default:
size = 15;
NOTICE_LOG(CONSOLE, "Debugging[%s]: Unknown channel 0x%02x", (emu ? "E" : "R"), data[1]);
break;
}
//if (DataReport && wm->GetMotionPlusActive())
//{
// if (data[1] == WM_REPORT_CORE_ACCEL_IR10_EXT6)
// static bool extension = false;
// if (extension != (bool)(data[17+4]&1))
// ERROR_LOG(CONSOLE, "Datareport extension %d", data[17+4]&1);
// extension = data[17+4]&1;
//}
if (!DataReport && logCom && size <= 30)
{
ERROR_LOG_S(CONSOLE, "Com[%s] %s: %s", (emu ? "E" : "R"), Name.c_str(), ArrayToString(data, size + 2, 0).c_str());
}
if (logAudio && AudioData)
{
//DEBUG_LOG(CONSOLE, "%s: %s\n", Name.c_str(), ArrayToString(data, std::min(10,size), 0, 30).c_str());
}
if (DataReport && (logData || logMP))
{
// decrypt extension data
//if (data[1] == 0x37 && !wm->GetMotionPlusActive())
//if (data[1] == 0x37)
// WiimoteDecrypt(&wm->m_ext_key, &data[17], 0x00, 0x06);
//if (data[1] == 0x35)
// WiimoteDecrypt(&wm->m_ext_key, &data[7], 0x00, 0x06);
//if (data[1] == 0x35 || data[1] == 0x37)
//{
// if (!g_DebugMP && mp->is_mp_data) return;
// if (!g_DebugData && !mp->is_mp_data) return;
//}
std::string SCore = "", SAcc = "", SIR = "", SExt = "", SExtID = "";
wm_buttons* core = (wm_buttons*)sr->data;
accel_cal* calib = (accel_cal*)&wm->m_eeprom[0x16];
wm_accel* accel = (wm_accel*)&data[4];
//SCore = StringFromFormat(
// "%d %d %d %d ",
// core->xL,
// core->yL,
// core->zL,
// core->unknown);
SAcc = StringFromFormat(
//"%3d %3d %3d"
//" | %3d %3d %3d"
//" | %3d %3d %3d"
"| %5.2f %5.2f %5.2f"
//, calib->zero_g.x, calib->zero_g.y, calib->zero_g.z
//, (calib->zero_g.x<<2) + calib->zero_g.xL, (calib->zero_g.y<<2) + calib->zero_g.yL, (calib->zero_g.z<<2) + calib->zero_g.zL
//, calib->one_g.x, calib->one_g.y, calib->one_g.z
//, (calib->one_g.x<<2) + calib->one_g.xL, (calib->one_g.y<<2) + calib->one_g.yL, (calib->one_g.z<<2) + calib->one_g.zL
//, accel->x, accel->y, accel->z
//, (accel->x<<2) + core->xL, (accel->y<<2) + core->yL, (accel->z<<2) + core->zL
, (accel->x - calib->zero_g.x) / float(calib->one_g.x-calib->zero_g.x), (accel->y - calib->zero_g.y) / float(calib->one_g.y-calib->zero_g.y), (accel->z - calib->zero_g.z) / float(calib->one_g.z-calib->zero_g.z));
NOTICE_LOG(CONSOLE, "%d", size);
if (data[1] == WM_REPORT_CORE_ACCEL_IR12)
{
wm_ir_extended *ir = (wm_ir_extended*)&data[7];
SIR = StringFromFormat(
"%4u %4u | %u"
, ir->x | ir->xhi << 8
, ir->y | ir->yhi << 8
, ir->size);
}
if (data[1] == WM_REPORT_CORE_ACCEL_EXT16)
{
wm_nc *nc = (wm_nc*)&data[7];
SExt = StringFromFormat(
"%02x %02x | %02x %02x %02x | %02x"
, nc->jx, nc->jy
, nc->ax, nc->ay, nc->az
, nc->bt);
}
if (data[1] == WM_REPORT_CORE_ACCEL_IR10_EXT6)
{
wm_ir_basic *ir = (wm_ir_basic*)&data[7];
SIR = StringFromFormat(
"%4u %4u %4u %4u"
, ir->x1 | ir->x1hi << 8
, ir->y1 | ir->y1hi << 8
, ir->x2 | ir->x2hi << 8
, ir->y2 | ir->y1hi << 8);
/*
wm_motionplus *mp = (wm_motionplus*)&data[17];
wm_nc_mp *nc_mp = (wm_nc_mp *)&data[17];
if (mp->is_mp_data)
{
SExt = StringFromFormat(""
//"%02x %02x %02x %02x %02x %02x"
//"| %04x %04x %04x
" %5.2f %5.2f %5.2f"
" %s%s%s"
//, mp->roll1, mp->roll2
//, mp->pitch1, mp->pitch2
//, mp->yaw1, mp->yaw2
//, mp->pitch2<<8 | mp->pitch1
//, mp->roll2<<8 | mp->roll1
//, mp->yaw2<<8 | mp->yaw1
//, mp->pitch2<<8 | mp->pitch1
//, mp->roll2<<8 | mp->roll1
//, mp->yaw2<<8 | mp->yaw1
, float((mp->pitch2<<8 | mp->pitch1) - 0x1f7f) / float(0x1fff)
, float((mp->roll2<<8 | mp->roll1) - 0x1f7f) / float(0x1fff)
, float((mp->yaw2<<8 | mp->yaw1) - 0x1f7f) / float(0x1fff)
, mp->pitch_slow?"*":" ", mp->roll_slow?"*":" ", mp->yaw_slow?"*":" ");
}
else
{
SExt = StringFromFormat(
"%02x %02x | %02x %02x | %02x %02x %02x | %02x %02x %02x",
nc_mp->bz, nc_mp->bc,
nc_mp->jx, nc_mp->jy,
nc_mp->ax+nc_mp->axL, nc_mp->ay+nc_mp->ayL, (nc_mp->az<<1)+nc_mp->azL);
}
SExtID = StringFromFormat(
"[%s|%d|%d]"
, mp->is_mp_data ? "+" : "e"
, mp->is_mp_data ? mp->extension_connected : nc_mp->extension_connected
, wm->m_extension->active_extension);
*/
//DEBUG_LOG_S(CONSOLE, "M+ %d Extension %d %d %s", mp->is_mp_data, mp->is_mp_data ?
// mp->extension_connected : ((wm_nc_mp*)&data[17])->extension_connected, wm->m_extension->active_extension,
// ArrayToString(((u8*)&wm->m_reg_motion_plus.ext_identifier), sizeof(wm->m_reg_motion_plus.ext_identifier), 0).c_str());
}
// select log data
WARN_LOG_S(CONSOLE, "Data"
"[%s]"
" | id %s"
" | %s"
" | c %s"
" | a %s"
" | ir %s"
" | ext %s"
//" | %s"
//" | %s"
//" | %s"
, (emu ? "E" : "R")
, SExtID.c_str()
, ArrayToString(data, 2, 0).c_str()
, SCore.c_str()
, SAcc.c_str()
, SIR.c_str()
, SExt.c_str()
//, ArrayToString(&data[4], 3, 0).c_str()
//, (accel->x - 0x7f) / float(0xff), (accel->y - 0x7f) / float(0xff), (accel->z - 0x7f) / float(0xff)
//, ArrayToString(&data[17], 6, 0).c_str(),
);
}
#endif
}
void Wiimote::ReportMode(const wm_report_mode* const dr)
{
//INFO_LOG(WIIMOTE, "Set data report mode");

View File

@ -39,10 +39,6 @@ static const u8 eeprom_data_0[] = {
// assuming last 2 bytes are checksum
0xA1, 0xAA, 0x8B, 0x99, 0xAE, 0x9E, 0x78, 0x30, 0xA7, /*0x74, 0xD3,*/ 0x00, 0x00, // messing up the checksum on purpose
0xA1, 0xAA, 0x8B, 0x99, 0xAE, 0x9E, 0x78, 0x30, 0xA7, /*0x74, 0xD3,*/ 0x00, 0x00,
// Accelerometer
// 0g x,y,z, 1g x,y,z, idk, last byte is a checksum
0x80, 0x80, 0x80, 0x00, 0x9A, 0x9A, 0x9A, 0x00, 0x40, 0xE3,
0x80, 0x80, 0x80, 0x00, 0x9A, 0x9A, 0x9A, 0x00, 0x40, 0xE3,
};
static const u8 motion_plus_id[] = { 0x00, 0x00, 0xA6, 0x20, 0x00, 0x05 };
@ -395,11 +391,10 @@ void Wiimote::GetAccelData(u8* const data, const ReportFeatures& rptf)
wm_accel& accel = *(wm_accel*)(data + rptf.accel);
wm_buttons& core = *(wm_buttons*)(data + rptf.core);
accel_cal& calib = *(accel_cal*)&m_eeprom[0x16];
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);
u16 x = (u16)(m_accel.x * ACCEL_RANGE + ACCEL_ZERO_G);
u16 y = (u16)(m_accel.y * ACCEL_RANGE + ACCEL_ZERO_G);
u16 z = (u16)(m_accel.z * ACCEL_RANGE + ACCEL_ZERO_G);
if (x > 1024)
x = 1024;
@ -756,7 +751,6 @@ void Wiimote::Update()
// send data report
if (rptf_size)
{
WiimoteEmu::Spy(this, data, rptf_size);
Core::Callback_WiimoteInterruptChannel(m_index, m_reporting_channel, data, rptf_size);
}
}

View File

@ -88,7 +88,6 @@ inline double trim(double a)
class Wiimote : public ControllerEmu
{
friend class WiimoteReal::Wiimote;
friend void Spy(Wiimote* wm_, const void* data_, size_t size_);
public:
enum
@ -107,6 +106,13 @@ public:
BUTTON_HOME = 0x8000,
};
enum
{
ACCEL_ZERO_G = 0x80,
ACCEL_ONE_G = 0x9A,
ACCEL_RANGE = (ACCEL_ONE_G - ACCEL_ZERO_G),
};
Wiimote(const unsigned int index);
std::string GetName() const override;
@ -234,6 +240,4 @@ private:
#pragma pack(pop)
};
void Spy(Wiimote* wm_, const void* data_, size_t size_);
}

View File

@ -495,64 +495,4 @@ struct wm_speaker_data
// Custom structs
/**
* @struct accel_t
* @brief Accelerometer struct. For any device with an accelerometer.
*/
struct accel_cal
{
struct
{
u8 x, y, z;
u8 xlo : 2;
u8 ylo : 2;
u8 zlo : 2;
} zero_g;
struct
{
u8 x, y, z;
u8 xlo : 2;
u8 ylo : 2;
u8 zlo : 2;
} one_g;
};
struct nu_js
{
u8 max, min, center;
};
struct cc_trigger
{
u8 neutral;
};
struct nu_cal
{
wm_accel cal_zero; // zero calibration
u8 pad1;
wm_accel cal_g; // g size
u8 pad2;
nu_js jx;
nu_js jy;
u8 sum[2];
};
struct cc_cal
{
nu_js Lx;
nu_js Ly;
nu_js Rx;
nu_js Ry;
cc_trigger Tl;
cc_trigger Tr;
};
struct gh3_cal
{
nu_js Lx;
nu_js Ly;
};
#pragma pack(pop)

View File

@ -677,8 +677,6 @@ int _IORead(HANDLE &dev_handle, OVERLAPPED &hid_overlap_read, u8* buf, int index
}
}
WiimoteEmu::Spy(nullptr, buf, bytes + 1);
return bytes + 1;
}
@ -699,8 +697,6 @@ int WiimoteWindows::IORead(u8* buf)
int _IOWrite(HANDLE &dev_handle, OVERLAPPED &hid_overlap_write, enum win_bt_stack_t &stack, const u8* buf, size_t len, DWORD* written)
{
WiimoteEmu::Spy(nullptr, buf, len);
switch (stack)
{
case MSBT_STACK_UNKNOWN: