X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=libs%2Fsurfaces%2Fwiimote%2Fwiimote.cc;h=aa36cdf30071f07aa03a544bcf09da946bfb7135;hb=548989fc75ba08912efe2bc48d24af5eb95c790d;hp=963bf90df7e686e2759ffbebb2cf4ac594c784d8;hpb=25a6296f865620d5013cd634e693f7179e7edc84;p=ardour.git diff --git a/libs/surfaces/wiimote/wiimote.cc b/libs/surfaces/wiimote/wiimote.cc index 963bf90df7..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; } } @@ -449,7 +447,7 @@ wiimote_control_protocol_mesg_callback (cwiid_wiimote_t *wiimote, int mesg_count { DEBUG_TRACE (DEBUG::WiimoteControl, "WiimoteControlProtocol::mesg_callback init\n"); - WiimoteControlProtocol *protocol = (WiimoteControlProtocol *)cwiid_get_data (wiimote); + WiimoteControlProtocol *protocol = reinterpret_cast (const_cast(cwiid_get_data (wiimote))); if (protocol) { protocol->wiimote_callback (mesg_count, mesg);