Wiimote: Fixed the shared eeprom settings, now the first 42 bytes are shared in dual mode. I'm only copying the data from the Wiimote. I'm not changing anything on the Wiimote eeprom.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2056 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
John Peterson 2009-02-01 14:58:44 +00:00
parent 3bd8f73844
commit e9036455d6
9 changed files with 68 additions and 62 deletions

View File

@ -37,7 +37,6 @@ struct Config
// Real Wiimote
bool bConnectRealWiimote, bUseRealWiimote, bUpdateRealWiimote;
int iAccNeutralX, iAccNeutralY, iAccNeutralZ;
};
extern Config g_Config;

View File

@ -41,8 +41,8 @@ namespace WiiMoteEmu
// Definitions and variable declarations
//******************************************************************************
u8 g_Leds = 0x1; // 4 bits
u8 g_Speaker = 0x1; // 1 = on
u8 g_Leds = 0x0; // 4 bits
u8 g_Speaker = 0x0; // 1 = on
u8 g_SpeakerVoice = 0x0; // 1 = on
u8 g_IR = 0x0; // 1 = on

View File

@ -75,7 +75,6 @@ extern u8 g_SpeakerVoice;
extern u8 g_IR;
extern u8 g_Eeprom[WIIMOTE_EEPROM_SIZE];
extern u8 g_RegSpeaker[WIIMOTE_REG_SPEAKER_SIZE];
extern u8 g_RegExt[WIIMOTE_REG_EXT_SIZE];
extern u8 g_RegExtTmp[WIIMOTE_REG_EXT_SIZE];

View File

@ -176,7 +176,19 @@ void LoadRecordedMovements()
}
// ================
// Update the accelerometer neutral values
void UpdateEeprom()
{
g_accel.cal_zero.x = g_Eeprom[22];
g_accel.cal_zero.y = g_Eeprom[23];
g_accel.cal_zero.z = g_Eeprom[24];
g_accel.cal_g.x = g_Eeprom[26] - g_Eeprom[22];
g_accel.cal_g.y = g_Eeprom[27] - g_Eeprom[24];
g_accel.cal_g.z = g_Eeprom[28] - g_Eeprom[24];
Console::Print("UpdateEeprom: %i %i %i\n",
WiiMoteEmu::g_Eeprom[22], WiiMoteEmu::g_Eeprom[23], WiiMoteEmu::g_Eeprom[27]);
}
// ===================================================
@ -192,12 +204,7 @@ void Initialize()
memcpy(g_Eeprom + 0x16D0, EepromData_16D0, sizeof(EepromData_16D0));
// Write default accelerometer neutral values
g_accel.cal_zero.x = g_Eeprom[22];
g_accel.cal_zero.y = g_Eeprom[23];
g_accel.cal_zero.z = g_Eeprom[24];
g_accel.cal_g.x = g_Eeprom[26];
g_accel.cal_g.y = g_Eeprom[27];
g_accel.cal_g.z = g_Eeprom[28];
UpdateEeprom();
/* Extension data for homebrew applications that use the 0x00000000 key. This
writes 0x0000 in encrypted form (0xfefe) to 0xfe in the extension register. */

View File

@ -28,6 +28,7 @@ u32 convert24bit(const u8* src);
u16 convert16bit(const u8* src);
void GetMousePos(float& x, float& y);
void UpdateEeprom();
void Initialize();
void DoState(void* ptr, int mode);
void Shutdown(void);

View File

