From 19252f4e0e7ecc0f75d78616bb0ac43825623e52 Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Sat, 18 May 2013 20:31:37 +1200 Subject: [PATCH] Initial commit with balance board working on Linux. Will not work on any other platform currently. Missing any sort of config, and definitely no emulation mode. --- Source/Core/Core/Src/Core.cpp | 6 +- Source/Core/Core/Src/HW/Wiimote.cpp | 9 +- Source/Core/Core/Src/HW/Wiimote.h | 13 +- Source/Core/Core/Src/HW/WiimoteReal/IONix.cpp | 25 ++-- .../Core/Src/HW/WiimoteReal/WiimoteReal.cpp | 137 +++++++++++++----- .../Core/Src/HW/WiimoteReal/WiimoteReal.h | 7 +- .../Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp | 66 ++++++--- .../Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h | 6 +- .../Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp | 6 +- Source/Core/Core/Src/Movie.cpp | 2 +- .../Core/DolphinWX/Src/WiimoteConfigDiag.cpp | 4 +- Source/Core/DolphinWX/Src/WiimoteConfigDiag.h | 4 +- 12 files changed, 196 insertions(+), 89 deletions(-) diff --git a/Source/Core/Core/Src/Core.cpp b/Source/Core/Core/Src/Core.cpp index ffd2c35472..268d474ae6 100644 --- a/Source/Core/Core/Src/Core.cpp +++ b/Source/Core/Core/Src/Core.cpp @@ -394,10 +394,10 @@ void EmuThread() Wiimote::Initialize(g_pWindowHandle); // Activate wiimotes which don't have source set to "None" - for (unsigned int i = 0; i != MAX_WIIMOTES; ++i) + for (unsigned int i = 0; i != MAX_BBMOTES; ++i) if (g_wiimote_sources[i]) - GetUsbPointer()->AccessWiiMote(i | 0x100)-> - Activate(true); + GetUsbPointer()->AccessWiiMote(i | 0x100)->Activate(true); + } // The hardware is initialized. diff --git a/Source/Core/Core/Src/HW/Wiimote.cpp b/Source/Core/Core/Src/HW/Wiimote.cpp index 20e10b5fb8..6723a26d28 100644 --- a/Source/Core/Core/Src/HW/Wiimote.cpp +++ b/Source/Core/Core/Src/HW/Wiimote.cpp @@ -42,9 +42,10 @@ void Shutdown() void Initialize(void* const hwnd) { // add 4 wiimotes - for (unsigned int i = 0; i<4; ++i) + for (unsigned int i = WIIMOTE_CHAN_0; iDoState(p); } diff --git a/Source/Core/Core/Src/HW/Wiimote.h b/Source/Core/Core/Src/HW/Wiimote.h index fa4ec895bd..51ab018417 100644 --- a/Source/Core/Core/Src/HW/Wiimote.h +++ b/Source/Core/Core/Src/HW/Wiimote.h @@ -8,7 +8,16 @@ #include "../../InputCommon/Src/InputConfig.h" #include "ChunkFile.h" -#define MAX_WIIMOTES 4 +enum { + WIIMOTE_CHAN_0 = 0, + WIIMOTE_CHAN_1, + WIIMOTE_CHAN_2, + WIIMOTE_CHAN_3, + WIIMOTE_BALANCE_BOARD, + MAX_WIIMOTES = WIIMOTE_BALANCE_BOARD, + MAX_BBMOTES = 5, +}; + #define WIIMOTE_INI_NAME "WiimoteNew" @@ -20,7 +29,7 @@ enum WIIMOTE_SRC_HYBRID = 3, // emu + real }; -extern unsigned int g_wiimote_sources[MAX_WIIMOTES]; +extern unsigned int g_wiimote_sources[MAX_BBMOTES]; namespace Wiimote { diff --git a/Source/Core/Core/Src/HW/WiimoteReal/IONix.cpp b/Source/Core/Core/Src/HW/WiimoteReal/IONix.cpp index 87ddc5086b..edd79f2bf6 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/IONix.cpp +++ b/Source/Core/Core/Src/HW/WiimoteReal/IONix.cpp @@ -63,23 +63,22 @@ WiimoteScanner::~WiimoteScanner() void WiimoteScanner::Update() {} -std::vector WiimoteScanner::FindWiimotes() +void WiimoteScanner::FindWiimotes(std::vector & found_wiimotes, Wiimote* & found_board) { - std::vector found_wiimotes; - // supposedly 1.28 seconds int const wait_len = 1; int const max_infos = 255; inquiry_info scan_infos[max_infos] = {}; auto* scan_infos_ptr = scan_infos; - + found_board = NULL; + // Scan for bluetooth devices int const found_devices = hci_inquiry(device_id, wait_len, max_infos, NULL, &scan_infos_ptr, IREQ_CACHE_FLUSH); if (found_devices < 0) { ERROR_LOG(WIIMOTE, "Error searching for bluetooth devices."); - return found_wiimotes; + return; } DEBUG_LOG(WIIMOTE, "Found %i bluetooth device(s).", found_devices); @@ -91,7 +90,7 @@ std::vector WiimoteScanner::FindWiimotes() // BT names are a maximum of 248 bytes apparently char name[255] = {}; - if (hci_read_remote_name(device_sock, &scan_infos[i].bdaddr, sizeof(name), name, 0) < 0) + if (hci_read_remote_name(device_sock, &scan_infos[i].bdaddr, sizeof(name), name, 1000) < 0) { ERROR_LOG(WIIMOTE, "name request failed"); continue; @@ -119,14 +118,20 @@ std::vector WiimoteScanner::FindWiimotes() auto* const wm = new Wiimote; wm->bdaddr = scan_infos[i].bdaddr; - found_wiimotes.push_back(wm); - - NOTICE_LOG(WIIMOTE, "Found wiimote (%s).", bdaddr_str); + if(IsBalanceBoardName(name)) + { + found_board = wm; + NOTICE_LOG(WIIMOTE, "Found balance board (%s).", bdaddr_str); + } + else + { + found_wiimotes.push_back(wm); + NOTICE_LOG(WIIMOTE, "Found wiimote (%s).", bdaddr_str); + } } } } - return found_wiimotes; } // Connect to a wiimote with a known address. diff --git a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp index aaaaff6301..1d3be13cc5 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp +++ b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp @@ -17,12 +17,13 @@ #include "../WiimoteEmu/WiimoteHid.h" -unsigned int g_wiimote_sources[MAX_WIIMOTES]; +unsigned int g_wiimote_sources[MAX_BBMOTES]; namespace WiimoteReal { void HandleFoundWiimotes(const std::vector&); +void TryToConnectBalanceBoard(Wiimote*); void TryToConnectWiimote(Wiimote*); void HandleWiimoteDisconnect(int index); void DoneWithWiimote(int index); @@ -31,8 +32,7 @@ bool g_real_wiimotes_initialized = false; std::recursive_mutex g_refresh_lock; -Wiimote* g_wiimotes[MAX_WIIMOTES]; - +Wiimote* g_wiimotes[MAX_BBMOTES]; WiimoteScanner g_wiimote_scanner; Wiimote::Wiimote() @@ -285,7 +285,7 @@ bool Wiimote::Prepare(int _index) u8 const mode_report[] = {WM_SET_REPORT | WM_BT_OUTPUT, WM_REPORT_MODE, 0, WM_REPORT_CORE}; // Set the active LEDs and turn on rumble. - u8 const led_report[] = {WM_SET_REPORT | WM_BT_OUTPUT, WM_LEDS, u8(WIIMOTE_LED_1 << index | 0x1)}; + u8 const led_report[] = {WM_SET_REPORT | WM_BT_OUTPUT, WM_LEDS, u8(WIIMOTE_LED_1 << (index%WIIMOTE_BALANCE_BOARD) | 0x1)}; // Turn off rumble u8 rumble_report[] = {WM_SET_REPORT | WM_BT_OUTPUT, WM_RUMBLE, 0}; @@ -325,11 +325,25 @@ unsigned int CalculateWantedWiimotes() return wanted_wiimotes; } +unsigned int CalculateWantedBB() +{ + unsigned int wanted_bb = 0; + if (WIIMOTE_SRC_REAL & g_wiimote_sources[WIIMOTE_BALANCE_BOARD] && !g_wiimotes[WIIMOTE_BALANCE_BOARD]) + ++wanted_bb; + return wanted_bb; +} + void WiimoteScanner::WantWiimotes(bool do_want) { m_want_wiimotes = do_want; } + +void WiimoteScanner::WantBB(bool do_want) +{ + m_want_bb = do_want; +} + void WiimoteScanner::StartScanning() { if (!m_run_thread) @@ -352,7 +366,7 @@ void CheckForDisconnectedWiimotes() { std::lock_guard lk(g_refresh_lock); - for (unsigned int i = 0; i != MAX_WIIMOTES; ++i) + for (unsigned int i = 0; i < MAX_BBMOTES; ++i) if (g_wiimotes[i] && !g_wiimotes[i]->IsConnected()) HandleWiimoteDisconnect(i); } @@ -366,12 +380,13 @@ void WiimoteScanner::ThreadFunc() while (m_run_thread) { std::vector found_wiimotes; + Wiimote* found_board = NULL; //NOTICE_LOG(WIIMOTE, "In loop"); - if (m_want_wiimotes) + if (m_want_wiimotes || m_want_bb) { - found_wiimotes = FindWiimotes(); + FindWiimotes(found_wiimotes, found_board); } else { @@ -384,7 +399,10 @@ void WiimoteScanner::ThreadFunc() // TODO: this is a fairly lame place for this CheckForDisconnectedWiimotes(); - HandleFoundWiimotes(found_wiimotes); + if(m_want_wiimotes) + HandleFoundWiimotes(found_wiimotes); + if(m_want_bb && found_board) + TryToConnectBalanceBoard(found_board); //std::this_thread::yield(); Common::SleepCurrentThread(500); @@ -439,6 +457,7 @@ void LoadSettings() sec.Get("Source", &g_wiimote_sources[i], i ? WIIMOTE_SRC_NONE : WIIMOTE_SRC_EMU); } + g_wiimote_sources[WIIMOTE_BALANCE_BOARD] = WIIMOTE_SRC_REAL; } // config dialog calls this when some settings change @@ -452,6 +471,7 @@ void Initialize() std::lock_guard lk(g_refresh_lock); g_wiimote_scanner.WantWiimotes(0 != CalculateWantedWiimotes()); + g_wiimote_scanner.WantBB(0 != CalculateWantedBB()); if (g_real_wiimotes_initialized) return; @@ -474,7 +494,7 @@ void Shutdown(void) g_real_wiimotes_initialized = false; - for (unsigned int i = 0; i < MAX_WIIMOTES; ++i) + for (unsigned int i = 0; i < MAX_BBMOTES; ++i) HandleWiimoteDisconnect(i); } @@ -482,9 +502,10 @@ void ChangeWiimoteSource(unsigned int index, int source) { { std::lock_guard lk(g_refresh_lock); - g_wiimote_sources[index] = source; g_wiimote_scanner.WantWiimotes(0 != CalculateWantedWiimotes()); + g_wiimote_scanner.WantBB(0 != CalculateWantedBB()); + // kill real connection (or swap to different slot) DoneWithWiimote(index); @@ -500,7 +521,7 @@ void TryToConnectWiimote(Wiimote* wm) { std::unique_lock lk(g_refresh_lock); - for (unsigned int i = 0; i != MAX_WIIMOTES; ++i) + for (unsigned int i = 0; i < MAX_WIIMOTES; ++i) { if (WIIMOTE_SRC_REAL & g_wiimote_sources[i] && !g_wiimotes[i]) @@ -525,16 +546,41 @@ void TryToConnectWiimote(Wiimote* wm) delete wm; } +void TryToConnectBalanceBoard(Wiimote* wm) +{ + std::unique_lock lk(g_refresh_lock); + + if (WIIMOTE_SRC_REAL & g_wiimote_sources[WIIMOTE_BALANCE_BOARD] + && !g_wiimotes[WIIMOTE_BALANCE_BOARD]) + { + if (wm->Connect() && wm->Prepare(WIIMOTE_BALANCE_BOARD)) + { + NOTICE_LOG(WIIMOTE, "Connected to Balance Board %i.", WIIMOTE_BALANCE_BOARD + 1); + + std::swap(g_wiimotes[WIIMOTE_BALANCE_BOARD], wm); + g_wiimotes[WIIMOTE_BALANCE_BOARD]->StartThread(); + + Host_ConnectWiimote(WIIMOTE_BALANCE_BOARD, true); + } + } + + g_wiimote_scanner.WantBB(0 != CalculateWantedBB()); + + lk.unlock(); + + delete wm; +} + void DoneWithWiimote(int index) { std::lock_guard lk(g_refresh_lock); - + if (g_wiimotes[index]) { g_wiimotes[index]->StopThread(); // First see if we can use this real Wiimote in another slot. - for (unsigned int i = 0; i != MAX_WIIMOTES; ++i) + for (unsigned int i = 0; i < MAX_WIIMOTES; ++i) { if (WIIMOTE_SRC_REAL & g_wiimote_sources[i] && !g_wiimotes[i]) @@ -560,9 +606,11 @@ void HandleWiimoteDisconnect(int index) Wiimote* wm = NULL; { - std::lock_guard lk(g_refresh_lock); - std::swap(wm, g_wiimotes[index]); - g_wiimote_scanner.WantWiimotes(0 != CalculateWantedWiimotes()); + std::lock_guard lk(g_refresh_lock); + + std::swap(wm, g_wiimotes[index]); + g_wiimote_scanner.WantWiimotes(0 != CalculateWantedWiimotes()); + g_wiimote_scanner.WantBB(0 != CalculateWantedBB()); } if (wm) @@ -583,31 +631,34 @@ void Refresh() g_wiimote_scanner.StopScanning(); { - std::unique_lock lk(g_refresh_lock); - std::vector found_wiimotes; - - if (0 != CalculateWantedWiimotes()) - { - // Don't hang Dolphin when searching - lk.unlock(); - found_wiimotes = g_wiimote_scanner.FindWiimotes(); - lk.lock(); - } - - CheckForDisconnectedWiimotes(); - - // Brief rumble for already connected Wiimotes. - for (int i = 0; i != MAX_WIIMOTES; ++i) - { - if (g_wiimotes[i]) + std::unique_lock lk(g_refresh_lock); + std::vector found_wiimotes; + Wiimote* found_board = NULL; + + if (0 != CalculateWantedWiimotes()) { - g_wiimotes[i]->StopThread(); - g_wiimotes[i]->Prepare(i); - g_wiimotes[i]->StartThread(); + // Don't hang Dolphin when searching + lk.unlock(); + g_wiimote_scanner.FindWiimotes(found_wiimotes, found_board); + lk.lock(); } - } - HandleFoundWiimotes(found_wiimotes); + CheckForDisconnectedWiimotes(); + + // Brief rumble for already connected Wiimotes. + for (int i = 0; i < MAX_BBMOTES; ++i) + { + if (g_wiimotes[i]) + { + g_wiimotes[i]->StopThread(); + g_wiimotes[i]->Prepare(i); + g_wiimotes[i]->StartThread(); + } + } + + HandleFoundWiimotes(found_wiimotes); + if(found_board) + TryToConnectBalanceBoard(found_board); } Initialize(); @@ -616,7 +667,6 @@ void Refresh() void InterruptChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size) { std::lock_guard lk(g_refresh_lock); - if (g_wiimotes[_WiimoteNumber]) g_wiimotes[_WiimoteNumber]->InterruptChannel(_channelID, _pData, _Size); } @@ -656,7 +706,14 @@ bool IsValidBluetoothName(const std::string& name) { return "Nintendo RVL-CNT-01" == name || - "Nintendo RVL-CNT-01-TR" == name; + "Nintendo RVL-CNT-01-TR" == name || + IsBalanceBoardName(name); +} + +bool IsBalanceBoardName(const std::string& name) +{ + return + "Nintendo RVL-WBC-01" == name; } }; // end of namespace diff --git a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h index b57e1be2f4..695dc86b82 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h +++ b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h @@ -117,11 +117,12 @@ public: bool IsReady() const; void WantWiimotes(bool do_want); + void WantBB(bool do_want); void StartScanning(); void StopScanning(); - std::vector FindWiimotes(); + void FindWiimotes(std::vector&, Wiimote*&); // function called when not looking for more wiimotes void Update(); @@ -133,6 +134,7 @@ private: volatile bool m_run_thread; volatile bool m_want_wiimotes; + volatile bool m_want_bb; #if defined(_WIN32) @@ -145,7 +147,7 @@ private: extern std::recursive_mutex g_refresh_lock; extern WiimoteScanner g_wiimote_scanner; -extern Wiimote *g_wiimotes[4]; +extern Wiimote *g_wiimotes[MAX_BBMOTES]; void InterruptChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size); void ControlChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size); @@ -158,6 +160,7 @@ int FindWiimotes(Wiimote** wm, int max_wiimotes); void ChangeWiimoteSource(unsigned int index, int source); bool IsValidBluetoothName(const std::string& name); +bool IsBalanceBoardName(const std::string& name); }; // WiimoteReal diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp index 41f751cb77..daa28b340d 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp @@ -32,7 +32,7 @@ CWII_IPC_HLE_Device_usb_oh1_57e_305::CWII_IPC_HLE_Device_usb_oh1_57e_305(u32 _De } else { - u8 maxWM = min(BT_DINF.num_registered, CONF_PAD_MAX_ACTIVE); + u8 maxWM = min(BT_DINF.num_registered, MAX_BBMOTES); bdaddr_t tmpBD = BDADDR_ANY; u8 i = 0; while (i < maxWM) @@ -43,28 +43,60 @@ CWII_IPC_HLE_Device_usb_oh1_57e_305::CWII_IPC_HLE_Device_usb_oh1_57e_305(u32 _De tmpBD.b[2] = BT_DINF.active[i].bdaddr[3] = BT_DINF.registered[i].bdaddr[3]; tmpBD.b[1] = BT_DINF.active[i].bdaddr[4] = BT_DINF.registered[i].bdaddr[4]; tmpBD.b[0] = BT_DINF.active[i].bdaddr[5] = BT_DINF.registered[i].bdaddr[5]; + if(i == WIIMOTE_BALANCE_BOARD) + { + const char * wmName = "Nintendo RVL-WBC-01"; + memcpy(BT_DINF.registered[i].name, wmName, 20); + memcpy(BT_DINF.balance_board.name, wmName, 20); + } + else + { + const char * wmName = "Nintendo RVL-CNT-01"; + memcpy(BT_DINF.registered[i].name, wmName, 20); + memcpy(BT_DINF.active[i].name, wmName, 20); + } INFO_LOG(WII_IPC_WIIMOTE, "Wiimote %d BT ID %x,%x,%x,%x,%x,%x", i, tmpBD.b[0], tmpBD.b[1], tmpBD.b[2], tmpBD.b[3], tmpBD.b[4], tmpBD.b[5]); m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, i, tmpBD, false)); i++; } - while (i < CONF_PAD_MAX_ACTIVE) + while (i < MAX_BBMOTES) { - const char * wmName = "Nintendo RVL-CNT-01"; - ++BT_DINF.num_registered; - BT_DINF.active[i].bdaddr[0] = BT_DINF.registered[i].bdaddr[0] = tmpBD.b[5] = i; - BT_DINF.active[i].bdaddr[1] = BT_DINF.registered[i].bdaddr[1] = tmpBD.b[4] = 0; - BT_DINF.active[i].bdaddr[2] = BT_DINF.registered[i].bdaddr[2] = tmpBD.b[3] = 0x79; - BT_DINF.active[i].bdaddr[3] = BT_DINF.registered[i].bdaddr[3] = tmpBD.b[2] = 0x19; - BT_DINF.active[i].bdaddr[4] = BT_DINF.registered[i].bdaddr[4] = tmpBD.b[1] = 2; - BT_DINF.active[i].bdaddr[5] = BT_DINF.registered[i].bdaddr[5] = tmpBD.b[0] = 0x11; - memcpy(BT_DINF.registered[i].name, wmName, 20); + if(i == WIIMOTE_BALANCE_BOARD) + { + const char * wmName = "Nintendo RVL-WBC-01"; + ++BT_DINF.num_registered; + BT_DINF.balance_board.bdaddr[0] = BT_DINF.registered[i].bdaddr[0] = tmpBD.b[5] = i; + BT_DINF.balance_board.bdaddr[1] = BT_DINF.registered[i].bdaddr[1] = tmpBD.b[4] = 0; + BT_DINF.balance_board.bdaddr[2] = BT_DINF.registered[i].bdaddr[2] = tmpBD.b[3] = 0x79; + BT_DINF.balance_board.bdaddr[3] = BT_DINF.registered[i].bdaddr[3] = tmpBD.b[2] = 0x19; + BT_DINF.balance_board.bdaddr[4] = BT_DINF.registered[i].bdaddr[4] = tmpBD.b[1] = 2; + BT_DINF.balance_board.bdaddr[5] = BT_DINF.registered[i].bdaddr[5] = tmpBD.b[0] = 0x11; + memcpy(BT_DINF.registered[i].name, wmName, 20); + memcpy(BT_DINF.balance_board.name, wmName, 20); + + INFO_LOG(WII_IPC_WIIMOTE, "Balance Board %d BT ID %x,%x,%x,%x,%x,%x", i, tmpBD.b[0], tmpBD.b[1], tmpBD.b[2], tmpBD.b[3], tmpBD.b[4], tmpBD.b[5]); + m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, i, tmpBD, false)); + } + else + { + const char * wmName = "Nintendo RVL-CNT-01"; + ++BT_DINF.num_registered; + BT_DINF.active[i].bdaddr[0] = BT_DINF.registered[i].bdaddr[0] = tmpBD.b[5] = i; + BT_DINF.active[i].bdaddr[1] = BT_DINF.registered[i].bdaddr[1] = tmpBD.b[4] = 0; + BT_DINF.active[i].bdaddr[2] = BT_DINF.registered[i].bdaddr[2] = tmpBD.b[3] = 0x79; + BT_DINF.active[i].bdaddr[3] = BT_DINF.registered[i].bdaddr[3] = tmpBD.b[2] = 0x19; + BT_DINF.active[i].bdaddr[4] = BT_DINF.registered[i].bdaddr[4] = tmpBD.b[1] = 2; + BT_DINF.active[i].bdaddr[5] = BT_DINF.registered[i].bdaddr[5] = tmpBD.b[0] = 0x11; + memcpy(BT_DINF.registered[i].name, wmName, 20); - INFO_LOG(WII_IPC_WIIMOTE, "Adding to SYSConf Wiimote %d BT ID %x,%x,%x,%x,%x,%x", i, tmpBD.b[0], tmpBD.b[1], tmpBD.b[2], tmpBD.b[3], tmpBD.b[4], tmpBD.b[5]); - m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, i, tmpBD, false)); + INFO_LOG(WII_IPC_WIIMOTE, "Adding to SYSConf Wiimote %d BT ID %x,%x,%x,%x,%x,%x", i, tmpBD.b[0], tmpBD.b[1], tmpBD.b[2], tmpBD.b[3], tmpBD.b[4], tmpBD.b[5]); + m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, i, tmpBD, false)); + + } i++; } - + // save now so that when games load sysconf file it includes the new wiimotes // and the correct order for connected wiimotes if (!SConfig::GetInstance().m_SYSCONF->SetArrayData("BT.DINF", (u8*)&BT_DINF, sizeof(_conf_pads)) || !SConfig::GetInstance().m_SYSCONF->Save()) @@ -99,18 +131,18 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::DoState(PointerWrap &p) p.DoPOD(m_HCIEndpoint); p.DoPOD(m_ACLEndpoint); p.Do(m_last_ticks); - p.DoArray(m_PacketCount,4); + p.DoArray(m_PacketCount,MAX_BBMOTES); p.Do(m_ScanEnable); p.Do(m_EventQueue); m_acl_pool.DoState(p); - for (unsigned int i = 0; i < 4; i++) + for (unsigned int i = 0; i < MAX_BBMOTES; i++) m_WiiMotes[i].DoState(p); // Reset the connection of real and hybrid wiimotes if (p.GetMode() == PointerWrap::MODE_READ && SConfig::GetInstance().m_WiimoteReconnectOnLoad) { - for (unsigned int i = 0; i < 4; i++) + for (unsigned int i = 0; i < MAX_BBMOTES; i++) { if (WIIMOTE_SRC_EMU == g_wiimote_sources[i] || WIIMOTE_SRC_NONE == g_wiimote_sources[i]) continue; diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h index f3d79b0fb8..7ac93b5be1 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h @@ -12,6 +12,7 @@ #include "WII_IPC_HLE.h" #include "WII_IPC_HLE_Device.h" #include "WII_IPC_HLE_WiiMote.h" +#include "../HW/Wiimote.h" struct SQueuedEvent { @@ -193,7 +194,7 @@ private: } } m_acl_pool; - u32 m_PacketCount[4]; + u32 m_PacketCount[MAX_BBMOTES]; u64 m_last_ticks; // Send ACL data to a device (wiimote) @@ -274,7 +275,6 @@ private: #pragma pack(push,1) #define CONF_PAD_MAX_REGISTERED 10 -#define CONF_PAD_MAX_ACTIVE 4 struct _conf_pad_device { @@ -286,7 +286,7 @@ private: { u8 num_registered; _conf_pad_device registered[CONF_PAD_MAX_REGISTERED]; - _conf_pad_device active[CONF_PAD_MAX_ACTIVE]; + _conf_pad_device active[MAX_WIIMOTES]; _conf_pad_device balance_board; u8 unknown[0x45]; }; diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp index 22930eb94c..9386682106 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp @@ -37,7 +37,7 @@ CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* , m_HIDInterruptChannel_Config(false) , m_HIDInterruptChannel_ConfigWait(false) , m_BD(_BD) - , m_Name("Nintendo RVL-CNT-01") + , m_Name(_Number == WIIMOTE_BALANCE_BOARD ? "Nintendo RVL-WBC-01" : "Nintendo RVL-CNT-01") , m_pHost(_pHost) { DEBUG_LOG(WII_IPC_WIIMOTE, "Wiimote: #%i Constructed", _Number); @@ -277,13 +277,13 @@ void CWII_IPC_HLE_WiiMote::ExecuteL2capCmd(u8* _pData, u32 _Size) break; case L2CAP_PSM_HID_CNTL: - if (number < 4) + if (number < MAX_BBMOTES) Wiimote::ControlChannel(number, pHeader->dcid, pData, DataSize); break; case L2CAP_PSM_HID_INTR: { - if (number < 4) + if (number < MAX_BBMOTES) { DEBUG_LOG(WIIMOTE, "Wiimote_InterruptChannel"); DEBUG_LOG(WIIMOTE, " Channel ID: %04x", pHeader->dcid); diff --git a/Source/Core/Core/Src/Movie.cpp b/Source/Core/Core/Src/Movie.cpp index c57ce8d4cc..75951df67d 100644 --- a/Source/Core/Core/Src/Movie.cpp +++ b/Source/Core/Core/Src/Movie.cpp @@ -392,7 +392,7 @@ void ChangeWiiPads(bool instantly) if (instantly && (g_numPads >> 4) == controllers) return; - for (int i = 0; i < 4; i++) + for (int i = 0; i < MAX_BBMOTES; i++) { g_wiimote_sources[i] = IsUsingWiimote(i) ? WIIMOTE_SRC_EMU : WIIMOTE_SRC_NONE; GetUsbPointer()->AccessWiiMote(i | 0x100)->Activate(IsUsingWiimote(i)); diff --git a/Source/Core/DolphinWX/Src/WiimoteConfigDiag.cpp b/Source/Core/DolphinWX/Src/WiimoteConfigDiag.cpp index f039fe4938..1a1544373c 100644 --- a/Source/Core/DolphinWX/Src/WiimoteConfigDiag.cpp +++ b/Source/Core/DolphinWX/Src/WiimoteConfigDiag.cpp @@ -15,7 +15,7 @@ WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputPlugin& plugin wxStaticText* wiimote_label[4]; wxChoice* wiimote_source_ch[4]; - for (unsigned int i = 0; i < 4; ++i) + for (unsigned int i = 0; i < MAX_WIIMOTES; ++i) { wxString str; str.Printf(_("Wiimote %i"), i + 1); @@ -206,7 +206,7 @@ void WiimoteConfigDiag::SelectSource(wxCommandEvent& event) void WiimoteConfigDiag::RevertSource() { - for (int i = 0; i < 4; ++i) + for (int i = 0; i < MAX_WIIMOTES; ++i) g_wiimote_sources[i] = m_orig_wiimote_sources[i]; } diff --git a/Source/Core/DolphinWX/Src/WiimoteConfigDiag.h b/Source/Core/DolphinWX/Src/WiimoteConfigDiag.h index 4c33661ca2..88fea037a9 100644 --- a/Source/Core/DolphinWX/Src/WiimoteConfigDiag.h +++ b/Source/Core/DolphinWX/Src/WiimoteConfigDiag.h @@ -76,9 +76,9 @@ private: wxNotebook* m_pad_notebook; std::map m_wiimote_index_from_ctrl_id; - unsigned int m_orig_wiimote_sources[4]; + unsigned int m_orig_wiimote_sources[MAX_WIIMOTES]; - wxButton* wiimote_configure_bt[4]; + wxButton* wiimote_configure_bt[MAX_WIIMOTES]; std::map m_wiimote_index_from_conf_bt_id; };