summaryrefslogtreecommitdiffstats
path: root/matchblox/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'matchblox/main.cpp')
-rw-r--r--matchblox/main.cpp108
1 files changed, 78 insertions, 30 deletions
diff --git a/matchblox/main.cpp b/matchblox/main.cpp
index 6d89b6a..466c418 100644
--- a/matchblox/main.cpp
+++ b/matchblox/main.cpp
@@ -7,7 +7,8 @@
#endif
-#include <wiimote.h>
+//#include <wiimote.h>
+#include <wiiuse.h>
#include <GL/glew.h>
#include <GL/glut.h>
#include <iostream>
@@ -33,37 +34,62 @@ C_MatchBloxEngine *g_pEngine;
bool InitWiiMotes()
{
- g_GameState.m_pTrackingWiimote = new wiimote();
+ //connect to the wiimote(s)
+ g_GameState.m_ppWiimotes = wiiuse_init(1);
- g_GameState.m_pTrackingWiimote->ChangedCallback = NULL; //no callbacks, we just poll...
- g_GameState.m_pTrackingWiimote->CallbackTriggerFlags = NO_CHANGE;
+#ifdef WIN32
+ wiiuse_set_bluetooth_stack(g_GameState.m_ppWiimotes, 1, WIIUSE_STACK_MS);
+#endif //WIN32
- printf("connecting:\n");
- int retries = 10;
- while(!g_GameState.m_pTrackingWiimote->Connect(wiimote::FIRST_AVAILABLE) && retries > 10)
+ int found = wiiuse_find(g_GameState.m_ppWiimotes, 1, 30);
+ int connected = wiiuse_connect(g_GameState.m_ppWiimotes , 1);
+ if (connected)
{
- Sleep(100);
- printf(".");
- retries--;
+ printf("Connected to %i wiimotes (of %i found).\n", connected, found);
+
+ wiiuse_set_leds(g_GameState.m_ppWiimotes[0], WIIMOTE_LED_1 | WIIMOTE_LED_2 | WIIMOTE_LED_3 | WIIMOTE_LED_4);
+ wiiuse_rumble(g_GameState.m_ppWiimotes[0], 1);
+ //wiiuse_motion_sensing(g_GameState.m_ppWiimotes[0], 1);
+ wiiuse_set_ir(g_GameState.m_ppWiimotes[0], 1);
+ Sleep(200);
+ wiiuse_rumble(g_GameState.m_ppWiimotes[0], 0);
}
-
- if (g_GameState.m_pTrackingWiimote->IsConnected())
- {
- printf("connected\n");
-
- g_GameState.m_pTrackingWiimote->SetLEDs(0x0f);
-
- g_GameState.m_pTrackingWiimote->SetReportType(wiimote::IN_BUTTONS_ACCEL_IR_EXT); // IR dots
- g_GameState.m_pTrackingWiimote->SetRumble(true);
- Sleep(500);
- g_GameState.m_pTrackingWiimote->SetRumble(false);
-
- return true;
- }
- else
- {
- return false;
+ else
+ {
+ printf("Failed to connect to any wiimote.\n");
+ return 0;
}
+ // g_GameState.m_pTrackingWiimote = new wiimote();
+
+ // g_GameState.m_pTrackingWiimote->ChangedCallback = NULL; //no callbacks, we just poll...
+ //g_GameState.m_pTrackingWiimote->CallbackTriggerFlags = NO_CHANGE;
+
+ // printf("connecting:\n");
+ // int retries = 10;
+ // while(!g_GameState.m_pTrackingWiimote->Connect(wiimote::FIRST_AVAILABLE) && retries > 10)
+ // {
+ // Sleep(100);
+ // printf(".");
+ // retries--;
+ // }
+
+ //if (g_GameState.m_pTrackingWiimote->IsConnected())
+ //{
+ // printf("connected\n");
+
+ // g_GameState.m_pTrackingWiimote->SetLEDs(0x0f);
+ //
+ // g_GameState.m_pTrackingWiimote->SetReportType(wiimote::IN_BUTTONS_ACCEL_IR, true); // IR dots
+ // g_GameState.m_pTrackingWiimote->SetRumble(true);
+ // Sleep(500);
+ // g_GameState.m_pTrackingWiimote->SetRumble(false);
+
+ // return true;
+ //}
+ //else
+ //{
+ // return false;
+ //}
}
bool LoadGreyScaleShader()
@@ -142,10 +168,32 @@ void init_gl(void)
void idle_func(void)
{
- //call engine idle func
- MenuRun();
+ //g_GameState.m_pTrackingWiimote->RefreshState();
+
+ if (wiiuse_poll(g_GameState.m_ppWiimotes, 1))
+ {
+
+ ////put wiimote data in message queue
+ input_payload_wiimote payload;
+ payload.btns = g_GameState.m_ppWiimotes[0]->btns;
+ payload.ir = g_GameState.m_ppWiimotes[0]->ir;
+ ////copy buttons bitmask
+ //payload.Button.Bits = g_GameState.m_pTrackingWiimote->Button.Bits;
+ ////copy the 4 ir dots
+ //memcpy((void*)payload.Dot, g_GameState.m_pTrackingWiimote->IR.Dot, 4*sizeof(wiimote::ir::dot));
+
+ struct messageq_s message;
+ message.recipient = MESSAGE_MENU | MESSAGE_RENDERER;
+ message.sender = MESSAGE_INPUT_WIIMOTE;
+ message.payload = &payload;
+ message.payload_size = sizeof(input_payload_wiimote);
+ messageq_send(&message);
+ }
- g_GameState.m_pTrackingWiimote->RefreshState();
+ g_pEngine->ProcessMsgs();
+
+ //call engine idle func
+ //MenuRun();
glutPostRedisplay();
}