@ -31,6 +31,7 @@
#include "wiimote_real.h" // Local
#include "wiimote_hid.h"
#include "EmuDefinitions.h"
#include "EmuMain.h"
#include "main.h"
#if defined(HAVE_WX) && HAVE_WX
#include "ConfigDlg.h"
@ -184,7 +185,7 @@ void handle_event(struct wiimote_t* wm)
void ReadWiimote()
{
handle_event(g_WiiMotesFromWiiUse[0]);
std::string Temp;
// Read formatted data
if (wiiuse_poll(g_WiiMotesFromWiiUse, MAX_WIIMOTES))
{
@ -219,6 +220,17 @@ void ReadWiimote()
* Take a look at wiimotes[i]->read_req
* for the data.
*/
if(g_WiiMotesFromWiiUse[0]->read_req->size == sizeof(WiiMoteEmu::EepromData_0)
&& g_WiiMotesFromWiiUse[0]->read_req->addr == 0)
{
Temp = ArrayToString(g_WiiMotesFromWiiUse[0]->read_req->buf, sizeof(WiiMoteEmu::EepromData_0), 0, 30);
memcpy(WiiMoteEmu::g_Eeprom, g_WiiMotesFromWiiUse[0]->read_req->buf, sizeof(WiiMoteEmu::EepromData_0));
WiiMoteEmu::UpdateEeprom();
Console::Print("EEPROM: %s\n", Temp.c_str());
Console::Print("Got neutral values: %i %i %i\n",
WiiMoteEmu::g_Eeprom[22],WiiMoteEmu::g_Eeprom[23], WiiMoteEmu::g_Eeprom[27]);
g_RunTemporary = false;
}
break;
case WIIUSE_NUNCHUK_INSERTED:
@ -230,7 +242,7 @@ void ReadWiimote()
*/
//wiiuse_set_nunchuk_orient_threshold((struct nunchuk_t*)&wiimotes[i]->exp.nunchuk, 90.0f);
//wiiuse_set_nunchuk_accel_threshold((struct nunchuk_t*)&wiimotes[i]->exp.nunchuk, 100);
printf("Nunchuk inserted.\n");
Console::Print("Nunchuk inserted.\n");
break;
case WIIUSE_CLASSIC_CTRL_INSERTED:

View File

@ -350,7 +350,7 @@ void ReadDebugging(bool Emu, const void* _pData)
size = sizeof(wm_status_report);
Name = "WM_STATUS_REPORT";
{
wm_status_report* pStatus = (wm_status_report*)(data + 2);
/*wm_status_report* pStatus = (wm_status_report*)(data + 2);
Console::Print(""
"Extension Controller: %i\n"
"Speaker enabled: %i\n"
@ -368,26 +368,16 @@ void ReadDebugging(bool Emu, const void* _pData)
(pStatus->leds >> 2),
(pStatus->leds >> 3),
pStatus->battery_low
);
);*/
}
break;
case WM_READ_DATA_REPLY: // 0x21
size = sizeof(wm_read_data_reply);
Name = "REPLY";
// Pick up accelerometer neutral values
// Show the accelerometer neutral values,
if (data[5] == 0x00 && data[6] == 0x10)
{
g_accel.cal_zero.x = data[13];
g_accel.cal_zero.y = data[14];
g_accel.cal_zero.z = data[15];
g_accel.cal_g.x = data[17] - data[13];
g_accel.cal_g.y = data[18] - data[14];
g_accel.cal_g.z = data[19] - data[15];
//Console::Print("Got neutral values: %i %i %i\n",
// g_accel.cal_zero.x, g_accel.cal_zero.y, g_accel.cal_zero.z + g_accel.cal_g.z);
}
Console::Print("\nGame got neutral values: %i %i %i\n\n",
data[13], data[14], data[19]);
break;
case WM_WRITE_DATA_REPLY: // 0x22
size = sizeof(wm_acknowledge) - 1;
@ -634,6 +624,9 @@ void DoInitialize()
// Load config settings
g_Config.Load();
// Run this first so that WiiMoteReal::Initialize() overwrites g_Eeprom
WiiMoteEmu::Initialize();
/* We will run WiiMoteReal::Initialize() even if we are not using a real wiimote,
to check if there is a real wiimote connected. We will initiate wiiuse.dll, but
we will return before creating a new thread for it if we find no real Wiimotes.
@ -643,8 +636,6 @@ void DoInitialize()
#if HAVE_WIIUSE
if (g_Config.bConnectRealWiimote) WiiMoteReal::Initialize();
#endif
WiiMoteEmu::Initialize();
}

View File

@ -73,6 +73,7 @@ bool g_LocalThread = true;
bool g_MotionSensing = false;
u64 g_UpdateTime = 0;
int g_UpdateCounter = 0;
bool g_RunTemporary = false;
//******************************************************************************
// Probably this class should be in its own file
@ -173,9 +174,11 @@ void ReadData()
memcpy(m_LastReport.m_PayLoad, pBuffer, MAX_PAYLOAD);
m_LastReportValid = true;
// Check if the data reporting mode is okay
//if (g_EmulatorRunning && pBuffer[0] != WiiMoteEmu::g_ReportingMode)
// SetDataReportingMode();
/* Check if the data reporting mode is okay. This should not cause any harm outside the dual mode
(being able to switch between the real and emulated wiimote) because WiiMoteEmu::g_ReportingMode
should always have the right reporting mode. */
if (g_EmulatorRunning && pBuffer[0] != WiiMoteEmu::g_ReportingMode)
SetDataReportingMode();
}
else
{
@ -427,42 +430,21 @@ int Initialize()
// Call Wiiuse.dll
g_WiiMotesFromWiiUse = wiiuse_init(MAX_WIIMOTES);
g_NumberOfWiiMotes = wiiuse_find(g_WiiMotesFromWiiUse, MAX_WIIMOTES, 5);
if (g_NumberOfWiiMotes > 0) g_RealWiiMotePresent = true;
Console::Print("Found No of Wiimotes: %i\n", g_NumberOfWiiMotes);
// Remove the wiiuse_poll() threshold
wiiuse_set_accel_threshold(g_WiiMotesFromWiiUse[0], 0);
// Update the global accelerometer neutral values
while(g_WiiMotesFromWiiUse[0]->accel_calib.cal_zero.x == 0)
{wiiuse_poll(g_WiiMotesFromWiiUse, MAX_WIIMOTES);}
g_accel.cal_zero.x = g_WiiMotesFromWiiUse[0]->accel_calib.cal_zero.x;
g_accel.cal_zero.y = g_WiiMotesFromWiiUse[0]->accel_calib.cal_zero.y;
g_accel.cal_zero.z = g_WiiMotesFromWiiUse[0]->accel_calib.cal_zero.z;
g_accel.cal_g.x = g_WiiMotesFromWiiUse[0]->accel_calib.cal_g.x;
g_accel.cal_g.y = g_WiiMotesFromWiiUse[0]->accel_calib.cal_g.y;
g_accel.cal_g.z = g_WiiMotesFromWiiUse[0]->accel_calib.cal_g.z;
Console::Print("Got neutral values: %i %i %i\n",
g_accel.cal_zero.x, g_accel.cal_zero.y, g_accel.cal_zero.z + g_accel.cal_g.z);
// Set the sensor bar position, this only affects the internal wiiuse api functions
wiiuse_set_ir_position(g_WiiMotesFromWiiUse[0], WIIUSE_IR_ABOVE);
// Update the global extension settings
g_Config.bNunchuckConnected = (g_WiiMotesFromWiiUse[0]->exp.type == EXP_NUNCHUK);
g_Config.bClassicControllerConnected = (g_WiiMotesFromWiiUse[0]->exp.type == EXP_CLASSIC);
if (g_NumberOfWiiMotes > 0) g_RealWiiMotePresent = true;
Console::Print("Found No of Wiimotes: %i\n", g_NumberOfWiiMotes);
// I don't seem to need wiiuse_connect()
//int Connect = wiiuse_connect(g_WiiMotesFromWiiUse, MAX_WIIMOTES);
//Console::Print("Connected: %i\n", Connect);
// If we are connecting from the config window without a game running we flash the lights
if (!g_EmulatorRunning)
{
// I don't seem to need wiiuse_connect()
//int Connect = wiiuse_connect(g_WiiMotesFromWiiUse, MAX_WIIMOTES);
//Console::Print("Connected: %i\n", Connect);
FlashLights(true);
}
else
{
//wiiuse_disconnect(g_WiiMotesFromWiiUse);
}
if (!g_EmulatorRunning) FlashLights(true);
// Create Wiimote classes
for (int i = 0; i < g_NumberOfWiiMotes; i++)
@ -472,6 +454,20 @@ int Initialize()
if (g_NumberOfWiiMotes > 0)
g_pReadThread = new Common::Thread(ReadWiimote_ThreadFunc, NULL);
// If we are not using the emulated wiimote we can run the thread temporary until the data has beeen copied
if(g_Config.bUseRealWiimote) g_RunTemporary = true;
/* Allocate memory and copy the Wiimote eeprom accelerometer neutral values to g_Eeprom. We can't
change the neutral values the wiimote will report, I think, unless we update its eeprom? In any
case it's probably better to let the current calibration be where it is and adjust the global
values after that. I don't feel comfortable with overwriting critical data on a lot of Wiimotes. */
byte *data = (byte*)malloc(sizeof(byte) * sizeof(WiiMoteEmu::EepromData_0));
wiiuse_read_data(g_WiiMotesFromWiiUse[0], data, 0, sizeof(WiiMoteEmu::EepromData_0));
// Update the global extension settings
g_Config.bNunchuckConnected = (g_WiiMotesFromWiiUse[0]->exp.type == EXP_NUNCHUK);
g_Config.bClassicControllerConnected = (g_WiiMotesFromWiiUse[0]->exp.type == EXP_CLASSIC);
// Initialized
if (g_NumberOfWiiMotes > 0) { g_RealWiiMoteInitialized = true; g_Shutdown = false; }
@ -551,7 +547,7 @@ void Update()
{
while (!g_Shutdown)
{
if(g_Config.bUseRealWiimote)
if(g_Config.bUseRealWiimote && !g_RunTemporary)
for (int i = 0; i < g_NumberOfWiiMotes; i++) g_WiiMotes[i]->ReadData();
else
ReadWiimote();

View File

@ -50,6 +50,7 @@ void ReadWiimote();
extern bool g_MotionSensing;
extern u64 g_UpdateTime;
extern int g_UpdateCounter;
extern bool g_RunTemporary;
#endif
}; // WiiMoteReal