Fixup real wiimote GUI.

This commit is contained in:
Jordan Woyak 2013-02-07 23:17:51 -06:00
parent 3063942dd0
commit 026793fa4a
5 changed files with 50 additions and 87 deletions

View File

@ -135,7 +135,10 @@ WiimoteScanner::WiimoteScanner()
} }
WiimoteScanner::~WiimoteScanner() WiimoteScanner::~WiimoteScanner()
{} {
// TODO: what do we want here?
//PairUp(true);
}
// Find and connect wiimotes. // Find and connect wiimotes.
// Does not replace already found wiimotes even if they are disconnected. // Does not replace already found wiimotes even if they are disconnected.
@ -216,8 +219,21 @@ std::vector<Wiimote*> WiimoteScanner::FindWiimotes(size_t max_wiimotes)
bool WiimoteScanner::IsReady() const bool WiimoteScanner::IsReady() const
{ {
// TODO: impl BLUETOOTH_FIND_RADIO_PARAMS radioParam;
return true; radioParam.dwSize = sizeof(radioParam);
HANDLE hRadio;
HBLUETOOTH_RADIO_FIND hFindRadio = Bth_BluetoothFindFirstRadio(&radioParam, &hRadio);
if (NULL != hFindRadio)
{
Bth_BluetoothFindRadioClose(hFindRadio);
return true;
}
else
{
return false;
}
} }
// Connect to a wiimote with a known device path. // Connect to a wiimote with a known device path.
@ -377,26 +393,6 @@ int Wiimote::IOWrite(const u8* buf, int len)
return 0; return 0;
} }
// return true if a device using MS BT stack is available
bool CanPairUp()
{
BLUETOOTH_FIND_RADIO_PARAMS radioParam;
radioParam.dwSize = sizeof(radioParam);
HANDLE hRadio;
HBLUETOOTH_RADIO_FIND hFindRadio = Bth_BluetoothFindFirstRadio(&radioParam, &hRadio);
if (NULL != hFindRadio)
{
Bth_BluetoothFindRadioClose(hFindRadio);
return true;
}
else
{
return false;
}
}
// WiiMote Pair-Up, function will return amount of either new paired or unpaired devices // WiiMote Pair-Up, function will return amount of either new paired or unpaired devices
// negative number on failure // negative number on failure
int PairUp(bool unpair) int PairUp(bool unpair)

View File

@ -265,7 +265,7 @@ void Wiimote::SetLEDs(int new_leds)
QueueReport(WM_CMD_LED, &buffer, sizeof(buffer)); QueueReport(WM_CMD_LED, &buffer, sizeof(buffer));
} }
bool Wiimote::EmuStart() void Wiimote::EmuStart()
{ {
DisableDataReporting(); DisableDataReporting();
} }
@ -298,7 +298,10 @@ void WiimoteScanner::WantWiimotes(size_t count)
void WiimoteScanner::StartScanning() void WiimoteScanner::StartScanning()
{ {
run_thread = true; run_thread = true;
scan_thread = std::thread(std::mem_fun(&WiimoteScanner::ThreadFunc), this); if (IsReady())
{
scan_thread = std::thread(std::mem_fun(&WiimoteScanner::ThreadFunc), this);
}
} }
void WiimoteScanner::StopScanning() void WiimoteScanner::StopScanning()
@ -307,7 +310,6 @@ void WiimoteScanner::StopScanning()
if (scan_thread.joinable()) if (scan_thread.joinable())
{ {
scan_thread.join(); scan_thread.join();
NOTICE_LOG(WIIMOTE, "Wiimote scanning has stopped");
} }
} }
@ -333,6 +335,8 @@ void WiimoteScanner::ThreadFunc()
//std::this_thread::yield(); //std::this_thread::yield();
Common::SleepCurrentThread(500); Common::SleepCurrentThread(500);
} }
NOTICE_LOG(WIIMOTE, "Wiimote scanning has stopped");
} }
void Wiimote::StartThread() void Wiimote::StartThread()
@ -395,8 +399,7 @@ void Initialize()
auto const wanted_wiimotes = CalculateWantedWiimotes(); auto const wanted_wiimotes = CalculateWantedWiimotes();
g_wiimote_scanner.WantWiimotes(wanted_wiimotes); g_wiimote_scanner.WantWiimotes(wanted_wiimotes);
//if (wanted_wiimotes > 0) g_wiimote_scanner.StartScanning();
g_wiimote_scanner.StartScanning();
g_real_wiimotes_initialized = true; g_real_wiimotes_initialized = true;
} }
@ -497,9 +500,21 @@ void HandleFoundWiimotes(const std::vector<Wiimote*>& wiimotes)
// This is called from the GUI thread // This is called from the GUI thread
void Refresh() void Refresh()
{ {
g_wiimote_scanner.StopScanning();
{
std::lock_guard<std::recursive_mutex> lk(g_refresh_lock); std::lock_guard<std::recursive_mutex> lk(g_refresh_lock);
// TODO: stuff, maybe auto wanted_wiimotes = CalculateWantedWiimotes();
auto const found_wiimotes = g_wiimote_scanner.FindWiimotes(wanted_wiimotes);
HandleFoundWiimotes(found_wiimotes);
wanted_wiimotes = CalculateWantedWiimotes();
g_wiimote_scanner.WantWiimotes(wanted_wiimotes);
}
g_wiimote_scanner.StartScanning();
} }
void InterruptChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size) void InterruptChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size)

