summaryrefslogtreecommitdiff
path: root/libs/surfaces/wiimote
diff options
context:
space:
mode:
authorTim Mayberry <mojofunk@gmail.com>2014-12-21 09:03:36 +0700
committerTim Mayberry <mojofunk@gmail.com>2014-12-21 12:53:00 +0700
commitdafcaec023d3c11a43e5c85d504f8919e7ee4cd9 (patch)
treef650ede9d52d16544dad22fd2d9f5f9ce8a9717b /libs/surfaces/wiimote
parent73d934bf43cc51b115a7e7f699655b52419c2fe2 (diff)
Limit Wiimote surface discovery to 5 connection attempts
If you don't connect a Wiimote then the connection attempts were endless.
Diffstat (limited to 'libs/surfaces/wiimote')
-rw-r--r--libs/surfaces/wiimote/wiimote.cc20
1 files changed, 9 insertions, 11 deletions
diff --git a/libs/surfaces/wiimote/wiimote.cc b/libs/surfaces/wiimote/wiimote.cc
index 124cf6c349..aa36cdf300 100644
--- a/libs/surfaces/wiimote/wiimote.cc
+++ b/libs/surfaces/wiimote/wiimote.cc
@@ -208,11 +208,10 @@ WiimoteControlProtocol::connect_idle ()
{
DEBUG_TRACE (DEBUG::WiimoteControl, "WiimoteControlProtocol::connect_idle init\n");
- bool retry = true;
+ bool retry = false;
if (connect_wiimote ()) {
stop_wiimote_discovery ();
- retry = false;
}
DEBUG_TRACE (DEBUG::WiimoteControl, "WiimoteControlProtocol::connect_idle done\n");
@@ -228,30 +227,29 @@ WiimoteControlProtocol::connect_wiimote ()
return true;
}
- bool success = true;
+ bool success = false;
// if we don't have a Wiimote yet, try to discover it; if that
// fails, wait for a short period of time and try again
- if (!wiimote) {
+ for (int i = 0; i < 5; ++i) {
cerr << "Wiimote: Not discovered yet, press 1+2 to connect" << endl;
bdaddr_t bdaddr = {{ 0, 0, 0, 0, 0, 0 }};
wiimote = cwiid_open (&bdaddr, 0);
callback_thread_registered = false;
- if (!wiimote) {
- success = false;
- } else {
+ if (wiimote) {
// a Wiimote was discovered
cerr << "Wiimote: Connected successfully" << endl;
// attach the WiimoteControlProtocol object to the Wiimote handle
if (cwiid_set_data (wiimote, this)) {
cerr << "Wiimote: Failed to attach control protocol" << endl;
- success = false;
+ } else {
+ success = true;
+ // clear the last button state to start processing events cleanly
+ button_state = 0;
+ break;
}
-
- // clear the last button state to start processing events cleanly
- button_state = 0;
}
}