Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'wii_bb'
Adds Balance Board support.
  • Loading branch information
Parlane committed May 21, 2013
2 parents f8a5d05 + d642abc commit 86b4a87
Show file tree
Hide file tree
Showing 17 changed files with 526 additions and 179 deletions.
6 changes: 3 additions & 3 deletions Source/Core/Core/Src/Core.cpp
Expand Up @@ -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.
Expand Down
9 changes: 5 additions & 4 deletions Source/Core/Core/Src/HW/Wiimote.cpp
Expand Up @@ -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; i<MAX_BBMOTES; ++i)
g_plugin.controllers.push_back(new WiimoteEmu::Wiimote(i));



g_controller_interface.SetHwnd(hwnd);
g_controller_interface.Initialize();

Expand Down Expand Up @@ -134,7 +135,7 @@ void Update(int _number)
unsigned int GetAttached()
{
unsigned int attached = 0;
for (unsigned int i=0; i<4; ++i)
for (unsigned int i=0; i<MAX_BBMOTES; ++i)
if (g_wiimote_sources[i])
attached |= (1 << i);
return attached;
Expand All @@ -151,7 +152,7 @@ void DoState(u8 **ptr, PointerWrap::Mode mode)
// TODO:

PointerWrap p(ptr, mode);
for (unsigned int i=0; i<4; ++i)
for (unsigned int i=0; i<MAX_BBMOTES; ++i)
((WiimoteEmu::Wiimote*)g_plugin.controllers[i])->DoState(p);
}

Expand Down
13 changes: 11 additions & 2 deletions Source/Core/Core/Src/HW/Wiimote.h
Expand Up @@ -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"

Expand All @@ -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
{
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/Core/Src/HW/WiimoteReal/IODummy.cpp
Expand Up @@ -32,9 +32,10 @@ WiimoteScanner::~WiimoteScanner()
void WiimoteScanner::Update()
{}

std::vector<Wiimote*> WiimoteScanner::FindWiimotes()
void WiimoteScanner::FindWiimotes(std::vector<Wiimote*> & found_wiimotes, Wiimote* & found_board)
{
return std::vector<Wiimote*>();
found_wiimotes.clear();
found_board = NULL;
}

bool WiimoteScanner::IsReady() const
Expand Down
25 changes: 15 additions & 10 deletions Source/Core/Core/Src/HW/WiimoteReal/IONix.cpp
Expand Up @@ -63,23 +63,22 @@ WiimoteScanner::~WiimoteScanner()
void WiimoteScanner::Update()
{}

std::vector<Wiimote*> WiimoteScanner::FindWiimotes()
void WiimoteScanner::FindWiimotes(std::vector<Wiimote*> & found_wiimotes, Wiimote* & found_board)
{
std::vector<Wiimote*> 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);
Expand All @@ -91,7 +90,7 @@ std::vector<Wiimote*> 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;
Expand Down Expand Up @@ -119,14 +118,20 @@ std::vector<Wiimote*> 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.
Expand Down

0 comments on commit 86b4a87

Please sign in to comment.