View File

@ -59,7 +59,7 @@ public:
void StopThread(); void StopThread();
// "handshake" / stop packets // "handshake" / stop packets
bool EmuStart(); void EmuStart();
void EmuStop(); void EmuStop();
// connecting and disconnecting from physical devices // connecting and disconnecting from physical devices
@ -153,6 +153,7 @@ private:
}; };
extern std::recursive_mutex g_refresh_lock; extern std::recursive_mutex g_refresh_lock;
extern WiimoteScanner g_wiimote_scanner;
extern Wiimote *g_wiimotes[4]; extern Wiimote *g_wiimotes[4];
void InterruptChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size); void InterruptChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size);

View File

@ -4,14 +4,6 @@
#include "HW/WiimoteReal/WiimoteReal.h" #include "HW/WiimoteReal/WiimoteReal.h"
#include "Frame.h" #include "Frame.h"
wxString ConnectedWiimotesString()
{
//static wxString str;
//str.Printf(_("%i connected"), WiimoteReal::Initialize());
//return str;
return "TODO: this text";
}
WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputPlugin& plugin) WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputPlugin& plugin)
: wxDialog(parent, -1, _("Dolphin Wiimote Configuration"), wxDefaultPosition, wxDefaultSize) : wxDialog(parent, -1, _("Dolphin Wiimote Configuration"), wxDefaultPosition, wxDefaultSize)
, m_plugin(plugin) , m_plugin(plugin)
@ -65,27 +57,17 @@ WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputPlugin& plugin
// "Real wiimotes" controls // "Real wiimotes" controls
connected_wiimotes_txt = new wxStaticText(this, -1, ConnectedWiimotesString());
wxButton* const refresh_btn = new wxButton(this, -1, _("Refresh"), wxDefaultPosition); wxButton* const refresh_btn = new wxButton(this, -1, _("Refresh"), wxDefaultPosition);
refresh_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &WiimoteConfigDiag::RefreshRealWiimotes, this); refresh_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &WiimoteConfigDiag::RefreshRealWiimotes, this);
#ifdef _WIN32
//wxButton* const pairup_btn = new wxButton(this, -1, _("Pair Up"), wxDefaultPosition);
//pairup_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &WiimoteConfigDiag::PairUpRealWiimotes, this);
// TODO: text if can't Pair
#endif
// "Real wiimotes" layout // "Real wiimotes" layout
wxStaticBoxSizer* const real_wiimotes_group = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Real Wiimotes")); wxStaticBoxSizer* const real_wiimotes_group = new wxStaticBoxSizer(wxVERTICAL, this, _("Real Wiimotes"));
wxFlexGridSizer* const real_wiimotes_sizer = new wxFlexGridSizer(3, 5, 5);
real_wiimotes_sizer->Add(connected_wiimotes_txt, 0, wxALIGN_CENTER_VERTICAL); if (!WiimoteReal::g_wiimote_scanner.IsReady())
#ifdef _WIN32 real_wiimotes_group->Add(new wxStaticText(this, -1, _("A supported bluetooth device could not be found.\n"
//real_wiimotes_sizer->Add(pairup_btn); "You must manually pair your wiimotes.")), 0, wxALIGN_CENTER | wxALL, 5);
#endif
real_wiimotes_sizer->Add(refresh_btn); real_wiimotes_group->Add(refresh_btn, 0, wxALIGN_CENTER);
real_wiimotes_group->Add(real_wiimotes_sizer, 1, wxALL, 5);
// "General Settings" controls // "General Settings" controls
const wxString str[] = { _("Bottom"), _("Top") }; const wxString str[] = { _("Bottom"), _("Top") };
@ -189,15 +171,9 @@ void WiimoteConfigDiag::ConfigEmulatedWiimote(wxCommandEvent& ev)
m_emu_config_diag->Destroy(); m_emu_config_diag->Destroy();
} }
void WiimoteConfigDiag::UpdateGUI()
{
connected_wiimotes_txt->SetLabel(ConnectedWiimotesString());
}
void WiimoteConfigDiag::RefreshRealWiimotes(wxCommandEvent&) void WiimoteConfigDiag::RefreshRealWiimotes(wxCommandEvent&)
{ {
WiimoteReal::Refresh(); WiimoteReal::Refresh();
UpdateGUI();
} }
void WiimoteConfigDiag::SelectSource(wxCommandEvent& event) void WiimoteConfigDiag::SelectSource(wxCommandEvent& event)
@ -214,24 +190,6 @@ void WiimoteConfigDiag::SelectSource(wxCommandEvent& event)
wiimote_configure_bt[index]->Enable(); wiimote_configure_bt[index]->Enable();
} }
// TODO: race conditiions
void WiimoteConfigDiag::UpdateWiimoteStatus()
{
for (int index = 0; index < 4; ++index)
{
if (m_orig_wiimote_sources[index] != g_wiimote_sources[index])
{
// Disconnect first, otherwise the new source doesn't seem to work
CFrame::ConnectWiimote(index, false);
// Connect wiimotes
if (WIIMOTE_SRC_EMU & g_wiimote_sources[index])
CFrame::ConnectWiimote(index, true);
else if (WIIMOTE_SRC_REAL & g_wiimote_sources[index] && WiimoteReal::g_wiimotes[index])
CFrame::ConnectWiimote(index, WiimoteReal::g_wiimotes[index]->IsConnected());
}
}
}
void WiimoteConfigDiag::RevertSource() void WiimoteConfigDiag::RevertSource()
{ {
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
@ -253,7 +211,6 @@ void WiimoteConfigDiag::Save(wxCommandEvent& event)
sec.Set("Source", (int)g_wiimote_sources[i]); sec.Set("Source", (int)g_wiimote_sources[i]);
} }
UpdateWiimoteStatus();
inifile.Save(ini_filename); inifile.Save(ini_filename);

View File

@ -26,15 +26,11 @@ public:
void RefreshRealWiimotes(wxCommandEvent& event); void RefreshRealWiimotes(wxCommandEvent& event);
void SelectSource(wxCommandEvent& event); void SelectSource(wxCommandEvent& event);
void UpdateWiimoteStatus();
void RevertSource(); void RevertSource();
void ConfigEmulatedWiimote(wxCommandEvent& event); void ConfigEmulatedWiimote(wxCommandEvent& event);
void Save(wxCommandEvent& event); void Save(wxCommandEvent& event);
void UpdateGUI();
void OnSensorBarPos(wxCommandEvent& event) void OnSensorBarPos(wxCommandEvent& event)
{ {
@ -73,8 +69,6 @@ private:
wxButton* wiimote_configure_bt[4]; wxButton* wiimote_configure_bt[4];
std::map<wxWindowID, unsigned int> m_wiimote_index_from_conf_bt_id; std::map<wxWindowID, unsigned int> m_wiimote_index_from_conf_bt_id;
wxStaticText* connected_wiimotes_txt;
}; };