summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSampo Savolainen <v2@iki.fi>2008-11-20 17:29:05 +0000
committerSampo Savolainen <v2@iki.fi>2008-11-20 17:29:05 +0000
commit9d444265ddd030d373b2a9d5b332fe2f2c91e194 (patch)
treed937b40e26aa9aabaabf3582048c769f2e56550e
parent5270db4086b73ee56af3d79abb22c4bec89588d8 (diff)
Fast enough, Paul?
Make the wiimote rediscover if disconnected. git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@4225 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r--libs/surfaces/wiimote/wiimote.cc43
-rw-r--r--libs/surfaces/wiimote/wiimote.h3
2 files changed, 40 insertions, 6 deletions
diff --git a/libs/surfaces/wiimote/wiimote.cc b/libs/surfaces/wiimote/wiimote.cc
index 6938c8e67f..af3bbc369d 100644
--- a/libs/surfaces/wiimote/wiimote.cc
+++ b/libs/surfaces/wiimote/wiimote.cc
@@ -19,7 +19,8 @@ uint16_t WiimoteControlProtocol::button_state = 0;
WiimoteControlProtocol::WiimoteControlProtocol ( Session & session)
: ControlProtocol ( session, "Wiimote"),
main_thread_quit (false),
- thread_registered_for_ardour (false),
+ restart_discovery (false),
+ callback_thread_registered_for_ardour (false),
wiimote_handle (0)
{
main_thread = Glib::Thread::create( sigc::mem_fun(*this, &WiimoteControlProtocol::wiimote_main), true);
@@ -50,20 +51,27 @@ WiimoteControlProtocol::wiimote_callback(cwiid_wiimote_t *wiimote, int mesg_coun
int i;
uint16_t b;
- if (!thread_registered_for_ardour) {
+ if (!callback_thread_registered_for_ardour) {
register_thread("Wiimote Control Protocol");
- thread_registered_for_ardour = true;
+ callback_thread_registered_for_ardour = true;
}
for (i=0; i < mesg_count; i++)
{
+ if (mesg[i].type == CWIID_MESG_ERROR) {
+ std::cerr << "Wiimote: disconnect" << std::endl;
+ restart_discovery = true;
+ slot_cond.signal();
+ return;
+ }
+
if (mesg[i].type != CWIID_MESG_BTN) continue;
// what buttons are pressed down which weren't pressed down last time
b = (mesg[i].btn_mesg.buttons ^ button_state) & mesg[i].btn_mesg.buttons;
button_state = mesg[i].btn_mesg.buttons;
-
+
// if B is pressed down
if (button_state & CWIID_BTN_B) {
if (b & CWIID_BTN_A) { // B is down and A is pressed
@@ -76,6 +84,12 @@ WiimoteControlProtocol::wiimote_callback(cwiid_wiimote_t *wiimote, int mesg_coun
if (b & CWIID_BTN_RIGHT) {
access_action("Editor/playhead-to-next-region-boundary");
}
+ if (b & CWIID_BTN_UP) {
+ next_marker();
+ }
+ if (b & CWIID_BTN_DOWN) {
+ prev_marker();
+ }
if (b & CWIID_BTN_HOME) {
access_action("Editor/add-location-from-playhead");
@@ -158,10 +172,13 @@ WiimoteControlProtocol::wiimote_main()
unsigned char rpt_mode = 0;
register_thread("Wiimote Discovery and Callback Thread");
+wiimote_discovery:
+
std::cerr << "Wiimote: discovering, press 1+2" << std::endl;
while (!wiimote_handle && !main_thread_quit) {
bdaddr = *BDADDR_ANY;
+ callback_thread_registered_for_ardour = false;
wiimote_handle = cwiid_open(&bdaddr, 0);
if (!wiimote_handle && !main_thread_quit) {
@@ -177,6 +194,8 @@ WiimoteControlProtocol::wiimote_main()
if (wiimote_handle) {
cwiid_close(wiimote_handle);
}
+ wiimote_handle = 0;
+
std::cerr << "Wiimote Control Protocol stopped before connected to a wiimote" << std::endl;
return;
}
@@ -187,16 +206,19 @@ WiimoteControlProtocol::wiimote_main()
if (cwiid_enable(wiimote_handle, CWIID_FLAG_REPEAT_BTN)) {
std::cerr << "cwiid_enable(), error" << std::endl;
cwiid_close(wiimote_handle);
+ wiimote_handle = 0;
return;
}
if (cwiid_set_mesg_callback(wiimote_handle, wiimote_control_protocol_cwiid_callback)) {
std::cerr << "cwiid_set_mesg_callback(), couldn't connect callback" << std::endl;
cwiid_close(wiimote_handle);
+ wiimote_handle = 0;
return;
}
if (cwiid_command(wiimote_handle, CWIID_CMD_RPT_MODE, CWIID_RPT_BTN)) {
std::cerr << "cwiid_command(), RPT_MODE error" << std::endl;
cwiid_close(wiimote_handle);
+ wiimote_handle = 0;
return;
}
@@ -211,7 +233,7 @@ WiimoteControlProtocol::wiimote_main()
while (!main_thread_quit) {
slot_mutex.lock();
- while (slot_list.empty() && !main_thread_quit)
+ while (slot_list.empty() && !main_thread_quit && !restart_discovery)
slot_cond.wait(slot_mutex);
if (main_thread_quit) {
@@ -219,6 +241,17 @@ WiimoteControlProtocol::wiimote_main()
break;
}
+ if (restart_discovery) {
+ std::cerr << "Wiimote: closing wiimote and restarting discovery" << std::endl;
+ if (wiimote_handle) {
+ cwiid_close(wiimote_handle);
+ wiimote_handle = 0;
+ }
+ slot_mutex.unlock();
+ restart_discovery = false;
+ goto wiimote_discovery;
+ }
+
sigc::slot<void> call_me = *slot_list.begin();
slot_list.pop_front();
slot_mutex.unlock();
diff --git a/libs/surfaces/wiimote/wiimote.h b/libs/surfaces/wiimote/wiimote.h
index a5b1ea4976..a6680edd2e 100644
--- a/libs/surfaces/wiimote/wiimote.h
+++ b/libs/surfaces/wiimote/wiimote.h
@@ -43,12 +43,13 @@ class WiimoteControlProtocol : public ARDOUR::ControlProtocol {
void wiimote_main();
volatile bool main_thread_quit;
+ volatile bool restart_discovery;
Glib::Thread *main_thread;
void update_led_state();
- bool thread_registered_for_ardour;
+ bool callback_thread_registered_for_ardour;
static uint16_t button_state;