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()
{}
{
// TODO: what do we want here?
//PairUp(true);
}
// Find and connect wiimotes.
// 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
{
// TODO: impl
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;
}
}
// Connect to a wiimote with a known device path.
@ -377,26 +393,6 @@ int Wiimote::IOWrite(const u8* buf, int len)
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
// negative number on failure
int PairUp(bool unpair)

View File

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

View File

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

View File

@ -4,14 +4,6 @@
#include "HW/WiimoteReal/WiimoteReal.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)
: wxDialog(parent, -1, _("Dolphin Wiimote Configuration"), wxDefaultPosition, wxDefaultSize)
, m_plugin(plugin)
@ -65,27 +57,17 @@ WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputPlugin& plugin
// "Real wiimotes" controls
connected_wiimotes_txt = new wxStaticText(this, -1, ConnectedWiimotesString());
wxButton* const refresh_btn = new wxButton(this, -1, _("Refresh"), wxDefaultPosition);
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
wxStaticBoxSizer* const real_wiimotes_group = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Real Wiimotes"));
wxFlexGridSizer* const real_wiimotes_sizer = new wxFlexGridSizer(3, 5, 5);
real_wiimotes_sizer->Add(connected_wiimotes_txt, 0, wxALIGN_CENTER_VERTICAL);
#ifdef _WIN32
//real_wiimotes_sizer->Add(pairup_btn);
#endif
real_wiimotes_sizer->Add(refresh_btn);
real_wiimotes_group->Add(real_wiimotes_sizer, 1, wxALL, 5);
wxStaticBoxSizer* const real_wiimotes_group = new wxStaticBoxSizer(wxVERTICAL, this, _("Real Wiimotes"));
if (!WiimoteReal::g_wiimote_scanner.IsReady())
real_wiimotes_group->Add(new wxStaticText(this, -1, _("A supported bluetooth device could not be found.\n"
"You must manually pair your wiimotes.")), 0, wxALIGN_CENTER | wxALL, 5);
real_wiimotes_group->Add(refresh_btn, 0, wxALIGN_CENTER);
// "General Settings" controls
const wxString str[] = { _("Bottom"), _("Top") };
@ -189,15 +171,9 @@ void WiimoteConfigDiag::ConfigEmulatedWiimote(wxCommandEvent& ev)
m_emu_config_diag->Destroy();
}
void WiimoteConfigDiag::UpdateGUI()
{
connected_wiimotes_txt->SetLabel(ConnectedWiimotesString());
}
void WiimoteConfigDiag::RefreshRealWiimotes(wxCommandEvent&)
{
WiimoteReal::Refresh();
UpdateGUI();
}
void WiimoteConfigDiag::SelectSource(wxCommandEvent& event)
@ -214,24 +190,6 @@ void WiimoteConfigDiag::SelectSource(wxCommandEvent& event)
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()
{
for (int i = 0; i < 4; ++i)
@ -253,7 +211,6 @@ void WiimoteConfigDiag::Save(wxCommandEvent& event)
sec.Set("Source", (int)g_wiimote_sources[i]);
}
UpdateWiimoteStatus();
inifile.Save(ini_filename);

View File

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